Skip to content

Commit

Permalink
JP-3695: Clean up unnecessary copies (#8676)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler Pauly <[email protected]>
  • Loading branch information
penaguerrero and tapastro authored Sep 20, 2024
1 parent d2e7e2b commit 4d60e7a
Show file tree
Hide file tree
Showing 45 changed files with 672 additions and 536 deletions.
88 changes: 87 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ calwebb_detector1
- Added the optional ``clean_flicker_noise`` step between ``jump`` and
``ramp_fit``. [#8669]

change_migration
----------------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

clean_flicker_noise
-------------------

Expand Down Expand Up @@ -91,6 +96,11 @@ datamodels
- Added `ModelLibrary` class to allow passing on-disk models between steps in the
image3 pipeline. [#8683]

dark_current
------------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

documentation
-------------

Expand All @@ -99,12 +109,24 @@ documentation
- Updated description of association keyword `expname`: including path information
in addition to the filename is discouraged, but allowed. [#8789]

dq_init
--------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

emicorr
-------

- Fixed a bug where MIRI EMI correction step would return NaNs when it was unable
to compute a correction. [#8675]

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

first_frame
-----------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

flat_field
----------

Expand All @@ -113,6 +135,11 @@ flat_field

- Replaced deep copies of NIRSpec WCS objects within most loops [#8793]

gain_scale
----------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

general
-------

Expand All @@ -126,12 +153,37 @@ general

- bump dependency to use ``stcal 1.9.0`` [#8808]

group_scale
-----------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

ipc
---

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

jump
----

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

klip
----

- Allowed klip to ingest a single shifted 3-D PSF model instead of a 4-D structure
containing one shifted PSF per science integration. [#8747]

lastframe
---------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

linearity
---------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

master_background
-----------------

Expand Down Expand Up @@ -196,6 +248,11 @@ pathloss

- Replaced deep copies of NIRSpec WCS objects within most loops [#8793]

persistence
-----------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

photom
------

Expand Down Expand Up @@ -232,6 +289,18 @@ ramp_fitting
- Updated the flow of the detector 1 pipeline when selecting the ``LIKELY`` algorithm
for ramp fitting. The ramps must contain a minimum number of groups (4).[#8631]

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

refpix
------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

regtest
-------

- Added memory usage test for Detector1 pipeline. [#8676]

resample
--------

Expand All @@ -245,6 +314,11 @@ resample
- Ensure that NaNs and DO_NOT_USE flags match up in all input data before
resampling. [#8557]

reset
-----

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

resample_spec
-------------

Expand All @@ -269,12 +343,19 @@ resample_spec
- Ensure that NaNs and DO_NOT_USE flags match up in all input data before
resampling. [#8557]

rscd
----

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

saturation
----------

- Add option for using the readout pattern information to improve saturation flagging
in grouped data. [#8731]


- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

scripts
-------

Expand All @@ -301,6 +382,11 @@ stpipe

- Log jwst version at end of `Step.run`. [#8769]

superbias
---------

- Removed unnecessary copies, and created a single copy at step.py level. [#8676]

tso_photometry
--------------

Expand Down
3 changes: 0 additions & 3 deletions docs/jwst/emicorr/arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ The ``emicorr`` step has the following step-specific arguments.
If True, the reference wavelength will be scaled to the
data's phase amplitude.

``--user_supplied_reffile`` (boolean, default=None)
This is to specify an ASDF-format user-created reference file.

``--save_intermediate_results`` (string, default=False)
This is a boolean flag to specify whether to write a step output
file with the EMI correction, and a reference file with all the
Expand Down
11 changes: 4 additions & 7 deletions jwst/charge_migration/charge_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
CHLO_DNU = CHLO + DNU


def charge_migration(input_model, signal_threshold):
def charge_migration(output_model, signal_threshold):
"""
Correct for chargemigration
Parameters
----------
input_model : `~jwst.datamodels.RampModel`
output_model : `~jwst.datamodels.RampModel`
The input science data to be corrected
signal_threshold : float
Expand All @@ -35,11 +35,8 @@ def charge_migration(input_model, signal_threshold):
DO_NOT_USE flags to groups exceeding signal_threshold
"""
data = input_model.data
gdq = input_model.groupdq

# Create the output model as a copy of the input
output_model = input_model.copy()
data = output_model.data
gdq = output_model.groupdq

log.info('Using signal_threshold: %.2f', signal_threshold)

Expand Down
19 changes: 10 additions & 9 deletions jwst/charge_migration/charge_migration_step.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#! /usr/bin/env python
import logging

from ..stpipe import Step

from stdatamodels.jwst import datamodels
from ..stpipe import Step

from . import charge_migration

Expand All @@ -25,22 +24,24 @@ class ChargeMigrationStep(Step):
skip = boolean(default=True)
"""

def process(self, input):
def process(self, step_input):

# Open the input data model
with datamodels.RampModel(input) as input_model:
with datamodels.RampModel(step_input) as input_model:

if (input_model.data.shape[1] < 3): # skip step if only 1 or 2 groups/integration
log.info('Too few groups per integration; skipping charge_migration')

result = input_model
result.meta.cal_step.charge_migration = 'SKIPPED'

return result
input_model.meta.cal_step.charge_migration = 'SKIPPED'
return input_model

# Work on a copy
result = input_model.copy()

# Retrieve the parameter value(s)
signal_threshold = self.signal_threshold

result = charge_migration.charge_migration(input_model, signal_threshold)
result = charge_migration.charge_migration(result, signal_threshold)
result.meta.cal_step.charge_migration = 'COMPLETE'

return result
38 changes: 21 additions & 17 deletions jwst/dark_current/dark_current_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class DarkCurrentStep(Step):

reference_file_types = ['dark']

def process(self, input):
def process(self, step_input):

# Open the input data model
with datamodels.RampModel(input) as input_model:
with datamodels.RampModel(step_input) as input_model:

# Get the name of the dark reference file to use
self.dark_name = self.get_reference_file(input_model, 'dark')
Expand All @@ -36,9 +36,11 @@ def process(self, input):
if self.dark_name == 'N/A':
self.log.warning('No DARK reference file found')
self.log.warning('Dark current step will be skipped')
result = input_model.copy()
result.meta.cal_step.dark = 'SKIPPED'
return result
input_model.meta.cal_step.dark = 'SKIPPED'
return input_model

# Work on a copy
result = input_model.copy()

# Create name for the intermediate dark, if desired.
dark_output = self.dark_output
Expand All @@ -49,7 +51,7 @@ def process(self, input):
)

# Open the dark ref file data model - based on Instrument
instrument = input_model.meta.instrument.name
instrument = result.meta.instrument.name
if instrument == 'MIRI':
dark_model = datamodels.DarkMIRIModel(self.dark_name)
else:
Expand All @@ -58,20 +60,23 @@ def process(self, input):
# Store user-defined average_dark_current in model, if provided
# A user-defined value will take precedence over any value present
# in dark reference file
self.set_average_dark_current(input_model, dark_model)
self.set_average_dark_current(result, dark_model)

# Do the dark correction
result = dark_sub.do_correction(
input_model, dark_model, dark_output
correction = dark_sub.do_correction(
result, dark_model, dark_output
)

out_data, dark_data = result
out_data, dark_data = correction

if dark_data is not None and dark_data.save:
save_dark_data_as_dark_model(dark_data, dark_model, instrument)
dark_model.close()

out_ramp = dark_output_data_2_ramp_model(out_data, input_model)
out_ramp = dark_output_data_2_ramp_model(out_data, result)

# Cleanup
del dark_model
del result

return out_ramp

Expand Down Expand Up @@ -140,7 +145,7 @@ def save_dark_data_as_dark_model(dark_data, dark_model, instrument):
out_dark_model.close()


def dark_output_data_2_ramp_model(out_data, input_model):
def dark_output_data_2_ramp_model(out_data, out_model):
"""
Convert computed output data from the dark step to a RampModel.
Expand All @@ -149,7 +154,7 @@ def dark_output_data_2_ramp_model(out_data, input_model):
out_data: ScienceData
Computed science data from the dark current step.
input_model: RampModel
out_model: RampModel
The input ramp model from which to subtract the dark current.
Return
Expand All @@ -161,10 +166,9 @@ def dark_output_data_2_ramp_model(out_data, input_model):
if out_data.cal_step == "SKIPPED":
# If processing was skipped in the lower-level routines,
# just return the unmodified input model
input_model.meta.cal_step.dark_sub = "SKIPPED"
return input_model
out_model.meta.cal_step.dark_sub = "SKIPPED"
return out_model
else:
out_model = input_model.copy()
out_model.meta.cal_step.dark_sub = out_data.cal_step
out_model.data = out_data.data
out_model.groupdq = out_data.groupdq
Expand Down
Loading

0 comments on commit 4d60e7a

Please sign in to comment.