Utilities

Some utilities useful internally and externally from ragavi

ragavi.utils.calc_amplitude(ydata)

Convert complex data to amplitude (absolute value)

Parameters:ydata (xarray.DataArray) – y axis data to be processed
Returns:amplitude (xarray.DataArray) – ydata converted to an amplitude
ragavi.utils.calc_imaginary(ydata)

Extract imaginary part from complex data

Parameters:ydata (xarray.DataArray) – y-axis data to be processed
Returns:imag (xarray.DataArray) – Imaginary part of ydata
ragavi.utils.calc_phase(ydata, unwrap=False)

Convert complex data to angle in degrees

Parameters:
  • wrap (bool) – whether to wrap angles between 0 and 2pi
  • ydata (xarray.DataArray) – y-axis data to be processed
Returns:

phase (xarray.DataArray) – ydata data converted to degrees

ragavi.utils.calc_real(ydata)

Extract real part from complex data

Parameters:ydata (xarray.DataArray) – y-axis data to be processed
Returns:real (xarray.DataArray) – Real part of ydata
ragavi.utils.calc_unique_bls(n_ants=None)

Calculate number of unique baselines :param n_ants: Available antennas :type n_ants: int

Returns:pq (int) – Number of unique baselines
ragavi.utils.calc_uvdist(uvw)

Calculate uv distance in metres

Parameters:uvw (xarray.DataArray) – UVW column from measurement set
Returns:uvdist (xarray.DataArray) – uv distance in meters
ragavi.utils.calc_uvwave(uvw, freq)

Calculate uv distance in wavelength for availed frequency. This function also calculates the corresponding wavelength. Uses output from ragavi.vis_utils.calc_uvdist()

Parameters:
  • freq (xarray.DataArray or :obj:`float) – Frequency(ies) from which corresponding wavelength will be obtained.
  • uvw (xarray.DataArray) – UVW column from the MS dataset
Returns:

uvwave (xarray.DataArray) – uv distance in wavelength for specific frequency

ragavi.utils.ctext(text, colour='green')

Colour some terminal output

ragavi.utils.get_antennas(ms_name)

Function to get antennae names from the ANTENNA subtable.

Parameters:ms_name (str) – Name of MS or table
Returns:ant_names (xarray.DataArray) – A xarray.DataArray containing names for all the antennas available.
ragavi.utils.get_cmap(cmap, fall_back='coolwarm', src='bokeh')

Get Hex colors that form a certain cmap. This function checks for the requested cmap in bokeh.palettes and colorcet.palettes. List of valid names can be found at: https: // colorcet.holoviz.org / user_guide / index.html https: // docs.bokeh.org / en / latest / docs / reference / palettes.html

ragavi.utils.get_diverging_cmap(n_colors, cmap1=None, cmap2=None)

Produce n_colors that diverge given two different colourmaps. This function depends on pl.diverging_palettes whose doc can be found at: https: // docs.bokeh.org / en / latest / docs / reference / palettes.html cmap1: : obj: str

Name of the first colourmap to use
cmap2: : obj: str
Name of the second colourmap to use
n_colors: : obj: int
Number of colours to generate.
Returns:colors (: obj: list) – A list of size n_colors containing the diverging colours
ragavi.utils.get_fields(ms_name)

Get field names from the FIELD subtable.

Parameters:ms_name (str) – Name of MS or table
Returns:field_names (xarray.DataArray) – String names for the available fields
ragavi.utils.get_flags(xds_table_obj, corr=None, chan=slice(0, None, None))

Get Flag values from the FLAG column. Allow for selections in the channel dimension or the correlation dimension

Parameters:
  • corr (int) – Correlation number to select.
  • xds_table_obj (xarray.Dataset) – MS as xarray dataset from xarrayms
Returns:

flags (xarray.DataArray) – Data array containing values from FLAG column selected by correlation if index is available.

ragavi.utils.get_frequencies(ms_name, spwid=None, chan=None, cbin=None)

Function to get channel frequencies from the SPECTRAL_WINDOW subtable

Parameters:
  • chan (slice or numpy.ndarray) – A slice object or numpy array to select some or all of the channels. Default is all the channels
  • cbin (int) – Number of channels to be binned together. If a value is provided, averaging is assumed to be turned on
  • ms_name (str) – Name of MS or table
  • spwid (int of slice) – Spectral window id number. Defaults to 0. If slicer is specified, frequencies from a range of spectral windows will be returned.
Returns:

frequencies (xarray.DataArray) – Channel centre frequencies for specified spectral window or all the frequencies for all spectral windows if one is not specified

ragavi.utils.get_linear_cmap(cmap, n, fall_back='coolwarm')

Produce n that differ linearly from a given colormap This function depends on pl.linear_palettes whose doc be found at: https: // docs.bokeh.org / en / latest / docs / reference / palettes.html cmap: : obj: str

The colourmap chosen
n: : obj: int
Number of colours to generate
Returns:colors (: obj: list) – A list of size n containing the linear colours
ragavi.utils.get_polarizations(ms_name)

Get the type of polarizations available in the measurement set

Parameters:ms_name (str) – Name of MS / table
Returns:cor2stokes (list) – Returns a list containing the types of correlation
ragavi.utils.name_2id(tab_name, field_name)

Translate field name to field id

Parameters:
  • tab_name (:obj:str`) – MS or Table name
  • field_name (str) – Field name to convert to field ID
Returns:

field_id (int) – Integer field id

ragavi.utils.resolve_ranges(inp)

Create a TAQL string that can be parsed given a range of values

Parameters:inp (str) –

A range of values to be constructed. Can be in the form of: “5”, “5,6,7”, “5~7” (inclusive range), “5:8” (exclusive range),

”5:” (from 5 to last)
Returns:res (str) – Interval string conforming to TAQL sets and intervals as shown in Casa TAQL Notes
ragavi.utils.slice_data(inp)

Creates a slicer for an array. To be used to get a data subset such as correlation or channel subsets.

Parameters:inp (str) – This can be of the form “5”, “10~20” (10 to 20 inclusive), “10:21” (same), “10:” (from 10 to end), “:10:2” (0 to 9 inclusive, stepped by 2), “~9:2” (same)
Returns:sl (slice) – slicer for an iterable object
ragavi.utils.time_convert(xdata)

Convert time from MJD to UTC time

Parameters:xdata (xarray.DataArray) – TIME column from the MS or table xarray dataset in MJD format.
Returns:newtime (xarray.DataArray) – TIME column in a more human readable UTC format. Stored as numpy.datetime type.
ragavi.utils.time_wrapper(func)

A decorator function to compute the execution time of a function

ragavi.utils.update_log_levels(in_logger, level)

Change the logging level of the parent plotter

ragavi.utils.update_logfile_name(in_logger, new_name)

Change the name of the resulting logfile