Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nirc2_reduce/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def __init__(self, fname):
self.hdulist = fits.open(fname, ignore_missing_end=True)
self.header = self.hdulist[0].header
self.data = self.hdulist[0].data
try:
self.date = self.header["DATE-OBS"]
except KeyError:
self.date = None
try:
targ = self.header["OBJECT"]
self.target = targ.split()[0].strip(", \n").capitalize()
Expand Down
30 changes: 21 additions & 9 deletions nirc2_reduce/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
from matplotlib import cm
from astropy.io import fits
from .image import Image
from .prettycolors import make_colormap, get_colormap
from .prettycolors import get_colormap
from scipy.signal import medfilt
from scipy.interpolate import RectBivariateSpline
from scipy.ndimage import rotate, center_of_mass
import astroscrappy
from image_registration.chi2_shifts import chi2_shift
from image_registration.fft_tools.shift import shiftnd, shift2d
from image_registration.fft_tools.shift import shift2d
import importlib.resources
import warnings
import yaml
import nirc2_reduce.data.header_kw_dicts as inst_info
from datetime import datetime


'''
Expand Down Expand Up @@ -69,17 +70,28 @@ def __init__(self, fnames, instrument):
subc : int. size of the subarray
target : str. the object you observed, scrubbed from the header.
"""
if isinstance(fnames, str):
fnames = [fnames,]
self.dummy_fits = Image(fnames[0]) # used to hijack header info
date = self.dummy_fits.date
self.instrument = instrument.lower()
with importlib.resources.open_binary(inst_info, f"{self.instrument}.yaml") as file:
if instrument == "nirc2" and date is None:
raise ValueError(
"Instrument is nirc2, but DATE-OBS could not be read from header."
"Either choose instrument nirc2_pre_oct23 or nirc2_post_oct23, "
"or ensure the date can be read from the header."
)
if instrument == "nirc2":
date = datetime.strptime(date, "%Y-%m-%d")
controller_update_date = datetime.strptime("2023-10-15", "%Y-%m-%d")
if date >= controller_update_date:
instrument = "nirc2_post_oct23"
else:
instrument = "nirc2_pre_oct23"
with importlib.resources.open_binary(inst_info, f"{instrument}.yaml") as file:
yaml_bytes = file.read()
self.header_kw_dict = yaml.safe_load(yaml_bytes)

if type(fnames) == str:
fnames = [
fnames,
] # needed to make pass through all the for loops

self.dummy_fits = Image(fnames[0]) # used to hijack header info
self.frames = np.asarray([Image(f).data for f in fnames])
self.subc = int(self.dummy_fits.header[self.header_kw_dict['subc']])
self.target = self.dummy_fits.header[self.header_kw_dict['object']]
Expand Down
4 changes: 2 additions & 2 deletions nirc2_reduce/tests/test_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_bxy3(datadir, rawdir):
os.path.join(rawdir, "bxy3_2.fits"),
os.path.join(rawdir, "bxy3_3.fits"),
]
obs = observation.Bxy3(fnames, "nirc2_pre_oct23")
obs = observation.Bxy3(fnames, "nirc2")
obs.make_sky(os.path.join(datadir, "sky_test.fits"))
obs.apply_sky(os.path.join(datadir, "sky_expected.fits"))
obs.apply_flat(os.path.join(datadir, "flat_expected.fits"))
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_nod(datadir, rawdir):
def test_raises(datadir, rawdir):

obs = observation.Nod(
os.path.join(rawdir, "bxy3_2.fits"), os.path.join(datadir, "sky_expected.fits"), "nirc2_pre_oct23"
os.path.join(rawdir, "bxy3_2.fits"), os.path.join(datadir, "sky_expected.fits"), "nirc2"
)
obs.frames = np.empty(obs.frames.shape)
obs.frames[:] = np.nan
Expand Down