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 https://arxiv.org/abs/1308.4267) 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.make_wcs(ra, dec, wcs_pixel_scale=0.002777777777777778)¶
Makes simple WCS object
- Parameters:
- rafloat
Reference RA in degrees
- decfloat
Reference Dec in degrees
- wcs_pixel_scalefloat, optional
Pixel scale in degrees/pixel (default = 10”/pixel)
- Returns:
- wastropy.wcs.WCS object
A simple TAN-projection WCS object for specified reference position
- 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.nproc()¶
Return the number of CPU cores _available_ to the current process, similar to what the Linux nproc command does. This can be less than the total number of CPU cores in the machine, which is returned by, e.g., multiprocessing.cpu_count()
- 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.radec2xy(wcs, ra, dec)¶
Returns x, y for input RA, Dec
- Parameters:
- wcsWCS object
WCS object defining transformation
- rafloat, list, or numpy array
RA value(s) in degrees
- decfloat, list, or numpy array
Dec value(s) in degrees
- Returns:
- x, yfloat, list, or numpy array
x and y pixel values corresponding to the input RA and Dec values
- 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.rename_skymodel_patches(skymodel, order_dec='high_to_low', order_ra='high_to_low', dec_bin_width=2.0)¶
Rename the patches in the input sky model according to the given scheme
Note: the patches are first binned by Dec and then sorted by RA within each bin. The patch names start from “Patch_1” and increase first by RA and then by Dec, ordered either with increasing or decreasing RA and Dec as given by the order_dec and order_ra args
- Parameters:
- skymodelLSMTool skymodel.SkyModel object
Input sky model
- order_decstr, optional
- The scheme to use for ordering:
‘high_to_low’: patches increase with decreasing Dec
‘low_to_high’: patches increase with increasing Dec
- order_rastr, optional
Same as order_dec, but for RA
- dec_bin_widthfloat, optional
Bin width in degrees for the Dec values
- 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
- rapthor.lib.miscellaneous.transfer_patches(from_skymodel, to_skymodel, patch_dict=None)¶
Transfers the patches defined in from_skymodel to to_skymodel
- Parameters:
- from_skymodelLSMTool skymodel.SkyModel object
Sky model from which to transfer patches
- to_skymodelLSMTool skymodel.SkyModel object
Sky model to which to transfer patches
- patch_dictdict, optional
Dict of patch positions
- rapthor.lib.miscellaneous.xy2radec(wcs, x, y)¶
Returns RA, Dec for input x, y
- Parameters:
- wcsWCS object
WCS object defining transformation
- xfloat, list, or numpy array
x value(s) in pixels
- yfloat, list, or numpy array
y value(s) in pixels
- Returns:
- RA, Decfloat, list, or numpy array
RA and Dec values corresponding to the input x and y pixel values