ch_util.tools

Tools for CHIME analysis

A collection of miscellaneous utility routines.

Correlator Inputs

Query the layout database to find out what is ultimately connected at the end of correlator inputs. This is done by calling the routine get_correlator_inputs(), which returns a list of the inputs. Routines such as get_feed_positions() operate on this list.

This can determine if we are connected to any of the following:

Example

Fetch the inputs for blanchard during layout 38:

>>> from datetime import datetime
>>> inputs = get_correlator_inputs(datetime(2016,05,23,00), correlator='pathfinder')
>>> inputs[1]
CHIMEAntenna(id=1, reflector=u'W_cylinder', antenna=u'ANT0123B', powered=True, pos=9.071800000000001, input_sn=u'K7BP16-00040401', pol=u'S', corr=u'K7BP16-0004', cyl=0)
>>> print "NS position:", inputs[1].pos
NS position: 9.0718
>>> print "Polarisation:", inputs[1].pol
Polarisation: S
>>> inputs[3]
CHIMEAntenna(id=3, reflector=u'W_cylinder', antenna=u'ANT0128B', powered=True, pos=9.681400000000002, input_sn=u'K7BP16-00040403', pol=u'S', corr=u'K7BP16-0004', cyl=0)

Housekeeping Inputs

Functions

Classes

Product Array Mapping

Tools for mapping between products stored in upper triangular format, and the underlying pairs of inputs.

Matrix Factorisation

A few useful routines for factorising matrices, usually for calibration.

Fringestopping

Routines for undoing the phase rotation of a fixed celestial source. The routine fringestop() is an easy to use routine for fringestopping data given a list of the feeds in the data. For more advanced usage fringestop_phase() can be used.

  • fringestop_phase()

  • fringestop()

Miscellaneous

  • invert_no_zero()

Functions

antenna_to_lna(graph, ant, pol)

Find an LNA connected to an antenna.

apply_gain(vis, gain[, axis, out, prod_map])

Apply per input gains to a set of visibilities packed in upper triangular format.

beam_index2number(beam_index)

Convert beam "index" (0-1023) to beam "number" (0-255, 1000-1255, etc.)

calibrate_temperature(raw)

Calibrate housekeeping temperatures.

change_chime_location([rotation, location, ...])

Change the orientation or location of CHIME.

change_pathfinder_location([rotation, ...])

Change the orientation or location of Pathfinder.

cmap(i, j, n)

Given a pair of feed indices, return the pair index.

decorrelation(timestream, times, feeds, src)

Apply the decorrelation corrections to a timestream from observing a source.

delay(times, feeds, src[, wterm, bterm, ...])

Calculate the delay in a visibilities observing a given source.

eigh_no_diagonal(A[, niter, eigvals])

Eigenvalue decomposition ignoring the diagonal elements.

fake_tone_database()

fast_pack_product_array(arr)

Equivalent to ch_util.tools.pack_product_array(arr, axis=0), but 10^5 times faster for full CHIME!

fringestop_time(timestream, times, freq, ...)

Fringestop timestream data to a fixed source.

get_correlator_inputs(lay_time[, ...])

Get the information for all channels in a layout.

get_default_frequency_map_stream()

Get the default CHIME frequency map stream.

get_feed_polarisations(feeds)

Get an array of the feed polarisations.

get_feed_positions(feeds[, get_zpos])

Get the positions of the CHIME antennas.

get_holographic_index(inputs)

Find the indices of the holography antennas.

get_noise_channel(inputs)

Returns the index of the noise source with the lowest chan id (for backwards compatability).

get_noise_source_index(inputs)

Find the indices of the noise sources.

hk_to_sensor(graph, inp)

Find what component a housekeeping channel is connected to.

icmap(ix, n)

Inverse feed map.

invert_no_zero(*args, **kwargs)

is_array(feed)

Is this feed part of an array?

is_array_on(inputs, *args)

Check if inputs are attached to an array antenna AND powered on AND flagged as good.

is_array_x(feed)

Is this an X-polarisation antenna in an array?

is_array_y(feed)

Is this a Y-polarisation antenna in an array?

is_chime(feed)

Is this feed a CHIME antenna?

is_chime_on(inputs, *args)

Check if inputs are attached to an array antenna AND powered on AND flagged as good.

is_holographic(feed)

Is this feed a holographic antenna?

is_noise_source(inp)

Is this correlator input connected to a noise source?

is_pathfinder(feed)

Is this feed a Pathfinder antenna?

lna_to_antenna(graph, lna)

Find an antenna connected to an LNA.

normalise_correlations(A[, norm])

Normalise to make a correlation matrix from a covariance matrix.

order_frequency_map_stream(fmap, stream_id)

Order stream_id components based on a frequency map.

pack_product_array(exp_arr[, axis])

Pack full correlation matrices into upper triangular form.

parse_chime_serial(sn)

parse_old_serial(sn)

parse_pathfinder_serial(sn)

rankN_approx(A[, rank])

Create the rank-N approximation to the matrix A.

redefine_stack_index_map(input_map, prod, ...)

Ensure that only baselines between array antennas are used to represent the stack.

reorder_correlator_inputs(input_map, corr_inputs)

Sort a list of correlator inputs into the order given in input map.

sensor_to_hk(graph, comp)

Find what housekeeping channel a component is connected to.

serial_to_id(serial)

Get the channel ID corresponding to a correlator input serial number.

serial_to_location(serial)

Get the internal correlator ordering and the crate, slot, and sma number from a correlator input serial number.

subtract_rank1_signal(vis, signal[, axis, ...])

Subtract a rank 1 signal from a set of visibilities packed in upper triangular format.

unpack_product_array(prod_arr[, axis, feeds])

Expand packed products to correlation matrices.

Classes

Antenna(**input_dict)

An antenna input.

ArrayAntenna(**input_dict)

Antenna that is part of a cylindrical interferometric array.

Blank(**input_dict)

Unconnected input.

CHIMEAntenna(**input_dict)

Antenna that is part of CHIME.

CorrInput(**input_dict)

Base class for describing a correlator input.

GBOAntenna(**input_dict)

GBO outrigger antenna for the CHIME/FRB project.

HCOAntenna(**input_dict)

HCRO outrigger antenna for the CHIME/FRB project.

HKInput([atmel, chan, mux])

A housekeeping input.

HolographyAntenna(**input_dict)

Antenna used for holography.

KKOAntenna(**input_dict)

KKO outrigger antenna for the CHIME/FRB project.

NoiseSource(**input_dict)

Broad band noise calibration source.

PCOAntenna

alias of KKOAntenna

PathfinderAntenna(**input_dict)

Antenna that is part of the Pathfinder.

RFIAntenna(**input_dict)

RFI monitoring antenna

TONEAntenna(**input_dict)

Antenna that is part of GBO/TONE Outrigger.

class ch_util.tools.Antenna(**input_dict)[source]

Bases: CorrInput

An antenna input.

reflector

The name of the reflector the antenna is on.

Type:

str

antenna

Serial number of the antenna.

Type:

str

rf_thru

Serial number of the RF room thru that the connection passes.

Type:

str

class ch_util.tools.ArrayAntenna(**input_dict)[source]

Bases: Antenna

Antenna that is part of a cylindrical interferometric array.

cyl

Index of the cylinder.

Type:

int

pos

Position of the antenna in meters in right-handed coordinates where x is eastward, y is northward, and z is upward.

Type:

[x, y, z]

pol

Orientation of the polarisation.

Type:

str

flag

Flag indicating whether or not the antenna is good.

Type:

bool

class ch_util.tools.Blank(**input_dict)[source]

Bases: CorrInput

Unconnected input.

class ch_util.tools.CHIMEAntenna(**input_dict)[source]

Bases: ArrayAntenna

Antenna that is part of CHIME.

class ch_util.tools.CorrInput(**input_dict)[source]

Bases: object

Base class for describing a correlator input.

Meant to be subclassed by actual types of inputs.

input_sn

Unique serial number of input.

Type:

str

corr

Unique serial number of correlator. Set to None if no correlator is connected.

Type:

str

corr_order

Order of input for correlator internal datastream.

Type:

int

crate

Crate number within the correlator. Set to None if correlator consists of single crate.

Type:

int

slot

Slot number of the fpga motherboard within the crate. Ranges from 0 to 15, left to right. Set to None if correlator consists of single slot.

Type:

int

sma

SMA number on the fpga motherboard within the slot. Ranges from 0 to 15, bottom to top.

Type:

int

property delay

The delay along the signal chain in seconds.

Postive delay values mean signals arriving later than the nominal value.

Note that these are always relative. Here CHIME inputs are chosen as the delay=0 reference.

property id

Channel ID. Automatically calculated from the serial number if id is not explicitly set.

Returns:

id – Channel id. Calculated from the serial.

Return type:

int

class ch_util.tools.GBOAntenna(**input_dict)[source]

Bases: ArrayAntenna

GBO outrigger antenna for the CHIME/FRB project.

class ch_util.tools.HCOAntenna(**input_dict)[source]

Bases: ArrayAntenna

HCRO outrigger antenna for the CHIME/FRB project.

class ch_util.tools.HKInput(atmel=None, chan=None, mux=None)[source]

Bases: object

A housekeeping input.

Parameters:
  • atmel (layout.component) – The ATMEL board.

  • chan (int) – The channel number.

  • mux (int) – The mux number; if this HK stream has no multiplexer, this will simply remain as Null

atmel

The ATMEL board.

Type:

layout.component

chan

The channel number.

Type:

int

mux

The mux number; if this HK stream has no multiplexer, this will simply remain as Null

Type:

int

class ch_util.tools.HolographyAntenna(**input_dict)[source]

Bases: Antenna

Antenna used for holography.

pos

Position of the antenna in meters in right-handed coordinates where x is eastward, y is northward, and z is upward.

Type:

[x, y, z]

pol

Orientation of the polarisation.

Type:

str

class ch_util.tools.KKOAntenna(**input_dict)[source]

Bases: ArrayAntenna

KKO outrigger antenna for the CHIME/FRB project.

class ch_util.tools.NoiseSource(**input_dict)[source]

Bases: CorrInput

Broad band noise calibration source.

ch_util.tools.PCOAntenna

alias of KKOAntenna

class ch_util.tools.PathfinderAntenna(**input_dict)[source]

Bases: ArrayAntenna

Antenna that is part of the Pathfinder.

powered

Flag indicating that the antenna is powered.

Type:

bool

class ch_util.tools.RFIAntenna(**input_dict)[source]

Bases: Antenna

RFI monitoring antenna

class ch_util.tools.TONEAntenna(**input_dict)[source]

Bases: ArrayAntenna

Antenna that is part of GBO/TONE Outrigger. Let’s allow for a global rotation and offset.

ch_util.tools.antenna_to_lna(graph, ant, pol)[source]

Find an LNA connected to an antenna.

Parameters:
  • graph (obj:layout.graph or datetime.datetime) – The graph in which to do the search. If you pass a time, then the graph will be constructed internally. (Note that the latter option will be quite slow if you do repeated calls!)

  • ant (layout.component) – The antenna.

  • pol (integer) – There can be up to two LNA’s connected to the two polarisation outputs of an antenna. Select which by passing 1 or 2. (Note that conversion to old-style naming ‘A’ and ‘B’ is done automatically.)

Returns:

lna – The LNA.

Return type:

layout.component or string

Raises:

layout.NotFound – Raised if the polarisation connector could not be found in the graph.

ch_util.tools.apply_gain(vis, gain, axis=1, out=None, prod_map=None)[source]

Apply per input gains to a set of visibilities packed in upper triangular format.

This allows us to apply the gains while minimising the intermediate products created.

Parameters:
  • vis (np.ndarray[..., nprod, ...]) – Array of visibility products.

  • gain (np.ndarray[..., ninput, ...]) – Array of gains. One gain per input.

  • axis (integer, optional) – The axis along which the inputs (or visibilities) are contained. Currently only supports axis=1.

  • out (np.ndarray) – Array to place output in. If None create a new array. This routine can safely use out = vis.

  • prod_map (ndarray of integer pairs) – Gives the mapping from product axis to input pairs. If not supplied, icmap() is used.

Returns:

out – Visibility array with gains applied. Same shape as vis.

Return type:

np.ndarray

ch_util.tools.beam_index2number(beam_index)[source]

Convert beam “index” (0-1023) to beam “number” (0-255, 1000-1255, etc.)

The beam “number”, with 1000s indicating the beam’s East-West index and the remainder going from 0 through 255 indicating the beam’s North-South index, is used in the CHIME/FRB beam_model package.

Parameters:

beam_index (int or np.ndarray of int) – The beam index or indices to be converted.

Returns:

beam_number – The corresponding beam number or numbers.

Return type:

same as beam_index

ch_util.tools.calibrate_temperature(raw)[source]

Calibrate housekeeping temperatures.

The offset used here is rough; the results are therefore not absolutely precise.

Parameters:

raw (numpy array) – The raw values.

Returns:

t – The temperature in degrees Kelvin.

Return type:

numpy array

ch_util.tools.change_chime_location(rotation=None, location=None, default=False)[source]

Change the orientation or location of CHIME.

Parameters:
  • rotation (float) – Rotation of the telescope from true north in degrees.

  • location (list) – [x, y, z] of the telescope in meters, where x is eastward, y is northward, and z is upward.

  • default (bool) – Set parameters back to default value. Overides other keywords.

ch_util.tools.change_pathfinder_location(rotation=None, location=None, default=False)[source]

Change the orientation or location of Pathfinder.

Parameters:
  • rotation (float) – Rotation of the telescope from true north in degrees.

  • location (list) – [x, y, z] of the telescope in meters, where x is eastward, y is northward, and z is upward.

  • default (bool) – Set parameters back to default value. Overides other keywords.

ch_util.tools.cmap(i, j, n)[source]

Given a pair of feed indices, return the pair index.

Parameters:
  • i (integer) – Feed index.

  • j (integer) – Feed index.

  • n (integer) – Total number of feeds.

Returns:

pi – Pair index.

Return type:

integer

ch_util.tools.decorrelation(timestream, times, feeds, src, wterm=True, bterm=True, prod_map=None, csd=False, inplace=False, static_delays=True)[source]

Apply the decorrelation corrections to a timestream from observing a source.

Parameters:
  • timestream (np.ndarray[nfreq, nprod, times]) – Array containing the timestream.

  • times (np.ndarray[times]) – The UNIX time of each sample, or (if csd=True), the CSD of each sample.

  • feeds (list of CorrInputs) – The feeds in the timestream.

  • src (ephem.FixedBody) – A PyEphem object representing the source to fringestop.

  • wterm (bool, optional) – Include elevation information in the calculation.

  • bterm (bool, optional) – Include a correction for baselines including the 26m Galt telescope.

  • prod_map (np.ndarray[nprod]) – The products in the timestream array.

  • csd (bool, optional) – Interpret the times parameter as CSDs.

  • inplace (bool, optional) – Fringestop the visibilities in place. If not set, leave the originals intact.

  • static_delays (bool, optional) – Correct for static cable delays in the system.

Returns:

corrected_timestream

Return type:

np.ndarray[nfreq, nprod, times]

ch_util.tools.delay(times, feeds, src, wterm=True, bterm=True, prod_map=None, csd=False, static_delays=True, obs=<caput.time.Observer object>)[source]

Calculate the delay in a visibilities observing a given source.

This includes both the geometric delay and static (cable) delays.

Parameters:
  • times (np.ndarray[times]) – The UNIX time of each sample, or (if csd=True), the CSD of each sample.

  • feeds (list of CorrInputs) – The feeds in the timestream.

  • src (ephem.FixedBody) – A PyEphem object representing the source to fringestop.

  • wterm (bool, optional) – Include elevation information in the calculation.

  • bterm (bool, optional) – Include a correction for baselines which include the 26m Galt telescope.

  • prod_map (np.ndarray[nprod]) – The products in the timestream array.

  • csd (bool, optional) – Interpret the times parameter as CSDs.

  • static_delays (bool, optional) – If set the returned value includes both geometric and static delays. If False only geometric delays are included.

Returns:

delay

Return type:

np.ndarray[nprod, nra]

ch_util.tools.eigh_no_diagonal(A, niter=5, eigvals=None)[source]

Eigenvalue decomposition ignoring the diagonal elements.

The diagonal elements are iteratively replaced with those from a rank=1 approximation.

Parameters:
  • A (np.ndarray[:, :]) – Matrix to decompose.

  • niter (int, optional) – Number of iterations to perform.

  • eigvals ((lo, hi), optional) – Indices of eigenvalues to select (inclusive).

Returns:

  • evals (np.ndarray[:])

  • evecs (np.ndarray[:, :])

ch_util.tools.fast_pack_product_array(arr)[source]

Equivalent to ch_util.tools.pack_product_array(arr, axis=0), but 10^5 times faster for full CHIME!

Currently assumes that arr is a 2D array of shape (nfeeds, nfeeds), and returns a 1D array of length (nfeed*(nfeed+1))/2. This case is all we need for phase calibration, but pack_product_array() is more general.

ch_util.tools.fringestop_time(timestream, times, freq, feeds, src, wterm=False, bterm=True, prod_map=None, csd=False, inplace=False, static_delays=True, obs=<caput.time.Observer object>)[source]

Fringestop timestream data to a fixed source.

Parameters:
  • timestream (np.ndarray[nfreq, nprod, times]) – Array containing the visibility timestream.

  • times (np.ndarray[times]) – The UNIX time of each sample, or (if csd=True), the CSD of each sample.

  • freq (np.ndarray[nfreq]) – The frequencies in the array (in MHz).

  • feeds (list of CorrInputs) – The feeds in the timestream.

  • src (ephem.FixedBody) – A PyEphem object representing the source to fringestop.

  • wterm (bool, optional) – Include elevation information in the calculation.

  • bterm (bool, optional) – Include a correction for baselines including the 26m Galt telescope.

  • prod_map (np.ndarray[nprod]) – The products in the timestream array.

  • csd (bool, optional) – Interpret the times parameter as CSDs.

  • inplace (bool, optional) – Fringestop the visibilities in place. If not set, leave the originals intact.

  • static_delays (bool, optional) – Correct for static cable delays in the system.

Returns:

fringestopped_timestream

Return type:

np.ndarray[nfreq, nprod, times]

ch_util.tools.get_correlator_inputs(lay_time, correlator=None, connect=True)[source]

Get the information for all channels in a layout.

Parameters:
  • lay_time (layout.graph or datetime) – layout.graph object, layout tag id, or datetime.

  • correlator (str, optional) – Fetch only for specified correlator. Use the serial number in database, or pathfinder or chime, which will substitute the correct serial. If None return for all correlators. Option tone added for GBO 12 dish outrigger prototype array.

  • connect (bool, optional) – Connect to database and set the user to Jrs65 prior to query. Default is True.

Returns:

channels – List of CorrInput instances. Returns None for MPI ranks other than zero.

Return type:

list

ch_util.tools.get_default_frequency_map_stream() Tuple[ndarray][source]

Get the default CHIME frequency map stream.

Level order is [shuffle, crate, slot, link].

Returns:

  • stream – [shuffle, crate, slot, link] for each frequency bin

  • stream_id – stream_id for each map combination shuffle*2**12 + crate*2**8 + slot*2**4 + link

ch_util.tools.get_feed_polarisations(feeds)[source]

Get an array of the feed polarisations.

Parameters:

feeds (list of CorrInput) – List of feeds to compute positions of.

Returns:

pol – Array of characters giving polarisation. If not an array feed returns ‘0’.

Return type:

np.ndarray

ch_util.tools.get_feed_positions(feeds, get_zpos=False)[source]

Get the positions of the CHIME antennas.

Parameters:
  • feeds (list of CorrInput) – List of feeds to compute positions of.

  • get_zpos (bool) – Return a third column with elevation information.

Returns:

positions – Array of feed positions. The first column is the E-W position (increasing to the E), and the second is the N-S position (increasing to the N). Non CHIME feeds get set to NaN.

Return type:

np.ndarray[nfeed, 2]

ch_util.tools.get_holographic_index(inputs)[source]

Find the indices of the holography antennas.

Parameters:

inputs (list of CorrInput)

Returns:

ixholo – Returns None if holographic antenna not found.

Return type:

list of int

ch_util.tools.get_noise_channel(inputs)[source]

Returns the index of the noise source with the lowest chan id (for backwards compatability).

ch_util.tools.get_noise_source_index(inputs)[source]

Find the indices of the noise sources.

Parameters:

inputs (list of CorrInput)

Returns:

ixns – Returns None if noise source not found.

Return type:

list of int

ch_util.tools.hk_to_sensor(graph, inp)[source]

Find what component a housekeeping channel is connected to.

This method is for finding either LNA or FLA’s that your housekeeping channel is connected to. (It currently cannot find accelerometers, other novel housekeeping instruments that may later exist; nor will it work if the FLA/LNA is connected via a very non-standard chain of components.)

Parameters:
  • graph (obj:layout.graph or datetime.datetime) – The graph in which to do the search. If you pass a time, then the graph will be constructed internally. (Note that the latter option will be quite slow if you do repeated calls!)

  • inp (HKInput) – The housekeeping input to search.

Returns:

comp – The LNA/FLA connected to the specified channel; None is returned if none is found.

Return type:

layout.component

Raises:

ValueError – Raised if one of the channels or muxes passed in hk_chan is out of range.

ch_util.tools.icmap(ix, n)[source]

Inverse feed map.

Parameters:
  • ix (integer) – Pair index.

  • n (integer) – Total number of feeds.

Returns:

fi, fj – Feed indices.

Return type:

integer

ch_util.tools.is_array(feed)[source]

Is this feed part of an array?

Parameters:

feed (CorrInput)

Returns:

isarr

Return type:

bool

ch_util.tools.is_array_on(inputs, *args)[source]

Check if inputs are attached to an array antenna AND powered on AND flagged as good.

Parameters:

inputs (CorrInput or list of CorrInput objects)

Returns:

pwds – If list, it is the same length as inputs. Value is True if input is attached to a ArrayAntenna and powered-on and False otherwise

Return type:

boolean or list of bools.

ch_util.tools.is_array_x(feed)[source]

Is this an X-polarisation antenna in an array?

ch_util.tools.is_array_y(feed)[source]

Is this a Y-polarisation antenna in an array?

ch_util.tools.is_chime(feed)[source]

Is this feed a CHIME antenna?

Parameters:

feed (CorrInput)

Returns:

ischime

Return type:

bool

ch_util.tools.is_chime_on(inputs, *args)

Check if inputs are attached to an array antenna AND powered on AND flagged as good.

Parameters:

inputs (CorrInput or list of CorrInput objects)

Returns:

pwds – If list, it is the same length as inputs. Value is True if input is attached to a ArrayAntenna and powered-on and False otherwise

Return type:

boolean or list of bools.

ch_util.tools.is_holographic(feed)[source]

Is this feed a holographic antenna?

Parameters:

feed (CorrInput)

Returns:

isholo

Return type:

bool

ch_util.tools.is_noise_source(inp)[source]

Is this correlator input connected to a noise source?

Parameters:

inp (CorrInput)

Returns:

isnoise

Return type:

bool

ch_util.tools.is_pathfinder(feed)[source]

Is this feed a Pathfinder antenna?

Parameters:

feed (CorrInput)

Returns:

ispathfinder

Return type:

bool

ch_util.tools.lna_to_antenna(graph, lna)[source]

Find an antenna connected to an LNA.

Parameters:
  • graph (obj:layout.graph or datetime.datetime) – The graph in which to do the search. If you pass a time, then the graph will be constructed internally. (Note that the latter option will be quite slow if you do repeated calls!)

  • lna (layout.component or string) – The LNA.

Returns:

antenna – The antenna.

Return type:

layout.component

ch_util.tools.normalise_correlations(A, norm=None)[source]

Normalise to make a correlation matrix from a covariance matrix.

Parameters:
  • A (np.ndarray[:, :]) – Matrix to normalise.

  • norm (np.ndarray[:,:]) – Normalize by diagonals of norm. If None, then normalize by diagonals of A.

Returns:

  • X (np.ndarray[:, :]) – Normalised correlation matrix.

  • ach (np.ndarray[:]) – Array of the square root diagonal elements that normalise the matrix.

ch_util.tools.order_frequency_map_stream(fmap: ndarray, stream_id: ndarray) ndarray[source]

Order stream_id components based on a frequency map.

Level order is [shuffle, crate, slot, link]

Parameters:
  • fmap – frequency map

  • stream_id – 1-D array of stream_ids associated with each row in fmap

Returns:

shuffle, crate, slot, link for each frequency

Return type:

stream

ch_util.tools.pack_product_array(exp_arr, axis=1)[source]

Pack full correlation matrices into upper triangular form.

It replaces the two feed axes of the matrix, with a single upper triangle product axis.

Parameters:
  • exp_arr (np.ndarray[..., nfeed, nfeed, ...]) – Array of full correlation matrices.

  • axis (int, optional) – Index of the first feed axis. The second feed axis must be the next one.

Returns:

prod_arr – Array containing products packed in upper triangle format.

Return type:

np.ndarray[…, nprod, …]

ch_util.tools.rankN_approx(A, rank=1)[source]

Create the rank-N approximation to the matrix A.

Parameters:
  • A (np.ndarray) – Matrix to approximate

  • rank (int, optional)

Returns:

B – Low rank approximation.

Return type:

np.ndarray

ch_util.tools.redefine_stack_index_map(input_map, prod, stack, reverse_stack)[source]

Ensure that only baselines between array antennas are used to represent the stack.

The correlator will have inputs that are not connected to array antennas. These inputs are flagged as bad and are not included in the stack, however, products that contain their chan_id can still be used to represent a characteristic baseline in the stack index map. This method creates a new stack index map that, if possible, only contains products between two array antennas. This new stack index map should be used when calculating baseline distances to fringestop stacked data.

Parameters:
  • input_map (list of CorrInput) – List describing the inputs as they are in the file, output from tools.get_correlator_inputs

  • prod (np.ndarray[nprod,] of dtype=('input_a', 'input_b')) – The correlation products as pairs of inputs.

  • stack (np.ndarray[nstack,] of dtype=('prod', 'conjugate')) – The index into the prod axis of a characteristic baseline included in the stack.

  • reverse_stack (np.ndarray[nprod,] of dtype=('stack', 'conjugate')) – The index into the stack axis that each prod belongs.

Returns:

  • stack_new (np.ndarray[nstack,] of dtype=(‘prod’, ‘conjugate’)) – The updated stack index map, where each element is an index to a product consisting of a pair of array antennas.

  • stack_flag (np.ndarray[nstack,] of dtype=bool) – Boolean flag that is True if this element of the stack index map is now valid, and False if none of the baselines that were stacked contained array antennas.

ch_util.tools.reorder_correlator_inputs(input_map, corr_inputs)[source]

Sort a list of correlator inputs into the order given in input map.

Parameters:
Returns:

corr_input_list – List of CorrInput instances in the new order. Returns None where the serial number had no matching entry in parameter corr_inputs.

Return type:

list

ch_util.tools.sensor_to_hk(graph, comp)[source]

Find what housekeeping channel a component is connected to.

Parameters:
  • graph (obj:layout.graph or datetime.datetime) – The graph in which to do the search. If you pass a time, then the graph will be constructed internally. (Note that the latter option will be quite slow if you do repeated calls!)

  • comp (layout.component or string) – The component to search for (you can pass by serial number if you wish). Currently, only components of type LNA, FLA and RFT thru are accepted.

Returns:

inp – The housekeeping input channel the sensor is connected to.

Return type:

HKInput

ch_util.tools.serial_to_id(serial)[source]

Get the channel ID corresponding to a correlator input serial number.

Parameters:

serial (string) – Correlator input serial number.

Returns:

id

Return type:

int

ch_util.tools.serial_to_location(serial)[source]

Get the internal correlator ordering and the crate, slot, and sma number from a correlator input serial number.

Parameters:

serial (string) – Correlator input serial number.

Returns:

location – (corr_order, crate, slot, sma)

Return type:

4-tuple

ch_util.tools.subtract_rank1_signal(vis, signal, axis=1, out=None, prod_map=None)[source]

Subtract a rank 1 signal from a set of visibilities packed in upper triangular format.

This allows us to subtract the noise injection solutions while minimising the intermediate products created.

Parameters:
  • vis (np.ndarray[..., nprod, ...]) – Array of visibility products.

  • signal (np.ndarray[..., ninput, ...]) – Array of underlying signals. One signal per input.

  • axis (integer, optional) – The axis along which the inputs (or visibilities) are contained. Currently only supports axis=1.

  • out (np.ndarray) – Array to place output in. If None create a new array. This routine can safely use out = vis.

  • prod_map (ndarray of integer pairs) – Gives the mapping from product axis to input pairs. If not supplied, icmap() is used.

Returns:

out – Visibility array with signal subtracted. Same shape as vis.

Return type:

np.ndarray

ch_util.tools.unpack_product_array(prod_arr, axis=1, feeds=None)[source]

Expand packed products to correlation matrices.

This turns an axis of the packed upper triangle set of products into the full correlation matrices. It replaces the specified product axis with two axes, one for each feed. By setting feeds this routine can also pull out a subset of feeds.

Parameters:
  • prod_arr (np.ndarray[..., nprod, :]) – Array containing products packed in upper triangle format.

  • axis (int, optional) – Axis the products are contained on.

  • feeds (list of int, optional) – Indices of feeds to include. If None (default) use all feeds.

Returns:

corr_arr – Expanded array.

Return type:

np.ndarray[…, nfeed, nfeed, …]