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

Implementing Calibrated Contrast Measurements #91

Merged
merged 33 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a3dc64b
Adding masking of MIRI FQPM edges for contrast curves
AarynnCarter Aug 11, 2023
a53739a
Converting pyfits to fits
AarynnCarter Aug 11, 2023
07f5f4b
Removing SpaceTelescope Data class
AarynnCarter Aug 11, 2023
abf970b
Source injection working for calibrated contrast
AarynnCarter Aug 15, 2023
141e1ab
Adding ability to inject and recover companion fluxes
AarynnCarter Aug 17, 2023
a3c6fc9
Adding determination of calibrated contrast curves
AarynnCarter Aug 18, 2023
d4da01a
Minor bug fixes
AarynnCarter Aug 25, 2023
92da1df
Small plotting change
AarynnCarter Aug 29, 2023
8087192
Merge branch 'develop' into calcon
mperrin Aug 31, 2023
f675740
Merge branch 'develop' into calcon
AarynnCarter Sep 20, 2023
d5850be
Merge branch 'calcon' of https://github.com/kammerje/spaceKLIP into c…
AarynnCarter Dec 11, 2023
6218033
Adjust to use os.path.splitext()
AarynnCarter Dec 11, 2023
11fdf6b
Adjust to use os.path.splitext()
AarynnCarter Dec 11, 2023
2696fb1
Adding function to set pixels surrounded by NaNs to desired value.
AarynnCarter Dec 11, 2023
8365553
Adjusting raw contrast print statement
AarynnCarter Dec 11, 2023
2379f94
converting from hardcoded 6.5 to JWST_CIRCUMSCRIBED_DIAMETER
AarynnCarter Dec 11, 2023
6c89911
Adding print statement for injection and recovery
AarynnCarter Dec 11, 2023
e754d1b
Minor documentation changes
AarynnCarter Dec 11, 2023
8482f7c
Reformat ax.scatter() call
AarynnCarter Dec 11, 2023
1674713
Removing conflicts
AarynnCarter Dec 11, 2023
fa44290
Ensuring everything is in arcseconds
AarynnCarter Dec 11, 2023
489b2c2
Changing to WebbPSF for MIRI filter info
AarynnCarter Dec 13, 2023
5a75647
making sure calcon works with latest version of develop + gitignore u…
AarynnCarter Dec 13, 2023
a06eb2a
Fixing bug when number of different KL modes == 1
AarynnCarter Dec 13, 2023
662113f
Merge branch 'develop' into calcon
mperrin Dec 14, 2023
5e10701
Merge branch 'develop' into calcon
mperrin Dec 14, 2023
af0df19
add more log statements and printed notification of files saved; also…
mperrin Dec 20, 2023
b5073a0
debug and enhance plotting code for raw and cal contrast
mperrin Dec 20, 2023
f6e903c
add plot title annotation of PSF subtraction strategy
mperrin Dec 20, 2023
45b1041
trivial bug fix, add missing 'self.'
mperrin Dec 20, 2023
b525077
Tutorial updates for calcon branch with working raw and calibrated co…
mperrin Dec 20, 2023
7b566ac
Adjusting install to jwst_new
AarynnCarter Dec 21, 2023
3ceda4a
Merge branch 'calcon' of https://github.com/kammerje/spaceKLIP into c…
AarynnCarter Dec 21, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ __pycache__/
*.py[cod]
*$py.class

# Transmission mask files
spaceKLIP/resources/transmissions/NRC*

# C extensions
*.so

Expand Down
1,415 changes: 1,059 additions & 356 deletions docs/source/tutorials/tutorial_NIRCam_contrast_analyses.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ jdaviz
jwst
matplotlib
numpy
pysynphot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would urge you to reconsider this dependency, since pysynphot is deprecated and no longer actively developed. Instead synphot should be preferred as the current tool, with similar but slightly different API after a refactoring. synphot is actively developed and supported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, this is an annoyance from upstream, but wanted to make sure you were aware.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is tied to the psf.py file, which is built upon WebbPSF_ext. I 100% agree we should change, but don't want to bloat this PR further / I think this will need a careful hand to make sure we don't break anything. Instead, I've made a new issue so that we don't lose track.

scipy
webbpsf
841 changes: 788 additions & 53 deletions spaceKLIP/analysistools.py

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions spaceKLIP/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# Load NIRCam, NIRISS, and MIRI filters
wave_nircam, weff_nircam, do_svo = get_filter_info('NIRCAM', return_more=True)
wave_niriss, weff_niriss = get_filter_info('NIRISS', do_svo=do_svo)
wave_miri, weff_miri = get_filter_info('MIRI', do_svo=do_svo)
wave_miri, weff_miri = get_filter_info('MIRI', do_svo=False)

class Database():
"""
Expand Down Expand Up @@ -1286,7 +1286,7 @@ def create_database(output_dir,

Automatically searches for uncal.fits in the input directory and creates
a database of the JWST data. Only works for stage0, stage1, or stage2 data
by default; set readlevel3=True to read in stage 3 outputs.
by default; set readlevel=3 to read in stage 3 outputs.

Parameters
----------
Expand All @@ -1309,6 +1309,11 @@ def create_database(output_dir,
default is None.
assoc_using_targname : bool, optional
Associate observations using the TARGNAME keyword. The default is True.
readlevel : str or int
Level of data products to read in, either '012' (or an integer 0,1,2) to read in
individual exposures, or '3' to read in level-3 PSF-subtracted products,
or '4' to read in extracted PSF fitting products.

verbose : bool, optional
Print information to the screen. The default is True.

Expand Down Expand Up @@ -1362,13 +1367,10 @@ def create_database(output_dir,
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,
verbose=verbose
)
elif str(readlevel) == '4':
db.read_jwst_s4_data(datapaths=datapaths,
verbose=verbose
)
else:
raise ValueError("Invalid/unknown value for readlevel parameter")
Expand Down
13 changes: 10 additions & 3 deletions spaceKLIP/imagetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
from webbpsf_ext.coords import dist_image
from webbpsf_ext.webbpsf_ext_core import _transmission_map

from webbpsf.constants import JWST_CIRCUMSCRIBED_DIAMETER

import logging
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
Expand Down Expand Up @@ -605,6 +607,7 @@ def subtract_background(self,
set to 5, a median of every 5 background images will be subtracted from
the corresponding 5 target images. The default is None (i.e. a median
across all images).

subdir : str, optional
Name of the directory where the data products shall be saved. The
default is 'bgsub'.
Expand Down Expand Up @@ -659,6 +662,7 @@ def subtract_background(self,
sci_bg_data = np.concatenate(sci_bg_data)
sci_bg_erro = np.concatenate(sci_bg_erro)
sci_bg_pxdq = np.concatenate(sci_bg_pxdq)

sci_bg_data_split = np.array_split(sci_bg_data, split_inds, axis=0)
sci_bg_erro_split = np.array_split(sci_bg_erro, split_inds, axis=0)
sci_bg_pxdq_split = np.array_split(sci_bg_pxdq, split_inds, axis=0)
Expand Down Expand Up @@ -695,6 +699,7 @@ def subtract_background(self,
ref_bg_data = np.concatenate(ref_bg_data)
ref_bg_erro = np.concatenate(ref_bg_erro)
ref_bg_pxdq = np.concatenate(ref_bg_pxdq)

ref_bg_data_split = np.array_split(ref_bg_data, split_inds, axis=0)
ref_bg_erro_split = np.array_split(ref_bg_erro, split_inds, axis=0)
ref_bg_pxdq_split = np.array_split(ref_bg_pxdq, split_inds, axis=0)
Expand Down Expand Up @@ -1391,7 +1396,7 @@ def blur_frames(self,
if self.database.obs[key]['EXP_TYPE'][j] in ['NRC_CORON']:
diam = 5.2
else:
diam = 6.5
diam = JWST_CIRCUMSCRIBED_DIAMETER
else:
raise UserWarning('Data originates from unknown telescope')
if fact_temp is not None:
Expand Down Expand Up @@ -2094,8 +2099,8 @@ def align_frames(self,
log.warning(' --> The following frames might not be properly aligned: '+str(ww))

# Write FITS file and PSF mask.
head_pri['XOFFSET'] = xoffset
head_pri['YOFFSET'] = yoffset
head_pri['XOFFSET'] = xoffset #arcseconds
head_pri['YOFFSET'] = yoffset #arcseconds
head_sci['CRPIX1'] = crpix1
head_sci['CRPIX2'] = crpix2
fitsfile = ut.write_obs(fitsfile, output_dir, data, erro, pxdq, head_pri, head_sci, is2d, imshifts, maskoffs)
Expand All @@ -2115,6 +2120,7 @@ def align_frames(self,
label='PA = %.0f deg' % self.database.obs[key]['ROLL_REF'][j])
ax.axhline(0., color='gray', lw=1, zorder=-1) # set zorder to ensure lines are drawn behind all the scatter points
ax.axvline(0., color='gray', lw=1, zorder=-1)

ax.set_aspect('equal')
xlim = ax.get_xlim()
ylim = ax.get_ylim()
Expand Down Expand Up @@ -2186,3 +2192,4 @@ def align_frames(self,
plt.savefig(output_file)
log.info(f" Plot saved in {output_file}")
plt.close()

9 changes: 7 additions & 2 deletions spaceKLIP/make_psfmasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@

# Write PSF mask.
hdul['SCI'].data = psfmask
hdul.writeto('resources/transmissions/' + apername + '_' + filt + '.fits', output_verify='fix', overwrite=True)
outfile = 'resources/transmissions/' + apername + '_' + filt + '.fits'
print(f"Wrote to {outfile}")
hdul.writeto(outfile, output_verify='fix', overwrite=True)

fitsfiles = ['JWST_MIRI_F1065C_transmission_webbpsf-ext_v2.fits',
'JWST_MIRI_F1140C_transmission_webbpsf-ext_v2.fits',
Expand All @@ -122,6 +124,7 @@
hdu.header['EXTNAME'] = 'SCI'
hdul.append(hdu)
hdul.writeto('resources/transmissions/' + fitsfile, output_verify='fix', overwrite=True)
print(f"Wrote to resources/transmissions/{fitsfile}")


def get_bar_offset_from_siaf(siaf, filt, channel='LW'):
Expand Down Expand Up @@ -198,7 +201,9 @@ def get_bar_offset_from_siaf(siaf, filt, channel='LW'):

# Write PSF mask.
hdul['SCI'].data = psfmask
hdul.writeto('resources/transmissions/' + apername + '_' + filt.upper() + '.fits', output_verify='fix', overwrite=True)
outfile = 'resources/transmissions/' + apername + '_' + filt.upper() + '.fits'
hdul.writeto(outfile, output_verify='fix', overwrite=True)
print(f"Wrote to {outfile}")

# Loop through apertures and filters.
fitsfile = 'jwst_nircam_psfmask_0003.fits'
Expand Down
Loading
Loading