The miscellaneous module

The miscellaneous module defines various miscellaneous functions used in Rapthor.

Module that holds miscellaneous functions and classes

rapthor.lib.miscellaneous.angular_separation(position1, position2)

Compute the angular separation between two RADec coordinates.

Parameters:
position1tuple of float

The first (RA, Dec) coordinates in degrees.

position2tuple of float

The second (RA, Dec) coordinates in degrees.

Returns:
separationastropy.units.Quantity

The angular separation between the two positions, in degrees by default.

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, use_lotss_estimate=False)

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

Note: by default, the calculations follow those of SKA Memo 113 (see https://arxiv.org/abs/1308.4267) and assume no tapering. International stations are not included. A alternvate estimate can be made for LOFAR data following Shimwell et. al (2022, A&A, 659, A1), where the noise in LOFAR images was found to behave as follows (for an 8 hour, 48 MHz observation):

noise = A×cos(90-elevation)^−2.0, where A is 62 μJy beam−1

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)

use_lotss_estimatebool, optional

If True, the empirical LoTSS noise estimate from Shimwell et. al (2022) is used instead of the one from SKA Memo 113

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.dec2ddmmss(deg, as_string=False)

Convert Dec coordinate (in degrees) to DD MM SS.S

Parameters:
degfloat

The Dec coordinate in degrees

as_stringbool

If True, return the Dec as a string with ‘d’, ‘m’, and ‘s’ as the separators. E.g.: ‘12d23m13.4s’. If False, return a tuple of (DD, MM, SS.S, sign)

Returns:
ddmmsstuple of (int, int, float, int) or string

A tuple of (DD, MM, SS.S, sign) or a string as ‘DDdMMmSS.Ss’

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_max_spectral_terms(skymodel_file)

Get the maximum number of spectral terms (including the zeroth term) in a sky model

Parameters:
skymodel_filestr

Input sky model filename

Returns:
ntermsint

Maximum number of spectral terms

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.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. NOTE: This function uses os.sched_getaffinity(), which is not available on every OS. Use multiprocessing.cpu_count() as fall-back.

rapthor.lib.miscellaneous.ra2hhmmss(deg, as_string=False)

Convert RA coordinate (in degrees) to HH MM SS.S

Parameters:
degfloat

The RA coordinate in degrees

as_stringbool

If True, return the RA as a string with ‘h’, ‘m’, and ‘s’ as the separators. E.g.: ‘12h23m13.4s’ If False, return a tuple of (HH, MM, SS.S)

Returns:
hhmmsstuple of (int, int, float) or string

A tuple of (HH, MM, SS.S) or a string as ‘HHhMMmSS.Ss’

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