Skip to content

Commit

Permalink
Add code style to assign_mtwcs
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed Jan 29, 2025
1 parent 89136ba commit a154888
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 34 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ repos:
- id: numpydoc-validation
exclude: |
(?x)^(
jwst/assign_mtwcs/.* |
jwst/assign_wcs/.* |
jwst/associations/.* |
jwst/background/.* |
Expand Down
6 changes: 3 additions & 3 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exclude = [
"jwst/conftest.py",
"pytest_jwst/**.py",
# "jwst/ami/**.py",
"jwst/assign_mtwcs/**.py",
# "jwst/assign_mtwcs/**.py",
"jwst/assign_wcs/**.py",
"jwst/associations/**.py",
"jwst/background/**.py",
Expand Down Expand Up @@ -141,7 +141,7 @@ ignore-fully-untyped = true # Turn of annotation checking for fully untyped cod
"F403", # import with *
"F405", # ambiguous import from *
]
"**/tests/__init__.py" = [
"**/tests/**.py" = [
"D104", # missing docstring in public package
]
"jwst/associations/tests*" = [
Expand All @@ -152,7 +152,7 @@ ignore-fully-untyped = true # Turn of annotation checking for fully untyped cod
"jwst/conftest.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"pytest_jwst/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
# "jwst/ami/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/assign_mtwcs/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
# "jwst/assign_mtwcs/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/assign_wcs/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/associations/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/background/**.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/assign_mtwcs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Pipeline step to create a gWCS object for a moving target."""

from .assign_mtwcs_step import AssignMTWcsStep


__all__ = ['AssignMTWcsStep']
__all__ = ["AssignMTWcsStep"]
35 changes: 20 additions & 15 deletions jwst/assign_mtwcs/assign_mtwcs_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@


class AssignMTWcsStep(Step):
"""
AssignMTWcsStep: Create a gWCS object for a moving target.
Parameters
----------
input : `~jwst.associations.Association`
A JWST association file.
"""
"""Create a gWCS object for a moving target."""

class_alias = "assign_mtwcs"

Expand All @@ -30,15 +23,27 @@ class AssignMTWcsStep(Step):
output_use_model = boolean(default=True) # When saving use `DataModel.meta.filename`
"""

def process(self, input):

if not isinstance(input, ModelLibrary):
def process(self, input_lib):
"""
Run the assign_mtwcs step.
Parameters
----------
input_lib : `~jwst.datamodels.ModelLibrary`
A collection of data models.
Returns
-------
`~jwst.datamodels.ModelLibrary`
The modified data models.
"""
if not isinstance(input_lib, ModelLibrary):
try:
input = ModelLibrary(input)
input_lib = ModelLibrary(input_lib)
except Exception:
log.warning("Input data type is not supported.")
record_step_status(input, "assign_mtwcs", False)
return input
record_step_status(input_lib, "assign_mtwcs", False)
return input_lib

Check warning on line 46 in jwst/assign_mtwcs/assign_mtwcs_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/assign_mtwcs/assign_mtwcs_step.py#L45-L46

Added lines #L45 - L46 were not covered by tests

result = assign_moving_target_wcs(input)
result = assign_moving_target_wcs(input_lib)
return result
48 changes: 34 additions & 14 deletions jwst/assign_mtwcs/moving_target_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
target in all exposures in an association and adds a step to
each of the WCS pipelines to allow aligning the exposures to the average
location of the target.
"""

import logging
from copy import deepcopy
import numpy as np
Expand All @@ -28,9 +28,21 @@


def assign_moving_target_wcs(input_models):
"""
Adjust the WCS of a moving target exposure.
Parameters
----------
input_models : `~jwst.datamodels.ModelLibrary`
A collection of data models.
Returns
-------
`~jwst.datamodels.ModelLibrary`
The modified data models.
"""
if not isinstance(input_models, ModelLibrary):
raise ValueError("Expected a ModelLibrary object")
raise TypeError(f"Expected a ModelLibrary object, not {type(input_models)}")

Check warning on line 45 in jwst/assign_mtwcs/moving_target_wcs.py

View check run for this annotation

Codecov / codecov/patch

jwst/assign_mtwcs/moving_target_wcs.py#L45

Added line #L45 was not covered by tests

# loop over only science exposures in the ModelLibrary
ind = input_models.indices_for_exptype("science")
Expand Down Expand Up @@ -60,15 +72,23 @@ def assign_moving_target_wcs(input_models):
model.meta.wcsinfo.mt_avdec = mt_avdec
if isinstance(model, datamodels.MultiSlitModel):
for ind, slit in enumerate(model.slits):
new_wcs = add_mt_frame(slit.meta.wcs,
mt_avra, mt_avdec,
slit.meta.wcsinfo.mt_ra, slit.meta.wcsinfo.mt_dec)
new_wcs = add_mt_frame(
slit.meta.wcs,
mt_avra,
mt_avdec,
slit.meta.wcsinfo.mt_ra,
slit.meta.wcsinfo.mt_dec,
)
del model.slits[ind].meta.wcs
model.slits[ind].meta.wcs = new_wcs
else:

new_wcs = add_mt_frame(model.meta.wcs, mt_avra, mt_avdec,
model.meta.wcsinfo.mt_ra, model.meta.wcsinfo.mt_dec)
new_wcs = add_mt_frame(

Check warning on line 85 in jwst/assign_mtwcs/moving_target_wcs.py

View check run for this annotation

Codecov / codecov/patch

jwst/assign_mtwcs/moving_target_wcs.py#L85

Added line #L85 was not covered by tests
model.meta.wcs,
mt_avra,
mt_avdec,
model.meta.wcsinfo.mt_ra,
model.meta.wcsinfo.mt_dec,
)
del model.meta.wcs
model.meta.wcs = new_wcs
if model.meta.exposure.type.lower() in IMAGING_TYPES:
Expand All @@ -80,7 +100,8 @@ def assign_moving_target_wcs(input_models):


def add_mt_frame(wcs, ra_average, dec_average, mt_ra, mt_dec):
""" Add a "moving_target" frame to the WCS pipeline.
"""
Add a "moving_target" frame to the WCS pipeline.
Parameters
----------
Expand All @@ -98,10 +119,10 @@ def add_mt_frame(wcs, ra_average, dec_average, mt_ra, mt_dec):
new_wcs : `~gwcs.WCS`
The WCS for the moving target observation.
"""
pipeline = wcs._pipeline[:-1]
pipeline = wcs._pipeline[:-1] # noqa: SLF001

mt = deepcopy(wcs.output_frame)
mt.name = 'moving_target'
mt.name = "moving_target"

rdel = ra_average - mt_ra
ddel = dec_average - mt_dec
Expand All @@ -111,10 +132,9 @@ def add_mt_frame(wcs, ra_average, dec_average, mt_ra, mt_dec):
elif isinstance(mt, cf.CompositeFrame):
transform_to_mt = Shift(rdel) & Shift(ddel) & Identity(1)
else:
raise ValueError("Unrecognized coordinate frame.")
raise TypeError(f"Unrecognized coordinate frame type {type(mt)}.")

Check warning on line 135 in jwst/assign_mtwcs/moving_target_wcs.py

View check run for this annotation

Codecov / codecov/patch

jwst/assign_mtwcs/moving_target_wcs.py#L135

Added line #L135 was not covered by tests

pipeline.append((
wcs.output_frame, transform_to_mt))
pipeline.append((wcs.output_frame, transform_to_mt))
pipeline.append((mt, None))
new_wcs = WCS(pipeline)
return new_wcs

0 comments on commit a154888

Please sign in to comment.