kmhess / SoFiA-image-pipeline

Generate figures of spectral line sources, for publication or quick inspection, based on SoFiA-2 output catalog and fits files.
GNU General Public License v3.0
16 stars 7 forks source link

SoFiA Image Pipeline (SIP)

DOI Docker build latest

Introduction

SIP takes a SoFiA generated source catalog and produce images for publication or quick inspection. Images include HI contours overlaid on multiwavelength images, HI moment maps, pixel-by-pixel SNR maps, pv-diagrams with SoFiA mask, and spectra with and without noise.

Requirements

This code has been developed and tested with Python 3.9.7, and appears to work with up to Python 3.13.

Combining individual images with the -m option requires ImageMagick be installed.

SIP was written with the outputs from SoFiA 2.4.1 (bba8c43) and later. Through troubleshooting, we have improved the output of both SIP and SoFiA-2, so for best performance, please use the latest version of each.

For the best SIP unit conversion performance, SoFiA-2 needs to have been run with the following parameters:

parameter.wcs = True
parameter.physical = True
parameter.offset = True

Installation

Setting up an environment

We recommend using a virtual environment to install and rup SIP so as to not conflict with other packages. For example:

python3 -m venv .venv
source .venv/bin/activate

PyPI

You can install the latest SIP released on PyPI by running pip install:

pip install sofia-image-pipeline

Development

You can install the latest GitHub version of SIP locally by cloning the repository and running:

python3 setup.py develop

Docker

We provide a Docker image for use in containerised applications. This image can be found here. To use the latest official Docker image:

docker run -it -v <cwd>/<folder>:/app/<folder> sofiapipeline/image_pipeline:latest -c <folder>/<catalog.xml>

Usage

SIP works under the assumption that the user has run SoFiA-2 which generated an xml and/or ascii catalog file, and fits moment maps and cubelets for each source. SIP assumes that these files are in the same directory structure as created by SoFiA-2 where the catalog file and *_cubelets/ folder are in the same directory. The output from SIP will be in a newly created folder next to *_cubelets/ called *_figures/.

$ sofia_image_pipeline

usage: sofia_image_pipeline [-h] -c CATALOG [-id [SOURCE_ID ...]] [-x SUFFIX] [-o ORIGINAL] [-b BEAM] [-cw CHAN_WIDTH] [-i IMAGE_SIZE] [-snr SNR_RANGE SNR_RANGE] [-s [SURVEYS ...]] [-m [IMAGEMAGICK]] [-ui USER_IMAGE] [-ur USER_RANGE USER_RANGE]  [-line SPECTRAL_LINE]
sofia_image_pipeline: error: the following arguments are required: -c/--catalog

Help

To get help on the parameters:

sofia_image_pipeline -h

Options

REQUIRED:
    -c     Catalog file. Can be the ascii file ending in .txt or the XML file from SoFiA-2.

OPTIONAL:
    -id    Select certain sources, or range of sources from catalog based on the source id number. Default is all sources. Include `0` to make summary image of all sources.
    -x     Output image file type. Any file type accepted by plt.savefig() is in theory valid.  Default is 'png'.
    -o     Path to the original data file on which source finding was conducted. This allows the spectrum with noise to be plotted over the full spectral range of the original cube.  
    -b     Synthesized beam dimensions. If the primary header of the FITS files do not contain the beam information, this can be provided by the user. Accepts 1 to 3 values in order (bmaj, bmin, bpa).
    -cw    Channel width. This is only necessary if a source cubelet is not available, for example if user only has a mom0.  Channel width must then be provided in the native units of the original data cube (typically Hz or m/s.)
    -i     Minimum image size (ARCMIN). Images will be square. If an HI source exceeds the requested size, a larger image to fit the HI contours will be generated. Default is 6 arcmin.
    -snr   Specify the SNR range within which to plot the lowest HI contour. Requires 2 values. Default is [2.0, 3.0].
    -s     List of surveys on which to overlay HI contours. Only the first entry will be used in the combined image if `-m` option is used. If 'none', work in offline mode. Default is 'DSS2 Blue'.
    -m     Make a combined image using ImageMagick.  If a path is provided after this option, it is assumed to be the path to the `convert` executable of ImageMagick. 
    -ui    User supplied image for overlaying HI contours.  Can use this in combination with `-s` and a list of surveys.
    -ur    Percentile range when plotting the user supplied image.  Requires two values. Default is [10., 99.].
    -l     Specify a spectral line for all sources in catalog. Default is 'HI'.  Also possible is 'CO' and 'OH'.

Examples

sofia_image_pipeline -c <path/to/catalog.xml>
sofia_image_pipeline -c <path/to/catalog.txt> -x pdf -o <path/to/original_cube.fits>
sofia_image_pipeline -c <path/to/catalog.txt> -s panstarrs 'GALEX Far UV' -m

Test data cube

The SoFiA test data cube can be found through the SoFiA-2 wiki here (14.2 MB). This cube contains HI emission from several galaxies around NGC 4036.

The current version of this repo also has a test data set (without instructions) in the test_data/ folder. The cube contains HI emission from several galaxies around UGC 7012.

Advanced tips

Known Issues

See the github repo for known bugs and desired enhancements. We aim to fix serious bugs as quickly as possible.

In addition we are aware of the following issues:

Other caveats

Version history

Copyright and licence

SIP was created by Kelley M. Hess

© 2022 Kelley M. Hess

This programme is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This programme is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this programme. If not, see http://www.gnu.org/licenses/.