Skip to content

Commit

Permalink
Merge branch 'main' into jp3789
Browse files Browse the repository at this point in the history
  • Loading branch information
penaguerrero authored Feb 27, 2025
2 parents 2c0e483 + 317db4a commit a093204
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 108 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ repos:
jwst/dark_current/.* |
jwst/emicorr/.* |
jwst/engdblog/.* |
jwst/exp_to_source/.* |
jwst/extract_2d/.* |
jwst/flatfield/.* |
jwst/fringe/.* |
Expand Down
2 changes: 0 additions & 2 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ exclude = [
"jwst/dark_current/**.py",
"jwst/emicorr/**.py",
"jwst/engdblog/**.py",
"jwst/exp_to_source/**.py",
"jwst/extract_2d/**.py",
"jwst/flatfield/**.py",
"jwst/fringe/**.py",
Expand Down Expand Up @@ -129,7 +128,6 @@ ignore-fully-untyped = true # Turn off annotation checking for fully untyped co
"jwst/dark_current/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/emicorr/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/engdblog/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/exp_to_source/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/extract_2d/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/flatfield/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/fringe/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ environment variable:

## Documentation

Documentation (built daily from the Github `main` branch) is available at:
Software documentation (built daily from the GitHub `main` branch) is available at:

https://jwst-pipeline.readthedocs.io/en/latest/

Expand All @@ -226,6 +226,13 @@ To build the docs yourself, clone this repository and build the documentation wi
make html
make latexpdf

For more user-focused documentation on the JWST calibration pipeline, see also the JDox pages at:

https://jwst-docs.stsci.edu/jwst-science-calibration-pipeline

The latest build information is also available on JDox at:

https://jwst-docs.stsci.edu/jwst-science-calibration-pipeline/jwst-operations-pipeline-build-information

## Contributions and Feedback

Expand Down
9 changes: 8 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ pipeline to custom process their JWST data. Additionally, the `jwst` package
contains the interface to JWST datamodels, the recommended method of reading and
writing JWST data files in Python.


If you have questions or concerns regarding the software, please contact the JWST Help
desk at `JWST Help Desk <https://jwsthelp.stsci.edu>`_.

Additional user-focused documentation on the
`JWST science calibration pipeline <https://jwst-docs.stsci.edu/jwst-science-calibration-pipeline>`__
and the
`latest build information <https://jwst-docs.stsci.edu/jwst-science-calibration-pipeline/jwst-operations-pipeline-build-information>`__
is also available on `JDox <https://jwst-docs.stsci.edu>`__.


--------------------------------

.. toctree::
Expand All @@ -52,6 +58,7 @@ desk at `JWST Help Desk <https://jwsthelp.stsci.edu>`_.
jwst/user_documentation/logging_configuration.rst
jwst/user_documentation/datamodels.rst
jwst/user_documentation/pub_deprecation.rst
jwst/user_documentation/more_information.rst

.. toctree::
:maxdepth: 2
Expand Down
14 changes: 14 additions & 0 deletions docs/jwst/user_documentation/more_information.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
More Information for JWST Users
===============================

The documentation hosted here focuses primarily on calibration software
implementation and use.

For more user-focused information on JWST instruments and calibration methods, please
see the
`JWST science calibration pipeline <https://jwst-docs.stsci.edu/jwst-science-calibration-pipeline>`__
pages hosted on `JDox <https://jwst-docs.stsci.edu>`__.

More information on the
`latest build <https://jwst-docs.stsci.edu/jwst-science-calibration-pipeline/jwst-operations-pipeline-build-information>`__
in use for data processing operations is also available on JDox.
9 changes: 4 additions & 5 deletions jwst/exp_to_source/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .exp_to_source import (
exp_to_source,
multislit_to_container,
)
"""Conversion of Stage 2 exposure-based data products to Stage 3 source-based data products."""

__all__ = ['exp_to_source', 'multislit_to_container']
from .exp_to_source import exp_to_source, multislit_to_container

__all__ = ["exp_to_source", "multislit_to_container"]
28 changes: 15 additions & 13 deletions jwst/exp_to_source/exp_to_source.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""exp_to_source: Reformat Level2b multi-source data to be source-based.
"""
"""Reformat Level2b multi-source data to be source-based."""

import logging

from collections import defaultdict
Expand All @@ -9,14 +9,15 @@

from jwst.datamodels import SourceModelContainer

__all__ = ['exp_to_source', 'multislit_to_container']
__all__ = ["exp_to_source", "multislit_to_container"]

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


def exp_to_source(inputs):
"""Reformat exposure-based MSA data to source-based.
"""
Reformat exposure-based MSA data to source-based.
Parameters
----------
Expand All @@ -33,7 +34,7 @@ def exp_to_source(inputs):
result = defaultdict(MultiExposureModel)

for exposure in inputs:
log.info(f'Reorganizing data from exposure {exposure.meta.filename}')
log.info(f"Reorganizing data from exposure {exposure.meta.filename}")

for slit in exposure.slits:
if slit.source_name is None:
Expand All @@ -43,7 +44,7 @@ def exp_to_source(inputs):
else:
# NIRSpec MOS slits get sorted by source_name
key = slit.source_name
log.debug(f'Copying source {key}')
log.debug(f"Copying source {key}")
result_slit = result[str(key)]
result_slit.exposures.append(slit)

Expand All @@ -55,8 +56,8 @@ def exp_to_source(inputs):
slit_model = slit.meta.model_type
slit_wcsinfo = slit.meta.wcsinfo.instance
slit_exptype = None
if hasattr(slit.meta, 'exposure'):
if hasattr(slit.meta.exposure, 'type'):
if hasattr(slit.meta, "exposure"):
if hasattr(slit.meta.exposure, "type"):
slit_exptype = slit.meta.exposure.type

# Before merge_tree the slits have a model_type of SlitModel.
Expand All @@ -74,8 +75,8 @@ def exp_to_source(inputs):
if slit_exptype is not None:
result_slit.exposures[-1].meta.exposure.type = slit_exptype
result_slit.meta.exposure.type = slit_exptype
log.debug(f'Input exposure type: {exposure.meta.exposure.type}')
log.debug(f'Output exposure type: {result_slit.meta.exposure.type}')
log.debug(f"Input exposure type: {exposure.meta.exposure.type}")
log.debug(f"Output exposure type: {result_slit.meta.exposure.type}")

if result_slit.meta.instrument.name is None:
result_slit.update(exposure)
Expand All @@ -90,7 +91,8 @@ def exp_to_source(inputs):


def multislit_to_container(inputs):
"""Reformat exposure-based MSA data to source-based containers.
"""
Reformat exposure-based MSA data to source-based containers.
Parameters
----------
Expand All @@ -106,7 +108,7 @@ def multislit_to_container(inputs):
The key is the ID of each slit, i.e. ``source_id``.
"""
containers = exp_to_source(inputs)
for id in containers:
containers[id] = SourceModelContainer(containers[id])
for container_id in containers:
containers[container_id] = SourceModelContainer(containers[container_id])

return containers
67 changes: 34 additions & 33 deletions jwst/exp_to_source/main.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
import os
import sys
import argparse
from pathlib import Path

from stdatamodels.jwst.datamodels import MultiSlitModel

from jwst.exp_to_source import exp_to_source


class Main():
"""Convert exposure-based slits data to source-based data
Docs from the source.
Parameters
----------
args: str or [str,...]
The command-line arguments. This is passed to
`argparse.parse_args`. If None, `sys.argv`
is used.
class Main:
"""
Convert exposure-based slits data to source-based data.
Attributes
----------
sources: {source: MultiExposureModel, ...}
A dict keyed on source name whose value is
the corresponding MultiExposureModel.
Command-line interface to the exp_to_source step. For help, use
exp_to_source -h. See also the exp_to_source readthedocs page:
https://jwst-pipeline.readthedocs.io/en/latest/api/jwst.exp_to_source.exp_to_source.html#jwst.exp_to_source.exp_to_source
"""

def __init__(self, args=None):
"""
Initialize and run the exp_to_source step.
Parameters
----------
args : str or [str,...]
The command-line arguments. This is passed to
`argparse.parse_args`. If None, `sys.argv`
is used.
"""
if args is None:
args = sys.argv[1:]
if isinstance(args, str):
args = args.split(' ')
args = args.split(" ")

parser = argparse.ArgumentParser(
description='Convert exposure-based data to source-based data',
usage='python -m jwst.exp_to_source.main files'
description="Convert exposure-based data to source-based data",
usage="python -m jwst.exp_to_source.main files",
)
parser.add_argument(
'files',
type=str,
nargs='+',
help='Files to convert')
parser.add_argument("files", type=str, nargs="+", help="Files to convert")

parser.add_argument(
'-o', '--output-path',
"-o",
"--output-path",
type=str,
default='.',
help='Folder to save results in. Default: "%(default)s"'
default=".",
help='Folder to save results in. Default: "%(default)s"',
)

parser.add_argument(
'--dry-run',
action='store_true', dest='dry_run',
help='Execute but do not save results.'
"--dry-run",
action="store_true",
dest="dry_run",
help="Execute but do not save results.",
)

try:
parsed = parser.parse_args(args=args)
except SystemExit:
return

# self.sources is a dict keyed on source name whose value is
# the corresponding MultiExposureModel,
# e.g. {source_name: MultiExposureModel, ...}
exposures = [MultiSlitModel(f) for f in parsed.files]
self.sources = exp_to_source(exposures)
if not parsed.dry_run:
for source in self.sources:
out_path = '.'.join([source, 'fits'])
out_path = os.path.join(parsed.output_path, out_path)
out_path = ".".join([source, "fits"])
out_path = Path(parsed.output_path) / out_path
self.sources[source].save(out_path)


if __name__ == '__main__':
if __name__ == "__main__":
Main()
16 changes: 6 additions & 10 deletions jwst/exp_to_source/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Testing helpers
from glob import glob
import os


INPUT_FILES_GLOB = 'data/jwst_nod?_cal.fits'
from pathlib import Path


def t_path(partial_path):
"""Construction the full path for test files"""
test_dir = os.path.dirname(__file__)
return os.path.join(test_dir, partial_path)
"""Construct the full path for test files."""
test_dir = Path(__file__).parent
return Path(test_dir) / partial_path


# Calculate some extra constants
INPUT_FILES_GLOB = t_path(INPUT_FILES_GLOB)
INPUT_FILES = glob(t_path(INPUT_FILES_GLOB))
INPUT_FILES = list(t_path("data").glob("jwst_nod?_cal.fits"))
INPUT_FILES = [str(infile) for infile in INPUT_FILES]
42 changes: 0 additions & 42 deletions jwst/exp_to_source/tests/tempfile_py2.py

This file was deleted.

0 comments on commit a093204

Please sign in to comment.