Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 0b7dc97

Browse files
committed
import changes from CRDS 7.5.0.2
1 parent 06ce982 commit 0b7dc97

6 files changed

+2588
-118
lines changed

crds/tmt/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@
2323
USEAFTER_KEYWORDS = ("META.OBSERVATION.DATE", "META.OBSERVATION.TIME") # Dataset keywords matching in UseAfter selectors
2424

2525
DEFAULT_SELECTORS = ("Match", "UseAfter") # Normal selector hierarchy in rmap
26-

crds/tmt/gen_system_crdscfg.py

+38-23
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,28 @@
1313
import sys
1414
import re
1515
import fnmatch
16+
import os.path
1617

1718
# ----------------------------------------------------------------------------------------------
1819

1920
import yaml
2021

2122
# ----------------------------------------------------------------------------------------------
2223

23-
from jwst import version
24-
from jwst.stpipe import cmdline as jwst_cmdline
24+
from jwst import __version__ as jwst_version
25+
from jwst.stpipe import pipeline
26+
from jwst import pipeline as pipepkg
2527

2628
# ----------------------------------------------------------------------------------------------
2729

2830
import crds
29-
from crds.core import log, exceptions, utils, timestamp
31+
from crds.core import log, exceptions, utils, timestamp, pysh
3032
from crds.core.log import srepr
3133

3234
# ----------------------------------------------------------------------------------------------
3335
VERSION_RE_STR = r"(\d+\.\d+.\d+).*"
3436

35-
CAL_VER = re.match(r"^" + VERSION_RE_STR, version.__version__).group(1)
37+
CAL_VER = re.match(r"^" + VERSION_RE_STR, jwst_version).group(1)
3638

3739
GENERATION_DATE = timestamp.now("T").split(".")[0]
3840

@@ -52,15 +54,15 @@ def __init__(self, input_yaml):
5254
self.pipeline_cfgs_to_steps = {}
5355
self.steps_to_reftypes = {}
5456
self.generate_pipeline_info()
55-
self.exptypes_to_cfgs = { exp_type : self.exptype_to_pipelines(exp_type)
57+
self.exptypes_to_cfgs = { exp_type : self.exptype_to_pipelines(exp_type)
5658
for exp_type in self.exp_types }
57-
self.exptypes_to_reftypes = { exp_type : self.exptype_to_reftypes(exp_type)
59+
self.exptypes_to_reftypes = { exp_type : self.exptype_to_reftypes(exp_type)
5860
for exp_type in self.exp_types }
5961

6062
def get_body(self):
6163
"""Load the input_yaml as a CRDS Struct and return it."""
62-
return utils.Struct(yaml.load(self.input_yaml))
63-
64+
return utils.Struct(yaml.safe_load(self.input_yaml))
65+
6466
def get_updated_yaml(self):
6567
"""Modify the input_yaml to replace the cal code version and generation date,
6668
useful for updating an existing reference and running it through this generator.
@@ -77,18 +79,31 @@ def get_updated_yaml(self):
7779
else:
7880
input_body += [line]
7981
return "\n".join(input_body).split(REFERENCE_DIVIDER)[0] + "\n" + REFERENCE_DIVIDER + "\n"
80-
82+
8183
def generate_pipeline_info(self):
8284
"""Based on the input YAML and JWST cal code, generate the mappings:
8385
pipeline_cfgs_to_steps
8486
steps_to_reftypes
8587
"""
88+
pysh.sh("rm -rf configs")
89+
pysh.sh("collect_pipeline_cfgs configs")
8690
self.pipeline_cfgs_to_steps["skip_2b.cfg"] = []
8791
for pipeline_cfg in self.loaded_cfg.pipeline_cfgs:
88-
steps_to_reftypes = jwst_cmdline.steps_to_reftypes_from_config(pipeline_cfg)
92+
log.info("Processing", repr(pipeline_cfg))
93+
cfgdir = "configs" # os.path.dirname(pipepkg.__file__) or ""
94+
cfgpath = os.path.join(cfgdir, pipeline_cfg)
95+
p = pipeline.Pipeline.from_config_file(cfgpath)
96+
steps_to_reftypes = {}
97+
for name, stepcfg in p.steps.items():
98+
if stepcfg.get("skip", True):
99+
log.info("Considering", repr(name), "skip")
100+
else:
101+
log.info("Considering", repr(name), "keep")
102+
step = p.step_defs[name] # class
103+
steps_to_reftypes[name] = step.reference_file_types
89104
self.pipeline_cfgs_to_steps[pipeline_cfg] = sorted(list(steps_to_reftypes.keys()))
90105
self.steps_to_reftypes.update(steps_to_reftypes)
91-
106+
92107
def generate_output_yaml(self):
93108
"""Generate the SYSTEM CRDSCFG reference YAML."""
94109
output_yaml = self.get_updated_yaml()
@@ -97,14 +112,14 @@ def generate_output_yaml(self):
97112
output_yaml += yaml.dump({"exptypes_to_pipelines" : self.exptypes_to_cfgs}) + "\n"
98113
output_yaml += yaml.dump({"exptypes_to_reftypes" : self.exptypes_to_reftypes}) + "\n"
99114
return output_yaml
100-
115+
101116
def __str__(self):
102117
return self.generate_output_yaml()
103-
118+
104119
def exptype_to_pipelines(self, exp_type):
105120
"""For a given EXP_TYPE string, return a list of reftypes needed to process that
106121
EXP_TYPE through the data levels appropriate for that EXP_TYPE.
107-
122+
108123
Return [reftypes... ]
109124
"""
110125
pipelines = []
@@ -116,15 +131,15 @@ def exptype_to_reftypes(self, exp_type):
116131
"""Return all reftypes associated with processing all steps of all pipelines for `exp_type`."""
117132
# with log.error_on_exception("Failed exptype_to_reftypes for", srepr(exp_type)):
118133
reftypes = []
119-
for pipeline in self.exptype_to_pipelines(exp_type):
134+
for pipeline in self.exptype_to_pipelines(exp_type):
120135
reftypes.extend(self.get_pipeline_types(pipeline, exp_type))
121136
reftypes = sorted(list(set(reftypes)))
122137
return reftypes
123-
138+
124139
def get_level_pipeline(self, level, exp_type):
125140
"""Interpret the level_pipeline_exptypes data structure relative to
126141
processing `level` and `exp_type` to determine a pipeline .cfg file.
127-
142+
128143
Return [ pipeline .cfg ] or []
129144
"""
130145
pipeline_exptypes = self.loaded_cfg.level_pipeline_exptypes[level]
@@ -135,16 +150,16 @@ def get_level_pipeline(self, level, exp_type):
135150
return [pipeline]
136151
log.error("Unhandled EXP_TYPE", srepr(exp_type), "for", srepr(level))
137152
return []
138-
153+
139154
# raise exceptions.CrdsPipelineCfgDeterminationError("Unhandled EXP_TYPE", srepr(exp_type))
140-
155+
141156
def get_pipeline_types(self, pipeline, exp_type):
142157
"""Based on a pipeline .cfg filename and an EXP_TYPE, look up
143158
the Steps corresponding to the .cfg and extrapolate those to the
144159
reftypes used by those Steps. If there are exceptions to the
145160
reftypes assigned for a particular Step that depend on EXP_TYPE,
146161
return the revised types for that Step instead.
147-
162+
148163
Return [reftypes, ...]
149164
"""
150165
steps = self.pipeline_cfgs_to_steps[pipeline]
@@ -160,8 +175,8 @@ def get_pipeline_types(self, pipeline, exp_type):
160175
found = False
161176
for exptype_pattern in exptypes:
162177
if glob_match(exptype_pattern, exp_type):
163-
log.verbose("Adding exceptional types", more_reftypes,
164-
"for step", srepr(step), "case", srepr(exptype_pattern),
178+
log.verbose("Adding exceptional types", more_reftypes,
179+
"for step", srepr(step), "case", srepr(exptype_pattern),
165180
"based on exp_type", srepr(exp_type))
166181
found = True
167182
reftypes.extend(more_reftypes)
@@ -171,7 +186,7 @@ def get_pipeline_types(self, pipeline, exp_type):
171186
else:
172187
raise exceptions.CrdsPipelineTypeDeterminationError("Unhandled EXP_TYPE for exceptional Step", srepr(step))
173188
return reftypes
174-
189+
175190
# --------------------------------------------------------------------------------------
176191

177192
def glob_match(expr, value):

0 commit comments

Comments
 (0)