drivecasa.utils - Miscellaneous subroutines


Co-erce unicode to ‘bytestring’

(or string containing unicode, or dict containing unicode) Useful when e.g. importing filenames from JSON (CASA sometimes breaks if passed Unicode strings.)


drivecasa.utils.derive_out_path(in_paths, out_dir, out_extension='', strip_in_extension=True, out_prefix=None)

Derives an ‘output’ path given some ‘input’ paths and an output directory.

In the simple case that only a single path is supplied, this is simply the pathname resulting from replacing extension suffix and moving dir, e.g.

input_dir/ -> output_dir/basename.out

If the out_dir is specified as ‘None’ then it is assumed that the new file should be located in the same directory as the first input path.

In the case that multiple input paths are supplied, their basenames are concatenated, e.g.

in_dir/ + in_dir/
-> out_dir/base1_base2.out

If the resulting output path is identical to any input path, this raises an exception.

NB the extension should be supplied including the ‘.’ prefix.


Ensure directory exists.

Roughly equivalent to mkdir -p

drivecasa.utils.get_box_mask_string(centre_pix_posns, width)

Get a mask string representing box apertures about (x,y) tuples

drivecasa.utils.get_circular_mask_string(centre_ra_dec_posns, aperture_radius='1arcmin')

Get a mask string representing circular apertures about (x,y) tuples


Ensure x is a (non-string) iterable; if not, enclose in a list.

Returns:x or [x], accordingly.
drivecasa.utils.save_script(script, filename)

Save a list of casa commands as a text file