Skip to content

Commit

Permalink
Merge pull request #182 from kammerje/cr_from_saif_toggle
Browse files Browse the repository at this point in the history
Determine crpix from saif toggle
  • Loading branch information
AarynnCarter authored Jun 18, 2024
2 parents f7ffaba + 6031d42 commit bcd9a96
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions spaceKLIP/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def read_jwst_s012_data(self,
datapaths,
psflibpaths=None,
bgpaths=None,
cr_from_siaf=False,
assoc_using_targname=True):
"""
Read JWST stage 0 (*uncal), 1 (*rate or *rateints), or 2 (*cal or
Expand Down Expand Up @@ -274,8 +275,12 @@ def read_jwst_s012_data(self,
BLURFWHM += [head.get('BLURFWHM', np.nan)]
head = hdul['SCI'].header
BUNIT += [head.get('BUNIT', 'NONE')]
CRPIX1 += [head.get('CRPIX1', np.nan)]
CRPIX2 += [head.get('CRPIX2', np.nan)]
if cr_from_siaf:
CRPIX1 += [ap.XSciRef]
CRPIX2 += [ap.YSciRef]
else:
CRPIX1 += [head.get('CRPIX1', np.nan)]
CRPIX2 += [head.get('CRPIX2', np.nan)]
VPARITY += [head.get('VPARITY', -1)]
V3I_YANG += [head.get('V3I_YANG', 0.)]
RA_REF += [head.get('RA_REF', np.nan)]
Expand Down Expand Up @@ -571,7 +576,8 @@ def read_jwst_s012_data(self,
pass

def read_jwst_s3_data(self,
datapaths):
datapaths,
cr_from_siaf=False):
"""
Read JWST stage 3 data (this can be *i2d data from the official JWST
pipeline, or data products from the pyKLIP and classical PSF
Expand Down Expand Up @@ -718,8 +724,12 @@ def read_jwst_s3_data(self,
if TYPE[-1] == 'CORON3':
head = hdul['SCI'].header
BUNIT += [head.get('BUNIT', 'NONE')]
CRPIX1 += [head.get('CRPIX1', np.nan)]
CRPIX2 += [head.get('CRPIX2', np.nan)]
if cr_from_siaf:
CRPIX1 += [ap.XSciRef]
CRPIX2 += [ap.YSciRef]
else:
CRPIX1 += [head.get('CRPIX1', np.nan)]
CRPIX2 += [head.get('CRPIX2', np.nan)]
HASH += [TELESCOP[-1] + '_' + INSTRUME[-1] + '_' + DETECTOR[-1] + '_' + FILTER[-1] + '_' + PUPIL[-1] + '_' + CORONMSK[-1] + '_' + SUBARRAY[-1]]
hdul.close()
TYPE = np.array(TYPE)
Expand Down Expand Up @@ -1277,6 +1287,7 @@ def create_database(output_dir,
assoc_using_targname=True,
verbose=True,
readlevel='012',
cr_from_siaf=False,
**kwargs):

""" Create a spaceKLIP database from JWST data
Expand Down Expand Up @@ -1360,11 +1371,13 @@ def create_database(output_dir,
db.read_jwst_s012_data(datapaths=datapaths,
psflibpaths=psflibpaths,
bgpaths=bgpaths,
cr_from_siaf=cr_from_siaf,
assoc_using_targname=assoc_using_targname)
elif str(readlevel) == '3':
# the above get_files usage won't match KLIP outputsa, so find them here
datapaths_klip = sorted(glob.glob(os.path.join(input_dir, "*KLmodes-all.fits")))
db.read_jwst_s3_data(datapaths=datapaths+datapaths_klip,
cr_from_siaf=cr_from_siaf,
)
elif str(readlevel) == '4':
db.read_jwst_s4_data(datapaths=datapaths,
Expand Down

0 comments on commit bcd9a96

Please sign in to comment.