How vvinuv/pymorph works
Purpose and entry point
PyMorph is a Python galaxy-morphology batch pipeline. It combines SExtractor detections/measurements with GALFIT parametric decomposition, plus in-process non-parametric morphology calculations. The installed CLI is pymorph_bin; orchestration is centered in src/pymorph/pymorph.py, with a working-directory config.ini as the operational contract.
Input modes and configuration boundary
The pipeline supports full astronomical frames or pre-cut postage stamps, selected by configuration and modes such as target-catalog fitting or discovery-and-fit. Inputs are FITS science images, optional RMS/weight maps, object catalogs, SExtractor catalogs, and one or more PSFs. Representative runnable datasets are examples/full_image/config.ini and examples/postage_stamps/config.ini; package defaults live at src/pymorph/config.ini.
Detection and initial-parameter stage
SExtractor is an external executable invoked to detect/measure sources and establish fit initialization, unless an appropriate catalog is supplied. PyMorph maintains SExtractor templates and convolution/filter assets, separating external-program configuration from Python orchestration:
• src/pymorph/runsexfunc.py
• src/pymorph/get_params.py
• src/pymorph/SEx/default.sex
Per-target image preparation
For each selected galaxy, the pipeline resolves target position/catalog data, creates or uses a cutout, handles weight-image semantics, estimates background, and builds neighbor masks. This is the important boundary between frame-scale survey data and isolated per-object fitting/measurement products:
• src/pymorph/weightimage.py
• src/pymorph/bkgdfunc.py
• src/pymorph/maskfunc.py
PSF selection
PSF handling chooses an individual, listed, or nearest suitable PSF for each target; selection can use coordinate-bearing filenames and SExtractor star/galaxy probability. The selected PSF becomes an explicit input to GALFIT and affects model convolution:
• src/pymorph/psffunc.py
• examples/full_image/psf_1447218+0838538.fits
• examples/postage_stamps/psflist.list
Parametric decomposition
GALFIT is the second required external executable. PyMorph generates GALFIT control files from SExtractor-derived initial values and configured component models (bulge, disk, bar), invokes GALFIT, and parses fit logs/results. Detailed mode can explore randomized initial configurations:
• src/pymorph/galfit_config_run.py
• src/pymorph/detailed_galfit.py
• src/pymorph/read_fitlog.py
Non-parametric measurements and derived quantities
An optional Python-native branch computes CASGM-style morphology metrics: concentration, asymmetry, clumpiness, Gini, and moment-related values. Cosmological conversion utilities support physical derived parameters:
• src/pymorph/casgm.py
• src/pymorph/cosmocal.py
• src/pymorph/bar_length.py
Results, diagnostics, and dependencies
Fit/measurement results flow into CSV/database writers, optional plots, and HTML reporting. Quality flags and fit-diagnosis thresholds govern result classification. Runtime infrastructure is local filesystem plus the configured SExtractor and GALFIT binaries; no network service or web runtime is indicated.
• src/pymorph/writecsv.py
• src/pymorph/writedbfunc.py
• src/pymorph/writehtml.py
Main entry points: weightimage.py Cutout & weight preparation · galfit_config_run.py GALFIT control generation · get_params.py Catalog parameter extraction · pymorph.py Pipeline orchestrator
Components 17
Inputs & Configuration
- pymorph_bin CLI · Launches batch orchestration.
- Pipeline orchestrator · Coordinates configured target processing.
src/pymorph/pymorph.py - Working config.ini · Selects modes, inputs, models, and thresholds.
examples/full_image/config.ini - FITS, catalogs & maps · Science frames or stamps with optional weights and catalogs.
Detection & Preparation
- SExtractor · Detects and measures sources when needed.
- SExtractor runner
src/pymorph/runsexfunc.py - Catalog parameter extraction · Derives target and fit starting values.
src/pymorph/get_params.py
Per-Target Analysis
- Cutout & weight preparation · Bridges survey-scale inputs to object products.
src/pymorph/weightimage.py - Background estimation
src/pymorph/bkgdfunc.py - Neighbor masking
src/pymorph/maskfunc.py - PSF selection · Chooses individual, listed, or nearest PSF.
src/pymorph/psffunc.py - GALFIT control generation · Builds component-model control files.
src/pymorph/galfit_config_run.py - GALFIT · Performs PSF-convolved parametric decomposition.
- Fit log parser
src/pymorph/read_fitlog.py - CASGM measurements · Optional non-parametric metric branch.
src/pymorph/casgm.py
Results & Diagnostics
- CSV & database writers
src/pymorph/writecsv.py - HTML reporting
src/pymorph/writehtml.py
Connections 26
- pymorph_bin CLI → Pipeline orchestrator: starts
- Working config.ini → Pipeline orchestrator: controls
- FITS, catalogs & maps → Pipeline orchestrator: provides targets
- Pipeline orchestrator → SExtractor runner: runs when catalog needed
- SExtractor runner → SExtractor: invokes
- SExtractor → Catalog parameter extraction: source catalog
- FITS, catalogs & maps → Catalog parameter extraction: supplied catalog
- Pipeline orchestrator → Cutout & weight preparation: per selected target
- Catalog parameter extraction → Cutout & weight preparation: target position
- FITS, catalogs & maps → Cutout & weight preparation: image and weights
- Cutout & weight preparation → Background estimation: cutout
- Cutout & weight preparation → Neighbor masking: cutout
- Catalog parameter extraction → PSF selection: source coordinates
- FITS, catalogs & maps → PSF selection: PSF candidates
- Catalog parameter extraction → GALFIT control generation: initial values
- Cutout & weight preparation → GALFIT control generation: fit image
- Background estimation → GALFIT control generation: sky estimate
- Neighbor masking → GALFIT control generation: mask
- PSF selection → GALFIT control generation: selected PSF
- GALFIT control generation → GALFIT: control file
- GALFIT → Fit log parser: fit logs and models
- Cutout & weight preparation → CASGM measurements: prepared image
- Neighbor masking → CASGM measurements: mask
- Fit log parser → CSV & database writers: parametric results
- CASGM measurements → CSV & database writers: optional metrics
- CSV & database writers → HTML reporting: classified results