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

JP-3753: Refactor extract1d #8961

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5c09b22
Start extract1d refactor
melanieclarke Oct 31, 2024
0ad2114
Add test for custom extraction with polynomial limits
melanieclarke Nov 5, 2024
cf90cf6
Fix log message f-string
melanieclarke Nov 5, 2024
91aa410
Deduplicate extraction interface
melanieclarke Nov 5, 2024
613c05a
Remove image reference type
melanieclarke Nov 6, 2024
f0cf3ff
Separate IFU from slit extraction
melanieclarke Nov 6, 2024
fdcd322
Remove NIRISS SOSS references from slit extraction code
melanieclarke Nov 6, 2024
1803933
Remove unnecessary middleman function; condense input type checking
melanieclarke Nov 6, 2024
4723b9b
Add helper functions for special extraction modes
melanieclarke Nov 7, 2024
bfe960f
Clean up messages
melanieclarke Nov 7, 2024
6bf0348
First version incorporating new extraction engine
melanieclarke Nov 8, 2024
a570f12
Fix extraction limit defaults and partial pixel weights
melanieclarke Nov 11, 2024
f648e1d
Npixels is sum of weights instead of sum of pixels with non-zero weight
melanieclarke Nov 11, 2024
91d30b4
Move profile and wavelength calculations out of integration loop
melanieclarke Nov 11, 2024
d338f88
Tidying up
melanieclarke Nov 11, 2024
4f66708
Update unit tests for new extract1d
melanieclarke Nov 12, 2024
326737e
Add left/right limit handling, fix partial pixel weights
melanieclarke Nov 12, 2024
e2f7465
Make polynomial coefficient definition backward compatible
melanieclarke Nov 12, 2024
faef7f5
Clean up aperture definition, fix edge cases
melanieclarke Nov 12, 2024
7e7aced
Coverage tests for step interface
melanieclarke Nov 13, 2024
6c784bc
Move aperture correction setup outside integration loop
melanieclarke Nov 13, 2024
e99e8fb
Return separate values from locn_from_wcs function
melanieclarke Nov 14, 2024
548d7a9
Rename 'boxcar' extraction to 'box'
melanieclarke Nov 14, 2024
a50f37f
Set up for future optimal extraction
melanieclarke Nov 14, 2024
0a976ae
Tidy up code organization, add docstrings
melanieclarke Nov 14, 2024
f829f2c
Code style fixes
melanieclarke Nov 14, 2024
49bc499
Make sure background values are finite: they default to 0, not NaN
melanieclarke Nov 15, 2024
a2e0aa6
More general check for unresampled nirspec data
melanieclarke Nov 18, 2024
8a99fbd
More robust file saving for containers
melanieclarke Nov 19, 2024
f2ad06a
Add option to save spatial profile
melanieclarke Nov 19, 2024
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
9 changes: 6 additions & 3 deletions jwst/datamodels/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def save(self,
path : str or None
- If None, the `meta.filename` is used for each model.
- If a string, the string is used as a root and an index is
appended.
appended, along with the '.fits' extension.

save_model_func: func or None
Alternate function to save each model instead of
Expand All @@ -353,8 +353,11 @@ def save(self,
save_path = model.meta.filename
else:
if len(self) <= 1:
idx = None
save_path = path+str(idx)+".fits"
idx = ''
if path.endswith(".fits"):
save_path = path.replace(".fits", f"{idx}.fits")
else:
save_path = f"{path}{idx}.fits"
output_paths.append(
model.save(save_path, **kwargs)
)
Expand Down
12 changes: 9 additions & 3 deletions jwst/datamodels/tests/test_model_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def test_group_id(tmp_path):
assert asn_group_ids == model_droup_ids


def test_save(tmp_cwd, container):
@pytest.mark.parametrize("path", ["foo", "foo.fits"])
def test_save(tmp_cwd, container, path):

# container pushes us to data/ directory so need to go back to tmp_cwd
# to avoid polluting the data/ directory
Expand All @@ -142,8 +143,13 @@ def test_save(tmp_cwd, container):
assert os.path.exists(fname)

# test specifying path saves to custom path with indices
path = "foo"
container.save(path)
expected_fnames = [path+str(i)+".fits" for i in range(len(container))]
expected_fnames = [path.replace(".fits", "")+str(i)+".fits" for i in range(len(container))]
for fname in expected_fnames:
assert os.path.exists(fname)

# test saving path when the container has length 1: no index appended
container = ModelContainer([container[0]])
container.save(path)
expected_fname = path.replace(".fits", "") + ".fits"
assert os.path.exists(expected_fname)
12 changes: 6 additions & 6 deletions jwst/extract_1d/apply_apcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ApCorrBase(abc.ABC):
}

def __init__(self, input_model, apcorr_table, sizeunit,
location = None, slit_name = None, **match_kwargs):
location=None, slit_name=None, **match_kwargs):
self.correction = None

self.model = input_model
Expand Down Expand Up @@ -155,7 +155,7 @@ def apply(self, spec_table):
"""
flux_cols_to_correct = ('flux', 'flux_error', 'surf_bright', 'sb_error')
var_cols_to_correct = ('flux_var_poisson', 'flux_var_rnoise', 'flux_var_flat',
'sb_var_poisson', 'sb_var_rnoise', 'sb_var_flat')
'sb_var_poisson', 'sb_var_rnoise', 'sb_var_flat')

for row in spec_table:
correction = self.apcorr_func(row['npixels'], row['wavelength'])
Expand All @@ -180,7 +180,7 @@ class ApCorrPhase(ApCorrBase):
"""
size_key = 'size'

def __init__(self, *args, pixphase = 0.5, **kwargs):
def __init__(self, *args, pixphase=0.5, **kwargs):
self.phase = pixphase # In the future we'll attempt to measure the pixel phase from inputs.

super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -297,7 +297,7 @@ class ApCorrRadial(ApCorrBase):
"""Aperture correction class used with spectral data produced from an extraction aperture radius."""

def __init__(self, input_model, apcorr_table,
location = None):
location=None):

self.correction = None
self.model = input_model
Expand Down Expand Up @@ -339,7 +339,7 @@ def apply(self, spec_table):
"""
flux_cols_to_correct = ('flux', 'flux_error', 'surf_bright', 'sb_error')
var_cols_to_correct = ('flux_var_poisson', 'flux_var_rnoise', 'flux_var_flat',
'sb_var_poisson', 'sb_var_rnoise', 'sb_var_flat')
'sb_var_poisson', 'sb_var_rnoise', 'sb_var_flat')

for i, row in enumerate(spec_table):
correction = self.apcorr_correction[i]
Expand Down Expand Up @@ -377,7 +377,7 @@ def match_wavelengths(self, wavelength_ifu):
def find_apcorr_func(self, iwave, radius_ifu):
# at ifu wavelength plane (iwave), the extraction radius is radius_ifu
# pull out the radius values (self.size) to use in the apcor ref file for this iwave
# self.size and self.apcorr have already been interpolated in wavelength to match the
# self.size and self.apcorr have already been interpolated in wavelength to match
# the ifu wavelength range.

radius_apcor = self.size[:, iwave]
Expand Down
Loading
Loading