faust_imaging module

FAUST Archival Pipeline

This module contains the implementation for the CASA spectral line imaging pipeline for the archival products of the ALMA Large Program FAUST. Please see the README file for further information and the documentation, which may be found under the docs/ directory or online at:

This script may be run under CASA v5 (Python 2) or CASA v6 (Python 3). The current calibration pipeline release, CASA v5.6, is recommended as it has received the most extensive testing. To use the script interactively, execute the module by running at the CASA IPython prompt: execfile('<PATH>/<TO>/faust_imaging.py').

Authors

Brian Svoboda and Claire Chandler.

Copyright 2020, 2021 Brian Svoboda under the MIT License.

class Target(name, res, vsys)

Bases: object

vlsr_from_window(velo_width)
Parameters:

velo_width (str) – CASA quantity string, e.g. ‘10km/s’.

class DataSet(field, setup=1, kind='joint')

Bases: object

Parameters:
  • field (str) – FAUST target field name.

  • setup (int) –

    FAUST Setup index number:

    1 : Band 6, 220 GHz 2 : Band 6, 250 GHz 3 : Band 3, 90 GHz

  • kind (str) – Datset descriptor for which measurement set files to use. Valid values include: (‘joint’, ‘12m’, ‘7m’). Note that only 12m data is availabe for Setup 3.

low_freqs = {1: 217, 2: 245, 3: 93}
high_freqs = {1: 235, 2: 262, 3: 108}
property ms_fmt
property cell_12m
property cell_7m
property cell
property gridder
property pblimit
property imsize

Get the image size in pixels dynamically according to the lowest frequency SPW of the Setup and antenna diameter (i.e., 12m or 7m). The field size size is calculated as 10% larger than the full-width at the 10%-maximum point of the primary beam (approximated as $1.13 lambda / D$).

check_if_product_dirs_exist()
calc_res(freq, diam)

Note that no factor of 1.028 is applied for FWHM of Airy pattern, just l/D.

ms_contains_diameter(ms_filen, diameter=None, epsilon=0.5)

Determine whether an MS contains an antenna with a given diameter.

Parameters:
  • diameter (number) – Antenna diameter in meters.

  • epsilon (number, default 0.5) – Fudge factor for querying the antennas min/max diameter.

class Spw(setup, restfreq, mol_name, name, ms_restfreq, spw_id, ot_name, nchan, chan_width, tot_bw)

Bases: object

Parameters:
  • setup (int) – Setup ID number (1, 2, 3)

  • restfreq (str) – Rest frequency of primary targeted line in the SPW, e.g. “93.17GHz”.

  • mol_name (str) – Molecule name of the primary targeted line in the SPW.

  • name (str) – Name of the spectral line.

  • ms_restfreq (str) – Line rest frequency listed in the measurement set, e.g. “93.17GHz”. Many of these values are not rest frequencies for specific molecular transitions but shifted values meant to center the bandpass.

  • spw_id (int) – ID number of the spectral window

  • ot_name (str) – Ending of the OT SPW label, e.g. “#BB_1#SW-01”. These are useful for selecting the spectral window ID number if the correlator ID numbers are inconsistent across 7M/12M datasets.

  • nchan (int) – Total number of channels (before flagging).

  • chan_width (number) – Channel width in TOPO frame. units: kHz.

  • tot_bw (number) – Total bandwidth in TOPO frame. units: MHz

property short_restfreq
property label
nchan_from_window(velo_width)
Parameters:

velo_width (str) – Full velocity width of window. CASA quantity string, e.g. ‘10km/s’.

copy()
with_chunk(chunk)
Parameters:

chunk (ChunkConfig, None) –

parse_spw_info_from_ms(ms_filen, field='CB68', out_filen=None)
write_all_spw_info()
spw_list_to_dict(spws)
class ImageManager(infile, cache=True)

Bases: object

Safely open a CASA image by creating a context manager. The image tool and file will be closed even if an error occurs while manipulating the image tool. Note that multiple images can be opened in a nested sequence.

Parameters:

infile (str) – CASA image file name, including any file suffixes.

Examples

The file is closed and the image tool destroyed when the scope of the context manager is exited. The following example shows how two images can be opened simulatenously in nested scopes.

>>> with ImageManager('foo.image') as tool1:
...     print(tool1.shape())
...     with ImageManager('bar.image') as tool2:
...         print(tool2.shape())
... print(tool1.shape())  # Error! The image tool is closed.
log_post(msg, priority='INFO')

Post a message to the CASA logger, logfile, and stdout/console.

Parameters:
  • msg (str) – Message to post.

  • priority (str, default 'INFO') – Priority level. Includes ‘INFO’, ‘WARN’, ‘SEVERE’.

check_delete_image_files(imagename, parallel=False, preserve_mask=False)

Check for and remove (if they exist) files created by clean such as ‘.flux’, ‘.image’, etc. NOTE this function has issues with deleting tables made by clean in parallel mode, probably because the directory structure is different.

Parameters:
  • imagename (str) – The relative path name to the files to delete.

  • parallel (bool, default False) – rmtables can’t remove casa-images made with parallel=True, they must be manually removed.

  • preserve_mask (bool, default False) – Whether to preserve the .mask file extension

safely_remove_file(filen)
if_exists_remove(filen)
delete_all_extensions(imagename, keep_exts=None)
Parameters:
  • imagename (str) –

  • keep_exts (None, iterable) – A list of extensions to keep, example: [‘mask’, ‘psf’]

delete_workdir(imagename)
replace_existing_file_with_new(old_filen, new_filen)

Replace an existing file with a new or temporary one. old_filen will be removed and replaced by new_filen.

remove_end_from_pathname(filen, end='.image')

Retrieve the file name excluding an ending extension or terminating string.

Parameters:
  • filen (str) –

  • end (str) – End to file name to remove. If an extension, include the period, e.g. “.image”.

export_fits(imagename, velocity=False, overwrite=True)
concat_parallel_image(imagename)

Create a contiguous image cube file from a ‘parallel image’ generated from a multiprocess tclean run with parallel=True. The function replaces the original parallel image with the contiguous image.

concat_parallel_all_extensions(imagebase)
get_freq_axis_from_image(imagename)

Compute the frequency axis from an image’s header coordinate system information.

Parameters:

imagename (str) –

Returns:

  • ndarray – Frequency axis.

  • str – Frequency axis unit (likely Hz).

calc_common_coverage_range(imagebase)

Calculate the common frequency coverage amongst a set of MSs/EBs. The .sumwt image extension is used from an existing “dirty” cube.

Parameters:

imagebase (str) – Image name without the “.sumwt” extension.

Returns:

  • str – The start frequency in the LSRK frame.

  • int – The number of channels from start at the native spectral resolution.

calc_chunk_freqs(imagebase, nchunks=1)

Divide the spectral axis of an image into continuous chunks in frequency. Returned frequencies specify the channel center frequency.

Parameters:
  • imagebase (str) – Image name base without the “.sumwt” extension.

  • nchunks (int) – Number of contiguous chunks to divide the frequency range into.

Returns:

(str) LSRK frequency of the bin left-edge of the first channel. units: Hz.

(int) Number of channels in the chunk.

Return type:

[[str, int], …]

primary_beam_correct(imagebase)
hanning_smooth_image(imagename, overwrite=True)

Hanning smooth an image. Produces a new file with the extension “.hanning”.

Parameters:
  • filen (str) –

  • overwrite (bool) –

smooth_cube_to_common_beam(imagename, beam=None)

Use the imsmooth task to convert a cube with per-plane beams into one with a single common beam.

Parameters:
  • imagename (str) – Name of the image, including extension such as “.image”.

  • beam (dict) – Gaussian beam parameter dictionary (see imsmooth help).

copy_pb_mask(imagename, pbimage)

Copy primary beam T/F mask back into the image after being removed by a task such as imsmooth.

calc_rms_from_image(imagename, chan_expr=None)

Calculate RMS values from the scaled MAD of all channels (unless given a range) for the given full imagename.

Parameters:
  • imagename (str) – CASA Image name, e.g., “244.936GHz_CS_joint_0.5_dirty.image”

  • chan_expr (str, None) – Channel selection expression passed to imstat parameter chans. If None, the full channel range is used.

Returns:

RMS

Return type:

float

create_mask_from_threshold(infile, outfile, thresh, overwrite=True)

Create a 1/0 mask according to whether pixel values in the input image are or are not above thresh in Jy.

Parameters:
  • infile (str) –

  • outfile (str) –

  • thresh (number) – units: Jy

  • overwrite (bool, default True) –

effective_beamwidth_from_image(imagename)

Median of the geometric-mean beamwidths in an image with perplane beams. If the image has a single plane or single restoring beam, then the geometric mean of the major & minor axes is returned.

Parameters:

imagename (str) –

make_multiscale_joint_mask(imagename, rms, sigma=5.0, mask_ang_scales=(0, 1, 3))

Create a joint mask from multiple smoothed copies of an image. A file with the .summask extension is created from the union of an RMS threshold applied to each image. The RMS is re-computed for each smoothed cube.

Parameters:
  • imagename (str) – Image name base without the extension.

  • rms (number) – RMS value of the unsmoothed image. units: Jy

  • sigma (number, Iterable(number)) – Multiple of the RMS to threshold each image. If passed as a number, the same threshold is applied to all images (whether unsmoothed or smoothed). If passed as a list-like, then the sigma value is used for the image with the corresponding scale in mask_ang_scales.

  • mask_ang_scales (Iterable(number)) – Gaussian kernel FWHM in units of arcseconds to convolve each image with (note: not in pixel units).

Returns:

  • Files are written for each smoothing scale – smoothed image: ‘<IMG>_smooth{.3f}.image’ (excluding scale=0) masked image: ‘<IMG>_smooth{.3f}.mask’

  • and the joint or unioned mask file across scales is written to – joint mask: ‘<IMG>.summask’

format_cube_robust(weighting)
format_rms(rms, sigma=1, unit='Jy')
check_max_residual(imagebase, sigma=5.5)

Check the residual image cube for channels with deviations higher than a multiple of the global RMS.

Parameters:
  • imagebase (str) – Image name without extension.

  • sigma (number) – Threshold to apply as a multiple of the RMS.

class ChunkConfig(start, start_chan_ix, nchan, index)

Bases: object

Parameters:
  • start (str) – CASA quantity string for the LSR frequency of the first channel of the chunk.

  • start_chan_ix (int) – Channel index of the starting channel in the full cube.

  • nchan (int) – Number of channels in the chunk.

  • index (int) – Chunk index number, used as part of the file names: “_chunk0”.

fullcube_chan_indices

Indices of the chunk channels in the full cube.

Type:

[int], None

convert_chunk_chan_to_full(ix)
Parameters:

ix (int) – Channel index of the chunked image cube.

convert_full_chan_to_chunk(ix)
Parameters:

ix (int) – Channel index of the full image cube.

class ImageConfig(dset, spw, fullcube=True, weighting=0.5, chunk=None)

Bases: object

Configuration object for tclean related custom tasks. Parameters specify deconvolution and image-cube properties such as the weighting. See the docstring for from_name() for more complete parameter descriptions.

Parameters:
  • dset (DataSet) –

  • spw (Spw) –

  • fullcube (bool) –

  • weighting (str, number) –

  • chunk (ChunkConfig, None) –

scales

List of scales in pixels to be used for multi-scale clean. Will be passed to the scales keyword argument in tclean.

Type:

Iterable

mask_ang_scales

FWHM sizes in arcsec for Gaussian smoothing kernels used in faust_imaging.ImageConfig.clean_line_nomask().

Type:

Iterable

autom_kwargs

Auto-multithresh keyword arguments passed to tclean.

Type:

dict

smallscalebias
Type:

number

gain
Type:

number

cyclefactor
Type:

number

uvtaper
Type:

(list, None)

parallel

Is MPI enabled in CASA?

Type:

bool

line_vwin

CASA quantity string for velocity window when fullcube=False.

Type:

str

preserve_all_intermediate_products = False
smallscalebias = -1.0
gain = 0.05
cyclefactor = 2.0
uvtaper = None
parallel = False
line_vwin = '20km/s'
classmethod from_name(field, label, kind='joint', **kwargs)

Create an ImageConfig object directly from the field name and SPW label without creating instances of auxillary class instances.

Parameters:
  • field (str) – Field name, e.g., “CB68”

  • label (str, None) – SPW label, e.g., “216.113GHz_DCOp”. If None then apply to all Setups and SPWs for target field.

  • kind (str) – Datset descriptor for which measurement set files to use. Valid values include: (‘joint’, ‘12m’, ‘7m’).

  • fullcube (bool) – Image the full spectral window or a small window around the SPWs defined rest frequency.

  • weighting (str, number) – Either a string for a weighting method recognized by tclean, such as ‘natural’ or ‘uniform’; or a number for a Briggs weighting robust value.

  • chunk (ChunkConfig, None) – Chunk configuration instance for dividing the frequency axis into individual, smaller memory foot-print intervals in frequency. The default value of None will apply no chunking along the frequency axis.

property is_chunked
property dirty_imagebase
property nomask_imagebase
property tinyimg_imagebase
property rms

Image RMS. By default, determined using imstat over the entire dirty cube. The RMS can also be manually set.

property selected_start_nchan
property spw_ids

Determine spectral window ID numbers based on the (unique) Data Descriptor name found in the correlator configuration of the MS. This avoids indexing issues between mixed sets of 12m & 7m EBs.

duplicate_into_chunks(nchunks=None)

Duplicate the image configuration into multiple versions set to be chunked in frequency. This eases memory requirements because each smaller image cubes may be processed independently. A full-bandwidth “.sumwt” file must exist to compute the starting frequencies. If neither faust_imaging.ImageConfig.make_dirty_cube() nor faust_imaging.ImageConfig.make_tiny_image_stamp() have been executed, the latter will be run before calculating the chunk frequencies.

Parameters:

nchunks (int, None) – Number of chunks to create. If unset then the number of chunks is chosen using a heuristic.

Returns:

Configuration object encapsulating ImageConfig instances with properties set for chunking.

Return type:

ChunkedConfigSet

get_imagebase(ext=None)

Get the relative path name for an image basename following

“images/<FIELD>/<LABEL>_<ARRAY>_<WEIGHTING>[_<EXT>]”

Note that this does not include image extensions such as “.image”

Parameters:

ext (str, Iterable, object) – If ext is None, then compose path of setup, spw, array. If ext is an iterable, append each by underscores. If other object, must have a __repr__ method for representation string.

mpicasa_cleanup(imagename)

Delete the “.workdirectory” folders that are occassionally generated and not removed in mpicasa. Also concatenate all image products into contiguous “serial” products using ia.imageconcat.

remove_all_files(confirm=True, remove_chunks=True)

Attempt to safely remove all files matching the image basename returned by faust_imaging.ImageConfig.get_imagebase().

Parameters:

confirm (bool) – Print the files to be removed to STDOUT and require keyboard confirmation before removing files.

make_tiny_image_stamp()

Image a small field in order to produce the “.sumwt” file without producing a full set of dirty image products (which may be very large). The default suffix set by TINYIMG_EXT is “_tinyimg”.

make_dirty_cube()

Generate a dirty image cube and associated tclean products. Run with equivalent parameters as clean_line but with niter=0. The default suffix set by DIRTY_EXT is “_dirty”.

clean_line_nomask(sigma=4.5, scale_upper_limit=60)

Deconvolve the image without using a mask to a depth of sigma and excluding multiscale size scales beyond scale_upper_limit.

Parameters:
  • sigma (number) – Global threshold to clean down to computed as multiple of the full-cube RMS.

  • scale_upper_limit (number, None) – Restrict the scales (in pixels) used by multi-scale clean to values less than this limit. If None, use all scales.

make_seed_mask(sigma=5.0)

Create a mask based on a significance cut applied to the restored image of the unmasked run generated from clean_line_nomask. This mask is used to “seed” the mask generated using auto-multithresh in clean_line with mask_method=’seed+multithresh’.

Parameters:

sigma (number) – Limit to threhsold the restored image on.

clean_line(mask_method='seed+multithresh', sigma=3.0, ext=None, restart=False, interactive=False)

Primary interface for calling tclean to deconvolve spectral windows. Multiple masking methods exist to automatically generate the clean masks used. The preferred method is mask_method=’seed+multithresh’, which requires that .clean_line_nomask is run first.

Parameters:
  • mask_method (str) –

    Masking method to use in the deconvolution process. Available methods

    "auto-multithresh" use auto-multithresh automated masking.

    "seed+multithresh" generate initial mask from free clean and then use auto-multithresh for automatic masking.

    "fixed" use the existing clean mask but keep it fixed and do not apply auto-multithresh.

    "taper" use mask generated from a separate tapered run. Generating the tapared masks requires re-implementation.

  • sigma (number) – Threshold in standard deviations of the noise to clean down to within the clean-mask. An absolute RMS is calculated from off-line channels in a dirty cube. The same value is applied to all channels.

  • ext (str) – String of the form ‘_EXT’ appended to the end of the image name.

  • restart (bool, default False) – Restart using the existing model and mask files.

  • interactive (bool, default False) – Begin tclean in interactive mode with interactive=True. This may be useful for touching-up some channels with particularly difficult to clean extended emission.

clean_line_interactive_restart(**kwargs)
postprocess(ext=None, make_fits=True, make_hanning=False, beam=None)

Post-process image products. The maximum residual is logged to the CASA log file and STDOUT, the image is primary beam corrected, smoothed to a common beam, and the final FITS file is exported.

Parameters:
  • ext (str) –

  • make_fits (bool) –

  • make_hanning (bool) –

  • beam (dict, None) – Gaussian beam parameter dictionary to use for common beam smoothing. If left as None, then the common beam of the image is used.

run_pipeline_tasks(ext='clean', nomask_sigma=4.5, seedmask_sigma=5.0, clean_sigma=3.0)

Helper method to run the pipeline tasks in sequence with reasonable default parameters. See run_pipeline() for further description.

Parameters:
  • ext (str) –

  • nomask_sigma (number) –

  • seedmask_sigma (number, Iterable(number)) –

  • clean_sigma (number) –

run_pipeline(ext='clean', use_chunking=True, nchunks=None, nomask_sigma=4.5, seedmask_sigma=5.0, clean_sigma=3.0)

Run all pipeline tasks with default parameters. Custom recipes should call the individual methods in sequence. The final pipeline product will be named of the form:

“<FILENAME>_<EXT>.image.pbcor.common.fits”

or if ext=None:

“<FILENAME>.image.pbcor.common.fits”

For convenience, some significance thresholds (“sigma”) may also be set for this method. For more customized pipeline procedures, calling the individual pipeline methods is recommended.

Parameters:
  • ext (str) – Extension name for final, deconvolved image products.

  • use_chunking (bool) – If True then chunk the image into separate frequency intervals, process individually in serial, and then concatenate the final results.

  • nchunks (int, None) – Number of approximately uniform frequency intervals to chunk image products into. If None then the number of chunks is chosen by heuristic.

  • nomask_sigma (number) – Global clean threshold for the un-masked clean run.

  • seedmask_sigma (number, Iterable(number)) – Significance with which to threshold the un-masked clean run to create the seed mask. If a list-like is passed, the corresponding significance is used for each smoothing scale (scales are set by mask_ang_scales).

  • clean_sigma (number) – Global clean threshold of the final clean run.

class ChunkedConfigSet(configs)

Bases: object

Parameters:

configs (Iterable(ImageConfig)) – List of chunked ImageConfig instances, such as generated by ImageConfig.duplicate_into_chunks().

configs
Type:

Iterable(ImageConfig)

nchunks
Type:

int

nchan_total

Total number of channels summing across all chunks.

Type:

int

get_imagebase(ext=None)
remove_all_files(confirm=True)
get_chunk_from_channel(ix)
Parameters:

ix (int) – Channel index number in the full, concatenated cube.

Return type:

ImageConfig

get_common_beam(ext='clean')

Calculate the common beam (largest area) among all chunked images.

Parameters:

ext (str) – Extension name suffix, e.g. ‘clean’, ‘nomask’, etc.

Returns:

Beam parameters formatted as strings with unit labels: major axis (arcsec), minor axis (arcsec), position angle (deg).

Return type:

(str, str, str)

Notes

A fudge factor of 0.3% is added to the beam size to account for discrepencies in how the common beam is calculated by CASA over the full cube compared to the largest-area common beam among the chunks. For typical ~0.35as HPBWs in the FAUST program, this multiplicatie factor corresponds to ~1 mas.

concat_cubes(ext='clean', im_exts=None)

Use ia.imageconcat to concatenate chunked image files into single a cube with contiguous data.

Parameters:
  • ext (str) – Extension name suffix, e.g. ‘clean’, ‘nomask’, etc.

  • im_exts (Iterable(str), None) – Names of image extensions, e.g. ‘mask’, ‘image.pbcor.common’, etc. If None then a default set of extensions is processed. The default extensions are “image”, “mask”, “model”, “pb”, “psf”, “residual”.

postprocess(ext='clean', use_existing_except=None, make_hanning=False)
Parameters:
  • ext (str) –

  • use_existing_except (Iterable(int), None) – If post-processing has already been run, but a few chunks have been modified (by manual cleaning for example), then only re-process the chunks set by this variable. If left unset (None), then all chunks are processed.

  • make_hanning (bool, default False) – Create the Hanning smoothed cube.

make_all_line_dirty_cubes(dset, weighting=0.5, fullcube=True)
postproc_all_cleaned_images(dset)
run_pipeline(field, setup=None, weightings=None, fullcube=True, do_cont=True, chunked=True)

Run all pipeline tasks over all setups, spectral windows, and uv-weightings.

Parameters:
  • field (str) –

  • setup (int, None) – Setup number, if None run on all setups in sequence.

  • weightings (Iterable, default (0.5,)) – List of uv-weightings to use in tclean, which may include the string “natural” or a number for the briggs robust parameter.

  • fullcube (bool, default True) – Image the full spectral window or a small window around the SPWs defined rest frequency.

  • do_cont (bool, default True) – Whether to image the continuum SPWs or not.

  • chunked (bool, default True) – Process frequency intervals of each SPW in serial to reduce memory requirements.

test_perchanwt()
test_rename_oldfiles(field, label=None, kind='joint', weighting=0.5)

Replace the rest frequency in each final image cube with the value given by Satoshi and then re-export the FITS cube.

Parameters:
  • field (str) – Field name, e.g., “CB68”

  • label (str, None) – SPW label, e.g., “216.113GHz_DCOp”. If None then apply to all Setups and SPWs for target field.

  • kind (str) –

  • weighting (str, number) –

class MomentMapper(imagename, vwin=5, m1_sigma=4, m2_sigma=5, overwrite=True)

Bases: object

Parameters:
  • imagename (str) – CASA image filename ending in ‘.image.common’.

  • vwin (number) – Velocity window (half-width) to use for estimating moments over relative to the systemic velocity. units: km/s

  • m1_sigma (number) – Multiple of the RMS to threshold the Moment 1 data on.

  • m2_sigma (number) – Multiple of the RMS to threshold the Moment 2 data on.

  • overwrite (bool, default True) – Overwrite moment maps and associated files if they exist.

get_cube_velocity_axis(as_region_subim=False, with_image_axes=False)

Velocity axis in units of km/s derived from the “.image.common” image file.

Parameters:
  • as_region_subim (bool, default False) – Compute velocity axis only over sub-image defined by the velocity window region.

  • with_image_axes (bool, default False) – Reshape to use the same dimensions as the image cube (Stokes, RA, Dec, Chan). False returns as 1D.

get_top_right_corner_pixels()
get_region()

Create a full-field sub-cube restricted to a window in velocity about the source systemic velocity.

get_vlsr_pb_plane()

Retrieve the primary beam near the center of the velocity window and thus the source systemic velocity.

get_rms_map(with_pb_atten=False)
make_max()

Make the peak intensity map (maximum). Use all emission within the velocity window.

make_mom0()

Make the integrated intensity map (moment 0). Use all emission within the velocity window that is also in the CLEAN mask. Expressions for the moment calculations can be found in the help documentation to the ia.moments toolkit function.

\[M_0 = \Delta v \Sum I_i\]
make_mom0_err()

Make the error map of the integrated intensity (moment 0).

\[\delta M_0 = \Delta v \sqrt{N} \sigma_\mathrm{rms}\]
make_mom1()

Make the intensity weighted mean velocity map (moment 1). Use all emission within the velocity window that is within the CLEAN mask and also above a significance threshold in the Hanning smoothed cube.

\[M_1 =\]

rac{sum I_i v_i}{M_0}

make_mom1_err()

Make the error map of the intensity weighted mean velocity (moment 1).

\[\delta M_1 = | M_1 | \sqrt{\left(\]

rac{sigma_mathrm{rms} sum v_i^2}{M_1 M_0} ight)^2 + left( rac{delta M_0}{M_0} ight)^2}

make_mom2()

Make the intensity weighted mean velocity dispersion map (moment 2). Use all emission within the velocity window that is within the CLEAN mask and also above a significance threshold in the Hanning smoothed cube.

\[M_2 = sqrt{\]

rac{sum I_i (v_i - M_1)^2}{M_0}}

make_moments(remove_hanning=True)

Create moment maps for the given image. The cube is masked using the associated clean mask.

Parameters:

remove_hanning (bool, default True) – Delete the hanning-smoothed cube after use.

make_moments_from_image(path, vwin=None, overwrite=True)
make_all_moment_maps(field, ext='clean', vwin=None, ignore_chunks=True, overwrite=True)

Generate all moment maps for images with the matching field ID name and extension. Moment maps will be written to the directory set in MOMA_DIR.

Parameters:
  • field (str) – Target field ID name

  • ext (str) – Image extension name, such as ‘clean’, ‘nomask’, etc.

  • vwin (number, None) – Velocity half-window to use for estimating moments over relative to the source systemic velocity (see value specified in ALL_TARGETS). If set to None, then a default half-window of 5km/s is used for all lines, except CCH, where a half-window of 1.25km/s used to accomodate the 2.5km/s spacing of the hyperfine satellite lines. If explicitly set, the half-window is used for all lines. units: km/s

  • ignore_chunks (bool) – If ‘True’ ignore chunk image files.

  • overwrite (bool, default True) – Overwrite moment maps files if they exist.

savefig(filen, dpi=300, plot_exts=('png', 'pdf'), close=True)

Save the figure instance to a file.

Parameters:
  • filen (str) – File name to write to, excluding the extension (e.g., “.pdf”).

  • dpi (number) –

  • plot_exts (Iterable) – Extensions to create plots for, e.g., “pdf”, “svg”, “png”, “eps”, “ps”.

  • close (bool) – Close figure instance when finished plotting.

class CubeSet(path, sigma=6)

Bases: object

Parameters:
  • path (str) – Full image path, including extension.

  • sigma (number) – Significance threshold used to select planes/channels to retrieve.

static get_chunk(imagename)
get_plane_from_image(filen, ix)
Parameters:
  • filen (str) – CASA image path, e.g. “images/CB68/CB68_<…>_clean.mask”

  • ix (int) – Channel index number (zero indexed).

Returns:

2D image plane of the selected channel.

Return type:

ndarray

get_image_planes(ix)
iter_planes()
get_good_channels()
calc_tick_loc(ang_tick=5)
Parameters:

ang_tick (number) – Tick interval in arcsec.

make_qa_plot(cset, kind='image', outfilen='qa_plot')

Generate Quality Assurance plots by visualizing each channel where significant emission occurs in the image cube of interest (i.e., .image or .residual).

Parameters:
  • cset (CubeSet) –

  • kind (str) –

    Kind of image data to plot:

    ’image’ : restored/cleaned image

    ’residual’ : residual image

  • outfilen (str) –

make_qa_plots_from_image(path, plot_sigma=None, overwrite=True)

Create a single set of Quality Assurance plots. Plots will be written to the directory specified in PLOT_DIR.

Parameters:
  • path (str) – Full path to imagename, including the ending “.image”.

  • plot_sigma (number, None) – Significance threshold to select a channel for plotting. If None, use the default set by CubeSet.

  • overwrite (bool) – Overwrite plot files if they exist.

make_all_qa_plots(field, ext='clean', ignore_chunks=True, overwrite=True)

Generate all Quality Assurance plots for all image cubes matching the given field ID name and extension. Plots will be written to the directory set in PLOT_DIR.

Parameters:
  • field (str) – Target field ID name

  • ext (str) – Image extension name, such as ‘clean’, ‘nomask’, etc.

  • ignore_chunks (bool) – If ‘True’ ignore chunk image files.

  • overwrite (bool, default True) – Overwrite plot files if they exist. Setting to False will avoid the potentially large run-time cost of reading cubes into memory to re-make existing plots.