DataSet

class jwst.persistence.persistence.DataSet(output_obj, input_traps_filled, flag_pers_cutoff, save_persistence, trap_density_model, trappars_model, persat_model)[source]

Bases: object

Input dataset to which persistence will be applied.

Parameters:
output_objJwstDataModel

Copy of input data model object

input_traps_filledCubeModel or None

Image of trap state. There will be one or more image planes, each of which corresponds to a trap “family,” i.e., a set of traps with similar capture and decay properties. If this is None, the state will be initialized to an array of zeros, indicating that there are no filled traps.

flag_pers_cutofffloat or None

If not None, pixels will be flagged if the value of persistence that was subtracted is larger than flag_pers_cutoff.

save_persistencebool

If True, the persistence that was subtracted will be written to an output file.

trap_density_modelTrapDensityModel

Image (reference file) of the total number of traps per pixel.

trappars_modelTrapParsModel

Table (reference file) giving parameters for traps.

persat_modelPersistenceSatModel

Persistence saturation limit (full-well) reference file.

Attributes:
output_objJwstDataModel

A copy of the input model. This will be modified in-place.

traps_filledTrapsFilledModel

The trap state at some time prior to the current exposure

flag_pers_cutofffloat or None

If not None, pixels will be flagged if the value of persistence that was subtracted is larger than flag_pers_cutoff.

save_persistencebool

If True, the persistence that was subtracted will be written to an output file.

output_persJwstDataModel or None

If save_persistence is True, the amount of persistence that was subtracted will be copied to the data attribute of a data model and written to a file.

trap_densityTrapDensityModel

Reference file, giving the total number of traps per pixel.

trappars_modelTrapParsModel

Reference file (table), giving parameters for traps.

persistencesatPersistenceSatModel

Persistence saturation limit (full-well) reference file.

tframefloat

The frame time, in seconds.

tgroupfloat

The group time, in seconds.

ngroupsint

The number of groups per integration.

nframesint

The number of frames per group.

groupgapint

The number of dropped frames. Currently not used.

nresetsint

The number of resets (frames) at the beginning of each integration.

Methods Summary

compute_decay(traps_filled, decay_param, delta_t)

Compute the number of trap decays.

compute_slope(integ)

Compute an estimate of the slope of the ramp for each pixel.

delta_fcn_capture(capture_param_k, ...)

Compute number of traps filled due to cosmic-ray jumps.

do_all()

Execute all tasks for persistence correction.

get_capture_param(par, k)

Extract capture parameters for the current trap family.

get_decay_param(par, k)

Extract decay parameter(s) for the current trap family.

get_group_info(integ)

Get some metadata.

get_parameters()

Read capture and decay parameters from a reference table.

get_slice(ref, sci)

Find the 2-D slice for a reference file.

get_subarray(ref, slc)

Extract a subarray from a reference file.

predict_capture(capture_param_k, ...)

Compute the number of traps that will be filled in time dt.

predict_ramp_capture(capture_param_k, ...)

Compute the number of traps that will be filled in time dt.

predict_saturation_capture(capture_param_k, ...)

Compute number of traps filled due to saturated pixels.

ref_matches_sci(ref, slc)

Test whether ref and sci cover the same area of the detector.

Methods Documentation

compute_decay(traps_filled, decay_param, delta_t)[source]

Compute the number of trap decays.

This is based on Michael Regan’s trapdecay.pro.

Parameters:
traps_filledndarray

This is a 2-D image of the number of filled traps in each pixel for the current trap family.

decay_paramfloat

The decay parameter. This is negative, but otherwise it’s the reciprocal of the e-folding time for trap decay for the current trap family.

delta_tfloat

The time interval, in seconds, over which the trap decay is to be computed.

Returns:
decayedndarray

Image of the 2-D computed number of trap decays for each pixel, for the current trap family.

compute_slope(integ)[source]

Compute an estimate of the slope of the ramp for each pixel.

We need a value for the slope that will not include cosmic-ray jumps, and groups that are flagged as saturated must also not contribute to the slope. The approach will be to find the difference between adjacent groups, set the difference to a very large value if the group was saturated, then sort the differences along the axis for the ramp. All the saturated groups will then be at the high end. Cosmic-ray-affected groups should be just below the saturated groups (unless the effect of a CR was very small, in which case it won’t matter where it is). We can therefore ignore all the CR jumps and saturated values just by knowing how many of them there are. The average of the remaining differences is the slope.

Two arrays are returned, both giving the slope at each pixel, but with different units for the slope. The reason for returning both arrays is that there is not a single factor relating the two; the factor can differ from one pixel to another.

Parameters:
integint

The number (index) of the current integration.

Returns:
grp_slopendarray

The 2-D ramp slope in units of counts (DN) per group.

slopendarray

The 2-D ramp slope in units of fraction of the persistence saturation limit per second.

delta_fcn_capture(capture_param_k, trap_density, integ, grp_slope, ngroups, t_group)[source]

Compute number of traps filled due to cosmic-ray jumps.

If a cosmic-ray hit was in group number g (meaning that data[integ, g, y, x] was higher than expected), then:

delta_t = (ngroups - g - 0.5) * t_group

is the time from the CR-affected group to the end of the integration, assuming that the CR hit in the middle (time-wise) of the group:

cr_filled = trap_density * jump
            * (par0 * (1 - exp(-delta_t / tau)) + par2)
Parameters:
capture_param_ktuple

Three values read from a reference table. These will be from three separate columns but just one row; the row corresponds to the current trap family. (The _k in the variable name indicates that the values are for one trap family.)

trap_densityndarray

Image (2-D) of the total number of traps per pixel.

integint

Integration number.

grp_slopendarray

Array of the 2-D slope of the ramp at each pixel. The slope was computed from the pixel values that were not saturated and were not affected by jumps, based on flags in the groupdq extension. The unit is counts (DN) per group.

ngroupsint

Total number of groups in the integration.

t_groupfloat

The time (seconds) from the start of one group to the start of the next group.

Returns:
ndarray

The computed 2-D cr_filled at the end of the integration.

do_all()[source]

Execute all tasks for persistence correction.

Returns:
output_objRampModel

The persistence-corrected science data.

traps_filledTrapsFilledModel or None

A model giving the number of traps that are filled in each pixel at the end of the exposure; there will be one plane for each trap family.

output_persRampModel

A model giving the value of persistence that was subtracted from each pixel of each group of each integration.

skippedbool

This will be True if the step has been skipped.

get_capture_param(par, k)[source]

Extract capture parameters for the current trap family.

Parameters:
partuple of ndarray

These were read from the trap parameters reference table. Each element of the tuple is a column from the table. Each row of the table is for a different trap family.

kint

Index of the current trap family.

Returns:
tuple of three floats

These are the capture parameters for the current trap family.

get_decay_param(par, k)[source]

Extract decay parameter(s) for the current trap family.

Parameters:
partuple of ndarray

These were read from the trap parameters reference table. Each element of the tuple is a column from the table. Each row of the table is for a different trap family.

kint

Index of the current trap family.

Returns:
float

This is the decay parameter for the current trap family.

get_group_info(integ)[source]

Get some metadata.

This method populates these attributes:

  • tframe

  • tgroup

  • ngroups

  • nframes

  • groupgap

  • nresets

Parameters:
integint

Integration number. This is needed because the number of resets before the first integration can be different from the number of resets between integrations.

get_parameters()[source]

Read capture and decay parameters from a reference table.

Returns:
par0ndarray

Column “capture0” from the trappars table.

par1ndarray

Column “capture1” from the trappars table.

par2ndarray

Column “capture2” from the trappars table.

par3ndarray

Column “decay_param” from the trappars table.

get_slice(ref, sci)[source]

Find the 2-D slice for a reference file.

Parameters:
refJwstDataModel

A reference image.

sciJwstDataModel

The science data.

Returns:
(slice, slice)

The elements are the Y and X slices that are intended to be used to extract a subarray from the reference file.

get_subarray(ref, slc)[source]

Extract a subarray from a reference file.

Parameters:
refJwstDataModel

Reference data.

slc(slice, slice)

The Y and X slices that can be used to extract a subarray from the reference file. This was returned by method get_slice().

Returns:
refsubJwstDataModel

This is a copy of ref, but the data attribute includes only the relevant slice.

predict_capture(capture_param_k, trap_density, integ, grp_slope, slope)[source]

Compute the number of traps that will be filled in time dt.

This is based on Michael Regan’s trapcapturemodel.pro.

Parameters:
capture_param_ktuple of three floats

Three values read from a reference table. These will be from three separate columns but just one row; the row corresponds to the current trap family. (The _k in the variable name indicates that the values are for one trap family.)

trap_densityndarray

Image (2-D) of the total number of traps per pixel.

integint

Integration number.

grp_slopendarray

The 2-D slope of the ramp at each pixel, in units of counts (DN) per group. See also slope. The slope was computed from the pixel values that were not saturated and were not affected by jumps, based on flags in the groupdq extension.

slopendarray

The 2-D slope of the ramp at each pixel, in units of fraction of the persistence saturation limit per second. This is the same as grp_slope except for units.

Returns:
ndarray

The 2-D computed traps_filled at the end of the integration.

predict_ramp_capture(capture_param_k, trap_density, slope, dt)[source]

Compute the number of traps that will be filled in time dt.

This is based on Michael Regan’s predictrampcapture3.pro.

Parameters:
capture_param_ktuple

Three values read from a reference table. These will be from three separate columns but just one row; the row corresponds to the current trap family. (The _k in the variable name indicates that the values are for one trap family.)

trap_densityndarray

Image (2-D) of the total number of traps per pixel.

slopendarray

Array of the 2-D slope of the ramp at each pixel. The slope was computed from the pixel values that were not saturated and were not affected by jumps, based on flags in the groupdq extension. The unit is fraction of the persistence saturation limit per second.

dtfloat

The time interval, in seconds, over which the charge capture is to be computed. This does not include saturated groups.

Returns:
ndarray

The computed 2-D traps_filled at the end of the integration.

predict_saturation_capture(capture_param_k, trap_density, incoming_filled_traps, sattime, sat_count, ngroups)[source]

Compute number of traps filled due to saturated pixels.

This is based on Michael Regan’s predictsaturationcapture.pro.

This should not be called for ramps that do not have any groups that exceed the persistence saturation limit. One reason is that incoming_filled_traps can be so small that exp_filled_traps would be negative.

trap_density, incoming_filled_traps, sattime, and sat_count are all 2-D arrays in the method predict_capture(), but these arrays have been masked to select only ramps with at least one saturated group, so in this method, these arrays are 1-D.

Parameters:
capture_param_ktuple

Three values read from a reference table. These will be from three separate columns but just one row; the row corresponds to the current trap family. (The _k in the variable name indicates that the values are for one trap family.)

trap_densityndarray

Image of the total number of traps per pixel.

incoming_filled_trapsndarray

Traps filled due to linear portion of the ramp. This may be modified in-place.

sattimendarray

Time (seconds) during which each pixel was saturated.

sat_countndarray

For each pixel, the number of groups with value exceeding the persistence saturation limit.

ngroupsint

The number of groups in the ramp.

Returns:
ndarray

The computed 2-D traps_filled at the end of the integration.

ref_matches_sci(ref, slc)[source]

Test whether ref and sci cover the same area of the detector.

Parameters:
refJwstDataModel

Reference data.

slc(slice, slice)

The Y and X slices that can be used to extract a subarray from the reference file. This was returned by method get_slice().

Returns:
bool

True if both are full-frame or if they are the same subarray; False otherwise.