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-3588: Use Pastasoss datamodel for NIRISS SOSS transform solution #8763

Merged
merged 30 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
27ebcf2
WIP pastassos addition
tapastro Aug 21, 2024
aa78c37
WIP pastasoss updates
tapastro Aug 27, 2024
7e07d39
wip soss updates
tapastro Sep 6, 2024
834f667
functional version?
tapastro Sep 7, 2024
9a20b3f
functional version new v2 re re fw
tapastro Sep 9, 2024
5b27ac8
logic error wrt padding
tapastro Sep 10, 2024
53725ce
logic error wrt padding pt2
tapastro Sep 10, 2024
6e83a2c
precommit fixes
tapastro Sep 10, 2024
ddadf64
changelog
tapastro Sep 10, 2024
e7a973a
more ruff
tapastro Sep 10, 2024
7718348
don't modify reftrace
tapastro Sep 11, 2024
1dbc67a
remove unused function
tapastro Sep 13, 2024
12701d5
check_dispersion_direction unused
tapastro Sep 18, 2024
1023fb7
remove stale code, getattr
tapastro Sep 18, 2024
029b47d
const vars, del xfrm
tapastro Sep 18, 2024
6600645
type hints OUT
tapastro Sep 18, 2024
9fe7b53
unnecessary comment
tapastro Sep 18, 2024
2b8d66a
add some docstring details
tapastro Sep 18, 2024
24ccdcf
typos
tapastro Sep 18, 2024
ca76a8c
typos pt2
tapastro Sep 18, 2024
b4b3d20
typo
tapastro Sep 18, 2024
c08fbf5
removing imports for type hints
tapastro Sep 18, 2024
daa848f
some cleanup
tapastro Sep 18, 2024
cff7f5f
give docstring a oneliner
tapastro Sep 18, 2024
a92492e
address doctest failure
tapastro Sep 18, 2024
6060576
further get_soss_traces updates
tapastro Sep 18, 2024
d3ef325
further get_soss_traces updates
tapastro Sep 18, 2024
5e73ce9
one last get_soss_traces update
tapastro Sep 18, 2024
73fed8a
how about no example
tapastro Sep 18, 2024
2910a86
Merge branch 'master' into jp-3588-pastasoss
tapastro Sep 20, 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
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ emicorr
- Fixed a bug where MIRI EMI correction step would return NaNs when it was unable
to compute a correction. [#8675]

extract_1d
----------

- Updated NIRISS SOSS extraction to utilize ``pastasoss``
rotation solution. [#8763]

flat_field
----------

Expand Down
5 changes: 0 additions & 5 deletions docs/jwst/extract_1d/arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ The ``extract_1d`` step has the following step-specific arguments.
used when soss_wave_grid is not provided to make sure the computation time or the memory
used stays reasonable. Default value is 20000.

``--soss_transform``
This is a NIRISS-SOSS algorithm-specific parameter; this defines a rotation to
apply to the reference files to match the observation. It should be specified as
a list of three floats, with default values of None.

``--soss_tikfac``
This is a NIRISS-SOSS algorithm-specific parameter; this is the regularization
factor used in the SOSS extraction. If not specified, ATOCA will calculate a
Expand Down
10 changes: 3 additions & 7 deletions jwst/extract_1d/extract_1d_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,13 @@
soss_estimate = input_file(default = None) # Estimate used to generate the wavelength grid
soss_rtol = float(default=1.0e-4) # Relative tolerance needed on a pixel model
soss_max_grid_size = integer(default=20000) # Maximum grid size, if wave_grid not specified
soss_transform = list(default=None, min=3, max=3) # rotation applied to the ref files to match observation.
soss_tikfac = float(default=None) # regularization factor for NIRISS SOSS extraction
soss_width = float(default=40.) # aperture width used to extract the 1D spectrum from the de-contaminated trace.
soss_bad_pix = option("model", "masking", default="masking") # method used to handle bad pixels
soss_modelname = output_file(default = None) # Filename for optional model output of traces and pixel weights
"""

reference_file_types = ['extract1d', 'apcorr', 'wavemap', 'spectrace', 'specprofile', 'speckernel']
reference_file_types = ['extract1d', 'apcorr', 'pastasoss', 'specprofile', 'speckernel']

def process(self, input):
"""Execute the step.
Expand Down Expand Up @@ -432,8 +431,7 @@
return input_model

# Load reference files.
spectrace_ref_name = self.get_reference_file(input_model, 'spectrace')
wavemap_ref_name = self.get_reference_file(input_model, 'wavemap')
pastasoss_ref_name = self.get_reference_file(input_model, 'pastasoss')

Check warning on line 434 in jwst/extract_1d/extract_1d_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/extract_1d_step.py#L434

Added line #L434 was not covered by tests
specprofile_ref_name = self.get_reference_file(input_model, 'specprofile')
speckernel_ref_name = self.get_reference_file(input_model, 'speckernel')

Expand All @@ -444,7 +442,6 @@
soss_kwargs['tikfac'] = self.soss_tikfac
soss_kwargs['width'] = self.soss_width
soss_kwargs['bad_pix'] = self.soss_bad_pix
soss_kwargs['transform'] = self.soss_transform
soss_kwargs['subtract_background'] = self.subtract_background
soss_kwargs['rtol'] = self.soss_rtol
soss_kwargs['max_grid_size'] = self.soss_max_grid_size
Expand All @@ -458,8 +455,7 @@
# Run the extraction.
result, ref_outputs, atoca_outputs = soss_extract.run_extract1d(
input_model,
spectrace_ref_name,
wavemap_ref_name,
pastasoss_ref_name,
specprofile_ref_name,
speckernel_ref_name,
subarray,
Expand Down
74 changes: 0 additions & 74 deletions jwst/extract_1d/soss_extract/atoca_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,80 +252,6 @@ def get_wv_map_bounds(wave_map, dispersion_axis=1):
return wave_top, wave_bottom


def check_dispersion_direction(wave_map, dispersion_axis=1, dwv_sign=-1):
"""Check that the dispersion axis is increasing in the good direction
given by `dwv_sign``
Parameters
----------
wave_map : array[float]
2d-map of the pixel central wavelength
dispersion_axis : int, optional
Which axis is the dispersion axis (0 or 1)
dwv_sign : int, optional
Direction of increasing wavelengths (-1 or 1)

Returns
-------
bool_map : array[bool]
Boolean 2d map of the valid dispersion direction, same shape as `wave_map`
"""

# Estimate the direction of increasing wavelength
wave_left, wave_right = get_wv_map_bounds(wave_map, dispersion_axis=dispersion_axis)
dwv = wave_right - wave_left

# Return bool map of pixels following the good direction
bool_map = (dwv_sign * dwv >= 0)
# The bad value could be from left or right so mask both
bool_map &= np.roll(bool_map, 1, axis=dispersion_axis)

return bool_map


def mask_bad_dispersion_direction(wave_map, n_max=10, fill_value=0, dispersion_axis=1, dwv_sign=-1):
"""Change value of the pixels in `wave_map` that do not follow the
general dispersion direction.

Parameters
----------
wave_map : array[float]
2d-map of the pixel central wavelength
n_max : int
Maximum number of iterations
fill_value : float
Value use to replace pixels that do not follow the dispersion direction
dispersion_axis : int, optional
Which axis is the dispersion axis (0 or 1)
dwv_sign : int, optional
Direction of increasing wavelengths (-1 or 1)

Returns
-------
wave_map : array[float]
The corrected wave_map.
convergence flag : bool
Boolean set to True if all the pixels are now valid, False otherwise.
"""
# Do not modify the input
wave_map = wave_map.copy()

# Make the correction iteratively
for i_try in range(n_max):
# Check which pixels are good
is_good_direction = check_dispersion_direction(wave_map, dispersion_axis, dwv_sign)
tapastro marked this conversation as resolved.
Show resolved Hide resolved
# Stop iteration if all good, or apply correction where needed.
if is_good_direction.all():
convergence_flag = True
break
else:
wave_map[~is_good_direction] = fill_value
else:
# Did not succeed! :(
convergence_flag = False

return wave_map, convergence_flag


def oversample_grid(wave_grid, n_os=1):
"""Create an oversampled version of the input 1D wavelength grid.

Expand Down
Loading
Loading