The miscellaneous module

The miscellaneous module defines various miscellaneous functions used in Rapthor.

Module that holds miscellaneous functions and classes

rapthor.lib.miscellaneous.approx_equal(x, y, *args, **kwargs)

Return True if x and y are approximately equal, otherwise False

If x and y are floats, return True if y is within either absolute error tol or relative error rel of x. You can disable either the absolute or relative check by passing None as tol or rel (but not both).

Parameters:
xfloat

First value to be compared

yfloat

Second value to be compared

rapthor.lib.miscellaneous.calc_theoretical_noise(obs_list, w_factor=1.5)

Return the expected theoretical image noise for a dataset. For convenience, the total unflagged fraction is also returned.

Note: the calculations follow those of SKA Memo 113 (see http://www.skatelescope.org/uploaded/59513_113_Memo_Nijboer.pdf) and assume no tapering. International stations are not included.

Parameters:
obs_listlist of Observation objects

List of the Observation objects that make up the full dataset

w_factorfloat, optional

Factor for increase of noise due to the weighting scheme used in imaging (typically ranges from 1.3 - 2)

Returns:
noisefloat

Estimate of the expected theoretical noise in Jy/beam

unflagged_fractionfloat

The total unflagged fraction of the input data

rapthor.lib.miscellaneous.convert_mjd2mvt(mjd_sec)

Converts MJD to casacore MVTime

Parameters:
mjd_secfloat

MJD time in seconds

Returns:
mvtimestr

Casacore MVTime string

rapthor.lib.miscellaneous.convert_mvt2mjd(mvt_str)

Converts casacore MVTime to MJD

Parameters:
mvt_strstr

MVTime time

Returns:
mjdtimefloat

MJD time in seconds

rapthor.lib.miscellaneous.create_directory(dirname)

Recursively create a directory, without failing if it already exists

Parameters:
dirnamestr

Path of directory

rapthor.lib.miscellaneous.dec2ddmmss(deg)

Convert Dec coordinate (in degrees) to DD MM SS

Parameters:
degfloat

The Dec coordinate in degrees

Returns:
ddint

The degree (DD) part

mmint

The arcminute (MM) part

ssfloat

The arcsecond (SS) part

signint

The sign (+/-)

rapthor.lib.miscellaneous.delete_directory(dirname)

Recursively delete a directory tree, without failing if it does not exist

Parameters:
dirnamestr

Path of directory

rapthor.lib.miscellaneous.download_skymodel(ra, dec, skymodel_path, radius=5.0, overwrite=False, source='TGSS', targetname='Patch')

Downloads a skymodel for the given position and radius

Parameters:
rafloat

Right ascension in degrees of the skymodel centre

decfloat

Declination in degrees of the skymodel centre

skymodel_pathstr

Full name (with path) to the output skymodel

radiusfloat, optional

Radius for the cone search in degrees. For Pan-STARRS, the radius must be <= 0.5 degrees

sourcestr, optional

Source where to obtain a skymodel from. Can be one of: TGSS, GSM, LOTSS, or PANSTARRS. Note: the PANSTARRS sky model is only suitable for use in astrometry checks and should not be used for calibration

overwritebool, optional

Overwrite the existing skymodel pointed to by skymodel_path

target_namestr, optional

Give the patch a certain name

rapthor.lib.miscellaneous.find_unflagged_fraction(ms_file, start_time, end_time)

Finds the fraction of data that is unflagged for an MS file in the given time range

Parameters:
ms_filestr

Filename of input MS

start_timefloat

MJD time in seconds for start of time range

end_timefloat

MJD time in seconds for end of time range

Returns:
unflagged_fractionfloat

Fraction of unflagged data

rapthor.lib.miscellaneous.get_flagged_solution_fraction(h5file, solsetname='sol000')

Get flagged fraction for solutions in given H5parm

Parameters:
h5filestr

Filename of input h5parm file

solsetnamestr, optional

The solution set name to use. The flagged fraction is calculated over all solution tables in the given solution set

Returns:
flagged_fractionfloat

Flagged fraction

rapthor.lib.miscellaneous.get_reference_station(soltab, max_ind=None)

Return the index of the station with the lowest fraction of flagged solutions

Parameters:
soltablosoto solution table object

The input solution table

max_indint, optional

The maximum station index to use when choosing the reference station. The reference station will be drawn from the first max_ind stations. If None, all stations are considered.

Returns:
ref_indint

Index of the reference station

rapthor.lib.miscellaneous.make_template_image(image_name, reference_ra_deg, reference_dec_deg, ximsize=512, yimsize=512, cellsize_deg=0.000417, freqs=None, times=None, antennas=None, aterm_type='tec', fill_val=0)

Make a blank FITS image and save it to disk

Parameters:
image_namestr

Filename of output image

reference_ra_degfloat

RA for center of output mask image

reference_dec_degfloat

Dec for center of output mask image

imsizeint, optional

Size of output image

cellsize_degfloat, optional

Size of a pixel in degrees

freqslist, optional

Frequencies to use to construct extra axes (for IDG a-term images)

timeslist, optional

Times to use to construct extra axes (for IDG a-term images)

antennaslist, optional

Antennas to use to construct extra axes (for IDG a-term images)

aterm_typestr, optional

One of ‘tec’ or ‘gain’

fill_valint, optional

Value with which to fill the data

rapthor.lib.miscellaneous.normalize_dec(num)

Normalize Dec to be in the range [-90, 90].

Based on https://github.com/phn/angles/blob/master/angles.py

Parameters:
numfloat

The Dec in degrees to be normalized.

Returns:
resfloat

Dec in degrees in the range [-90, 90].

rapthor.lib.miscellaneous.normalize_ra(num)

Normalize RA to be in the range [0, 360).

Based on https://github.com/phn/angles/blob/master/angles.py

Parameters:
numfloat

The RA in degrees to be normalized.

Returns:
resfloat

RA in degrees in the range [0, 360).

rapthor.lib.miscellaneous.ra2hhmmss(deg)

Convert RA coordinate (in degrees) to HH MM SS

Parameters:
degfloat

The RA coordinate in degrees

Returns:
hhint

The hour (HH) part

mmint

The minute (MM) part

ssfloat

The second (SS) part

rapthor.lib.miscellaneous.rasterize(verts, data, blank_value=0)

Rasterize a polygon into a data array

Parameters:
vertslist of (x, y) tuples

List of input vertices of polygon to rasterize

data2-D array

Array into which rasterize polygon

blank_valueint or float, optional

Value to use for blanking regions outside the poly

Returns:
data2-D array

Array with rasterized polygon

rapthor.lib.miscellaneous.read_vertices(filename)

Returns facet vertices stored in input file

rapthor.lib.miscellaneous.remove_soltabs(solset, soltabnames)

Remove H5parm soltabs from a solset

Note: the H5parm must be opened with readonly = False

Parameters:
solsetlosoto solution set object

The solution set from which to remove soltabs

soltabnameslist

Names of soltabs to remove

rapthor.lib.miscellaneous.string2bool(invar)

Converts a string to a bool

Parameters:
invarstr

String to be converted

Returns:
resultbool

Converted bool

rapthor.lib.miscellaneous.string2list(invar)

Converts a string to a list

Parameters:
invarstr

String to be converted

Returns:
resultlist

Converted list