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.
A namedtuple for bunching together the paths to maps produced by clean.
('image', 'model', 'residual', 'psf', 'mask')
clean(script, vis_paths, niter, threshold_in_jy, mask='', modelimage='', other_clean_args=None, out_dir=None, out_path=None, overwrite=False)¶
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
CleanMapsobject detailing the expected paths.
NB Attempting to run with pre-existing outputs and
overwrite=Falsewill 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.
Returns: expected_map_paths – namedtuple,listing paths for resulting maps. Return type:
concat(script, vis_paths, out_basename=None, out_dir=None, out_path=None, overwrite=False)¶
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.
export_fits(script, image_path, out_dir=None, out_path=None, overwrite=False)¶
Convert an image ms to FITS format.
Returns: Path to resulting FITS file.
import_uvfits(script, uvfits_path, out_dir=None, out_path=None, overwrite=False)¶
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/obs1.ms.
- 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.
Nonesignifies 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
out_dirarg is ignored and the specified path used instead.
- overwrite – Delete any pre-existing data at the output path (danger!).
Path to newly converted ms.
mstransform(script, vis_path, out_path, other_transform_args=None, overwrite=False)¶
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())
Apply pre-configured simulated noise via sm.corrupt
Parameters: skycoord (astropy.coordinates.SkyCoord) – Sky position
Returns (str): casa me.direction instantiation expression.
Parameters: time (astropy.time.Time) – Reference time
- Returns (str): casa me.epoch instantiation expression
- (uses UTC conversion from astropy Time).
make_componentlist(script, source_list, out_path, overwrite=True)¶
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.SkyCoordinstances, while flux and frequency should be quantities supplied using the
- out_path (str) – Path to save the component list at
- overwrite (bool) – Delete any pre-existing component list at out_path.
observe(script, stop_delay, start_delay=<Quantity 0.0 s>)¶
Simulate an empty-field observation’s UVW data with sm.observe
- stop_delay (astropy.units.Quantity) – Time-span. Stop observing this
long after the reference time defined by
- 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).
- stop_delay (astropy.units.Quantity) – Time-span. Stop observing this long after the reference time defined by
Use sm.predict to add synthetic source-visibilities to a MeasurementSet.
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.
Set autocorrelation weight with sm.setauto.
setconfig(script, telescope_name, antennalist_path)¶
Configure the telescope parameters with sm.setconfig
setfeed(script, mode='perfect X Y', pol=[''])¶
Set feed polarisation with sm.setfeed
Set pointing centre of simulated field of view with sm.setfield.
setlimits(script, shadow_limit=0.001, elevation_limit=<Quantity 15.0 deg>)¶
Set shadowing / elevation limits before simulated data are flagged.
Runs sm.setlimits cf https://casa.nrao.edu/docs/CasaRef/simulator.setlimits.html
setpb(script, telescope_name, primary_beam_hwhm, frequency)¶
Configure Gaussian primary beam parameters for a measurement simulation.
Runs vp.setpbgauss cf https://casa.nrao.edu/docs/CasaRef/vpmanager.setpbgauss.html
setspwindow(script, freq_start, freq_resolution, freq_delta, n_channels, stokes='XX XY YX YY')¶
Define a spectral window with sm.setspwindow.
- script (list) – casapy script-list
- freq_start (astropy.units.Quantity) – Starting frequency for spectral window.
- freq_resolution (astropy.units.Quantity) – Frequency width of each channel.
- freq_delta (astropy.units.Quantity) – Frequency increment per channel.
- n_channels (int) – Number of channels
- stokes (str) – Stokes types to simulate
settimes(script, integration_time, reference_time)¶
Set integration time, reference time with sm.settimes
The ‘reference time’ defines an epoch, start and stop are defined relative to that epoch.