Skip to content

Commit 26bd3ba

Browse files
Apply code style rules to stpipe (#9150)
2 parents 695d774 + a86a74e commit 26bd3ba

File tree

11 files changed

+362
-304
lines changed

11 files changed

+362
-304
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ repos:
8383
jwst/skymatch/.* |
8484
jwst/spectral_leak/.* |
8585
jwst/srctype/.* |
86-
jwst/stpipe/.* |
8786
jwst/straylight/.* |
8887
jwst/superbias/.* |
8988
jwst/tests/.* |

.ruff.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ exclude = [
7979
# "jwst/source_catalog/**.py",
8080
"jwst/spectral_leak/**.py",
8181
"jwst/srctype/**.py",
82-
"jwst/stpipe/**.py",
82+
# "jwst/stpipe/**.py",
8383
"jwst/straylight/**.py",
8484
"jwst/superbias/**.py",
8585
"jwst/tests/**.py",
@@ -209,7 +209,7 @@ ignore-fully-untyped = true # Turn of annotation checking for fully untyped cod
209209
# "jwst/source_catalog/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
210210
"jwst/spectral_leak/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
211211
"jwst/srctype/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
212-
"jwst/stpipe/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
212+
# "jwst/stpipe/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
213213
"jwst/straylight/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
214214
"jwst/superbias/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
215215
"jwst/tests/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]

jwst/stpipe/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
"""JWST implementation of steps and pipelines."""
2+
13
from .core import JwstStep as Step, JwstPipeline as Pipeline
24
from .utilities import record_step_status, query_step_status
35

46

5-
__all__ = ['Step', 'Pipeline', 'record_step_status', 'query_step_status']
7+
__all__ = ["Step", "Pipeline", "record_step_status", "query_step_status"]

jwst/stpipe/core.py

Lines changed: 79 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
JWST-specific Step and Pipeline base classes.
3-
"""
1+
"""JWST-specific Step and Pipeline base classes."""
2+
43
from functools import wraps
54
import logging
65
import warnings
@@ -20,18 +19,19 @@
2019

2120

2221
class JwstStep(Step):
22+
"""A JWST pipeline step."""
2323

2424
spec = """
2525
output_ext = string(default='.fits') # Output file type
26-
""" # noqa: E501
26+
""" # noqa: E501
2727

2828
@classmethod
2929
def _datamodels_open(cls, init, **kwargs):
3030
return datamodels.open(init, **kwargs)
3131

32-
3332
def load_as_level2_asn(self, obj):
34-
"""Load object as an association
33+
"""
34+
Load object as an association.
3535
3636
Loads the specified object into a Level2 association.
3737
If necessary, prepend `Step.input_dir` to all members.
@@ -51,11 +51,12 @@ def load_as_level2_asn(self, obj):
5151
from ..associations.lib.update_path import update_key_value
5252

5353
asn = LoadAsLevel2Asn.load(obj, basename=self.output_file)
54-
update_key_value(asn, 'expname', (), mod_func=self.make_input_path)
54+
update_key_value(asn, "expname", (), mod_func=self.make_input_path)
5555
return asn
5656

5757
def load_as_level3_asn(self, obj):
58-
"""Load object as an association
58+
"""
59+
Load object as an association.
5960
6061
Loads the specified object into a Level3 association.
6162
If necessary, prepend `Step.input_dir` to all members.
@@ -75,52 +76,111 @@ def load_as_level3_asn(self, obj):
7576
from ..associations.lib.update_path import update_key_value
7677

7778
asn = LoadAsAssociation.load(obj)
78-
update_key_value(asn, 'expname', (), mod_func=self.make_input_path)
79+
update_key_value(asn, "expname", (), mod_func=self.make_input_path)
7980
return asn
8081

8182
def finalize_result(self, result, reference_files_used):
83+
"""
84+
Update the result with the software version and reference files used.
85+
86+
Parameters
87+
----------
88+
result : `~jwst.datamodels.DataModel`
89+
The output data model to be updated.
90+
reference_files_used : list of tuple
91+
The names and file paths of reference files used.
92+
"""
8293
if isinstance(result, JwstDataModel):
83-
result.meta.calibration_software_revision = __version_commit__ or 'RELEASE'
94+
result.meta.calibration_software_revision = __version_commit__ or "RELEASE"
8495
result.meta.calibration_software_version = __version__
8596

8697
if len(reference_files_used) > 0:
8798
for ref_name, filename in reference_files_used:
8899
if hasattr(result.meta.ref_file, ref_name):
89100
getattr(result.meta.ref_file, ref_name).name = filename
90101
result.meta.ref_file.crds.sw_version = crds_client.get_svn_version()
91-
result.meta.ref_file.crds.context_used = crds_client.get_context_used(result.crds_observatory)
102+
result.meta.ref_file.crds.context_used = crds_client.get_context_used(
103+
result.crds_observatory
104+
)
92105
if self.parent is None:
93106
log.info(f"Results used CRDS context: {result.meta.ref_file.crds.context_used}")
94107

95-
96108
def remove_suffix(self, name):
109+
"""
110+
Remove the suffix if a known suffix is already in name.
111+
112+
Parameters
113+
----------
114+
name : str
115+
The name to remove the suffix from.
116+
117+
Returns
118+
-------
119+
name : str
120+
The name with the suffix removed.
121+
"""
97122
return remove_suffix(name)
98123

99124
@wraps(Step.run)
100125
def run(self, *args, **kwargs):
126+
"""
127+
Run the step.
128+
129+
Parameters
130+
----------
131+
*args
132+
Arguments passed to `stpipe.Step.run`.
133+
**kwargs
134+
Keyword arguments passed to `stpipe.Step.run`.
135+
136+
Returns
137+
-------
138+
result : Any
139+
The step output
140+
"""
101141
result = super().run(*args, **kwargs)
102142
if not self.parent:
103143
log.info(f"Results used jwst version: {__version__}")
104144
return result
105145

106146
@wraps(Step.__call__)
107-
def __call__(self, *args, **kwargs):
147+
def __call__(self, *args, **kwargs): # numpydoc ignore=RT01
148+
"""Deprecated method. Use `run` instead.""" # noqa: D401
108149
if not self.parent:
109150
warnings.warn(
110151
"Step.__call__ is deprecated. It is equivalent to Step.run "
111152
"and is not recommended. See "
112153
"https://jwst-pipeline.readthedocs.io/en/latest/jwst/"
113154
"user_documentation/running_pipeline_python.html"
114155
"#advanced-use-pipeline-run-vs-pipeline-call for more details.",
115-
UserWarning
156+
UserWarning,
157+
stacklevel=2,
116158
)
117159
return super().__call__(*args, **kwargs)
118160

119161

120-
# JwstPipeline needs to inherit from Pipeline, but also
121-
# be a subclass of JwstStep so that it will pass checks
122-
# when constructing a pipeline using JwstStep class methods.
123162
class JwstPipeline(Pipeline, JwstStep):
124-
def finalize_result(self, result, reference_files_used):
163+
"""
164+
A JWST pipeline.
165+
166+
JwstPipeline needs to inherit from Pipeline, but also
167+
be a subclass of JwstStep so that it will pass checks
168+
when constructing a pipeline using JwstStep class methods.
169+
"""
170+
171+
def finalize_result(self, result, _reference_files_used):
172+
"""
173+
Update the result with the software version and reference files used.
174+
175+
Parameters
176+
----------
177+
result : `~jwst.datamodels.DataModel`
178+
The output data model to be updated.
179+
_reference_files_used : list of tuple
180+
The names and file paths of reference files used.
181+
"""
125182
if isinstance(result, JwstDataModel):
126-
log.info(f"Results used CRDS context: {crds_client.get_context_used(result.crds_observatory)}")
183+
log.info(
184+
"Results used CRDS context: "
185+
f"{crds_client.get_context_used(result.crds_observatory)}"
186+
)

jwst/stpipe/integration.py

Lines changed: 77 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
"""
2-
Entry point implementations.
3-
"""
1+
"""Entry point implementations."""
42

53

64
def get_steps():
75
"""
8-
Return tuples describing the stpipe.Step subclasses provided
9-
by this package. This method is registered with the stpipe.steps
6+
Return tuples describing the stpipe.Step subclasses provided by this package.
7+
8+
This method is registered with the stpipe.steps
109
entry point.
1110
1211
Returns
@@ -21,77 +20,77 @@ def get_steps():
2120
# class definitions. We need to avoid importing jwst.pipeline and
2221
# jwst.step to keep the CLI snappy.
2322
return [
24-
("jwst.pipeline.Ami3Pipeline", 'calwebb_ami3', True),
25-
("jwst.pipeline.Coron3Pipeline", 'calwebb_coron3', True),
26-
("jwst.pipeline.DarkPipeline", 'calwebb_dark', True),
27-
("jwst.pipeline.Detector1Pipeline", 'calwebb_detector1', True),
28-
("jwst.pipeline.GuiderPipeline", 'calwebb_guider', True),
29-
("jwst.pipeline.Image2Pipeline", 'calwebb_image2', True),
30-
("jwst.pipeline.Image3Pipeline", 'calwebb_image3', True),
31-
("jwst.pipeline.Spec2Pipeline", 'calwebb_spec2', True),
32-
("jwst.pipeline.Spec3Pipeline", 'calwebb_spec3', True),
33-
("jwst.pipeline.Tso3Pipeline", 'calwebb_tso3', True),
34-
("jwst.step.AmiAnalyzeStep", 'ami_analyze', False),
35-
("jwst.step.AmiAverageStep", 'ami_average', False),
36-
("jwst.step.AmiNormalizeStep", 'ami_normalize', False),
37-
("jwst.step.AssignMTWcsStep", 'assign_mtwcs', False),
38-
("jwst.step.AssignWcsStep", 'assign_wcs', False),
39-
("jwst.step.BackgroundStep", 'background', False),
40-
("jwst.step.BadpixSelfcalStep", 'badpix_selfcal', False),
41-
("jwst.step.BarShadowStep", 'barshadow', False),
42-
("jwst.step.Combine1dStep", 'combine_1d', False),
43-
("jwst.step.StackRefsStep", 'stack_refs', False),
44-
("jwst.step.AlignRefsStep", 'align_refs', False),
45-
("jwst.step.KlipStep", 'klip', False),
46-
("jwst.step.HlspStep", 'hlsp', False),
47-
("jwst.step.CleanFlickerNoiseStep", 'clean_flicker_noise', False),
48-
("jwst.step.CubeBuildStep", 'cube_build', False),
49-
("jwst.step.CubeSkyMatchStep", 'cube_skymatch', False),
50-
("jwst.step.DarkCurrentStep", 'dark_current', False),
51-
("jwst.step.DQInitStep", 'dq_init', False),
52-
("jwst.step.EmiCorrStep", 'emicorr', False),
53-
("jwst.step.Extract1dStep", 'extract_1d', False),
54-
("jwst.step.Extract2dStep", 'extract_2d', False),
55-
("jwst.step.FirstFrameStep", 'firstframe', False),
56-
("jwst.step.FlatFieldStep", 'flat_field', False),
57-
("jwst.step.FringeStep", 'fringe', False),
58-
("jwst.step.GainScaleStep", 'gain_scale', False),
59-
("jwst.step.GroupScaleStep", 'group_scale', False),
60-
("jwst.step.GuiderCdsStep", 'guider_cds', False),
61-
("jwst.step.ImprintStep", 'imprint', False),
62-
("jwst.step.IPCStep", 'ipc', False),
63-
("jwst.step.JumpStep", 'jump', False),
64-
("jwst.step.LastFrameStep", 'lastframe', False),
65-
("jwst.step.LinearityStep", 'linearity', False),
66-
("jwst.step.MasterBackgroundStep", 'master_background', False),
67-
("jwst.step.MasterBackgroundMosStep", 'master_background_mos', False),
68-
("jwst.step.MRSIMatchStep", 'mrs_imatch', False),
69-
("jwst.step.MSAFlagOpenStep", 'msa_flagging', False),
70-
("jwst.step.NSCleanStep", 'nsclean', False),
71-
("jwst.step.OutlierDetectionStep", 'outlier_detection', False),
72-
("jwst.step.PathLossStep", 'pathloss', False),
73-
("jwst.step.PersistenceStep", 'persistence', False),
74-
("jwst.step.PhotomStep", 'photom', False),
75-
("jwst.step.PixelReplaceStep", 'pixel_replace', False),
76-
("jwst.step.RampFitStep", 'ramp_fit', False),
77-
("jwst.step.RefPixStep", 'refpix', False),
78-
("jwst.step.ResampleStep", 'resample', False),
79-
("jwst.step.ResampleSpecStep", 'resample_spec', False),
80-
("jwst.step.ResetStep", 'reset', False),
81-
("jwst.step.ResidualFringeStep", 'residual_fringe', False),
82-
("jwst.step.RscdStep", 'rscd', False),
83-
("jwst.step.SaturationStep", 'saturation', False),
84-
("jwst.step.SkyMatchStep", 'skymatch', False),
85-
("jwst.step.SourceCatalogStep", 'source_catalog', False),
86-
("jwst.step.SourceTypeStep", 'srctype', False),
87-
("jwst.step.SpectralLeakStep", 'spectral_leak', False),
88-
("jwst.step.StraylightStep", 'straylight', False),
89-
("jwst.step.SuperBiasStep", 'superbias', False),
90-
("jwst.step.TSOPhotometryStep", 'tso_photometry', False),
91-
("jwst.step.TweakRegStep", 'tweakreg', False),
92-
("jwst.step.ChargeMigrationStep", 'charge_migration', False),
93-
("jwst.step.WavecorrStep", 'wavecorr', False),
94-
("jwst.step.WfsCombineStep", 'calwebb_wfs-image3', False),
95-
("jwst.step.WfssContamStep", 'wfss_contam', False),
96-
("jwst.step.WhiteLightStep", 'white_light', False),
23+
("jwst.pipeline.Ami3Pipeline", "calwebb_ami3", True),
24+
("jwst.pipeline.Coron3Pipeline", "calwebb_coron3", True),
25+
("jwst.pipeline.DarkPipeline", "calwebb_dark", True),
26+
("jwst.pipeline.Detector1Pipeline", "calwebb_detector1", True),
27+
("jwst.pipeline.GuiderPipeline", "calwebb_guider", True),
28+
("jwst.pipeline.Image2Pipeline", "calwebb_image2", True),
29+
("jwst.pipeline.Image3Pipeline", "calwebb_image3", True),
30+
("jwst.pipeline.Spec2Pipeline", "calwebb_spec2", True),
31+
("jwst.pipeline.Spec3Pipeline", "calwebb_spec3", True),
32+
("jwst.pipeline.Tso3Pipeline", "calwebb_tso3", True),
33+
("jwst.step.AmiAnalyzeStep", "ami_analyze", False),
34+
("jwst.step.AmiAverageStep", "ami_average", False),
35+
("jwst.step.AmiNormalizeStep", "ami_normalize", False),
36+
("jwst.step.AssignMTWcsStep", "assign_mtwcs", False),
37+
("jwst.step.AssignWcsStep", "assign_wcs", False),
38+
("jwst.step.BackgroundStep", "background", False),
39+
("jwst.step.BadpixSelfcalStep", "badpix_selfcal", False),
40+
("jwst.step.BarShadowStep", "barshadow", False),
41+
("jwst.step.Combine1dStep", "combine_1d", False),
42+
("jwst.step.StackRefsStep", "stack_refs", False),
43+
("jwst.step.AlignRefsStep", "align_refs", False),
44+
("jwst.step.KlipStep", "klip", False),
45+
("jwst.step.HlspStep", "hlsp", False),
46+
("jwst.step.CleanFlickerNoiseStep", "clean_flicker_noise", False),
47+
("jwst.step.CubeBuildStep", "cube_build", False),
48+
("jwst.step.CubeSkyMatchStep", "cube_skymatch", False),
49+
("jwst.step.DarkCurrentStep", "dark_current", False),
50+
("jwst.step.DQInitStep", "dq_init", False),
51+
("jwst.step.EmiCorrStep", "emicorr", False),
52+
("jwst.step.Extract1dStep", "extract_1d", False),
53+
("jwst.step.Extract2dStep", "extract_2d", False),
54+
("jwst.step.FirstFrameStep", "firstframe", False),
55+
("jwst.step.FlatFieldStep", "flat_field", False),
56+
("jwst.step.FringeStep", "fringe", False),
57+
("jwst.step.GainScaleStep", "gain_scale", False),
58+
("jwst.step.GroupScaleStep", "group_scale", False),
59+
("jwst.step.GuiderCdsStep", "guider_cds", False),
60+
("jwst.step.ImprintStep", "imprint", False),
61+
("jwst.step.IPCStep", "ipc", False),
62+
("jwst.step.JumpStep", "jump", False),
63+
("jwst.step.LastFrameStep", "lastframe", False),
64+
("jwst.step.LinearityStep", "linearity", False),
65+
("jwst.step.MasterBackgroundStep", "master_background", False),
66+
("jwst.step.MasterBackgroundMosStep", "master_background_mos", False),
67+
("jwst.step.MRSIMatchStep", "mrs_imatch", False),
68+
("jwst.step.MSAFlagOpenStep", "msa_flagging", False),
69+
("jwst.step.NSCleanStep", "nsclean", False),
70+
("jwst.step.OutlierDetectionStep", "outlier_detection", False),
71+
("jwst.step.PathLossStep", "pathloss", False),
72+
("jwst.step.PersistenceStep", "persistence", False),
73+
("jwst.step.PhotomStep", "photom", False),
74+
("jwst.step.PixelReplaceStep", "pixel_replace", False),
75+
("jwst.step.RampFitStep", "ramp_fit", False),
76+
("jwst.step.RefPixStep", "refpix", False),
77+
("jwst.step.ResampleStep", "resample", False),
78+
("jwst.step.ResampleSpecStep", "resample_spec", False),
79+
("jwst.step.ResetStep", "reset", False),
80+
("jwst.step.ResidualFringeStep", "residual_fringe", False),
81+
("jwst.step.RscdStep", "rscd", False),
82+
("jwst.step.SaturationStep", "saturation", False),
83+
("jwst.step.SkyMatchStep", "skymatch", False),
84+
("jwst.step.SourceCatalogStep", "source_catalog", False),
85+
("jwst.step.SourceTypeStep", "srctype", False),
86+
("jwst.step.SpectralLeakStep", "spectral_leak", False),
87+
("jwst.step.StraylightStep", "straylight", False),
88+
("jwst.step.SuperBiasStep", "superbias", False),
89+
("jwst.step.TSOPhotometryStep", "tso_photometry", False),
90+
("jwst.step.TweakRegStep", "tweakreg", False),
91+
("jwst.step.ChargeMigrationStep", "charge_migration", False),
92+
("jwst.step.WavecorrStep", "wavecorr", False),
93+
("jwst.step.WfsCombineStep", "calwebb_wfs-image3", False),
94+
("jwst.step.WfssContamStep", "wfss_contam", False),
95+
("jwst.step.WhiteLightStep", "white_light", False),
9796
]

jwst/stpipe/tests/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
import io
2-
3-
4-
def setup():
5-
from jwst.stpipe import log
6-
7-
# Turn off default logging when running tests
8-
buffer = io.BytesIO(b"[*]\n")
9-
10-
log.load_configuration(buffer)

0 commit comments

Comments
 (0)