Skip to content

Commit

Permalink
Merge branch 'develop' into gs-inject-source
Browse files Browse the repository at this point in the history
  • Loading branch information
AarynnCarter authored Aug 7, 2024
2 parents 39442c2 + 507ca49 commit c5a38ca
Show file tree
Hide file tree
Showing 24 changed files with 2,379 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/autolabel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
- uses: Naturalclar/[email protected]
with:
title-or-body: "both"
parameters: '[ {"keywords": ["NIRCam Stage 1/2 Pipeline"], "labels": ["NIRCam"], "assignees": ["AarynnCarter","mperrin","JarronL"]}, {"keywords": ["MIRI Stage 1/2 Pipeline"], "labels": ["MIRI"], "assignees": ["AarynnCarter","mperrin","JarronL"]}, {"keywords": ["Image Tools"], "labels": ["image tools"], "assignees": ["kglidic","kammerje","AarynnCarter","wbalmer","kdlawson","JarronL"]}, {"keywords": ["PSF Subtraction"], "labels": ["PSF subtraction"], "assignees": ["kdlawson","wbalmer","AarynnCarter"]}, {"keywords": ["Analysis Tools"], "labels": ["analysis tools"], "assignees": ["kdlawson","wbalmer","AarynnCarter","juliengirard","kammerje","kglidic"]}, {"keywords": ["Other"], "labels": [], "assignees": ["kdlawson","AarynnCarter","juliengirard","JarronL","kglidic"]}, {"keywords": ["Documentation"], "labels": ["documentation"], "assignees": ["AarynnCarter","mperrin","kglidic"]}]'
parameters: '[ {"keywords": ["NIRCam Stage 1/2 Pipeline"], "labels": ["NIRCam"], "assignees": ["AarynnCarter","mperrin","JarronL"]}, {"keywords": ["MIRI Stage 1/2 Pipeline"], "labels": ["MIRI"], "assignees": ["AarynnCarter","mperrin","JarronL"]}, {"keywords": ["Image Tools"], "labels": ["image tools"], "assignees": ["kglidic","kammerje","AarynnCarter","wbalmer","kdlawson","JarronL"]}, {"keywords": ["PSF Subtraction"], "labels": ["PSF subtraction"], "assignees": ["kdlawson","wbalmer","AarynnCarter"]}, {"keywords": ["Analysis Tools"], "labels": ["analysis tools"], "assignees": ["kdlawson","wbalmer","AarynnCarter","juliengirard","kammerje","kglidic"]}, {"keywords": ["Other"], "labels": ["other"], "assignees": ["kdlawson","AarynnCarter","juliengirard","JarronL","kglidic"]}, {"keywords": ["Documentation"], "labels": ["documentation"], "assignees": ["AarynnCarter","mperrin","kglidic"]}]'
github-token: "${{ secrets.GITHUB_TOKEN }}"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,9 @@ tests/ultranest
tests/species_*

# setuptools-scm

# PyCharm files
.idea/


spaceKLIP/_version.py
8 changes: 2 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ With the Anaconda environment created, move to the cloned directory and install
::

cd where/you/saved/the/git/repo
conda install conda-forge::git-lfs
pip install -r requirements.txt
pip install -e .

NEW AS OF 1 JUNE 2023: you also need to make the custom PSF mask files before running spaceKLIP for the first time:

::

cd spaceKLIP/
python make_psfmasks.py
Note that installing git-lfs from pip does not work as of 25 June 2024.

Finally, and very importantly, you will need to download the reference files and set the environment variables supporting the functioning of :code:`webbpsf` and :code:`webbpsf_ext`. Instructions to do this can be found at the respective package websites (`WebbPSF <https://webbpsf.readthedocs.io/en/latest/installation.html#installing-the-required-data-files>`_, `WebbPSF_ext <https://github.com/JarronL/webbpsf_ext>`_). Ensure that if you edit your .bashrc file, close and reopen your terminal to fully apply the changes (:code:`source ~/.bashrc` or :code:`source ~/.zshrc` may also work).

Expand Down
10 changes: 5 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt
sphinx
pandoc
nbsphinx
sphinx-rtd-theme
sphinx_automodapi
sphinx>=7.2.6
pandoc>=2.3
nbsphinx>=0.9.3
sphinx-rtd-theme>=2.0.0
sphinx_automodapi>=0.17.0
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
astropy
astroquery
jwst
astropy>=6.0.1
astroquery>=0.4.7
jwst>=1.14.0
matplotlib>=3.7.1
numpy<2
synphot
stsynphot
scipy
stsci.stimage==0.2.6
webbpsf
synphot>=1.4.0
stsynphot>=1.3.0
scipy>=1.13.0
stsci.stimage>=0.2.9
webbpsf>=1.2.1
webbpsf_ext>=1.2.0
pyklip @ git+https://bitbucket.org/pyKLIP/pyklip.git@jwst
pyklip>=2.7.1
293 changes: 217 additions & 76 deletions spaceKLIP/analysistools.py

Large diffs are not rendered by default.

440 changes: 426 additions & 14 deletions spaceKLIP/coron1pipeline.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spaceKLIP/coron2pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def run_obs(database,
verbose=verbose, **kwargs)

# Update spaceKLIP database.
database.update_obs(key, j, fitsout_path)
database.update_obs(key, j, fitsout_path, update_pxar=True)

# Also process rate files?
if do_rates:
Expand Down
35 changes: 29 additions & 6 deletions spaceKLIP/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import webbpsf, webbpsf_ext

from astropy.table import Table
from astroquery.svo_fps import SvoFps
from jwst.pipeline import Detector1Pipeline, Image2Pipeline, Coron3Pipeline
from stdatamodels.jwst import datamodels

from .utils import nircam_apname, get_nrcmask_from_apname, get_filter_info

Expand Down Expand Up @@ -191,6 +191,7 @@ def read_jwst_s012_data(self,
APERNAME = []
PPS_APER = []
PIXSCALE = [] # arcsec
PIXAR_SR = [] # sr
BUNIT = []
CRPIX1 = [] # pix
CRPIX2 = [] # pix
Expand Down Expand Up @@ -274,6 +275,7 @@ def read_jwst_s012_data(self,
raise UserWarning('Data originates from unknown telescope')
BLURFWHM += [head.get('BLURFWHM', np.nan)]
head = hdul['SCI'].header
PIXAR_SR += [head.get('PIXAR_SR', np.nan)]
BUNIT += [head.get('BUNIT', 'NONE')]
if cr_from_siaf:
CRPIX1 += [ap.XSciRef]
Expand Down Expand Up @@ -313,6 +315,7 @@ def read_jwst_s012_data(self,
APERNAME = np.array(APERNAME)
PPS_APER = np.array(PPS_APER)
PIXSCALE = np.array(PIXSCALE)
PIXAR_SR = np.array(PIXAR_SR)
BUNIT = np.array(BUNIT)
CRPIX1 = np.array(CRPIX1)
CRPIX2 = np.array(CRPIX2)
Expand Down Expand Up @@ -410,6 +413,7 @@ def read_jwst_s012_data(self,
'APERNAME',
'PPS_APER',
'PIXSCALE',
'PIXAR_SR',
'BUNIT',
'CRPIX1',
'CRPIX2',
Expand Down Expand Up @@ -443,6 +447,7 @@ def read_jwst_s012_data(self,
'object',
'object',
'float',
'float',
'object',
'float',
'float',
Expand Down Expand Up @@ -481,10 +486,9 @@ def read_jwst_s012_data(self,
maskfile = allpaths[ww][j].replace('.fits', '_psfmask.fits')
if not os.path.exists(maskfile):
if EXP_TYPE[ww][j] == 'NRC_CORON':
maskpath = APERNAME[ww][j] + '_' + FILTER[ww][j] + '.fits'
maskfile = os.path.join(maskbase, maskpath)
if not os.path.exists(maskfile):
maskfile = 'NONE'
pipeline = Detector1Pipeline()
input = datamodels.open(allpaths[ww][j])
maskfile = pipeline.get_reference_file(input, 'psfmask')
elif EXP_TYPE[ww][j] == 'MIR_4QPM' or EXP_TYPE[ww][j] == 'MIR_LYOT':
if APERNAME[ww][j] == 'MIRIM_MASK1065':
maskpath = 'JWST_MIRI_F1065C_transmission_webbpsf-ext_v2.fits'
Expand Down Expand Up @@ -521,6 +525,7 @@ def read_jwst_s012_data(self,
APERNAME[ww][j],
PPS_APER[ww][j],
PIXSCALE[ww][j],
PIXAR_SR[ww][j],
BUNIT[ww][j],
CRPIX1[ww][j],
CRPIX2[ww][j],
Expand Down Expand Up @@ -627,6 +632,7 @@ def read_jwst_s3_data(self,
APERNAME = []
PPS_APER = []
PIXSCALE = [] # arcsec
PIXAR_SR = [] # sr
MODE = []
ANNULI = []
SUBSECTS = []
Expand Down Expand Up @@ -723,6 +729,7 @@ def read_jwst_s3_data(self,
BLURFWHM += [head.get('BLURFWHM', np.nan)]
if TYPE[-1] == 'CORON3':
head = hdul['SCI'].header
PIXAR_SR += [head.get('PIXAR_SR', np.nan)]
BUNIT += [head.get('BUNIT', 'NONE')]
if cr_from_siaf:
CRPIX1 += [ap.XSciRef]
Expand Down Expand Up @@ -753,6 +760,7 @@ def read_jwst_s3_data(self,
APERNAME = np.array(APERNAME)
PPS_APER = np.array(PPS_APER)
PIXSCALE = np.array(PIXSCALE)
PIXAR_SR = np.array(PIXAR_SR)
MODE = np.array(MODE)
ANNULI = np.array(ANNULI)
SUBSECTS = np.array(SUBSECTS)
Expand Down Expand Up @@ -794,6 +802,7 @@ def read_jwst_s3_data(self,
'APERNAME',
'PPS_APER',
'PIXSCALE',
'PIXAR_SR',
'MODE',
'ANNULI',
'SUBSECTS',
Expand Down Expand Up @@ -823,6 +832,7 @@ def read_jwst_s3_data(self,
'object',
'object',
'float',
'float',
'object',
'int',
'int',
Expand Down Expand Up @@ -858,6 +868,7 @@ def read_jwst_s3_data(self,
APERNAME[ww[j]],
PPS_APER[ww[j]],
PIXSCALE[ww[j]],
PIXAR_SR[ww[j]],
MODE[ww[j]],
ANNULI[ww[j]],
SUBSECTS[ww[j]],
Expand Down Expand Up @@ -1021,8 +1032,10 @@ def print_obs(self,
else:
print_tab.remove_columns(['TARG_RA', 'TARG_DEC', 'EXPSTART', 'APERNAME', 'PPS_APER',
'CRPIX1', 'CRPIX2', 'RA_REF', 'DEC_REF', 'FITSFILE', 'MASKFILE'])
print_tab['XOFFSET'] *= 1e3
print_tab['XOFFSET'] = np.round(print_tab['XOFFSET'])
print_tab['XOFFSET'][print_tab['XOFFSET'] == 0.] = 0.
print_tab['YOFFSET'] *= 1e3
print_tab['YOFFSET'] = np.round(print_tab['YOFFSET'])
print_tab['YOFFSET'][print_tab['YOFFSET'] == 0.] = 0.
print_tab.pprint()
Expand Down Expand Up @@ -1102,7 +1115,8 @@ def update_obs(self,
yoffset=None,
crpix1=None,
crpix2=None,
blurfwhm=None):
blurfwhm=None,
update_pxar=False):
"""
Update the content of the observations database.
Expand Down Expand Up @@ -1138,6 +1152,9 @@ def update_obs(self,
blurfwhm : float, optional
New FWHM for the Gaussian filter blurring (pix) for the observation
to be updated. The default is None.
update_pxar : bool, optional
Update the pixel area column of the database based on the FITS file
header information? The default is False.
Returns
-------
Expand Down Expand Up @@ -1174,6 +1191,12 @@ def update_obs(self,
self.obs[key]['FITSFILE'][index] = fitsfile
if maskfile is not None:
self.obs[key]['MASKFILE'][index] = maskfile
if update_pxar:
try:
pxar = pyfits.getheader(self.obs[key]['FITSFILE'][index], 'SCI')['PIXAR_SR']
self.obs[key]['PIXAR_SR'][index] = pxar
except:
pass
hdul.close()

pass
Expand Down
Loading

0 comments on commit c5a38ca

Please sign in to comment.