8000 Apply code style rules to stpipe by emolter · Pull Request #9150 · spacetelescope/jwst · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Apply code style rules to stpipe #9150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ repos:
jwst/skymatch/.* |
jwst/spectral_leak/.* |
jwst/srctype/.* |
jwst/stpipe/.* |
jwst/straylight/.* |
jwst/superbias/.* |
jwst/tests/.* |
Expand Down
4 changes: 2 additions & 2 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ exclude = [
# "jwst/source_catalog/**.py",
"jwst/spectral_leak/**.py",
"jwst/srctype/**.py",
"jwst/stpipe/**.py",
# "jwst/stpipe/**.py",
"jwst/straylight/**.py",
"jwst/superbias/**.py",
"jwst/tests/**.py",
Expand Down Expand Up @@ -209,7 +209,7 @@ ignore-fully-untyped = true # Turn of annotation checking for fully untyped cod
# "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"]
"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"]
"jwst/srctype/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/stpipe/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
# "jwst/stpipe/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/straylight/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/superbias/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/tests/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
Expand Down
4 changes: 3 additions & 1 deletion jwst/stpipe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""JWST implementation of steps and pipelines."""

from .core import JwstStep as Step, JwstPipeline as Pipeline
from .utilities import record_step_status, query_step_status


__all__ = ['Step', 'Pipeline', 'record_step_status', 'query_step_status']
__all__ = ["Step", "Pipeline", "record_step_status", "query_step_status"]
98 changes: 79 additions & 19 deletions jwst/stpipe/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
JWST-specific Step and Pipeline base classes.
"""
"""JWST-specific Step and Pipeline base classes."""

from functools import wraps
import logging
import warnings
Expand All @@ -20,18 +19,19 @@


class JwstStep(Step):
"""A JWST pipeline step."""

spec = """
output_ext = string(default='.fits') # Output file type
""" # noqa: E501
""" # noqa: E501

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


def load_as_level2_asn(self, obj):
"""Load object as an association
"""
Load object as an association.

Loads the specified object into a Level2 association.
If necessary, prepend `Step.input_dir` to all members.
Expand All @@ -51,11 +51,12 @@ def load_as_level2_asn(self, obj):
from ..associations.lib.update_path import update_key_value

asn = LoadAsLevel2Asn.load(obj, basename=self.output_file)
update_key_value(asn, 'expname', (), mod_func=self.make_input_path)
update_key_value(asn, "expname", (), mod_func=self.make_input_path)
return asn

def load_as_level3_asn(self, obj):
"""Load object as an association
"""
Load object as an association.

Loads the specified object into a Level3 association.
If necessary, prepend `Step.input_dir` to all members.
Expand All @@ -75,52 +76,111 @@ def load_as_level3_asn(self, obj):
from ..associations.lib.update_path import update_key_value

asn = LoadAsAssociation.load(obj)
update_key_value(asn, 'expname', (), mod_func=self.make_input_path)
update_key_value(asn, "expname", (), mod_func=self.make_input_path)
return asn

def finalize_result(self, result, reference_files_used):
"""
Update the result with the software version and reference files used.

Parameters
----------
result : `~jwst.datamodels.DataModel`
The output data model to be updated.
reference_files_used : list of tuple
The names and file paths of reference files used.
"""
if isinstance(result, JwstDataModel):
result.meta.calibration_software_revision = __version_commit__ or 'RELEASE'
result.meta.calibration_software_revision = __version_commit__ or "RELEASE"
result.meta.calibration_software_version = __version__

if len(reference_files_used) > 0:
for ref_name, filename in reference_files_used:
if hasattr(result.meta.ref_file, ref_name):
getattr(result.meta.ref_file, ref_name).name = filename
result.meta.ref_file.crds.sw_version = crds_client.get_svn_version()
result.meta.ref_file.crds.context_used = crds_client.get_context_used(result.crds_observatory)
result.meta.ref_file.crds.context_used = crds_client.get_context_used(
result.crds_observatory
)
if self.parent is None:
log.info(f"Results used CRDS context: {result.meta.ref_file.crds.context_used}")


def remove_suffix(self, name):
"""
Remove the suffix if a known suffix is already in name.

Parameters
----------
name : str
The name to remove the suffix from.

Returns
-------
name : str
The name with the suffix removed.
"""
return remove_suffix(name)

@wraps(Step.run)
def run(self, *args, **kwargs):
"""
Run the step.

Parameters
----------
*args
Arguments passed to `stpipe.Step.run`.
**kwargs
Keyword arguments passed to `stpipe.Step.run`.

Returns
-------
result : Any
The step output
"""
result = super().run(*args, **kwargs)
if not self.parent:
log.info(f"Results used jwst version: {__version__}")
return result

@wraps(Step.__call__)
def __call__(self, *args, **kwargs):
def __call__(self, *args, **kwargs): # numpydoc ignore=RT01
"""Deprecated method. Use `run` instead.""" # noqa: D401
if not self.parent:
warnings.warn(
"Step.__call__ is deprecated. It is equivalent to Step.run "
"and is not recommended. See "
"https://jwst-pipeline.readthedocs.io/en/latest/jwst/"
"user_documentation/running_pipeline_python.html"
"#advanced-use-pipeline-run-vs-pipeline-call for more details.",
UserWarning
UserWarning,
stacklevel=2,
)
return super().__call__(*args, **kwargs)


# JwstPipeline needs to inherit from Pipeline, but also
# be a subclass of JwstStep so that it will pass checks
# when constructing a pipeline using JwstStep class methods.
class JwstPipeline(Pipeline, JwstStep):
def finalize_result(self, result, reference_files_used):
"""
A JWST pipeline.

JwstPipeline needs to inherit from Pipeline, but also
be a subclass of JwstStep so that it will pass checks
when constructing a pipeline using JwstStep class methods.
"""

def finalize_result(self, result, _reference_files_used):
"""
Update the result with the software version and reference files used.

Parameters
----------
result : `~jwst.datamodels.DataModel`
The output data model to be updated.
_reference_files_used : list of tuple
The names and file paths of reference files used.
"""
if isinstance(result, JwstDataModel):
log.info(f"Results used CRDS context: {crds_client.get_context_used(result.crds_observatory)}")
log.info(
"Results used CRDS context: "
f"{crds_client.get_context_used(result.crds_observatory)}"
)
155 changes: 77 additions & 78 deletions jwst/stpipe/integration.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""
Entry point implementations.
"""
"""Entry point implementations."""


def get_steps():
"""
Return tuples describing the stpipe.Step subclasses provided
by this package. This method is registered with the stpipe.steps
Return tuples describing the stpipe.Step subclasses provided by this package.

This method is registered with the stpipe.steps
entry point.

Returns
Expand All @@ -21,77 +20,77 @@ def get_steps():
# class definitions. We need to avoid importing jwst.pipeline and
# jwst.step to keep the CLI snappy.
return [
("jwst.pipeline.Ami3Pipeline", 'calwebb_ami3', True),
("jwst.pipeline.Coron3Pipeline", 'calwebb_coron3', True),
("jwst.pipeline.DarkPipeline", 'calwebb_dark', True),
("jwst.pipeline.Detector1Pipeline", 'calwebb_detector1', True),
("jwst.pipeline.GuiderPipeline", 'calwebb_guider', True),
("jwst.pipeline.Image2Pipeline", 'calwebb_image2', True),
("jwst.pipeline.Image3Pipeline", 'calwebb_image3', True),
("jwst.pipeline.Spec2Pipeline", 'calwebb_spec2', True),
("jwst.pipeline.Spec3Pipeline", 'calwebb_spec3', True),
("jwst.pipeline.Tso3Pipeline", 'calwebb_tso3', True),
("jwst.step.AmiAnalyzeStep", 'ami_analyze', False),
("jwst.step.AmiAverageStep", 'ami_average', False),
("jwst.step.AmiNormalizeStep", 'ami_normalize', False),
("jwst.step.AssignMTWcsStep", 'assign_mtwcs', False),
("jwst.step.AssignWcsStep", 'assign_wcs', False),
("jwst.step.BackgroundStep", 'background', False),
("jwst.step.BadpixSelfcalStep", 'badpix_selfcal', False),
("jwst.step.BarShadowStep", 'barshadow', False),
("jwst.step.Combine1dStep", 'combine_1d', False),
("jwst.step.StackRefsStep", 'stack_refs', False),
("jwst.step.AlignRefsStep", 'align_refs', False),
("jwst.step.KlipStep", 'klip', False),
("jwst.step.HlspStep", 'hlsp', False),
("jwst.step.CleanFlickerNoiseStep", 'clean_flicker_noise', False),
("jwst.step.CubeBuildStep", 'cube_build', False),
("jwst.step.CubeSkyMatchStep", 'cube_skymatch', False),
("jwst.step.DarkCurrentStep", 'dark_current', False),
("jwst.step.DQInitStep", 'dq_init', False),
("jwst.step.EmiCorrStep", 'emicorr', False),
("jwst.step.Extract1dStep", 'extract_1d', False),
("jwst.step.Extract2dStep", 'extract_2d', False),
("jwst.step.FirstFrameStep", 'firstframe', False),
("jwst.step.FlatFieldStep", 'flat_field', False),
("jwst.step.FringeStep", 'fringe', False),
("jwst.step.GainScaleStep", 'gain_scale', False),
("jwst.step.GroupScaleStep", 'group_scale', False),
("jwst.step.GuiderCdsStep", 'guider_cds', False),
("jwst.step.ImprintStep", 'imprint', False),
("jwst.step.IPCStep", 'ipc', False),
("jwst.step.JumpStep", 'jump', False),
("jwst.step.LastFrameStep", 'lastframe', False),
("jwst.step.LinearityStep", 'linearity', False),
("jwst.step.MasterBackgroundStep", 'master_background', False),
("jwst.step.MasterBackgroundMosStep", 'master_background_mos', False),
("jwst.step.MRSIMatchStep", 'mrs_imatch', False),
("jwst.step.MSAFlagOpenStep", 'msa_flagging', False),
("jwst.step.NSCleanStep", 'nsclean', False),
("jwst.step.OutlierDetectionStep", 'outlier_detection', False),
("jwst.step.PathLossStep", 'pathloss', False),
("jwst.step.PersistenceStep", 'persistence', False),
("jwst.step.PhotomStep", 'photom', False),
("jwst.step.PixelReplaceStep", 'pixel_replace', False),
("jwst.step.RampFitStep", 'ramp_fit', False),
("jwst.step.RefPixStep", 'refpix', False),
("jwst.step.ResampleStep", 'resample', False),
("jwst.step.ResampleSpecStep", 'resample_spec', False),
("jwst.step.ResetStep", 'reset', False),
("jwst.step.ResidualFringeStep", 'residual_fringe', False),
("jwst.step.RscdStep", 'rscd', False),
("jwst.step.SaturationStep", 'saturation', False),
("jwst.step.SkyMatchStep", 'skymatch', False),
("jwst.step.SourceCatalogStep", 'source_catalog', False),
("jwst.step.SourceTypeStep", 'srctype', False),
("jwst.step.SpectralLeakStep", 'spectral_leak', False),
("jwst.step.StraylightStep", 'straylight', False),
("jwst.step.SuperBiasStep", 'superbias', False),
("jwst.step.TSOPhotometryStep", 'tso_photometry', False),
("jwst.step.TweakRegStep", 'tweakreg', False),
("jwst.step.ChargeMigrationStep", 'charge_migration', False),
("jwst.step.WavecorrStep", 'wavecorr', False),
("jwst.step.WfsCombineStep", 'calwebb_wfs-image3', False),
("jwst.step.WfssContamStep", 'wfss_contam', False),
("jwst.step.WhiteLightStep", 'white_light', False),
("jwst.pipeline.Ami3Pipeline", "calwebb_ami3", True),
("jwst.pipeline.Coron3Pipeline", "calwebb_coron3", True),
("jwst.pipeline.DarkPipeline", "calwebb_dark", True),
("jwst.pipeline.Detector1Pipeline", "calwebb_detector1", True),
("jwst.pipeline.GuiderPipeline", "calwebb_guider", True),
("jwst.pipeline.Image2Pipeline", "calwebb_image2", True),
("jwst.pipeline.Image3Pipeline", "calwebb_image3", True),
("jwst.pipeline.Spec2Pipeline", "calwebb_spec2", True),
("jwst.pipeline.Spec3Pipeline", "calwebb_spec3", True),
("jwst.pipeline.Tso3Pipeline", "calwebb_tso3", True),
("jwst.step.AmiAnalyzeStep", "ami_analyze", False),
("jwst.step.AmiAverageStep", "ami_average", False),
("jwst.step.AmiNormalizeStep", "ami_normalize", False),
("jwst.step.AssignMTWcsStep", "assign_mtwcs", False),
("jwst.step.AssignWcsStep", "assign_wcs", False),
("jwst.step.BackgroundStep", "background", False),
("jwst.step.BadpixSelfcalStep", "badpix_selfcal", False),
("jwst.step.BarShadowStep", "barshadow", False),
("jwst.step.Combine1dStep", "combine_1d", False),
("jwst.step.StackRefsStep", "stack_refs", False),
("jwst.step.AlignRefsStep", "align_refs", False),
("jwst.step.KlipStep", "klip", False),
("jwst.step.HlspStep", "hlsp", False),
("jwst.step.CleanFlickerNoiseStep", "clean_flicker_noise", False),
("jwst.step.CubeBuildStep", "cube_build", False),
("jwst.step.CubeSkyMatchStep", "cube_skymatch", False),
("jwst.step.DarkCurrentStep", "dark_current", False),
("jwst.step.DQInitStep", "dq_init", False),
("jwst.step.EmiCorrStep", "emicorr", False),
("jwst.step.Extract1dStep", "extract_1d", False),
("jwst.step.Extract2dStep", "extract_2d", False),
("jwst.step.FirstFrameStep", "firstframe", False),
("jwst.step.FlatFieldStep", "flat_field", False),
("jwst.step.FringeStep", "fringe", False),
("jwst.step.GainScaleStep", "gain_scale", False),
("jwst.step.GroupScaleStep", "group_scale", False),
("jwst.step.GuiderCdsStep", "guider_cds", False),
("jwst.step.ImprintStep", "imprint", False),
("jwst.step.IPCStep", "ipc", False),
("jwst.step.JumpStep", "jump", False),
("jwst.step.LastFrameStep", "lastframe", False),
("jwst.step.LinearityStep", "linearity", False),
("jwst.step.MasterBackgroundStep", "master_background", False),
("jwst.step.MasterBackgroundMosStep", "master_background_mos", False),
("jwst.step.MRSIMatchStep", "mrs_imatch", False),
("jwst.step.MSAFlagOpenStep", "msa_flagging", False),
("jwst.step.NSCleanStep", "nsclean", False),
("jwst.step.OutlierDetectionStep", "outlier_detection", False),
("jwst.step.PathLossStep", "pathloss", False),
("jwst.step.PersistenceStep", "persistence", False),
("jwst.step.PhotomStep", "photom", False),
("jwst.step.PixelReplaceStep", "pixel_replace", False),
("jwst.step.RampFitStep", "ramp_fit", False),
("jwst.step.RefPixStep", "refpix", False),
("jwst.step.ResampleStep", "resample", False),
("jwst.step.ResampleSpecStep", "resample_spec", False),
("jwst.step.ResetStep", "reset", False),
("jwst.step.ResidualFringeStep", "residual_fringe", False),
("jwst.step.RscdStep", "rscd", False),
("jwst.step.SaturationStep", "saturation", False),
("jwst.step.SkyMatchStep", "skymatch", False),
("jwst.step.SourceCatalogStep", "source_catalog", False),
("jwst.step.SourceTypeStep", "srctype", False),
("jwst.step.SpectralLeakStep", "spectral_leak", False),
("jwst.step.StraylightStep", "straylight", False),
("jwst.step.SuperBiasStep", "superbias", False),
("jwst.step.TSOPhotometryStep", "tso_photometry", False),
("jwst.step.TweakRegStep", "tweakreg", False),
("jwst.step.ChargeMigrationStep", "charge_migration", False),
("jwst.step.WavecorrStep", "wavecorr", False),
("jwst.step.WfsCombineStep", "calwebb_wfs-image3", False),
("jwst.step.WfssContamStep", "wfss_contam", False),
("jwst.step.WhiteLightStep", "white_light", False),
]
10 changes: 0 additions & 10 deletions jwst/stpipe/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
import io


def setup():
from jwst.stpipe import log

# Turn off default logging when running tests
buffer = io.BytesIO(b"[*]\n")

log.load_configuration(buffer)
Loading
0