API

Contexts

Contexts are objects supplying information to implementers of Providers.

class InitialisationContext

Initialisation Context object passed to Providers.

It provides initialisation information to a Provider, allowing Providers to perform setup based on configuration.

class CustomSourceProvider(SourceProvider):
    def init(self, init_context):
        config = context.cfg()
        ...
cfg

Configuration

class StartContext

Start Context object passed to Providers.

It provides information to the user implementing a data source about the extents of the data tile that should be provided.

# uvw varies by time and baseline and has 3 coordinate components
cube.register_array("uvw", ("ntime", "nbl", 3), np.float64)

...

class CustomSourceProvider(SourceProvider):
    def start(self, start_context):
        # Query dimensions directly
        (lt, ut), (lb, ub) = context.dim_extents("ntime", "nbl")
        ...

Public methods of a HyperCube are proxied on this object. Other useful information, such as the configuration, iteration space arguments are also present on this object.

cfg

Configuration

class StopContext

Stop Context object passed to Providers.

It provides information to the user implementing a data source about the extents of the data tile that should be provided.

# uvw varies by time and baseline and has 3 coordinate components
cube.register_array("uvw", ("ntime", "nbl", 3), np.float64)

...

class CustomSourceProvider(SourceProvider):
    def stop(self, stop_context):
        # Query dimensions directly
        (lt, ut), (lb, ub) = context.dim_extents("ntime", "nbl")
        ...

Public methods of a HyperCube are proxied on this object. Other useful information, such as the configuration, iteration space arguments are also present on this object.

cfg

Configuration

class SourceContext

Context object passed to data sources.

It provides information to the user implementing a data source about the extents of the data tile that should be provided.

# uvw varies by time and baseline and has 3 coordinate components
cube.register_array("uvw", ("ntime", "nbl", 3), np.float64)

...

class UVWSourceProvider(SourceProvider):
    def __init__(self, uvw_data):
        # All UVW coordinates
        self._uvw_data = uvw_data

    def uvw(self, context):
        print context.help(display_cube=True)

        # Query dimensions directly
        (lt, ut), (lb, ub) = context.dim_extents("ntime", "nbl")
        # Get the cube extents, ignoring
        # last dimension which is always (0, 3)
        (lt, ut), (lb, ub), (_, _) = context.array_extents("uvw")
        # Return data tile from larger array
        return self._uvw_data[lt:ut, lb:ub, :]

Public methods of a HyperCube are proxied on this object. Other useful information, such as the configuration, iteration space arguments, expected array shape and data type, and the abstract array schema are also present on this object.

array_schema

The array schema of the array associated with this data source. For instance if model_vis is registered on a hypercube as follows:

# Register model_vis array_schema on hypercube
cube.register_array("model_vis",
    ("ntime", "nbl", "nchan", "ncorr"),
    np.complex128)

...
# Create a source context for model_vis data source
context = SourceContext("model_vis", ...)
...
# Obtain the array schema
context.array_schema == ("ntime", "nbl", "nchan", "ncorr")
cfg

Configuration

dtype

The expected data type of the array that should be produced by the data source

help(display_cube=False)

Get help associated with this context

Parameters:display_cube (bool) – Add hypercube description to the output
Returns:A help string associated with this context
Return type:str
iter_args

Iteration arguments that describe the tile sizes over which iteration is performed. In the following example, iteration is occuring in tiles of 100 Timesteps, 64 Channels and 50 Point Sources.

context.iter_args == [("ntime", 100),
        ("nchan", 64), ("npsrc", 50)]
name

The name of the data source of this context.

shape

The expected shape of the array that should be produced by the data source

class SinkContext

Context object passed to data sinks.

Primarily, it exists to provide a tile of output data to the user.

class MySinkProvider(SinkProvider):
    vis_queue = Queue(10)

    ...
    def model_vis(self, context):
        print context.help(display_cube=True)
        # Consume data
        vis_queue.put(context.data)

Public methods of a HyperCube are proxied on this object. Other useful information, such as the configuration, iteration space arguments and the abstract array schema are also present on this object.

array_schema

The array schema of the array associated with this data source. For instance if model_vis is registered on a hypercube as follows:

# Register model_vis array_schema on hypercube
cube.register_array("model_vis",
    ("ntime", "nbl", "nchan", "ncorr"),
    np.complex128)

...
# Create a source context for model_vis data source
context = SourceContext("model_vis", ...)
...
# Obtain the array schema
context.array_schema == ("ntime", "nbl", "nchan", "ncorr")
cfg

Configuration

data

The data tile available for consumption by the associated sink

help(display_cube=False)

Get help associated with this context

Parameters:display_cube (bool) – Add hypercube description to the output
Returns:A help string associated with this context
Return type:str
input

The dictionary of inputs used to produce data. For example, if one wished to find the antenna pair used to produce a particular model visibility, one could do the following:

def model_vis(self, context):
    ant1 = context.input["antenna1"]
    ant2 = context.input["antenna2"]
    model_vis = context.data
iter_args

Iteration arguments that describe the tile sizes over which iteration is performed. In the following example, iteration is occuring in tiles of 100 Timesteps, 64 Channels and 50 Point Sources.

context.iter_args == [("ntime", 100),
        ("nchan", 64), ("npsrc", 50)]
name

The name of the data sink of this context.

Abstract Provider Classes

This is the Abstract Base Class that all Source Providers must inherit from. Alternatively, the SourceProvider class inherits from AbstractSourceProvider and provides some useful concrete implementations.

class AbstractSourceProvider
close()

Perform any required cleanup

init(init_context)

Called when initialising Providers

name()

Return the name associated with this data source

sources()

Returns a dictionary of source methods, keyed on source name

start(start_context)

Called at the start of any solution

stop(stop_context)

Called at the end of any solution

updated_arrays()

Return an iterable/mapping of hypercube arrays to update

updated_dimensions()

Return an iterable/mapping of hypercube dimensions to update

This is the Abstract Base Class that all Sink Providers must inherit from. Alternatively, the SinkProvider class inherits from AbstractSinkProvider and provides some useful concrete implementations.

class AbstractSinkProvider
clear_cache()

Clears any caches associated with the sink

close()

Perform any required cleanup

init(init_context)

Called when initialising Providers

name()

Returns this data sink’s name

sinks()

Returns a dictionary of sink methods, keyed on sink name

start(start_context)

Called at the start of any solution

stop(stop_context)

Called at the end of any solution

Source Provider Implementations

class MSSourceProvider

Source Provider that retrieves input data from a MeasurementSet

__init__(manager, vis_column=None)

Constructs an MSSourceProvider object

Parameters:
  • manager (MeasurementSetManager) – The MeasurementSetManager used to access the Measurement Set.
  • vis_column (str) – Column from which observed visibilities will be read
antenna1(context)

antenna1 data source

antenna2(context)

antenna2 data source

flag(context)

Flag data source

frequency(context)

Frequency data source

observed_vis(context)

Observed visibility data source

parallactic_angles(context)

parallactic angle data source

ref_frequency(context)

Reference frequency data source

uvw(context)

Per-antenna UVW coordinate data source

weight(context)

Weight data source

class FitsBeamSourceProvider

Feeds holography cubes from a series of eight FITS files matching a filename_schema. A schema of 'beam_$(corr)_$(reim).fits' matches:

['beam_xx_re.fits', 'beam_xx_im.fits',
 'beam_xy_re.fits', 'beam_xy_im.fits',
  ...
  'beam_yy_re.fits', 'beam_yy_im.fits']

while 'beam_$(CORR)_$(REIM).fits' matches

['beam_XX_RE.fits', 'beam_XX_IM.fits',
  'beam_XY_RE.fits', 'beam_XY_IM.fits',
  ...
  'beam_YY_RE.fits', 'beam_YY_IM.fits']

Missing files will result in zero values for that correlation and real/imaginary component. The shape of the FITS data will be inferred from the first file found and subsequent files should match that shape.

The type of correlation will be derived from the feed type. Currently, linear ['xx', 'xy', 'yx', 'yy'] and circular ['rr', 'rl', 'lr', 'll'] are supported.

__init__(filename_schema, l_axis=None, m_axis=None)

Constructs a FitsBeamSourceProvider object

Parameters:
  • filename_schema (str) – See FitsBeamSourceProvider for valid schemas
  • l_axis (str) – FITS axis interpreted as the L axis. L and X are sensible values here. -L will invert the coordinate system on that axis.
  • m_axis (str) – FITS axis interpreted as the M axis. M and Y are sensible values here. -M will invert the coordinate system on that axis.
beam_extents(context)

Beam extent data source

beam_freq_map(context)

Beam frequency map data source

ebeam(context)

ebeam cube data source

filename_schema

Filename schema

init(init_context)

Perform any initialisation

name()

Name of this Source Provider

shape

Shape of the beam cube

updated_dimensions()

Indicate dimension sizes

class CachedSourceProvider

Caches calls to data_sources on the listed providers

__init__(providers, cache_data_sources=None, clear_start=False, clear_stop=False)
Parameters:
  • providers (SourceProvider or Sequence of SourceProviders) – providers containing data sources to cache
  • cache_data_sources (list of str) – list of data sources to cache (Defaults to None in which case all data sources are cached)
  • clear_start (bool) – clear cache on start
  • clear_stop (bool) – clear cache on stop
init(init_context)

Perform any initialisation required

start(start_context)

Perform any logic on solution start

stop(stop_context)

Perform any logic on solution stop

updated_dimensions()

Update the dimensions

Sink Provider Implementations

class MSSinkProvider

Sink Provider that receives model visibilities produced by montblanc

__init__(manager, vis_column=None)

Constructs an MSSinkProvider object

Parameters:
  • manager (MeasurementSetManager) – The MeasurementSetManager used to access the Measurement Set.
  • vis_column (str) – Column to which model visibilities will be read
model_vis(context)

model visibility data sink