Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

galactic noise adder upgrades #740

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

karenterveer
Copy link
Collaborator

@karenterveer karenterveer commented Nov 6, 2024

more sky models, speed up module.

It should run exactly like before, just with the added option of being able to choose from more sky models during the begin() call. For some sky models, additional modules are necessary, but if they are not installed the module will default to the standard galaxy model.
The generation of sky powers was moved to begin() as otherwise the generation happens in every single run, slowing down the model considerably.

more sky models, speed up module
Copy link
Collaborator

@sjoerd-bouma sjoerd-bouma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Karen! It would be great to finally have Moritz' changes from #591 implemented (even though his commit credit seems to have disappeared into the ether :/). Unfortunately my questions from #591 haven't gone away yet ;)

Comment on lines 15 to 21
except:
logger.warning("radiocalibrationtoolkit import failed. Consider installing it to use more sky models.")

try:
from pylfmap import LFmap # Documentation: https://github.com/F-Tomas/pylfmap needs cfitsio installation
except:
logger.warning("LFmap import failed. Consider installing it to use LFmap as sky model.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace these with except ImportError

Comment on lines 99 to 103
self.__interpolation_frequencies = np.around(
np.logspace(
*np.log10(freq_range / units.MHz), num=30
), 0
) * units.MHz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing (by comparison to the number of interpolation frequencies previously) 30 points is usually plenty - we can always add this as an additional optional argument if that seems useful.

Also, nitpicky - dividing and then multiplying by units.MHz is probably superfluous.

Comment on lines +187 to +194
last_freqs = None
for channel in station.iter_channels():
if (not last_freqs is None) and (
not np.allclose(last_freqs, channel.get_frequencies(), rtol=0, atol=0.1 * units.MHz)):
logger.error("The frequencies of each channel must be the same, but they are not!")
return

last_freqs = channel.get_frequencies()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of 'implicit' in NuRadioMC that all channels in a station have the same sampling rate. Is there a specific use case you are aware of that would trigger this?

Anyway, it's always good to have additional checks, so I don't think this needs to be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these were also changes that Moritz implemented - I am also not sure in which case they would be needed, but he clearly deemed this important. I also think we can keep it since it does not seem to cause any problems

Comment on lines 60 to 89
interpolation_frequencies: array of float
freq_range: array of len=2, default: [30, 80] * units.MHZ
The sky brightness temperature will be evaluated for the frequencies
in this list. Brightness temperature for frequencies in between are
within this limit. Brightness temperature for frequencies in between are
calculated by interpolation the log10 of the temperature
The interpolation_frequencies have to cover the entire passband
specified in the run method.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing signatures of existing functions without a deprecation warning is not ideal. Maybe we should keep interpolation_frequencies and add the new freq_range (or maybe min_freq and max_freq?) as additional optional arguments, but raise a DeprecationWarning every time someone uses interpolation_frequencies. We can then fully deprecate in a future release.

(This is another 'coding practice' thing that we have mostly ignored in the past, and I don't think it's particularly dangerous in this case, but maybe it's something we should start doing)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...alternatively, we can keep the argument interpolation_frequencies. Your call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, I kept both and print a warning when interpolation_frequencies is used.
I much prefer freq_range since it does not require the user to set up the frequencies themselves, especially since log interpolation seems like a more ideal choice for Galactic Noise.

Comment on lines 94 to 95
if freq_range is None:
freq_range = np.array([30, 80]) * units.MHz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relatedly - changing from a default of [10,1100] to [30,80] MHz is quite a big change, and e.g. for RNO-G the new default is definitely not what we want. I would prefer to keep the old default and just raise an error (or a warning) if the chosen model is not compatible with the frequency range.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(oops, I changed the default for LOFAR related reasons but meant to change it back for the commit)

Comment on lines +286 to +295
delta_phases = (
2 * np.pi * freqs[passband_filter] / (scipy.constants.c * units.m / units.s) * n_air *
(
sin_zenith *
(np.cos(azimuth) * channel_pos_x + channel_pos_y * np.sin(azimuth)) +
channel_depth *
((n_ice / n_air) ** 2 + sin_zenith ** 2) /
np.sqrt((n_ice / n_air) ** 2 - sin_zenith ** 2)
)
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is Moritz' change to account for the same signal in different antennas. This is definitely an upgrade we want to have, but as mentioned in #591 I don't think this is correct for deep in-ice antennas (I am okay with not fixing that for now, although maybe issuing a warning for channel depths over 10 m would be good?), and it also doesn't look right to me for above-surface antennas right now (that probably should be fixed and should be relatively straightforward).

Comment on lines +297 to +298
# add random polarizations and phase to electric field
polarizations = np.random.uniform(0, 2. * np.pi, len(S))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...also an open question whether random polarizations are right (technically, this implies that the signal from each signal is fully linearly polarized in a random direction for each antenna. I don't think this is right, we should think about how to do this correctly, even if the impact in the end is probably small).

@karenterveer
Copy link
Collaborator Author

Have implemented the changes, except the points raised in #591 - But I agree that this should be addressed or (for now) removed before merge.
As for the random polarizations it might be good to check how big the impact really is, but as this is not a new change in the GalacticNoiseAdder I think it can be kept for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants