drivecasa.commands - Convenience routines for building command lists

This subpackage provides convenience functions for composing casapy data-reduction scripts.

While the casapy scripts can be composed by hand, use of convenience functions helps to prevent syntax errors, and allows for various optional extras such as forcing overwriting of previous datasets, automatic derivation of output filenames, etc.

drivecasa.commands.reduction - Data reduction commands


All the data-reduction command composing functions have a common set of parameters:
  • script: The list to which the requested commands should be appended.
  • out_dir: The output directory to place output files in, using a derived filename.
  • out_path: Overrides out_dir, specifies an output file / directory path exactly.
  • overwrite: Deletes any pre-existing data at the output location - use with caution!

The composing functions return the paths to the files which should be created once the scripted command has been executed.

class drivecasa.commands.reduction.CleanMaps[source]

A namedtuple for bunching together the paths to maps produced by clean.

Fields: ('image', 'model', 'residual', 'psf', 'mask')

drivecasa.commands.reduction.clean(script, vis_paths, niter, threshold_in_jy, mask='', modelimage='', other_clean_args=None, out_dir=None, out_path=None, overwrite=False)[source]

Perform clean process to produce an image/map.

If out_path is None, then the output basename is derived by appending a .clean or .dirty suffix to the input basename. The various outputs are then further suffixed by casa, e.g. foo.clean.image, foo.clean.psf, etc. Since multiple outputs are generated, this function returns a CleanMaps object detailing the expected paths.

NB Attempting to run with pre-existing outputs and overwrite=False will not throw an error, in contrast to most other routines. From the CASA cookbook, w.r.t. the outputs:

“If an image with that name already exists, it will in general be overwritten. Beware using names of existing images however. If the clean is run using an imagename where <imagename>.residual and <imagename>.model already exist then clean will continue starting from these (effectively restarting from the end of the previous clean). Thus, if multiple runs of clean are run consecutively with the same imagename, then the cleaning is incremental (as in the difmap package).”

You can override this behaviour by specifying overwrite=True, in which case all pre-existing outputs will be deleted.

NB niter = 0 implies create a ‘dirty’ map, outputs will be named accordingly.


This function can accept a list of multiple input visibilities. This functionality is not extensively tested and should be considered experimental - the CASA cookbook is vague on how parameters should be passed in this use-case.

listing paths for resulting maps.
Return type:expected_map_paths(CleanMaps)
drivecasa.commands.reduction.concat(script, vis_paths, out_basename=None, out_dir=None, out_path=None, overwrite=False)[source]

Concatenates multiple visibilities into one.

By default, output basename is derived by concatenating the basenames of the input visibilities, with the prefix concat_. However, this can result in something very long and unwieldy. Alternatively you may specify the exact out_path, or just the out_basename.

Returns:Path to concatenated ms.
drivecasa.commands.reduction.export_fits(script, image_path, out_dir=None, out_path=None, overwrite=False)[source]

Convert an image ms to FITS format.

Returns:Path to resulting FITS file.
drivecasa.commands.reduction.import_uvfits(script, uvfits_path, out_dir=None, out_path=None, overwrite=False)[source]

Import UVFITS and convert to .ms format.

If out_path is None, a sensible output .ms directory path will be derived by taking the FITS basename, switching the extension to .ms, and locating as a subdirectory of out_dir, e.g. if uvfits_path = '/my/data/obs1.fits', out_dir = '/tmp/junkdata' then the output data will be located at /tmp/junkdata/

  • script – List to which the relevant casapy command line will be appended.
  • uvfits_path – path to input data file.
  • out_dir – Directory in which to place output file. None signifies to place output .ms in same directory as the original FITS file.
  • out_path – Provides an override to the automatic output naming system. If this is not None then the out_dir arg is ignored and the specified path used instead.
  • overwrite – Delete any pre-existing data at the output path (danger!).

Path to newly converted ms.

drivecasa.commands.reduction.mstransform(script, vis_path, out_path, other_transform_args=None, overwrite=False)[source]

Useful for pre-imaging steps of interferometric data reduction.



drivecasa.commands.simulation - simulation commands

Provides convenience functions for composing casapy simulation scripts.


Flush simulated data to disk and close simulator tool (sm.close())

cf :param script: casapy script-list :type script: list


Apply pre-configured simulated noise via sm.corrupt


Configure noise first using e.g. set_simplenoise()

Parameters:script (list) – casapy script-list
drivecasa.commands.simulation.make_componentlist(script, source_list, out_path, overwrite=True)[source]

Build a componentlist and save it to disk.

Runs cl.done() to clear any previous entries, the cl.addcomponent for each source in the list, and finally cl.rename, cl.close.


Typically used when simulating observations.

  • script (list) – List of strings to append commands to.
  • source_list – List of (position, flux, frequency) tuples. Positions should be astropy.coordinates.SkyCoord instances, while flux and frequency should be quantities supplied using the astropy.units functionality.
  • out_path (str) – Path to save the component list at
  • overwrite (bool) – Delete any pre-existing component list at out_path.
Returns (str):
Absolute path to the output component list
drivecasa.commands.simulation.observe(script, stop_delay, start_delay=<Quantity 0.0 s>)[source]

Simulate an empty-field observation’s UVW data with sm.observe


  • script (list) – casapy script-list
  • stop_delay (astropy.units.Quantity) – Time-span. Stop observing this long after the reference time defined by settimes().
  • start_delay (astropy.units.Quantity) – Time-span. Start observing this long after the reference time defined by settimes(). (Defaults to 0, so the observation starts immediately at the reference time).
drivecasa.commands.simulation.open_sim(script, output_ms_path, overwrite=True)[source]

Open new MeasurementSet with simulator tool (


  • script (list) – casapy script-list
  • output_ms_path (str) – Path to the new CASA MeasurementSet.
  • overwrite (bool) – Delete any pre-existing component list at out_path.
drivecasa.commands.simulation.predict(script, component_list_path)[source]

Use sm.predict to add synthetic source-visibilities to a MeasurementSet.


  • script (list) – casapy script-list
  • component_list_path (str) – Path to component-list (in CASA-table format).
drivecasa.commands.simulation.set_simplenoise(script, noise_std_dev)[source]

Use sm.setnoise to assign a simple fixed-sigma noise to visibilities.


NB should be followed by a call to corrupt() to actually apply the noise addition.

  • script (list) – casapy script-list
  • noise_std_dev (astropy.units.Quantity) – Standard deviation of the noise (units of Jy).
drivecasa.commands.simulation.setauto(script, autocorr_weight=0.0)[source]

Set autocorrelation weight with sm.setauto.


  • script (list) – casapy script-list
  • autocorr_weight (float) – Weight to assign autocorrelations
drivecasa.commands.simulation.setconfig(script, telescope_name, antennalist_path)[source]

Configure the telescope parameters with sm.setconfig


  • script (list) – casapy script-list
  • telescope_name (str) – e.g. ‘VLA’
  • antennalist_path (str) – antenna-list config file
drivecasa.commands.simulation.setfeed(script, mode='perfect X Y', pol=[''])[source]

Set feed polarisation with sm.setfeed


  • script (list) – casapy script-list
  • mode (str) – choice between ‘perfect R L’ and ‘perfect X Y’
  • pol (str) – Polarization (undocumented).
drivecasa.commands.simulation.setfield(script, pointing_centre)[source]

Set pointing centre of simulated field of view with sm.setfield.


drivecasa.commands.simulation.setlimits(script, shadow_limit=0.001, elevation_limit=<Quantity 15.0 deg>)[source]

Set shadowing / elevation limits before simulated data are flagged.

Runs sm.setlimits cf

  • script (list) – casapy script-list
  • shadow_limit (float) – Maximum fraction of geometrically shadowed area before flagging occurs
  • elevation_limit (astropy.units.Quantity) – Minimum elevation angle before flagging occurs
drivecasa.commands.simulation.setpb(script, telescope_name, primary_beam_hwhm, frequency)[source]

Configure Gaussian primary beam parameters for a measurement simulation.

Runs vp.setpbgauss followed by sm.setvp to activate it. cf

  • script (list) – casapy script-list
  • telescope_name (str) – e.g. ‘VLA’
  • primary_beam_hwhm (astropy.units.Quantity) – HWHM radius, i.e. angular radius to point of half-maximum in primary beam.
  • frequency (astropy.units.Quantity) – Reference frequency for primary beam.
drivecasa.commands.simulation.setspwindow(script, freq_start, freq_resolution, freq_delta, n_channels, stokes='XX XY YX YY')[source]

Define a spectral window with sm.setspwindow.


drivecasa.commands.simulation.settimes(script, integration_time, reference_time, use_hour_angle=True)[source]

Set integration time, reference time with sm.settimes


The ‘reference time’ defines an epoch, start and stop are defined relative to that epoch.