pypeit.state package
Submodules
- pypeit.state.run_state module
AlignCalibStateArcCalibStateBaseCalibStateBiasCalibStateDarkCalibStateFlatCorrectionMetricFlatsSlitFlatsStateFlatsState._abc_implFlatsState.calib_idFlatsState.correctionsFlatsState.detFlatsState.illumflat_filesFlatsState.input_filesFlatsState.lampoff_filesFlatsState.model_configFlatsState.output_fileFlatsState.pixelflat_filesFlatsState.pixelflat_sourceFlatsState.qa_filesFlatsState.requiredFlatsState.slitsFlatsState.statusFlatsState.step
RunPypeItStateRunPypeItState._abc_implRunPypeItState._print_science_status()RunPypeItState.add_or_get_science()RunPypeItState.alignRunPypeItState.arcRunPypeItState.biasRunPypeItState.current_calibIDRunPypeItState.current_detRunPypeItState.current_stepRunPypeItState.darkRunPypeItState.flatsRunPypeItState.get_science_status()RunPypeItState.get_status()RunPypeItState.load()RunPypeItState.merge_from_disk()RunPypeItState.model_configRunPypeItState.outfileRunPypeItState.pathRunPypeItState.previous_stepRunPypeItState.print_status()RunPypeItState.pypeit_fileRunPypeItState.safe_update_calib()RunPypeItState.safe_update_science()RunPypeItState.safe_write()RunPypeItState.scattlightRunPypeItState.scienceRunPypeItState.science_entry()RunPypeItState.slitsRunPypeItState.tiltimgRunPypeItState.tiltsRunPypeItState.update_calib()RunPypeItState.write()RunPypeItState.wv_calib
ScattLightCalibStateScienceFrameStateScienceFrameState._abc_implScienceFrameState.bkg_idScienceFrameState.calib_idScienceFrameState.comb_idScienceFrameState.detScienceFrameState.extractScienceFrameState.findobjScienceFrameState.frameScienceFrameState.model_configScienceFrameState.nobjScienceFrameState.objectsScienceFrameState.objtypeScienceFrameState.processScienceFrameState.raw_filesScienceFrameState.skysubScienceFrameState.slitsScienceFrameState.spec1d_fileScienceFrameState.spec2d_file
ScienceObjScienceSlitScienceStepSlitEdgesSlitEdgesStateTiltImgCalibStateTiltsSlitTiltsStateWvCalibSlitWvCalibStatesame_det()
- pypeit.state.science_status module
_basename_from_product()_basename_lookup()_derive_from_intermediate()_det_from_name()_exposure_ids()_obj_from_specobj()_raw_files_by_basename()_safe_float()_slit_status_map()derive_science_from_disk()planned_science_from_fitstbl()record_extract()record_findobj()record_process()seed_planned_science()seed_planned_science_entries()
Module contents
The PypeIt reduction-state package.
This package holds the data model and I/O for the reduction state recorded
while run_pypeit runs (and read by the PypeIt Dashboard and
pypeit_status):
pypeit.state.run_state— the pydantic data model (RunPypeItStateand the per-step / per-frame classes) and its JSON I/O. This is Qt-free and free of product imports.pypeit.state.science_status— helpers that translate the science reduction products (SpecObjs/AllSpec2DObj/ slit bitmasks), or the on-disk products, into the science portion of the state.
For backward compatibility, the public names of pypeit.state.run_state
are re-exported here, so from pypeit import state followed by
state.RunPypeItState (etc.) continues to work.
Generated by JXP and Claude.
- class pypeit.state.AlignCalibState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.ArcCalibState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.BaseCalibState(**data)[source]
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.BiasCalibState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.DarkCalibState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.FlatCorrectionMetric(**data)[source]
Bases:
BaseModelMean and scatter of one applied flat-field correction over a single slit’s good, on-slit pixels.
Generated by JXP and Claude.
- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.FlatsSlit(**data)[source]
Bases:
BaseModelPer-slit flat-field state: an overall status plus the per-correction mean/RMS metrics.
Generated by JXP and Claude.
- _abc_impl = <_abc._abc_data object>
-
corrections:
Optional[Dict[str,FlatCorrectionMetric]]
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.FlatsState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.RunPypeItState(**data)[source]
Bases:
BaseModelThe state of a PypeIt run.
This pydantic model records, for one
.pypeitreduction, the status of every calibration step per calibration group and per detector/mosaic. Each calibration field (bias,dark,slits,arc,tiltimg,wv_calib,tilts,scattlight,flats,align) is a list of per-(calib_id, det)entries (subclasses ofBaseCalibState) carrying that step’sstatus,requiredflag, input/output/QA files, and step-specific metrics (and, forslits/wv_calib/tilts/flats, per-slit/order detail).It is written to
<pypeit_root>_state.json(seeoutfile) and is updated incrementally during a run; usesafe_write()/safe_update_calib()so state I/O can never abort the reduction, andget_status()for a tabular summary. It is read by the PypeIt Dashboard andpypeit_status; it is not meant to be edited by hand.Generated by JXP and Claude.
- Variables:
pypeit_file (str) – The
.pypeitfile this state belongs to.current_step (str) – The step most recently updated.
current_det (int) – The detector most recently updated.
current_calibID (int) – The calibration group most recently updated.
previous_step (str) – The step updated before
current_step.path (str) – Optional explicit path for the state JSON file; if
None,outfileis derived frompypeit_file.
- _abc_impl = <_abc._abc_data object>
- _print_science_status()[source]
Print the per-exposure science-frame status table to stdout (the four macro-steps, object count, and product presence).
Generated by JXP and Claude.
- add_or_get_science(frame, det, calib_id=-1, objtype='science', comb_id=None, bkg_id=None)[source]
Find the science entry for
(frame, det)or create it.Generated by JXP and Claude.
- Parameters:
- Returns:
The existing or newly-created entry.
- Return type:
-
align:
Optional[List[AlignCalibState]]
-
arc:
Optional[List[ArcCalibState]]
-
bias:
Optional[List[BiasCalibState]]
-
dark:
Optional[List[DarkCalibState]]
-
flats:
Optional[List[FlatsState]]
- get_science_status()[source]
Return a pandas DataFrame summarizing the science-frame state: one row per
(frame, det)with the four macro-step statuses, object count, and product presence.Generated by JXP and Claude.
- Returns:
None if there are no science entries.
- Return type:
pandas.DataFrameor None
- get_status()[source]
Summarize the state as a tabular, per-step status overview.
This is intentionally less detailed than the full serialized state (
write()): it omits the per-slit detail and metrics, giving a scannable health overview (used byprint_status()and the dashboard’s Status view).Generated by JXP and Claude.
- Returns:
One row per
(calibration_group, detector, step)with columnscalibration_group,detector,steps,required,status, andoutput_file; missing entries are filled with"--". ReturnsNoneif no calibration entries exist.- Return type:
pandas.DataFrameor None
- load(path=None)[source]
Load the state from
outfile, if it exists.Generated by JXP and Claude.
- merge_from_disk()[source]
Overlay the calibration and science statuses from the existing on-disk state file onto this state, matching entries by
(calib_id, det)and(frame, det).A step-runner script (
pypeit_run_to_calibstep/pypeit_reduce_by_step) starts with a fresh state — its calibrations are the required (undone) set and it has no science — so writing it would reset the other portion of the shared*_state.json(e.g. a science step-build would blank out the calibration statuses a prior calibration build wrote, and vice versa). Calling this first preserves whatever the other runner already recorded. This instance’soutfile(andpypeit_file) is left untouched, so the subsequent write goes to the same file. Best-effort: a missing or unreadable state file leavesselfunchanged.Generated by JXP and Claude.
- Returns:
self(updated in place).- Return type:
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- property outfile
Path to the state JSON file.
Generated by JXP and Claude.
- print_status()[source]
Pretty-print the reduction state to the terminal: a per-(group, detector) calibration table (from
get_status()) followed by the science-frame status (_print_science_status()). Used by pypeit_status.Generated by JXP and Claude.
- Returns:
None.
- safe_update_calib(step, calib_id, det, key, value, slit=None)[source]
Wrapper on
update_calib()that catches and logs any error so that state bookkeeping can never crash a PypeIt reduction.Generated by JXP and Claude.
- Parameters:
- Returns:
True if the update succeeded, False otherwise.
- Return type:
- safe_update_science(frame, det, step=None, status=None, calib_id=-1, objtype='science', **fields)[source]
Get-or-create a science entry and update a step status and/or top-level fields, catching and logging any error so science bookkeeping can never crash a reduction.
Generated by JXP and Claude.
- Parameters:
frame (
str) – The exposure basename.step (
str, optional) – One ofscience_steps; if given, itsstatusis set tostatus.status (
str, optional) – Status to assign tostep.calib_id (
int, optional) – Calibration group (on create).objtype (
str, optional) – ‘science’/’standard’ (on create).**fields – Other top-level
ScienceFrameStatefields to set (e.g.nobj,spec1d_file,spec2d_file).
- Returns:
The entry (None on failure).
- Return type:
ScienceFrameStateor None
- safe_write()[source]
Write the state, catching and logging any error so that state I/O can never crash a PypeIt reduction.
Generated by JXP and Claude.
- Returns:
True if the write succeeded, False if it failed (in which case a warning is logged and the run continues).
- Return type:
-
scattlight:
Optional[List[ScattLightCalibState]]
-
science:
Optional[List[ScienceFrameState]]
- science_entry(frame, det)[source]
Return the science entry matching
(frame, det), or None.Generated by JXP and Claude.
- Parameters:
- Returns:
ScienceFrameStateor None.
-
slits:
Optional[List[SlitEdgesState]]
-
tiltimg:
Optional[List[TiltImgCalibState]]
-
tilts:
Optional[List[TiltsState]]
- update_calib(step, calib_id, det, key, value, slit=None)[source]
Create or update the state entry for a single calibration step.
Looks up the entry matching
(calib_id, det)for the givenstep; if none exists it is created. The requestedkeyis then set tovalue(appended if the field is a list), either on the step entry or, whenslitis given, on the per-slit/order sub-entry.Generated by JXP and Claude.
- Parameters:
step (
str) – Calibration step name (must be a key ofcalib_classes).calib_id (
int) – Calibration group ID.det (
int,tuple,list) – Detector (int) or detector mosaic (tuple/list of ints).key (
str) – Name of the field to set on the step (or per-slit) entry.value – Value to assign. A list/tuple replaces the field with a flat list (e.g.
input_files); a scalar appended to a field that already holds a list accumulates (e.g. flatstypes); otherwise the scalar is assigned.slit (
int, optional) – Slit/order ID. If provided,keyis set on the per-slit sub-entry rather than the step entry itself.
- write()[source]
Serialize the state to its JSON file (
self.outfile).Generated by JXP and Claude.
This may raise on I/O or serialization errors; use
safe_write()from within a reduction so a failure here can never abort the run.
-
wv_calib:
Optional[List[WvCalibState]]
- class pypeit.state.ScattLightCalibState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.ScienceFrameState(**data)[source]
Bases:
BaseModelState of one reduced science/standard exposure on one detector/mosaic.
Generated by JXP and Claude.
- _abc_impl = <_abc._abc_data object>
-
extract:
ScienceStep
-
findobj:
ScienceStep
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
-
objects:
Optional[List[ScienceObj]]
-
process:
ScienceStep
-
skysub:
ScienceStep
-
slits:
Optional[Dict[int,ScienceSlit]]
- class pypeit.state.ScienceObj(**data)[source]
Bases:
BaseModelOne detected (and possibly extracted) object on a science exposure.
Generated by JXP and Claude.
- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.ScienceSlit(**data)[source]
Bases:
BaseModelPer-slit science status (from the slit bitmask).
Generated by JXP and Claude.
- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.ScienceStep(**data)[source]
Bases:
BaseModelStatus of one macro-step (process/findobj/skysub/extract) of a science exposure.
Generated by JXP and Claude.
- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.SlitEdges(**data)[source]
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.SlitEdgesState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.TiltImgCalibState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.TiltsSlit(**data)[source]
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.TiltsState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.WvCalibSlit(**data)[source]
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pypeit.state.WvCalibState(**data)[source]
Bases:
BaseCalibState- _abc_impl = <_abc._abc_data object>
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
-
slits:
Optional[Dict[int,WvCalibSlit]]
- pypeit.state.same_det(det1, det2)[source]
Compare two detector identifiers for equality, treating a detector mosaic the same whether it is stored as a tuple or a list.
A single detector is an
int; a detector mosaic is a tuple of ints (e.g.(1, 5)). Because pydantic coerces the storeddetfield to alist, a direct==comparison between a stored mosaic ([1, 5]) and an incoming mosaic ((1, 5)) is always False. This helper normalizes both sides before comparing.Generated by JXP and Claude.