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.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')

Download the skymodel for the target field

Parameters:
rafloat

Right ascension of the skymodel centre.

decfloat

Declination of the skymodel centre.

skymodel_pathstr

Full name (with path) to the skymodel.

radiusfloat

Radius for the TGSS/GSM cone search in degrees.

sourcestr

Source where to obtain a skymodel from. Can be TGSS or GSM. Default is TGSS.

overwritebool

Overwrite the existing skymodel pointed to by skymodel_path.

target_namestr

Give the patch a certain name. Default is “Patch”.

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, optional

RA for center of output mask image

reference_dec_degfloat, optional

Dec for center of output mask image

imsizeint, optional

Size of output image

cellsize_degfloat, optional

Size of a pixel in degrees

freqslist

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

timeslist

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

antennaslist

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

aterm_typestr

One of ‘tec’ or ‘gain’

fill_valint

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