losoto package

Subpackages

Submodules

losoto.h5parm module

losoto.h5parm.openSoltab(h5parmFile, solsetName=None, soltabName=None, address=None, readonly=True)

Convenience function to get a soltab object from an h5parm file and an address like “solset000/phase000”.

Parameters
  • h5parmFile (str) – H5parm filename.

  • solsetName (str) – solset name

  • soltabName (str) – soltab name

  • address (str) – solset/soltab name (to use in place of the parameters solset and soltab).

  • readonly (bool, optional) – if True the table is open in readonly mode, by default True.

Returns

A solution table object.

Return type

Soltab obj

class losoto.h5parm.h5parm(h5parmFile, readonly=True, complevel=0, complib='zlib')

Bases: object

Create an h5parm object.

Parameters
  • h5parmFile (str) – H5parm filename.

  • readonly (bool, optional) – if True the table is open in readonly mode, by default True.

  • complevel (int, optional) – compression level from 0 to 9 when creating the file, by default 5.

  • complib (str, optional) – library for compression: lzo, zlib, bzip2, by default zlib.

close()

Close the open table.

makeSolset(solsetName=None, addTables=True)

Create a new solset, if the provided name is not given or exists then it falls back on the first available sol###.

Parameters
  • solset (str) – Name of the solution set.

  • addTables (bool, optional) – If True add antenna/direction/array tables, by default True.

Returns

Newly created solset object.

Return type

solset obj

getSolsets()

Get all solution set objects.

Returns

A list of all solsets objects.

Return type

list

getSolsetNames()

Get all solution set names.

Returns

A list of str of all solsets names.

Return type

list

getSolset(solset)

Get a solution set with a given name.

Parameters

solset (str) – Name of the solution set.

Returns

Return solset object.

Return type

solset obj

printInfo(filter=None, verbose=False)

Used to get readable information on the h5parm file.

Parameters
  • filter (str, optional) – Solution set name to get info for

  • verbose (bool, optional) – If True, return additional info on axes

Returns

Returns a string with info about H5parm contents.

Return type

str

class losoto.h5parm.Solset(solset)

Bases: object

Create a solset object

Parameters

solset (pytables group) – The solution set pytables group object

close()
delete()

Delete this solset.

rename(newname, overwrite=False)

Rename this solset.

Parameters
  • newname (str) – New solution set name.

  • overwrite (bool, optional) – Overwrite existing solset with same name.

makeSoltab(soltype=None, soltabName=None, axesNames=[], axesVals=[], chunkShape=None, vals=None, weights=None, parmdbType='', weightDtype='f16')

Create a Soltab into this solset.

Parameters
  • soltype (str) – Solution-type (e.g. amplitude, phase)

  • soltabName (str, optional) – The solution-table name, if not specified is generated from the solution-type

  • axesNames (list) – List with the axes names

  • axesVals (list) – List with the axes values (each is a separate np.array)

  • chunkShape (list, optional) – List with the chunk shape

  • vals (numpy array) – Array with shape given by the axesVals lenghts

  • weights (numpy array) – Same shape of the vals array 0->FLAGGED, 1->MAX_WEIGHT

  • parmdbType (str) – Original parmdb solution type

  • weightDtype (str) – THe dtype of weights allowed values are (‘f16’ or ‘f32’ or ‘f64’)

Returns

Newly created soltab object

Return type

soltab obj

getSoltabs(useCache=False, sel={})

Get all Soltabs in this Solset.

Parameters
  • useCache (bool, optional) – soltabs obj will use cache, by default False

  • sel (dict, optional) – selection dict, by default no selection

Returns

List of solution tables objects for all available soltabs in this solset

Return type

list

getSoltabNames()

Get all Soltab names in this Solset.

Returns

List of str for all available soltabs in this solset.

Return type

list

getSoltab(soltab, useCache=False, sel={})

Get a soltab with a given name.

Parameters
  • soltab (str) – A solution table name.

  • useCache (bool, optional) – Soltabs obj will use cache, by default False.

  • sel (dict, optional) – Selection dict, by default no selection.

Returns

A solution table obj.

Return type

soltab obj

getAnt()

Get the antenna subtable with antenna names and positions.

Returns

Available antennas in the form {name1:[position coords], name2:[position coords], …}.

Return type

dict

getSou()

Get the source subtable with direction names and coordinates.

Returns

Available sources in the form {name1:[ra,dec], name2:[ra,dec], …}.

Return type

dict

getAntDist(ant=None)

Get antenna distance to a specified one.

Parameters

ant (str (optional)) – An antenna name. If None, then w.r.t. the antennas centroid.

Returns

Dict of distances to each antenna. The distance with the antenna “ant” is 0.

Return type

str

class losoto.h5parm.Soltab(soltab, useCache=False, args={})

Bases: object

Parameters
  • soltab (pytables Table obj) – Pytable Table object.

  • useCache (bool, optional) – Cache all data in memory, by default False.

  • **args (optional) – Used to create a selection. Selections examples: axisName = None # to select all axisName = xxx # to select ONLY that value for an axis axisName = [xxx, yyy, zzz] # to selct ONLY those values for an axis axisName = ‘xxx’ # regular expression selection axisName = {min: xxx} # to selct values grater or equal than xxx axisName = {max: yyy} # to selct values lower or equal than yyy axisName = {min: xxx, max: yyy} # to selct values greater or equal than xxx and lower or equal than yyy

delete()

Delete this soltab.

rename(newname, overwrite=False)

Rename this soltab.

Parameters
  • newname (str) – New solution table name.

  • overwrite (bool, optional) – Overwrite existing soltab with same name.

setCache(val, weight)

Set cache values.

Parameters
  • val (array) –

  • weight (array) –

getSolset()

This is used to obtain the parent solset object to e.g. get antennas or create new soltabs.

Returns

A solset obj.

Return type

solset obj

getAddress()

Get the “solset000/soltab000” type string for this Soltab.

Returns

The solset/soltab address of self.obj as a string.

Return type

str

clearSelection()

Clear selection, all values are now considered.

setSelection(update=False, **args)
Set a selection criteria. For each axes there can be a:
  • string: regexp

  • list: use only the listed values

  • dict: with min/max/[step] to select a range.

Parameters
  • **args – Valid axes names of the form: pol=’XX’, ant=[‘CS001HBA’,’CS002HBA’], time={‘min’:1234,’max’:’2345’,’step’:4}.

  • update (bool) – Only update axes passed as arguments, the rest is maintained. Default: False.

getType()

Get the solution type of this Soltab.

Returns

Return the type of the solution-tables (e.g. amplitude).

Return type

str

getAxesNames()

Get axes names.

Returns

A list with all the axis names in the correct order for slicing the getValuesGrid() reurned matrix.

Return type

list

getAxisLen(axis, ignoreSelection=False)

Return an axis lenght.

Parameters
  • axis (str) – The name of the axis.

  • ignoreSelection (bool, optional) – If True returns the axis lenght without any selection active, by default False.

Returns

The axis lenght.

Return type

int

getAxisType(axis)

Return the axis dtype

Parameters

axis (str) – The name of the axis.

Returns

The axis dtype.

Return type

dtype

getAxisValues(axis, ignoreSelection=False)

Get the values of a given axis.

Parameters
  • axis (str) – The name of the axis.

  • ignoreSelection (bool, optional) – If True returns the axis values without any selection active, by default False.

Returns

A copy of all values present along a specific axis.

Return type

list

setAxisValues(axis, vals)

Set the value of a specific axis

Parameters
  • axis (str) – The name of the axis.

  • vals (array) – Values

setValues(vals, selection=None, weight=False)

Save values in the val grid

Parameters
  • vals (array, float) – values to write as an n-dimentional array which match the selection dimention if a float is passed or the selected data are set to that value

  • selection (selection format, optional) – To set only a subset of data, overriding global selectioan, by default use global selection. This is used to set values in a loop of getValueIter(). Global seclection is NOT overwritten.

  • weight (bool, optional) – If true store in the weights instead that in the vals, by default False

flush()

Copy cached values into the table

getValues(retAxesVals=True, weight=False, refAnt=None, refDir=None)

Creates a simple matrix of values. Fetching a copy of all selected rows into memory.

Parameters
  • retAxesVals (bool, optional) – If true returns also the axes vals as a dict of: {‘axisname1’:[axisvals1],’axisname2’:[axisvals2],…}. By default True.

  • weight (bool, optional) – If true get the weights instead that the vals, by defaul False.

  • refAnt (str, optional) – In case of phase or rotation solutions, reference to this station name. By default no reference. If “closest” reference to the closest antenna. If “auto” select automatically from least flagged and closest to the centre

  • refDir (str, optional) – In case of phase or rotation solutions, reference to this Direction. By default no reference. If “center”, reference to the central direction.

Returns

A numpy ndarray (values or weights depending on parameters) If selected, returns also the axes values

Return type

array

getValuesIter(returnAxes=[], weight=False, refAnt=None, refDir=None)

Return an iterator which yields the values matrix (with axes = returnAxes) iterating along the other axes. E.g. if returnAxes are [‘freq’,’time’], one gets a interetion over all the possible NxM matrix where N are the freq and M the time dimensions. The other axes are iterated in the getAxesNames() order. Note that all the data are fetched in memory before returning them one at a time. This is quicker.

Parameters
  • returnAxes (list) – Axes of the returned array, all _others_ will be cycled on each element combinations.

  • weight (bool, optional) – If true return also the weights, by default False.

  • refAnt (str) – In case of phase solutions, reference to this station name.

  • refDir (str) – In case of phase solutions, reference to this direction name.

Returns

  • 1) data ndarray of dim=dim(returnAxes) and with the axes ordered as in getAxesNames()

  • 2) (if weight == True) weight ndarray of dim=dim(returnAxes) and with the axes ordered as in getAxesNames()

  • 3) a dict with axis values in the form

  • {‘axisname1’ ([axisvals1],’axisname2’:[axisvals2],…})

  • 4) a selection which should be used to write this data back using a setValues()

autoRefAnt()

Get the least flagged antennas usign the 10 closest to the array centre

addHistory(entry, date=True)

Adds entry to the table history with current date and time

Since attributes cannot by default be larger than 64 kB, each history entry is stored in a separate attribute.

Parameters

entry (str) – entry to add to history list

getHistory()

Get the soltab history.

Returns

The table history as a string with each entry separated by newlines.

Return type

str

losoto.lib_losoto module

class losoto.lib_losoto.LosotoParser(parsetFile)

Bases: backports.configparser.ConfigParser

A parser for losoto parset files.

Parameters

parsetFile (str) – Name of the parset file.

checkSpelling(s, soltab, availValues=[])

check if any value in the step is missing from a value list and return a warning

getstr(s, v, default=None)
getbool(s, v, default=None)
getfloat(s, v, default=None)
getint(s, v, default=None)
getarray(s, v, default=None)
getarraystr(s, v, default=None)
getarraybool(s, v, default=None)
getarrayfloat(s, v, default=None)
getarrayint(s, v, default=None)
getarrayfloat2d(s, v, default=None)

Alternative to parse 1,2 or ndim array input. ‘getarrayfloat() does not support more than 1 dim. TODO: it might be cleaner to unify these functions…

losoto.lib_losoto.getParAxis(parser, step, axisName)

Axes values can be selected with: - an array of values - a string (reg exp): passed as axisName.regexp = … - a min,max,step format: passed as axisName.minmaxstep = …

Parameters
  • parser (parser obj) – configuration file

  • step (str) – this step

  • axisName (str) – an axis name

Returns

a selection criteria

Return type

str, dict or list

losoto.lib_losoto.getStepSoltabs(parser, step, H)

Return a list of soltabs object for a step and apply selection creteria

Parameters
  • parser (parser obj) – configuration file

  • step (str) – current step

  • H (h5parm obj) – the h5parm object

Returns

list of soltab obj with applied selection

Return type

list

losoto.lib_losoto.deprecated_alias(**aliases)
losoto.lib_losoto.rename_kwargs(func_name, kwargs, aliases)

losoto.lib_operations module

class losoto.lib_operations.multiprocManager(procs=0, funct=None)

Bases: object

class multiThread(inQueue, outQueue, funct)

Bases: multiprocessing.context.Process

This class is a working thread which load parameters from a queue and return in the output queue

run()

Method to be run in sub-process; can be overridden in sub-class

put(args)

Parameters to give to the next jobs sent into queue

get()

Return all the results as an iterator

wait()

Send poison pills to jobs and wait for them to finish The join() should kill all the processes

losoto.lib_operations.reorderAxes(a, oldAxes, newAxes)

Reorder axis of an array to match a new name pattern.

Parameters
  • a (np array) – The array to transpose.

  • oldAxes (list of str) – A list like [‘time’,’freq’,’pol’]. It can contain more axes than the new list, those are ignored. This is to pass to oldAxis the soltab.getAxesNames() directly even on an array from getValuesIter()

  • newAxes (list of str) – A list like [‘time’,’pol’,’freq’].

Returns

With axis transposed to match the newAxes list.

Return type

np array

losoto.lib_operations.removeKeys(dic, keys=[])

Remove a list of keys from a dict and return a new one.

Parameters
  • dic (dcit) – The input dictionary.

  • keys (list of str) – A list of arguments to remove or a string for single argument.

Returns

Dictionary with removed keys.

Return type

dict

losoto.lib_operations.normalize_phase(phase)

Normalize phase to the range [-pi, pi].

Parameters

phase (array of float) – Phase to normalize.

Returns

Normalized phases.

Return type

array of float

losoto.lib_unwrap module

losoto.lib_unwrap.unwrap_fft(phase, iterations=3)

Unwrap phase using Fourier techniques.

For details, see: Marvin A. Schofield & Yimei Zhu, Optics Letters, 28, 14 (2003)

Keyword arguments: phase – array of phase solutions iterations – number of iterations to perform

losoto.lib_unwrap.unwrap(phase, window_size=5)

Unwrap phase by estimating the trend of the phase signal.

losoto.lib_unwrap.unwrap_huib(x, window=10, alpha=0.01, iterations=3, clip_range=[170.0, 180.0])

Unwrap the x array, if it is shorter than 2*window, use np.unwrap()

losoto.lib_unwrap.dct2(arr, inverse=False)
losoto.lib_unwrap.laplacian(arr, inverse=False)
losoto.lib_unwrap.unwrap_2d(arr, flags=None, coord_x=None, coord_y=None)

if flags are specified do interp

losoto.phase_colormap module

Module contents