|
8 | 8 |
|
9 | 9 | import numpy as np
|
10 | 10 | import logging
|
11 |
| - |
| 11 | +from jwst import datamodels |
12 | 12 | from stdatamodels.jwst.datamodels import dqflags
|
13 | 13 | from astropy.stats import sigma_clipped_stats as scs
|
14 | 14 | from astropy.convolution import convolve_fft, Gaussian2DKernel
|
@@ -230,7 +230,7 @@ def correct_xartifact(input_model, modelpars):
|
230 | 230 | return input_model
|
231 | 231 |
|
232 | 232 | def clean_showers(input_model, allregions, shower_plane=3, shower_x_stddev=18.0, shower_y_stddev=5.0,
|
233 |
| - shower_low_reject=0.1, shower_high_reject=99.9): |
| 233 | + shower_low_reject=0.1, shower_high_reject=99.9, save_shower_model=False): |
234 | 234 | """
|
235 | 235 | Corrects the MIRI MRS data for straylight produced by residual cosmic ray showers.
|
236 | 236 |
|
@@ -298,7 +298,44 @@ def clean_showers(input_model, allregions, shower_plane=3, shower_x_stddev=18.0,
|
298 | 298 | # Subtract the shower model from the original data
|
299 | 299 | input_model.data = input_model.data - shower_model
|
300 | 300 |
|
| 301 | + if save_shower_model: |
| 302 | + output_shower_model = _make_intermediate_model(input_model, shower_model) |
| 303 | + else: |
| 304 | + output_shower_model = None |
| 305 | + |
301 | 306 | # Delete our temporary working copy of the data
|
302 | 307 | del usedata
|
303 | 308 |
|
304 |
| - return input_model |
| 309 | + return input_model, output_shower_model |
| 310 | + |
| 311 | + |
| 312 | +def _make_intermediate_model(input_model, intermediate_data): |
| 313 | + """ |
| 314 | + Make a data model to contain intermediate outputs. |
| 315 | +
|
| 316 | + The output model type depends on the shape of the input |
| 317 | + intermediate data. |
| 318 | +
|
| 319 | + Parameters |
| 320 | + ---------- |
| 321 | + input_model : `~jwst.datamodel.JwstDataModel` |
| 322 | + The input data. |
| 323 | + intermediate_data : array-like |
| 324 | + The intermediate data to save. |
| 325 | +
|
| 326 | + Returns |
| 327 | + ------- |
| 328 | + intermediate_model : ~jwst.datamodel.JwstDataModel` |
| 329 | + A model containing only the intermediate data and top-level |
| 330 | + metadata matching the input. |
| 331 | + """ |
| 332 | + if intermediate_data.ndim == 4: |
| 333 | + intermediate_model = datamodels.RampModel(data=intermediate_data) |
| 334 | + elif intermediate_data.ndim == 3: |
| 335 | + intermediate_model = datamodels.CubeModel(data=intermediate_data) |
| 336 | + else: |
| 337 | + intermediate_model = datamodels.ImageModel(data=intermediate_data) |
| 338 | + |
| 339 | + # Copy metadata from input model |
| 340 | + intermediate_model.update(input_model) |
| 341 | + return intermediate_model |
0 commit comments