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

Flux unit conversion behavior with arrays of different sizes and scalars #3182

Open
pllim opened this issue Sep 5, 2024 · 0 comments
Open

Comments

@pllim
Copy link
Contributor

pllim commented Sep 5, 2024

This was #2891 by @astrofrog that got accidentally deleted.

This is a spin-off from a discussion in #2889 (comment)

The unit conversion class UnitConverterWithSpectral can deal with spectral density conversions, e.g. Fnu to Flam and so on. However, these conversions require knowledge about the wavelength/frequency at which to do the conversion. The unit conversion class knows about the spectral axis of the data that is being converted, so when we convert an array of values where the length of the array is the same as that of the spectral axis, everything is fine. However, there are cases where we might end up converting an array with a different size - for example sometimes to_unit is called with two values, when converting the min/max limits of the axes. In this case, it's not 100% clear what should happen, but there are a couple of options:

  • Convert using the first wavelength/frequency in the spectral axis array
  • Convert twice - using both the first and last value in the spectral axis array and then determining the smallest and largest result, which will ensure that the limits cover the whole span of resulting values.

I think the second option is probably preferable? I am going to pre-emptively update #2889 to match this, but happy to change it back to the first option if people prefer.

To identify, when to_unit is being called for limits, we have to rely on checking that the length of the values passed is 2. Obviously there is a corner case where this will cause an issue which is if someone loads in a real spectrum with only two wavelengths/frequencies, but I think we can probably agree that's going to be very rare?

Then the question is how we deal with scalars or arrays that don't have the same shape as the spectral axis. These should probably just raise an exception since they aren't valid, but currently exceptions seem to just get swallowed up and aren't apparent to the user. Are we ok with that? In principle I don't think arrays with the wrong length should ever happen (besides length 2 as mentioned above) but it would be good to properly raise an error if they do.

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

No branches or pull requests

1 participant