astromatic API Reference

Wrappers around the software library.

class moastro.astromatic.Astromatic(configs=None, workDir='.', defaultsPath=None)[source]

Abstract base class for the Astromatic software wrappers (SExtractor, SCAMP, Swarp).

add_default_param_to_configs(defaultsCommand, name='defaults.txt')[source]

Adds the default parameters filepath to the configs dictionary. Writes a new defaults file is one is not found/available.

add_to_configs(key, value)[source]

Add a key, with a value, to the configs dictionary. Use this to ensure the configs are initialized.


Place holder subclass to generate the command line string for running the Terapix program.


Joins the command line configuration arguments together, returning a string.


Runs the command process. The optional virtualHost is a tuple with format:

(user@host, rootPath)
set_null_config(key, null='""')[source]

Sets the value of the key configuration to the null value, which is a null string (“”) by default. If null is None, the the key is deleted altogether.


Writes the Swarp internal defaults and returns its path.

write_input_file_list(inputFITSPaths, name='inputlist')[source]

Writes the path of each FITS file to a file workDir/inputlist.txt

class moastro.astromatic.BatchSourceExtractor(imageLog, imageKeys, imagePathKey, catalogKey, weightKey=None, weightType=None, psfKey=None, configs={}, workDir='se', defaultsPath='se/', catPostfix='se_cat')[source]

Run Source Extractor in parallel on multiple processors. ImageLog is used to store results from each run.

run(nthreads=8, debug=False)[source]

docstring for run

set_check_images(checkKeyDict, checkDir)[source]
Parameters:checkKeyDict – dictionary specifying SE check image types, and the image log keys to store paths to those images under. Keys are check type (SEGMENTATION, etc), values are image log keys.
class moastro.astromatic.PSFex(catalogPaths, imageLog=None, imageKeys=None, defaultsPath=None, configs=None, xmlKey=None, workDir='psfex', groupName=None)[source]

Wrapper on the PSFex PSF-modelling software.


Returns the path to the specified type of check iamage.

classmethod from_db(imageLog, imageKeys, catalogPathKey, configs=None, xmlKey=None, defaultsPath=None, workDir='psfex')[source]

Creates a PSFex run from an image log database.

  • imageLog – a ImageLog-compatible database instance.
  • imageKeys – image keys in the imageLog where SE catalogs will be gathered.
  • catalogPathKey – record field where the SE (Source Extractor) catalogs are found for each image
  • xmlKey – key to install XML. If None, then PSFex will not produce XML output.
  • configs – (optional) dictionary of PSFex settings. Keys and values are standard PSFex command line arguments.
  • defaultsPath – path to where a PSFex configuration file can be found
  • workDir – directory where PSFex outputs are saved.

Makes the source extractor command (for CL execution). Returns a string.


Get the paths to each image, in the same order as the input catalog paths.


Files the psf file paths into the image log under psfKey for all images.


Files the xml filepaths into image log under xmlKey for all images.

set_check_images(checkList, prefix, checkDir)[source]

Sets which check images should be made, and where they should be saved. By default, all checkimages retain the base file name, plus and appropriate extension.

Parameters:checkList – sequence of check image types. May include:
  • CHI
  • prefix – filename prefix for all check images.
  • checkDir – directory where the check images should be saved.
set_check_plots(plotList, prefix, plotDir, plotType='PDF')[source]

Sets which check figures (plplot) should be made, and where they should be saved.

Parameters:checkList – sequence of check figure types. May include:
  • FWHM - map of PSF FWHM over field

  • ELLIPTICITY - map of PSF ellipticity over field

  • COUNTS - map of spatial density of point sources

  • COUNT_FRACTION - map of fraction of points accepted for

    PSF evaluation

  • CHI2 - map of average chi^2/d.o.f over field

  • MOFFAT_RESIDUALS - map of moffat residuals

  • ASYMMETRY - map of asymmetry indices

class moastro.astromatic.Scamp(seCatPaths, imageLog=None, imageKeys=None, defaultsPath=None, configs=None, checks=None, workDir='scamp', useFileRefs=False)[source]

Python wrapper class for Terapix’s SCAMP application for astrometric and photometric registration of mosaics.


the useFileRefs=True feature seems to be broken b/c SCAMP doesn’t

recognize the files that it downloaded itself. For now, always use False for this option.

classmethod from_db(imageLog, imageKeys, seCatKey, defaultsPath=None, configs=None, checks=None, workDir='scamp', useFileRefs=False)[source]

Construct a SCAMP run from an image log database.


Writes the command to run scamp, and returns as a string.


Returns the paths to existing reference catalogs.


Insert the SExtractor objects from the self.headDB dictionary to the given imageLog under the key scampKey. Must have instantiated Scamp with Scamp.from_db() so that the image keys are known.


Initializes the scamp checkplot types, and associated file names.

By default, the file names are lower-cased versions of the check type, and the files are placed in the workDir.

class moastro.astromatic.SourceExtractor(fitsPath, catalogName, weightPath=None, weightType=None, psfPath=None, configs=None, workDir='sex', defaultsPath='se/')[source]

Represents a run of Terapix’s Source Extractor.


Returns the path to the SE catalog.


Returns the path to a check image of type checkType. Returns None if no such check image exists.


Makes the source extractor command (for CL execution). Returns a string.

set_check_images(checkList, checkDir)[source]

Sets which check images should be made, and where they should be saved. By default, all checkimages retain the base file name, plus an appropriate extension.

set_weight_file(weightPath, weightType)[source]

Sets a weight image as a FITS at weightPath of SE weight image type weightType.

class moastro.astromatic.Swarp(imagePaths, mosaicName, scampHeadPaths=None, weightPaths=None, defaultsPath=None, configs=None, workDir='mosaic', uniqueExt='')[source]

This class wraps the functionality of Astromatic’s Swarp mosaic software.


Copies the WCS keys in the header of the mosaic image (as produced) by to an ascii header file at headerPath.

This is useful for creating a .head file for use with a second run of Swarp with another data set (like a different colour) so that the pixel-sky projection is the same in both.

TODO DEPRECATED Refactored as a function in Keep this method around as a wrapper to Terapix.copyHeaderWCS().

classmethod from_db(imageLog, imageKeys, pathKey, mosaicName, scampHeadPathKey=None, weightPathKey=None, defaultsPath=None, configs=None, workDir='mosaic', uniqueExt='')[source]

Construct a Swarp run from database records.


Produces the command to run Swarp.

Returns:tuple of (mosaic path, mosaic weight path).

Use the header of targetFITSPath to define output pixel space.

This method links targetFITSPath to mosaicName”.head”, which Swarp automatically recognizes.


Alternative to set_target_wcs, it creates writes the header to the appropriate filename and tells swarp to use it as a base WCS reference.

write_input_file_list(paths, name='list')[source]

Override the Terapix class’s method so that lists of imagePaths, associated with a single image image key can be expanded.

The motivation for this is when doing a combine step on a previous resampling step. Resampling will break apart multi-extension FITS files, causing a single image of weight image to now be several images. When the user applies Swarp on the combine step, the imagePathKey (and the weightKey) must be lists to that set of FITS files.