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

Resampling breaks if limits of new_wavs are too close to spec_wavs #8

Open
timothygebhard opened this issue Sep 4, 2023 · 0 comments

Comments

@timothygebhard
Copy link

Note: This might be the same problem pointed out by @cylammarco here: #1 (comment), but unfortunately that issue is closed, and the issue is still present 4 years later.


The following minimal example:

old_flux = np.zeros(100)
old_wlen = np.linspace(1, 2, 101)
new_wlen = np.linspace(1, 2, 51)
new_flux = spectres(
    new_wavs=new_wlen, 
    spec_wavs=old_wlen, 
    spec_fluxes=old_flux, 
)

gives me a warning:

Spectres: new_wavs contains values outside the range in spec_wavs, new_fluxes and new_errs will be filled with the value set in the 'fill' keyword argument.

This seems very counterintuitive because in this case, the new wavelengths are obviously just a subset of the old wavelengths.

It goes on, however. This minimal example also gives me the above warning:

old_flux = np.zeros(100)
old_wlen = np.linspace(1, 2, 100)
new_wlen = np.linspace(1.01, 1.99, 33)
new_flux = spectres(
    new_wavs=new_wlen, 
    spec_wavs=old_wlen, 
    spec_fluxes=old_flux, 
)

If I set new_wlen = np.linspace(1.01, 1.99, 34), though, the warning disappears.


On a bit of a sidenote, I have also (accidentally) noticed that the spectres() method does not necessarily seem to expect spec_wavs and spec_fluxes to have the same length. For example, the following code runs without complaints:

old_flux = np.zeros(100)
old_wlen = np.linspace(1, 2, 165)
new_wlen = np.linspace(1.4, 1.6, 20)
new_flux = spectres(
    new_wavs=new_wlen, 
    spec_wavs=old_wlen, 
    spec_fluxes=old_flux, 
)

How should one interpret this — 165 wavelengths, but only 100 flux values? Especially considering that increasing the number of wavelengths from 165 to 166 actually breaks the code with a ValueError: operands could not be broadcast together with shapes (3,) (2,).


Thank you in advance already — any help on this is very much appreciated! 🙂

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

No branches or pull requests

1 participant