Skip to content

Commit edfab6f

Browse files
committed
Code style updates for nsclean
1 parent 9720238 commit edfab6f

File tree

4 files changed

+73
-70
lines changed

4 files changed

+73
-70
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ repos:
6868
jwst/model_blender/.* |
6969
jwst/mrs_imatch/.* |
7070
jwst/msaflagopen/.* |
71-
jwst/nsclean/.* |
7271
jwst/outlier_detection/.* |
7372
jwst/pathloss/.* |
7473
jwst/persistence/.* |

.ruff.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ exclude = [
6161
"jwst/model_blender/**.py",
6262
"jwst/mrs_imatch/**.py",
6363
"jwst/msaflagopen/**.py",
64-
"jwst/nsclean/**.py",
64+
#"jwst/nsclean/**.py",
6565
"jwst/outlier_detection/**.py",
6666
"jwst/pathloss/**.py",
6767
"jwst/persistence/**.py",
@@ -188,7 +188,7 @@ ignore-fully-untyped = true # Turn of annotation checking for fully untyped cod
188188
"jwst/model_blender/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
189189
"jwst/mrs_imatch/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
190190
"jwst/msaflagopen/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
191-
"jwst/nsclean/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
191+
#"jwst/nsclean/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
192192
"jwst/outlier_detection/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
193193
"jwst/pathloss/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
194194
"jwst/persistence/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]

jwst/nsclean/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Correct NIRSpec rate data for 1/f noise."""
2+
13
from .nsclean_step import NSCleanStep
24

3-
__all__ = ['NSCleanStep']
5+
__all__ = ["NSCleanStep"]

jwst/nsclean/nsclean_step.py

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,60 @@
88

99
class NSCleanStep(Step):
1010
"""
11+
Perform 1/f noise correction.
12+
1113
NSCleanStep: This step performs 1/f noise correction ("cleaning")
1214
of NIRSpec images, using the "NSClean" method.
1315
1416
NOTE: This step is a deprecated alias to the ``clean_flicker_noise`` step.
17+
18+
Attributes
19+
----------
20+
fit_method : str, optional
21+
The background fit algorithm to use. Options are 'fft' and 'median';
22+
'fft' performs the original NSClean implementation.
23+
fit_by_channel : bool, optional
24+
If set, flicker noise is fit independently for each detector channel.
25+
Ignored for subarray data and for `fit_method` = 'fft'.
26+
background_method : {'median', 'model', None}
27+
If 'median', the preliminary background to remove and restore
28+
is a simple median of the background data. If 'model', the
29+
background data is fit with a low-resolution model via
30+
`~photutils.background.Background2D`. If None, the background
31+
value is 0.0.
32+
background_box_size : tuple of int, optional
33+
Box size for the data grid used by `Background2D` when
34+
`background_method` = 'model'. For best results, use a box size
35+
that evenly divides the input image shape.
36+
mask_spectral_regions : bool, optional
37+
Mask regions of the image defined by WCS bounding boxes for slits/slices.
38+
n_sigma : float, optional
39+
Sigma clipping threshold to be used in detecting outliers in the image.
40+
fit_histogram : bool, optional
41+
If set, the 'sigma' used with `n_sigma` for clipping outliers
42+
is derived from a Gaussian fit to a histogram of values.
43+
Otherwise, a simple iterative sigma clipping is performed.
44+
single_mask : bool, optional
45+
If set, a single mask will be created, regardless of
46+
the number of input integrations. Otherwise, the mask will
47+
be a 3D cube, with one plane for each integration.
48+
user_mask : None, str, or `~jwst.datamodels.ImageModel`
49+
Optional user-supplied mask image; path to file or opened datamodel.
50+
save_mask : bool, optional
51+
Save the computed mask image.
52+
save_background : bool, optional
53+
Save the computed background image.
54+
save_noise : bool, optional
55+
Save the computed noise image.
1556
"""
1657

1758
class_alias = "nsclean"
1859

1960
spec = """
2061
fit_method = option('fft', 'median', default='fft') # Noise fitting algorithm
2162
fit_by_channel = boolean(default=False) # Fit noise separately by amplifier
22-
background_method = option('median', 'model', None, default=None) # Background fitting algorithm
23-
background_box_size = int_list(min=2, max=2, default=None) # Background box size for modeled background
63+
background_method = option('median', 'model', None, default=None) # Background fit
64+
background_box_size = int_list(min=2, max=2, default=None) # Background box size
2465
mask_spectral_regions = boolean(default=True) # Mask WCS-defined spectral regions
2566
n_sigma = float(default=5.0) # Clipping level for outliers
2667
fit_histogram = boolean(default=False) # Fit a value histogram to derive sigma
@@ -32,75 +73,28 @@ class NSCleanStep(Step):
3273
skip = boolean(default=True) # By default, skip the step
3374
"""
3475

35-
def process(self, input):
76+
def process(self, input_data):
3677
"""
37-
Fit and subtract 1/f background noise from a NIRSpec image
78+
Fit and subtract 1/f background noise from a NIRSpec image.
3879
3980
Parameters
4081
----------
41-
input : `~jwst.datamodels.ImageModel`, `~jwst.datamodels.IFUImageModel`
82+
input_data : `~jwst.datamodels.ImageModel`, `~jwst.datamodels.IFUImageModel`
4283
Input datamodel to be corrected.
4384
44-
fit_method : str, optional
45-
The background fit algorithm to use. Options are 'fft' and 'median';
46-
'fft' performs the original NSClean implementation.
47-
48-
fit_by_channel : bool, optional
49-
If set, flicker noise is fit independently for each detector channel.
50-
Ignored for subarray data and for `fit_method` = 'fft'.
51-
52-
background_method : {'median', 'model', None}
53-
If 'median', the preliminary background to remove and restore
54-
is a simple median of the background data. If 'model', the
55-
background data is fit with a low-resolution model via
56-
`~photutils.background.Background2D`. If None, the background
57-
value is 0.0.
58-
59-
background_box_size : tuple of int, optional
60-
Box size for the data grid used by `Background2D` when
61-
`background_method` = 'model'. For best results, use a box size
62-
that evenly divides the input image shape.
63-
64-
mask_spectral_regions : bool, optional
65-
Mask regions of the image defined by WCS bounding boxes for slits/slices.
66-
67-
n_sigma : float, optional
68-
Sigma clipping threshold to be used in detecting outliers in the image.
69-
70-
fit_histogram : bool, optional
71-
If set, the 'sigma' used with `n_sigma` for clipping outliers
72-
is derived from a Gaussian fit to a histogram of values.
73-
Otherwise, a simple iterative sigma clipping is performed.
74-
75-
single_mask : bool, optional
76-
If set, a single mask will be created, regardless of
77-
the number of input integrations. Otherwise, the mask will
78-
be a 3D cube, with one plane for each integration.
79-
80-
user_mask : None, str, or `~jwst.datamodels.ImageModel`
81-
Optional user-supplied mask image; path to file or opened datamodel.
82-
83-
save_mask : bool, optional
84-
Save the computed mask image.
85-
86-
save_background : bool, optional
87-
Save the computed background image.
88-
89-
save_noise : bool, optional
90-
Save the computed noise image.
91-
9285
Returns
9386
-------
9487
output_model : `~jwst.datamodels.ImageModel`, `~jwst.datamodels.IFUImageModel`
9588
The 1/f corrected datamodel.
9689
"""
97-
message = ("The 'nsclean' step is a deprecated alias to 'clean_flicker_noise' "
98-
"and will be removed in future builds.")
90+
message = (
91+
"The 'nsclean' step is a deprecated alias to 'clean_flicker_noise' "
92+
"and will be removed in future builds."
93+
)
9994
self.log.warning(message)
10095

10196
# Open the input data model
102-
with datamodels.open(input) as input_model:
103-
97+
with datamodels.open(input_data) as input_model:
10498
# clean_flicker_noise allows flat handling, but NIRSpec is
10599
# not supported via CRDS files, since it does not have a full
106100
# frame flat. Since this step is for NIRSpec only, don't allow
@@ -109,37 +103,45 @@ def process(self, input):
109103

110104
# Do the NSClean correction
111105
result = clean_flicker_noise.do_correction(
112-
input_model, input_dir=self.input_dir, fit_method=self.fit_method,
106+
input_model,
107+
input_dir=self.input_dir,
108+
fit_method=self.fit_method,
113109
fit_by_channel=self.fit_by_channel,
114110
background_method=self.background_method,
115111
background_box_size=self.background_box_size,
116112
mask_science_regions=self.mask_spectral_regions,
117-
flat_filename=flat_filename, n_sigma=self.n_sigma,
118-
fit_histogram=self.fit_histogram, single_mask=self.single_mask,
119-
user_mask=self.user_mask, save_mask=self.save_mask,
120-
save_background=self.save_background, save_noise=self.save_noise)
113+
flat_filename=flat_filename,
114+
n_sigma=self.n_sigma,
115+
fit_histogram=self.fit_histogram,
116+
single_mask=self.single_mask,
117+
user_mask=self.user_mask,
118+
save_mask=self.save_mask,
119+
save_background=self.save_background,
120+
save_noise=self.save_noise,
121+
)
121122
output_model, mask_model, background_model, noise_model, status = result
122123

123124
# Save the mask, if requested
124125
if self.save_mask and mask_model is not None:
125-
mask_path = self.make_output_path(
126-
basepath=input_model.meta.filename, suffix='mask')
126+
mask_path = self.make_output_path(basepath=input_model.meta.filename, suffix="mask")
127127
self.log.info(f"Saving mask file {mask_path}")
128128
mask_model.save(mask_path)
129129
mask_model.close()
130130

131131
# Save the background, if requested
132132
if self.save_background and background_model is not None:
133133
bg_path = self.make_output_path(
134-
basepath=input_model.meta.filename, suffix='flicker_bkg')
134+
basepath=input_model.meta.filename, suffix="flicker_bkg"
135+
)
135136
self.log.info(f"Saving background file {bg_path}")
136137
background_model.save(bg_path)
137138
background_model.close()
138139

139140
# Save the noise, if requested
140141
if self.save_noise and noise_model is not None:
141142
noise_path = self.make_output_path(
142-
basepath=input_model.meta.filename, suffix='flicker_noise')
143+
basepath=input_model.meta.filename, suffix="flicker_noise"
144+
)
143145
self.log.info(f"Saving noise file {noise_path}")
144146
noise_model.save(noise_path)
145147
noise_model.close()

0 commit comments

Comments
 (0)