tomasstolker / species

Toolkit for atmospheric characterization of directly imaged exoplanets
https://species.readthedocs.io
MIT License
22 stars 10 forks source link

Using wavel_range with database.add_model() #93

Closed gabrielastro closed 7 months ago

gabrielastro commented 7 months ago

Is there a change in the use of wavel_range when adding spectra to the database? I checked out the latest version of species and get:

In [6]: database.add_model(model='exo-rem-highres', teff_range=(1000, 1900), wavel_range=(1,5), unpack_tar=False)
…
Wavelength range (um) = 0.67 - 250.0
Sampling (lambda/d_lambda) = 20000
Teff range (K) = 1000 - 1900

Adding Exo-REM model spectra... exo-rem-highres_teff_1000_logg_3.0_feh_-0.5_co_0.10_spec.dat---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-ceb61b05de29> in <module>
----> 1 database.add_model(model='exo-rem-highres', teff_range=(1000, 1900), wavel_range=(1,5), unpack_tar=False)

[…]/species/data/database.py in add_model(self, model, wavel_range, wavel_sampling, teff_range, unpack_tar)
    716 
    717         with h5py.File(self.database, "a") as hdf5_file:
--> 718             add_model_grid(
    719                 model_tag=model,
    720                 input_path=self.data_folder,

[…]/species/data/model_data/model_spectra.py in add_model_grid(model_tag, input_path, database, wavel_range, teff_range, wavel_sampling, unpack_tar)
    336 
    337                 else:
--> 338                     flux_resample = spectres.spectres(
    339                         wavelength,
    340                         data_wavel,

~/.local/lib/python3.10/site-packages/spectres/spectral_resampling.py in spectres(new_wavs, spec_wavs, spec_fluxes, spec_errs, fill, verbose)
     75 
     76     old_edges, old_widths = make_bins(old_wavs)
---> 77     new_edges, new_widths = make_bins(new_wavs)
     78 
     79     # Generate output arrays to be populated

~/.local/lib/python3.10/site-packages/spectres/spectral_resampling.py in make_bins(wavs)
      7     """ Given a series of wavelength points, find the edges and widths
      8     of corresponding wavelength bins. """
----> 9     edges = np.zeros(wavs.shape[0]+1)
     10     widths = np.zeros(wavs.shape[0])
     11     edges[0] = wavs[0] - (wavs[1] - wavs[0])/2

AttributeError: 'NoneType' object has no attribute 'shape'

Removing wavel_range=(1,5) "works" but then the computer nearly froze while it was doing Adding Exo-REM model spectra... exo-rem-highres_teff_… I had to suspend ipython3 and do kill %%.

Thank you! Sorry if I am missing something simple.

gabrielastro commented 7 months ago

The issue seems to be with wavelength not being set (before being passed to spectres.spectres(…) at model_spectra.py:338) in the case that wavel_range is not None but wavel_sampling is None, currently not explicitly covered at model_spectra.py:255 :detective: :wink:.

tomasstolker commented 7 months ago

Thanks for noticing this issue! Indeed, currently wavel_range can only be used in combination with wavel_sampling. Having the option to only use wavel_range would be useful though.

tomasstolker commented 7 months ago

This has been addressed in commit d768d2f. Setting wavel_range while not setting wavel_sampling should work both with add_model and add_custom_model!

gabrielastro commented 7 months ago

Thank you! It works. Very minor suggestion: Could species print to the screen the wavelength range that will be added? I am using a script and watching the output got afraid I had somehow forgotten to change back the range and thought it would add the full spectrum again (i.e. lead to a freeze)…

gabrielastro commented 7 months ago

Thanks!