pypeit / PypeIt

The Python Spectroscopic Data Reduction Pipeline
BSD 3-Clause "New" or "Revised" License
163 stars 104 forks source link

sky flat frames #818

Open rcooke-ast opened 4 years ago

rcooke-ast commented 4 years ago

It's a slight pain to have to go and manually define sky flats. I've written a small snippet of code that uses header info about the observation, finds the altitude of the sun, and labels "science" frames that are not standard star frames as twilight flats... Any buyers?

from astropy.coordinates import EarthLocation, AltAz, get_sun
from astropy.time import Time
import astropy.units as u
import numpy as np

# Setup some dummy values for example
mjd = 58837.793121
lat, lon, height = 19.82833*u.deg, 155.47833*u.deg, 4160.0*u.m

# lat = self.spectrograph.telescope['latitude']*u.deg
# lon = self.spectrograph.telescope['longitude']*u.deg
# height = self.spectrograph.telescope['elevation']*u.m
obsloc = EarthLocation(lat=lat, lon=lon, height=height)
obstime = Time(mjd, format='mjd')
altazframe = AltAz(obstime=obstime, location=obsloc)
sunaltazs = get_sun(obstime).transform_to(altazframe)
if sunaltazs.alt.value > -15.0:
    print("If this is not a standard, it's probably a sky flat!")
jhennawi commented 4 years ago

Yes, we had some code like this in LowRedux as well. You can probably cut on the exposure time to figure out whether it is a sky flat or standard exposure.