OttoStruve / muler

A Python package for working with pipeline-produced spectra from IGRINS, HPF, and Keck NIRSPEC
https://muler.readthedocs.io
MIT License
15 stars 9 forks source link

configuring .read() functions for IGRINS retell files #118

Closed ericasaw closed 1 year ago

ericasaw commented 2 years ago

Hi Gully, I've been working on refining the IGRINS plp reductions using a legacy script. In that script, the SNR 's are written to an additional HDU extension named "SNR". I was wondering if there was a way to change the statement on line 199 of igrins.py to be another try/except statement that checks the .spec_a0v.fits file for a "SNR" extension before raising an error. Like

try: 
 sn_hdus = fits.open(sn_file, memmap=False)
 cached_hdus = [hdus, sn_hdus]
except FileNotFoundError:
  try:
    #just to test if the SNR extension exists
    sn_hdus = hdus['SNR'] 
    cached_hdus = [hdus[:-1], sn_hdus] #SNR is always the last extension in the new files
  except KeyError:
    #raise error about no .sn file or SNR extension

or something of the sort. Let me know what you think!

gully commented 2 years ago

Thank you @ericasaw for opening an Issue! 🙏

@kfkaplan and I started an overhaul to the IGRINS uncertainty in Issue #89. Do you know to-what-extent that proposed fix could address your Issue?

It sounds like you are working with a custom script, so my suspicion is that the Pull Request does not achieve your goals. Would you be open to making a pull request to address your use case?

We should consider finishing and merging #89 at some point because it makes the SNR more accurate and supports wider use cases.

kfkaplan commented 2 years ago

The IGRINS PLP should output .spec.fits and .variance.fits files for the flux and variance. I highly recommend you use those files to read into muler. If you are using an older version of the IGRINS PLP, I recommend you update to the latest version and re-reduce your data.

ericasaw commented 2 years ago

@kfkaplan The reduction is in addition to using the IGRINS PLP, a step afterward, the output is different than the IGRINS PLP output. The script I am using checks the pixel alignment between the standard star and the target using a strong telluric feature and shifts so the pixels are aligned. Usually, the offset is small and negligible, but sometimes it can provide some good SNR improvements for reduced data.

kfkaplan commented 2 years ago

Ah I see. In that case, I would go with @gully's suggestion that you make the changes you need to Muler and submit them as a pull request. Alternatively, your custom script could output modified files in the same format as the IGRINS PLP that Muler could then read in.

kfkaplan commented 2 years ago

Also I almost forgot, this sounds very similar to my IGRINS A0V corrector code which shifts pixels to correct for flexure (https://github.com/kfkaplan/IGRINS_A0V_corrector).

Feel free to use it as an example or copy code from for outputting modified files in the IGRINS PLP format.