Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine crpix from saif toggle #182

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Changes from 2 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
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_saif=False,
wbalmer marked this conversation as resolved.
Show resolved Hide resolved
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_saif:
wbalmer marked this conversation as resolved.
Show resolved Hide resolved
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_saif=False):
wbalmer marked this conversation as resolved.
Show resolved Hide resolved
"""
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_saif:
wbalmer marked this conversation as resolved.
Show resolved Hide resolved
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_saif=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_saif=cr_from_saif,
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_saif=cr_from_saif,
wbalmer marked this conversation as resolved.
Show resolved Hide resolved
)
elif str(readlevel) == '4':
db.read_jwst_s4_data(datapaths=datapaths,
Expand Down