API reference

This section documents the public Python API: the CLI entry point, the main hst123 orchestration class, CLI registration in hst123.utils.options, path helpers, optional HDF5 export for DOLPHOT tables, and shared primitive utilities.

Entry point

hst123._pipeline.main()[source]

Command-line entry point for the full HST123 pipeline.

Reads sys.argv[1:3] as right ascension and declination, then applies all flags from hst123.add_options(). Orchestrates MAST download or raw ingest, builds the observation table, alignment, optional drizzle-all, DOLPHOT, and catalog scraping according to the selected options.

See also

hst123.hst123

Programmatic use of the same pipeline steps.

Notes

Calling --help prints usage and exits. The function may call sys.exit on fatal configuration errors or after --hierarch-test.

Pipeline class

The class hst123 holds pipeline state (options, coordinates, input lists, reference path) and delegates to primitives (_fits, _phot, _astrom, _dolphot, _scrape_dolphot) for instrument-specific work.

class hst123._pipeline.hst123[source]

End-to-end HST reduction and photometry pipeline.

Construct once, then call handle_args() (or set self.options['args'] programmatically) before invoking download, alignment, drizzle, or DOLPHOT steps.

Attributes:
input_imageslist of str

Paths to science FITS after ingest.

obstableastropy.table.Table or None

Per-exposure metadata table from input_list().

referencestr

Path to the drizzled reference image when set.

optionsdict

global_defaults, detector_defaults, instrument_defaults, acceptable_filters, drizzle_defaults, and args (CLI namespace).

coordastropy.coordinates.SkyCoord or None

Target position from the command line.

See also

hst123.main

CLI entry point.

add_options(parser=None, usage=None)[source]

Add hst123 command-line arguments to an argparse parser.

Parameters:
parserargparse.ArgumentParser, optional

Parser to add arguments to; if None, a new parser is created.

usagestr, optional

Usage string when parser is None.

Returns:
argparse.ArgumentParser

Parser with all hst123 options registered.

check_archive(product, archivedir=None)[source]

Ensure the archive tree exists and report whether the product file is present.

Parameters:
productdict-like

Row with productFilename, instrument_name, ra, etc.

archivedirstr, optional

Root archive directory; defaults to args.archive.

Returns:
tuple (bool, str)

(file_exists, full_path) where full_path is the target archive path.

clear_downloads(options)[source]

Clear Astropy’s download cache to avoid failures when the cache is full.

Parameters:
optionsdict

Must include astropath (suffix under $HOME for the cache location).

Notes

No-op when --no-clear-downloads is set.

compress_reference(reference)[source]

Collapse multi-extension drizzle products to a single PRIMARY for DOLPHOT.

AstroDrizzle often writes PRIMARY (image) + HDRTAB. Older logic treated any 2-HDU file as PRIMARY+SCI and replaced PRIMARY with extension 1, which swaps the science image for a binary table and breaks calcsky (crash / SIGTRAP). Only SCI is promoted when the primary HDU has no image array.

Parameters:
referencestr

Path to the drizzled FITS file (updated in place).

Returns:
None

Returns None if reference does not exist.

copy_raw_data(rawdir, reverse=False, check_for_coord=False)[source]

Sync FITS between a raw directory and the working directory.

Parameters:
rawdirstr

Directory containing *.fits (used as the source when reverse is True).

reversebool, optional

If False, copy pipeline input_images into rawdir. If True, copy from rawdir into work_dir, keeping a copy under work_dir/raw/ and a symlink (or copy) at the work-dir top level.

check_for_coordbool, optional

If True with reverse, only copy exposures that pass needs_to_be_reduced().

Notes

Used after downloads or when ingesting an existing raw cache.

copy_raw_data_archive(product, archivedir=None, workdir=None, check_for_coord=False)[source]

Copy one MAST product from the archive into the working directory.

Parameters:
productdict-like

Row from get_productlist() (used with _archive_path_for_product()).

archivedir, workdirstr, optional

Archive root and destination directory (defaults from args).

check_for_coordbool, optional

If True, skip copying when needs_to_be_reduced() rejects the file.

Returns:
int or None

0 on success or skip-when-identical; None if missing or filtered out.

download_files(productlist, dest=None, archivedir=None, clobber=False, work_dir=None)[source]

Download MAST products via astroquery.mast.Observations.download_products.

Parameters:
productlisttable-like

Rows from get_productlist() (must include downloadFilename, obsID).

deststr, optional

Directory for downloaded FITS when not using an archive layout.

archivedirstr, optional

When set, check_archive places files under {inst}/{det}/{ra}/....

clobberbool, optional

If False, skip when the destination file already exists.

work_dirstr, optional

Parent for .mast_download_staging (isolates astroquery temp from CWD).

Returns:
bool

True when the download loop completes (individual files may warn on failure).

Notes

Staging always lives under work_dir so mastDownload is not created in an unrelated shell current directory.

Downloads run sequentially. Observations.download_products (astroquery) is not thread-safe; parallel calls caused intermittent I/O operation on closed file errors and staging-directory races ([Errno 17] File exists). --max-cores still applies to drizzle/DOLPHOT parallelism elsewhere.

drizzle_all(obstable, hierarchical=False, clobber=False, do_tweakreg=True)[source]

Drizzle each unique drizname group (visit/filter/epoch) from obstable.

Parameters:
obstableastropy.table.Table

Must include drizname and image columns (from input_list()).

hierarchicalbool, optional

If True, after per-epoch drizzles, run a second TweakReg pass and apply shifts tied to the deepest stacked image.

clobberbool, optional

If False, skip drizzle when the output file already exists. Set True when using --redo-astrodrizzle, --redo, or --clobber (see want_redo_astrodrizzle()).

do_tweakregbool, optional

Run TweakReg on each group before AstroDrizzle when alignment is enabled.

Notes

Optional per-drizzle calcsky for non-reference products is controlled by HST123_DOLPHOT_SKY_FOR_DRIZZLE_ALL.

Groups are processed sequentially: each step calls run_tweakreg(), which sets the process working directory to workspace/; parallelizing groups in threads would race on chdir. DOLPHOT prep thread count is set by --max-cores (same as AstroDrizzle workers).

expand_obstable_for_split_images(visit_obstable, split_images)[source]

Build one obstable row per DOLPHOT split/chip path from the visit table.

Avoids input_list() over split_images, which re-opens every chip FITS many times per file (very slow on network-backed storage).

Parameters:
visit_obstableastropy.table.Table

Per-visit observation table (same exposures as the parents of split_images).

split_imageslist of str

Chip-level FITS paths (e.g. *.chipN.fits) or undivided exposures.

Returns:
astropy.table.Table or None

Table aligned to split_images, or None if a parent exposure cannot be matched.

fix_hdu_wcs_keys(image, change_keys, ref_url)[source]

Rewrite WCSNAME-like keys and expand CRDS reference paths for alignment.

Parameters:
imagestr

FITS path opened in update mode.

change_keysiterable of str

Header keys to normalize (strip WCSNAME values, resolve ref$ paths).

ref_urlstr

CRDS / reference root URL prefix (see ref_prefix_for_header in hst123.utils.reference_download).

fix_idcscale(image)[source]

Ensure WFC3 IDC headers carry IDCSCALE from detector defaults.

Parameters:
imagestr

Path to a FITS file updated in place.

fix_phot_keys(image)[source]

Propagate the first PHOTPLAM / PHOTFLAM pair to every HDU.

Parameters:
imagestr

Path to a FITS file updated in place.

get_dolphot_photometry(split_images, reference, visit_obstable=None)[source]

Parse DOLPHOT output for the pipeline coordinate and print summary photometry.

Delegates to hst123.primitives.run_dolphot.DolphotPrimitive.get_dolphot_photometry().

Parameters:
visit_obstableastropy.table.Table, optional

Per-visit observation table. When provided, scraping reuses it for chip-level paths instead of rebuilding metadata via input_list() on every split FITS.

get_productlist(coord, search_radius)[source]

Query MAST for HST science products near a sky position.

Parameters:
coordastropy.coordinates.SkyCoord

Field center.

search_radiusfloat or str

Search radius passed to astroquery.mast.Observations.query_region.

Returns:
astropy.table.Table or None

Table with productFilename, downloadFilename, obsID, etc., or None if no rows match the configured filters.

handle_args(parser)[source]

Parse CLI arguments, normalize work/raw dirs, and apply overrides to self.options.

Parameters:
parserargparse.ArgumentParser

Parser from add_options().

Returns:
argparse.Namespace

Parsed options (also stored as self.options['args']).

handle_reference(obstable, refname)[source]

Resolve the drizzled reference image path, building it via pick_reference() if needed.

Parameters:
obstableastropy.table.Table

Current visit table.

refnamestr or None

User-supplied reference path, or None to generate.

Returns:
str or None

Path to the reference FITS, or None if missing or drizzle failed.

input_list(img, show=True, save=False, file=None, image_number=[])[source]

Build the observation metadata table for a list of FITS paths.

Parameters:
imglist of str

Input image paths; missing files may be filled via try_to_get_image().

showbool, optional

If True, log a one-line summary of inputs (and a debug table).

savebool, optional

If True, store the table on self.obstable.

filestr, optional

If set, write a formatted text summary under work_dir.

image_numberlist, optional

Optional per-row image indices; default is zeros.

Returns:
astropy.table.Table or None

Columns match hst123.settings names (image, exptime, datetime, filter, instrument, detector, zeropoint, chip, …). Returns None if no valid inputs remain.

make_dolphot_file(images, reference)[source]

Write the DOLPHOT parameter file listing chip images and reference.

Delegates to hst123.primitives.run_dolphot.DolphotPrimitive.make_dolphot_file().

needs_to_be_reduced(image, save_c1m=False)[source]

Decide whether an exposure should enter the reduction pipeline.

Parameters:
imagestr

Path to the FITS file.

save_c1mbool, optional

If True, allow WFPC2 *_c1m.fits through the instrument-shape checks.

Returns:
warningstr

Human-readable reason when the file is rejected (may be empty when accepted).

acceptbool

True if the file passes quality, filter, date, and coordinate checks.

Notes

Applies --before / --after, EXPFLAG, exposure time, filter allow-list, and optional on-sky containment tests for self.coord.

organize_reduction_tables(obstable, byvisit=False)[source]

Split a full observation table into per-visit sub-tables when requested.

Parameters:
obstableastropy.table.Table

Table including a visit column.

byvisitbool, optional

If True, return one table per visit; if False, return a single-element list.

Returns:
list of astropy.table.Table

Tables in processing order.

pick_deepest_images(images, reffilter=None, avoid_wfpc2=False, refinst=None)[source]

Select the longest-exposure images in preferred filters for a reference stack.

Parameters:
imageslist of str

Paths to calibrated FITS files.

reffilterstr, optional

If set, restrict to this filter (must be in acceptable_filters).

avoid_wfpc2bool, optional

If True, skip WFPC2 exposures.

refinststr, optional

If set, restrict to this instrument name.

Returns:
list of str

Deepest exposures matching the constraints.

pick_reference(obstable)[source]

Build or reuse the astrometric reference drizzle for alignment and DOLPHOT.

Chooses the deepest exposures in the preferred filter, optionally runs an instrument-mask drizzle when n<3, then drizzles to the visit reference filename ({inst}.{filt}.ref_{visit}.drc.fits) under work_dir.

Parameters:
obstableastropy.table.Table

Observation table with at least an image column.

Returns:
str or None

Path to the drizzled reference .drc.fits, or None on failure.

prepare_dolphot(image)[source]

Mask, split, and sky-subtract one exposure for DOLPHOT.

Delegates to hst123.primitives.run_dolphot.DolphotPrimitive.prepare_dolphot().

refresh_obstable_zeropoints_from_fits(obstable)[source]

Recompute zeropoint for each row with one FitsPrimitive.get_zpt() call per image (single FITS open each), preserving chip-specific calibration.

run_astrodrizzle(obstable, output_name=None, ra=None, dec=None, clean=None, save_fullfile=False)[source]

Drizzle a stack of exposures with DrizzlePac (sky match, CR rejection, combine).

Copies inputs to scratch paths (WFPC2 *_c0m / *_c1m), runs photeq when applicable, invokes drizzlepac.astrodrizzle.AstroDrizzle(), then renames sidecars and optionally writes a multi-extension .drc.fits.

Parameters:
obstableastropy.table.Table

Must include an image column listing calibrated FITS paths.

output_namestr, optional

Desired output path (*.drc.fits logical name); default drizzled.drc.fits.

ra, decfloat, optional

Field center for output WCS (degrees); default from self.coord.

cleanbool or None

DrizzlePac clean flag; resolved via resolve_drizzle_clean_flag().

save_fullfilebool, optional

If True, build a multi-extension DRC product when supported.

Returns:
bool

True if the drizzle product exists on disk; False otherwise.

run_cosmic(image, options, output=None)[source]

Run LAcosmic-style cosmic-ray detection (astroscrappy) on SCI extensions.

Parameters:
imagestr

Input FITS path.

optionsdict

Detector block with rdnoise, gain, saturate, sig_clip, sig_frac, and obj_lim (see settings.detector_defaults).

outputstr, optional

Output path; defaults to overwriting image.

Notes

When --add-crmask is set, updates matching DQ extensions or WFPC2 *_c1m.

run_dolphot()[source]

Execute DOLPHOT using the prepared parameter and image list.

Delegates to hst123.primitives.run_dolphot.DolphotPrimitive.run_dolphot().

sanitize_reference(reference)[source]

Normalize a drizzled reference FITS for DOLPHOT (single science HDU, headers).

Promotes SCI data to PRIMARY when needed, strips COMMENT/HISTORY, applies mask-based NaN/median masking, and fills detector calibration keywords.

Parameters:
referencestr

Path to the reference image (updated in place).

Returns:
None

Returns None if the file is missing.

sanitize_wfpc2(image)[source]

Rewrite a WFPC2 MEF so PRIMARY and SCI extensions match DOLPHOT expectations.

Parameters:
imagestr

Path to a WFPC2 *_c0m.fits file (modified in place).

split_image_contains(image, coord)[source]

Return whether a DOLPHOT chip image’s WCS encloses the target sky position.

Uses linear WCS only (mode='wcs') for robustness near chip edges.

Parameters:
imagestr

Path to a single-HDU chip file (e.g. *_c0m.chip1.fits).

coordastropy.coordinates.SkyCoord

Target position.

Returns:
bool

True if the projected pixel coordinates lie inside the image bounds.

try_to_get_image(image)[source]

Recover a missing exposure from the local archive layout (--archive).

Parameters:
imagestr

Destination path for the FITS file.

Returns:
bool

True if a file was copied from the archive, False otherwise.

update_image_wcs(image, options, use_db=True)[source]

Run STScI updatewcs on a calibrated image after header hygiene.

Skips images already marked TWEAKSUC or hierarchically aligned. Otherwise resolves CRDS paths, optionally calls AstrometryDB (use_db), then applies fix_hdu_wcs_keys and fix_idcscale.

Parameters:
imagestr

Path to the FITS file.

optionsdict

Unused legacy parameter (detector defaults come from self.options).

use_dbbool, optional

Forwarded to run_updatewcs().

Returns:
bool or None

True on success, None if updatewcs raised.

CLI options and redo helpers

CLI options: RA/Dec, work dir, download, tweakreg, drizzle, DOLPHOT, scrape-dolphot.

hst123.utils.options.add_options(parser=None, usage=None, version=None)[source]

Register hst123 arguments on an argparse parser. Returns the parser.

hst123.utils.options.want_redo_astrodrizzle(args) bool[source]

Return True if AstroDrizzle should overwrite existing drizzle outputs.

True when --clobber, --redo, or --redo-astrodrizzle is set.

hst123.utils.options.want_redo_astrometry(args) bool[source]

Return True if alignment should not be skipped based on prior success headers.

True when --clobber, --redo, or --redo-astrometry is set.

Path helpers

Path helpers for FITS files (stable across os.chdir()).

The pipeline changes the working directory to <work-dir>/workspace for alignment; relative paths must be normalized to absolute before that.

hst123.utils.paths.normalize_fits_path(path: str) str[source]

Return an absolute, normalized path for FITS references.

Parameters:
pathstr

User-supplied path; empty string is returned unchanged.

Returns:
str

os.path.normpath of the expanded absolute path.

Notes

After alignment, the process cwd is <work-dir>/workspace when --work-dir is set; unresolved relative paths would double-resolve (e.g. test_data/foo.fits under work_dir).

hst123.utils.paths.normalize_work_and_raw_dirs(work_dir, raw_dir)[source]

Resolve CLI --work-dir and --raw-dir to absolute paths.

Default raw directory is <work-dir>/raw. Call once after parsing arguments so paths remain valid after os.chdir(work_dir).

Parameters:
work_dirstr or None

--work-dir value, or None for current directory.

raw_dirstr or None

--raw-dir; if None, ".", or "./", use <work>/raw.

Returns:
tuple of str

(work_abs, raw_abs) absolute paths.

hst123.utils.paths.pipeline_chip_output_dir(work_dir: str | PathLike[str] | None) str | None[source]

Directory for DOLPHOT *.chipN.fits and *.chipN.sky.fits (base work_dir).

Chip sidecars are written here even when the parent exposure lives under pipeline_workspace_dir().

hst123.utils.paths.pipeline_workspace_dir(work_dir: str | PathLike[str] | None) str | None[source]

Return <work_dir>/workspace — calibrated inputs, TweakReg scratch, etc.

Drizzled stacks (per-epoch *.ut*.drc.fits and --drizzle-all) are written under <work_dir>/drizzle/, not here. The main reference drizzle (*.ref_*.drc.fits) stays in work_dir root.

Returns:
str or None

Absolute path, or None if work_dir is missing/empty.

Parallel BLAS / OpenMP guard

Context managers to silence stdout/stderr during noisy imports or C I/O.

Use suppress_stdout() for Python-level streams and suppress_stdout_fd() when C libraries write to file descriptor 1.

limit_blas_threads_when_parallel() avoids BLAS/OpenMP oversubscription when DrizzlePac uses multiple workers (num_cores > 1).

hst123.utils.stdio.limit_blas_threads_when_parallel(num_cores: int) Iterator[None][source]

When num_cores > 1, set common thread env vars to 1 for the duration.

Multi-worker DrizzlePac plus multi-threaded NumPy/BLAS often oversubscribes CPUs; capping worker-local BLAS threads usually improves wall time without changing outputs.

hst123.utils.stdio.suppress_stdout() Iterator[None][source]

Redirect sys.stdout and sys.stderr to os.devnull until exit.

Yields:
None

Notes

Does not affect the C runtime stdout; see suppress_stdout_fd().

hst123.utils.stdio.suppress_stdout_fd() Iterator[None][source]

Redirect OS file descriptor 1 (stdout) to os.devnull.

Yields:
None

Notes

For C extensions (e.g. DrizzlePac photeq) that write to the C stdio stdout. Python suppress_stdout() does not catch those writes. Stderr (fd 2) is left unchanged so logging handlers on stderr still work.

Work directory cleanup

After AstroDrizzle or TweakReg, the pipeline can remove scratch FITS and replay external logs into the session log. Use --keep-drizzle-artifacts to retain intermediates.

Relocate or remove drizzlepac / TweakReg scratch files in the work directory.

Default pipeline behavior keeps the work tree tidy: logs go under logs/ and common intermediate FITS/text files from AstroDrizzle are deleted after a successful step. Use --keep-drizzle-artifacts to skip this.

Intermediate names such as single_sci.fits, single_wht.fits, staticMask.fits, and drz_med.fits are produced by DrizzlePac during run_astrodrizzle. WFPC2 pipeline scratch files matching *hst123drz*_c0m.fits / *hst123drz*_c1m.fits come from wfpc2_astrodrizzle_scratch_paths in hst123.utils.astrodrizzle_helpers.

hst123.utils.workdir_cleanup.cleanup_after_astrodrizzle(work_dir: str, *, log: Logger, keep_artifacts: bool = False, base_work_dir: str | PathLike[str] | None = None) None[source]

After a successful AstroDrizzle run: remove well-known scratch products.

astrodrizzle.log is normally written under .hst123_runfiles/ and ingested into the session log (nothing to archive in the work root).

Matching uses both fixed basenames (legacy drizzle cwd) and globs because DrizzlePac often emits root-prefixed mask names (e.g. *_crmask.fits) rather than bare crmask.fits in work_dir.

When --drizzle-all is used, drizzle products live under <base_work_dir>/drizzle/. work_dir is typically <base>/workspace (the AstroDrizzle scratch/output tree); DrizzlePac may also drop staticMask.fits and similar files in the base work directory, so pass base_work_dir to scrub both trees.

hst123.utils.workdir_cleanup.cleanup_after_tweakreg(work_dir: str, *, log: Logger, keep_artifacts: bool = False) None[source]

After TweakReg: replay shift / headerlet text into the session log, then remove those files (no separate log copies under logs/ unless keep_artifacts). Also remove shifts WCS helper and extracted headerlet FITS.

hst123.utils.workdir_cleanup.remove_files_matching_globs(work_dir: str | PathLike[str], patterns: Sequence[str], *, log: Logger | None = None, log_each_path: bool = False) int[source]

Remove regular files under work_dir matching each glob in patterns.

Patterns are joined with work_dir (not the process CWD), so cleanup finds products under --work-dir (e.g. test_data/*.drc.noise.fits) regardless of where the CLI was launched.

The same path is only removed once even if multiple patterns match.

Parameters:
work_dir

Working directory containing pipeline outputs.

patterns

Glob patterns relative to work_dir (e.g. *drc.noise.fits).

log

If set and log_each_path is True, log.info each removed file.

log_each_path

Log every removal (default False for silent bulk deletes).

Returns:
int

Number of files removed.

hst123.utils.workdir_cleanup.remove_superseded_instrument_mask_reference_drizzle(logical_drc_path: str | PathLike[str], *, log: Logger, keep_artifacts: bool = False) None[source]

Remove the instrument-only reference drizzle produced when n_input < 3.

hst123.hst123.pick_reference() first drizzles to {inst}.ref.drc.fits (e.g. acs_wfc_full.ref.drc.fits) to build static masks, then drizzles again to the filter-named product (e.g. acs.f814w.ref_0001.drc.fits). The first file is interstitial and should be deleted after the final reference succeeds.

DOLPHOT catalog → HDF5

Parse DOLPHOT multi-extension output (catalog, .columns, .param, .data, .info, .warnings) and export a single HDF5 file with a labeled catalog plus metadata.

Designed against DOLPHOT 3.x text products: whitespace-separated numeric dpXXXX catalog, one descriptive line per column in dpXXXX.columns, and sidecar metadata files.

class hst123.utils.dolphot_catalog_hdf5.DolphotColumn(index_1based: int, index_0based: int, description: str, raw_line: str)[source]

One row from a DOLPHOT *.columns file.

description: str
index_0based: int
index_1based: int
raw_line: str
hst123.utils.dolphot_catalog_hdf5.dolphot_columns_to_astropy_table(catalog: ndarray, columns: list[DolphotColumn], names: list[str] | None = None)[source]

Build an astropy.table.Table with descriptive column names.

Parameters:
catalogndarray

Output of load_dolphot_catalog_array().

columnslist of DolphotColumn

From parse_dolphot_columns_file().

nameslist of str, optional

HDF5-safe names; defaults to unique_hdf5_column_names().

hst123.utils.dolphot_catalog_hdf5.find_column_index_0based(columns: list[DolphotColumn], key: str, image: str = '') int | None[source]

Match DOLPHOT *.columns semantics used by hst123.primitives.scrape_dolphot.ScrapeDolphotPrimitive.get_dolphot_column().

key must appear in the column description. If image is non-empty, it must appear in the description (after stripping a .fits suffix). If image is empty, any column whose description contains key may match—the first such column is returned (same as substring "" in line being true for every line).

hst123.utils.dolphot_catalog_hdf5.group_param_by_image(param: Mapping[str, str]) tuple[dict[str, str], dict[str, dict[str, str]]][source]

Split flat imgNNNN_* keys into per-image dicts (img0001, …).

hst123.utils.dolphot_catalog_hdf5.load_dolphot_catalog_array(path: str | Path) ndarray[source]

Load the main DOLPHOT catalog (numeric rows, whitespace-separated).

Parameters:
pathpath-like

Path to dpXXXX (no extension), same as dolphot['base'] in the pipeline.

Returns:
numpy.ndarray

2-D float array of shape (n_sources, n_columns).

Notes

Uses numpy.loadtxt(). Scraping uses a single load plus vectorized filtering (see hst123.primitives.scrape_dolphot) so the catalog is read once per scrape.

hst123.utils.dolphot_catalog_hdf5.merge_image_metadata(param: Mapping[str, str], info: Mapping[str, Any], data: Mapping[str, Any], warnings: Mapping[str, Any]) dict[str, Any][source]

Combine parsed sidecars into one JSON-serializable tree keyed by img0000 .. imgNNNN.

hst123.utils.dolphot_catalog_hdf5.parse_column_index_and_description(line: str) tuple[int, str] | None[source]

Parse a single *.columns line of the form N. description.

Returns:
(1-based index, description) or None if the line does not match.
hst123.utils.dolphot_catalog_hdf5.parse_dolphot_columns_file(path: str | Path) list[DolphotColumn][source]

Read a DOLPHOT *.columns file into structured column definitions.

Parameters:
pathpath-like

Path to dpXXXX.columns.

Returns:
list of DolphotColumn

One entry per line, in file order (column 1 .. N).

hst123.utils.dolphot_catalog_hdf5.parse_dolphot_data_file(path: str | Path) dict[str, Any][source]

Parse dpXXXX.data: WCS, alignment iteration counts, PSF quality, aperture-correction stats.

hst123.utils.dolphot_catalog_hdf5.parse_dolphot_info_file(path: str | Path) dict[str, Any][source]

Parse dpXXXX.info: MJD per input image, limits, filter/exptime lines, alignment, apcor.

Structure varies slightly by instrument; unknown lines are kept in extra_lines.

hst123.utils.dolphot_catalog_hdf5.parse_dolphot_param_file(path: str | Path) dict[str, str][source]

Parse dpXXXX.param (key = value lines, DOLPHOT style).

hst123.utils.dolphot_catalog_hdf5.parse_dolphot_warnings_file(path: str | Path) dict[str, Any][source]

Parse dpXXXX.warnings into all lines and optional buckets by image path.

hst123.utils.dolphot_catalog_hdf5.read_dolphot_catalog_hdf5(path: str | Path, photometry_path: str = 'photometry')[source]

Read back a table written by write_dolphot_catalog_hdf5().

Returns:
astropy.table.Table
hst123.utils.dolphot_catalog_hdf5.unique_hdf5_column_names(columns: list[DolphotColumn]) list[str][source]

Return safe column names, de-duplicated with numeric suffixes if needed.

hst123.utils.dolphot_catalog_hdf5.write_dolphot_catalog_hdf5(out_path: str | Path, base: str | Path, *, photometry_path: str = 'photometry', include_raw_sidecars: bool = True, compression: bool = True, dolphot_dir: str | Path | None = None, embed_dolphot_directory_text: bool = False) Path[source]

Write one HDF5 file with the full DOLPHOT catalog and metadata.

Parameters:
out_pathpath-like

Output .h5 file.

basepath-like

DOLPHOT output base path without extension (same as pipeline dolphot['base']).

photometry_pathstr

HDF5 path for the Table (Astropy default metadata).

include_raw_sidecarsbool

If True, store UTF-8 text of .param, .info, .data, .warnings, and .columns as datasets under metadata/raw/.

compressionbool

If True, use gzip compression on the table (requires Astropy + h5py).

dolphot_dirpath-like, optional

Directory scanned for a full file manifest (default: base.parent, i.e. the DOLPHOT output folder such as <work>/dolphot/). Every file path, size, and mtime are stored. Optional text embedding under metadata/dolphot_directory/text_embed/ when embed_dolphot_directory_text is True.

embed_dolphot_directory_textbool, optional

If True, embed small UTF-8 text files from dolphot_dir (can be slow for large trees). Default False (manifest only).

Returns:
pathlib.Path

Path to the written file.

Raises:
ImportError

If h5py is not installed.

Data model

Lightweight HST file handle with path properties and metadata (dict-based).

class hst123.datamodels.hst_model.HSTModel(filepath, meta: dict | None = None)[source]

Base class for associating a FITS path with metadata.

Subclasses may extend on_init() for additional setup.

Parameters:
filepathstr or None

Path to an HST data file, or None for in-memory-only use.

metadict, optional

Initial metadata merged into meta.

Attributes:
filepathstr or None

Path passed at construction.

metadict

Metadata dictionary (e.g. model_type, filename).

property basename: str | None

Base filename of filepath, or None if no path is set.

Returns:
str or None
property dirname: str | None

Directory containing filepath, or None if no path is set.

Returns:
str or None
init_meta(meta: dict | None = None) None[source]

Reset metadata and merge optional user values.

Parameters:
metadict, optional

Keys merged into meta.

on_init() None[source]

Hook invoked after init_meta(); default sets model type and filename.

Override in subclasses for custom initialization.

Primitives base class

class hst123.primitives.base.BasePrimitive(pipeline)[source]

Bases: object

Attach to the pipeline and share options/state via self._p.

Parameters:
pipeline

The running hst123 instance (required).

Attributes:
_p

Same object as pipeline.

_log

Logger named after the primitive module (hst123.primitives…).

Raises:
TypeError

If pipeline is None.

property pipeline

Pipeline instance (alias of self._p).

Returns:
object