cschreib / slinefit

Measure redshifts and emission/absorption lines in 1D galaxy spectra.
MIT License
10 stars 1 forks source link

LSF extension reading issue #6

Closed themiyan closed 1 year ago

themiyan commented 1 year ago

Hi Corentin,

Thanks for the LSF 🍻🍻🍻🍻

Trying to get it run but running into a problem as follows:

themiya@plexus:/data/themiya/go_2565_slinefit$ /data/themiya/softwares/slinefit/bin/slinefit onedspec_obs200_12629_for_slinefit.fits z0=3.20 dz=0.25 delta_z=0.01 num_mc=200 threads=32 width_min=5000 width_max=50000 delta_width=1 same_width use_global_chi2 full_range verbose lines=[em_halpha] fit_continuum_template template_dir=/data/themiya/softwares/slinefit/bin/templates/ residual_rescale_global save_rescaling residual_rescale save_model lsf_hdu=lsf
warning: could not convert 'lsf_hdu' argument to type ulong
note: running slinefit v2.2
note: read input spectrum...
terminate called after throwing an instance of 'vif::fits::exception'
  what():  FITS file has wrong number of dimensions (expected 1, got 0)
Aborted (core dumped)

This could be just the string not being converted correctly, I've tried caps etc.

It does work if I give an integer but cannot give the correct number. For example when using tabular input LSF should be the 6th integer (counting from 1).

themiya@plexus:/data/themiya/go_2565_slinefit$ /data/themiya/softwares/slinefit/bin/slinefit onedspec_obs200_12629_for_slinefit.fits z0=3.20 dz=0.25 delta_z=0.01 num_mc=200 threads=32 width_min=5000 width_max=50000 delta_width=1 same_width use_global_chi2 full_range verbose lines=[em_halpha] fit_continuum_template template_dir=/data/themiya/softwares/slinefit/bin/templates/ residual_rescale_global save_rescaling residual_rescale save_model lsf_hdu=6
note: running slinefit v2.2
note: read input spectrum...

error: /data/themiya/softwares/slinefit/external/include/vif/io/fits/base.hpp:593: requested HDU does not exists in this FITS file (6 vs. 6)

It works when lsf_hdu=5 is given but fit fails because it is the wrong extension.

The input can be found here: https://www.dropbox.com/scl/fi/p3iqxeaemjvb1lsimhj1n/onedspec_obs200_12629_for_slinefit.fits?rlkey=5mynpgwdddlbwl04yc5fiesqe&dl=0

cschreib commented 1 year ago

Hi Themiya! Sorry, I guess this should be better documented. Indeed you can't use a string here, it must be an integer. The HDU index is 0-based, not 1-based, so the primary HDU has index 0, the first extension has index 1, etc. So lsf_hdu=5 should be what you want.

The data in the HDU should be a 1D image, just like the flux and error spectra, and not a table. The 1D image must have the same wavelength sampling as the flux spectrum (CDELT, etc.).

I'll try to take a look at the data when I get a chance.

cschreib commented 1 year ago

Ok, I just had a look at your input, at first glance it looks good. I'll try to run it through.

cschreib commented 1 year ago

Well that didn't take long; slinefit assumes the LSF is in microns, but yours seems to be in Angstroms. You should convert the LSF to microns. In the meantime, I'll change the code to read the BUNIT keyword rather than blindly assume microns, so in the next commit you'll have to set BUNIT in the LSF HDU (either to micron or angstrom).

cschreib commented 1 year ago

After adding BUNIT = angstrom to the header, and the latest commit 97baeb7d4bf0dbe0772a6db81180ebcce1dd09ef, it seems to be alright (white: observed, yellow: best fit model without LSF, red: best with model with LSF) image

The command I used:

slinefit onedspec_obs200_12629_for_slinefit.fits fit_continuum_template template_dir="../bin/templates" full_range use_global_chi2 residual_rescale z0=3.2 dz=0.5 delta_z=0.1 flux_hdu=1 error_hdu=2 lsf_hdu=5 verbose save_model

Output without LSF:

note: rescaling uncertainties from global residual (10.3732)
best redshift: 3.20523 + 0.00212125 - 0.000719856 (chi2: 354.76, reduced: 1.20258, odds: 0.996995)

Output with LSF:

note: rescaling uncertainties from global residual (10.3056)
best redshift: 3.20662 + 0.00486101 - 0.00455042 (chi2: 321.487, reduced: 1.08979, odds: 0.955948)
themiyan commented 1 year ago

Great I get the same results as you when I add the BUNIT = angstrom keyword.

Also I was just being stupid, I interpolated the sigma grid to be microns but forgot sigma is not dimensionless unlike R, so didn't do that conversion.

I think for the PRISM mode in NIRSpec LSF will be important, specially for breaks around 1-2 microns. The chi2 is quite better after errors are scaled too. Screenshot 2023-10-09 at 11 02 26

Thanks Corentin!

themiyan commented 1 year ago

We did some sims. Clear improvement with the LSF!

Screenshot 2023-10-11 at 19 43 01