Skip to content

Python API

Author: Pier-Francesco Rocci

Developed with assistance from ChatGPT, Claude, and Mistral.

Version: 0.3.4.2

Generated from source by scripts/docs.ps1 (or scripts/tasks.sh docs). Do not edit this file manually.

Quick Start | User Guide

Import public symbols from proper_transient_finder. Coordinates are zero-based; candidate scores do not confirm astrophysical variability.

compare_images

compare_images(reference_fits: str | PathLike[str], science_fits: str | PathLike[str], output_dir: str | PathLike[str] | None=None, *, config: PipelineConfig | Mapping[str, object] | None=None, threshold_sigma: float=5.0) -> PipelineResult

Compare calibrated FITS exposures and return images and candidate catalogs.

Omit output_dir for an in-memory run: inputs are read but no files or plots are created. Supply it to save the ordinary full-pipeline products, logs and status. config accepts a copied/revalidated PipelineConfig or a mapping. Scientific and overwrite defaults are identical to the CLI.

Raises ValueError for invalid settings or incompatible images, and OSError subclasses for missing inputs or protected/unwritable outputs. Exceptions propagate to the caller; this function never exits or prints to stdout. Cross-filter comparisons require config.cross_filter=True and remain experimental: candidate scores do not establish variability significance.

compare_batch

compare_batch(jobs: Iterable[BatchJob], output_dir: str | PathLike[str] | None=None, *, config: PipelineConfig | Mapping[str, object] | None=None, threshold_sigma: float=5.0, fail_fast: bool=False, retain_results: bool | None=None, check_only: bool=False) -> BatchResult

Run named FITS pairs sequentially using the unchanged single-pair pipeline.

Each persisted job writes under output_dir/name; the root must be new/empty, or is replaced first when overwrite is enabled, an interactive terminal confirms the replacement, or assume_yes is set. batch_summary.json is atomically updated before/after each job. Structural name/config/output errors raise before any processing or output creation. Image-processing exceptions are recorded per job. By default execution continues; fail_fast stops after the first failure and marks remaining jobs skipped. Interrupts propagate after recording partial progress when possible.

Full PipelineResult objects are retained by default only without output_dir; override retain_results explicitly to select memory usage. With check_only, input preflight is performed without creating any outputs or subtracting. Scientific defaults, input checks, and cross-filter caveats remain unchanged.

load_batch_manifest

load_batch_manifest(manifest_path: str | PathLike[str]) -> list[BatchJob]

Load a JSON array of jobs, resolving FITS/mask/PSF paths relative to its file.

Each object requires ref/new and optionally name, config, threshold_sigma. Missing names become pair-0001, pair-0002, etc. Unknown keys and malformed objects raise ValueError. Path existence and scientific checks occur during batch processing/preflight. Loading alone creates no output files.

prepare_template_request

prepare_template_request(science_fits: str | Path, template_filter: str, *, survey: str='auto', science_filter: str | None=None) -> TemplateRequest

Read only the science input and describe the HiPS request without network use.

The returned request asks the service for exactly the science WCS and shape, so the whole footprint is covered by a single HiPS cutout; no local tiling or mosaic is planned. Nothing is downloaded or written here.

fetch_survey_template

fetch_survey_template(request: TemplateRequest, cache_dir: str | Path, *, timeout: float=30, max_download_mb: float=DEFAULT_MAX_DOWNLOAD_MB, check_moc_coverage: bool=True) -> SurveyTemplate

Download a HiPS template or provider fallback, or reuse a cached template.

The returned image is already projected onto the requested science WCS and shape. Pan-STARRS asinh values are linearized, non-finite pixels are masked, and no variance plane is invented. Explicit HiPS identifiers are checked against the CDS MOCServer coverage map before downloading unless check_moc_coverage is false. The service image is cached with a checksum-verified JSON manifest.

compare_survey_images

compare_survey_images(science_fits: str | Path, output_dir: str | Path, *, template_filter: str, survey: str='auto', cache_dir: str | Path='survey_cache', config: PipelineConfig | Mapping[str, Any] | None=None, science_filter: str | None=None, science_units: str | None=None, template_units: str | None=None, template_gain: float | None=None, timeout: float=30, max_download_mb: float=DEFAULT_MAX_DOWNLOAD_MB, check_moc_coverage: bool=True, threshold_sigma: float=5, check_only: bool=False) -> PipelineResult | dict

Acquire a HiPS template and call the unchanged comparison API.

The template is projected onto the science pixel grid by the service, so the pipeline runs without an extra reprojection. Check-only validates local WCS/options without downloads or writes; it does not certify service availability, calibration, overlap or detectability. HiPS pixels are not original detector counts: cache-owned copies are labeled with the verified science count unit so the pipeline can fit one global stellar flux scale. science_units may declare that unit when the science header omits BUNIT; it never converts pixels. Input FITS files are never edited. Provider-native fallback templates are experimental and can be used by the normal subtraction pipeline; their cross-provider calibration remains unverified.

compare_survey_batch

compare_survey_batch(science_images: Iterable[str | Path], output_dir: str | Path, *, template_filter: str, survey: str='auto', cache_dir: str | Path='survey_cache', fail_fast: bool=False, check_only: bool=False, **options: Any) -> BatchResult

Sequential HiPS survey comparisons with existing lightweight batch result types.

Field Type Default
acquisition_only list[dict] []

load_science_list

load_science_list(list_path: str | Path) -> list[Path]

Load text lines or a JSON array of science paths, relative to the list file.

TemplateRequest

Validated science pixel grid and explicitly selected HiPS template band.

Field Type Default
science_fits Path required
survey str required
template_filter str required
science_filter str required
native_science_filter str required
ra_deg float required
dec_deg float required
size_deg float required
science_mjd float \| None required
hips_id str ''
width int 0
height int 0
grid_sha256 str ''

SurveyTemplate

Locally cached HiPS FITS on the science grid and auditable metadata.

Field Type Default
fits_path Path required
metadata dict required

BatchJob

One named pair. Mapping config overrides batch settings; a dataclass replaces them.

Names must be unique ignoring case and use 1-64 letters, digits, underscores or hyphens, beginning with a letter/digit. Windows device names are forbidden. A missing threshold inherits the batch threshold.

Field Type Default
name str required
reference_fits str \| PathLike[str] required
science_fits str \| PathLike[str] required
config PipelineConfig \| Mapping[str, object] \| None None
threshold_sigma float \| None None

BatchItemResult

Per-job status; full image results are optional to bound batch memory usage.

Field Type Default
name str required
state str required
output_dir Path \| None required
accepted_candidates int \| None None
rejected_candidates int \| None None
elapsed_seconds float 0.0
error_type str \| None None
error str \| None None
result PipelineResult \| None None
preflight dict \| None None
reference_fits Path \| None None
science_fits Path \| None None

BatchResult

Ordered job records, including failures/skips; success is not scientific confirmation.

survey_status is set by survey batches. Provider fallbacks are normal completed survey jobs; legacy acquisition-only fields remain for compatibility.

Field Type Default
items tuple[BatchItemResult, ...] required
state str required
output_dir Path \| None required
check_only bool False
survey_status dict \| None None

PipelineConfig

Explicit assumptions and conservative candidate-selection defaults.

Field Type Default
method str 'kernel'
smooth_psf bool False
fitted_psf bool True
align bool False
reproject bool False
reproject_units str 'auto'
iterative bool False
beta bool True
shift bool False
inf_loss float 0.15
gain float \| None None
saturation float \| None None
cosmic_rays bool True
psf_radius int 8
ref_psf_radius int \| None None
new_psf_radius int \| None None
min_stars int 6
alignment_tolerance float 0.35
flux_scale float \| None None
max_scale_scatter float 0.15
ref_mask str \| None None
new_mask str \| None None
ref_psf str \| None None
new_psf str \| None None
min_pixels int 3
min_fwhm_ratio float 0.6
max_fwhm_ratio float 1.8
max_elongation float 2.0
max_dipole_ratio float 0.5
min_psf_correlation float 0.65
max_candidates int 1000
plots bool True
overwrite bool False
assume_yes bool False
cross_filter bool False
color_association_fwhm float 1.0
color_reference_snr float 5.0
color_quantile float 0.95
color_error_margin float 3.0
science_filter str \| None None

PipelineResult

Comparison output; arrays and tables remain editable by the caller.

Coordinates are zero-based. Positive residuals are science minus scaled reference; in cross-filter mode their sign can instead reflect color. score is empirically calibrated, while products['score'] is raw. A missing output_dir means no products were written to disk.

Field Type Default
candidates pd.DataFrame required
rejected_candidates pd.DataFrame required
background_diagnostics pd.DataFrame required
difference NDArray[np.float64] required
score NDArray[np.float64] required
psf NDArray[np.float64] required
mask NDArray[np.bool_] required
products dict[str, np.ndarray] required
metadata dict[str, Any] required
output_dir Path \| None required

ProperTransientFinder

Validated PSF matching, signed transient detection, and artifact vetting.

ProperTransientFinder(ref_path: str | PathLike[str], new_path: str | PathLike[str], output_dir: str | PathLike[str], config: PipelineConfig | Mapping[str, object] | None=None)
ProperTransientFinder.preflight(threshold_sigma=5.0) -> dict

Read and validate inputs without writing outputs, registering, or estimating PSFs.

ProperTransientFinder.perform_image_subtraction()
ProperTransientFinder.detect_sources_in_difference(threshold_sigma=5.0)
ProperTransientFinder.run_full_pipeline(threshold_sigma=5.0, estimate_psf_separately=False)

compare_cross_filter

compare_cross_filter(reference_fits, science_fits, output_dir, *, reproject=False, max_scale_scatter=0.15, threshold_sigma=5.0, **config) -> pd.DataFrame

Save an experimental PSF-matched comparison and return warning-labeled candidates.

A global stellar scale does not correct color. Flux errors and scores exclude that systematic. Extra keywords are ordinary PipelineConfig options; the cross-filter flag and explicit arguments here take precedence.

main

main(argv: list[str] | None=None) -> int

Command-line interface shared by the standalone wrapper and module.

Configuration Validation

Defaults above are read directly from the dataclass. Range and compatibility checks are enforced by PipelineConfig; see the user guide for their meaning.

Acknowledgments

  • ProperImage for astronomical image processing.
  • Astropy for FITS, WCS, and astronomy utilities.