tomasstolker / species

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

wavelength / spectral spacing for exo-rem-highres grid #94

Closed wbalmer closed 6 months ago

wbalmer commented 6 months ago

Hi Tomas,

I'm really interested in using the exo-rem highres grid for our AF Lep b analysis, but FitModel stalls at interpolating the grid on our SPHERE IFS spectrum because the wavelength of that spectrum is not uniform.

I get this warning, but have to manually kill the process.

Interpolating SPHERE...

/Users/wbalmer/species/species/util/spec_util.py:122: UserWarning: The wavelength spacing is not uniform (3.152470770057788e-05 +/- 6.685785633535913e-06). The smoothing with the Gaussian kernel requires either the spectral resolution or the wavelength spacing to be uniformly sampled. warnings.warn(`

How would you recommend I proceed? Is there a way to resample the exo-rem-highres to a uniform spectral resolution? I tried

database.add_model(model=model_choice, teff_range=(700., 1300.), wavel_sampling=2000.)

but to no avail.

wbalmer commented 6 months ago

I was able to fix this by ingesting the model like

database.add_model(model=model_choice, teff_range=(700., 1300.), wavel_sampling=2000., wavel_range=(0.9,5))

tomasstolker commented 6 months ago

Thanks for noticing that! Reopening this issue because the warning should not have occurred because all grid have been resampled to a constant lambda/Delta_lambda.

tomasstolker commented 6 months ago

Hm I am not sure what caused the warning to show up. I am not able reproduce it.

It is indeed anyway a good idea to use wavel_sampling and wavel_range (if the data allows) with a high-resolution grid, to limit the disk storage and speed up the interpolation at the start of FitModel.

wbalmer commented 6 months ago

I think it could be for two reasons, either because my SPHERE spectrum has some nans (e.g. some upper limit values) or because it is extracted on an uneven wavelength grid that is more true to the instrument's wavelength calibration (the extraction comes from our SPHERE-DC friends). Probably the latter? I can send you the file if you'd like to use it to bug test.

tomasstolker commented 6 months ago

Any NaN fluxes are removed from the spectra when using add_object I think, so that should hopefully not cause a problem. In case you want to treat these wavelengths as upper limits in the fit, then you could also set the fluxes to zero and the uncertainty to the upper limit.

For the smoothing, the wavelength sampling of the data will not matter, only of the model spectra. The model spectra are first smoothed to the instrument resolution and then resampled to the data wavelengths. The latter is just a linear interpolation.

Perhaps you could try redownloading the grid in case you downloaded it a while ago and I may have fixed an issue that I forgot about. But the grid is very large so might not be worth it if it is running fine now.

gabrielastro commented 6 months ago

Hello Tomas and William! I get the same as William and thought it was due to the spacing of my data. (By the way, I ignored the warnings, especially since the deviation is small, and it seems ok.)

For what it is worth, I downloaded exo-rem-highres.tgz a few days ago and it has (~20 s to compute, instead of re-downloading the file):

~$ md5sum exo-rem-highres.tgz 
0149900c72bf44fb3342b0892e94d38d  exo-rem-highres.tgz

@wbalmer, maybe you can compare against this and/or the timestamp on Tomas' website (https://home.strw.leidenuniv.nl/~stolker/species/):

[ ] exo-rem-highres.tgz     2023-07-23 15:14    16G  
tomasstolker commented 6 months ago

After some testing, I found that the issue was with the grid. I had used a smaller number of decimals to store the data compared to other grids.

The wavelength precision had therefore changed between the resampling of the grid (on my end) and storing the data in the text files that are used by species.

I have created and new grid for 'exo-rem' and 'exo-rem-highres'. It is uploading but will take another hour since it is 22 GB...

gabrielastro commented 6 months ago

Ah! right, I should have noticed (current version):

# Wavelength (um) - Flux (W m-2 um-1)
6.700000e-01 5.828044e+02
6.700166e-01 5.827946e+02
6.700332e-01 5.825590e+02
6.700498e-01 5.821541e+02

Two more decimal places for lambda should do it. The flux however has enough precision (1e-7 in relative terms).

A bigger issue is the non-monotonicity over Teff=1100–1200 K [spectral features change smoothly up to and down to those temperatures but not smoothly across that range], however, which is either physical and not caught by the Teff spacing, or numerical (which would be due to non-converged structures and/or spectra).

wbalmer commented 6 months ago

Ah, good to note! Thanks for updating this Tomas.