wodenpy.use_libwoden

Ways to interact with the C/GPU via ctypes.

array_layout_struct

Ctypes class to match the struct array_layout_t, for passing to libwoden*.so

class array_layout_struct.Array_Layout_Ctypes[source]

A ctypes structure representing the layout of an array of antennas.

ant_X

Pointer to an array of antenna X positions.

Type:

POINTER(c_double)

ant_Y

Pointer to an array of antenna Y positions.

Type:

POINTER(c_double)

ant_Z

Pointer to an array of antenna Z positions.

Type:

POINTER(c_double)

X_diff_metres

Pointer to an array of X position differences in metres.

Type:

POINTER(c_double)

Y_diff_metres

Pointer to an array of Y position differences in metres.

Type:

POINTER(c_double)

Z_diff_metres

Pointer to an array of Z position differences in metres.

Type:

POINTER(c_double)

ant_east

Pointer to an array of antenna east positions.

Type:

POINTER(c_double)

ant_north

Pointer to an array of antenna north positions.

Type:

POINTER(c_double)

ant_height

Pointer to an array of antenna height positions.

Type:

POINTER(c_double)

latitude

The latitude of the array.

Type:

c_double

num_baselines

The number of baselines in the array.

Type:

c_int

num_tiles

The number of tiles in the array.

Type:

c_int

lst_base

The local sidereal time of the array.

Type:

c_double

beam_settings

Classes to match the BeamTypes enum in libwoden, and to group beam types for WODEN. Beam group are useful to calculate associated values for specific beam types, e.g. azimuth/altitude, hour angle/declination, etc.

class beam_settings.BeamGroups[source]

A class to represent different groups of beam types. Each group contains a list of BeamTypes values that are used in WODEN.

eb_beam_values

All the EveryBeam beam types.

Type:

list

eb_ms_beam_values

All the EveryBeam beam types that need a measurement set.

Type:

list

azza_beam_values

All beams that need azimuth/altitude calculated before sending to CPU/GPU.

Type:

list

hadec_beam_values

All beams that need Hour Angle/Declination calculated/filled before sending to CPU/GPU.

Type:

list

off_cardinal_beam_values

All beams that have off-cardinal dipole alignments, e.g. not N/S or E/W at 0,90 degrees, but rather 45, 135 degrees. Currently empty pending further development (something in LOFAR is definitely off-cardinal but needs more research).

Type:

list

python_calc_beams

All beams that are calculated in Python before sending to CPU/GPU (e.g. any UVBeam beam types).

Type:

list

uvbeam_beams

All the UVBeam beam types.

Type:

list

class beam_settings.BeamTypes(value)[source]

Enumeration of beam types used in WODEN.

This class allows us to label the WODEN primary beam models with a unique name/value, but as it’s an enum each label only takes 8 bytes of memory, so we can stack loads of them into an array. We can also do numpy operations on them like np.where.

NO_BEAM

No beam type.

Type:

int

GAUSS_BEAM

Gaussian beam type.

Type:

int

FEE_BEAM

FEE beam type.

Type:

int

ANALY_DIPOLE

Analytical dipole beam type.

Type:

int

FEE_BEAM_INTERP

Interpolated FEE beam type.

Type:

int

MWA_ANALY

MWA analytical beam type.

Type:

int

EB_OSKAR

EveryBeam OSKAR beam type.

Type:

int

EB_LOFAR

EveryBeam LOFAR beam type.

Type:

int

EB_MWA

EveryBeam MWA beam type.

Type:

int

UVB_MWA

pyuvdata UVData MWA beam type.

Type:

int

UVB_MWA

pyuvdata UVData HERA beam type.

Type:

int

create_woden_struct_classes

A central Class to dynamically create the classes for the WODEN data structures, based on the required precision.

class create_woden_struct_classes.Woden_Struct_Classes(precision='double')[source]

Create and store the classes for the WODEN data structures.

Variables:
  • precision (str) – Either “float” or “double” to determine the precision of the data types.

  • Components_Ctypes (Components_Ctypes) – Equivalent to the C struct components_t.

  • Source_Ctypes (Source_Ctypes) – Equivalent to the C struct source_t.

  • Source_Catalogue (Source_Catalogue) – Equivalent to the C struct source_catalogue_t.

  • Woden_Settings (Woden_Settings) – Equivalent to the C struct woden_settings_t.

  • Visi_Set (Visi_Set) – Equivalent to the C struct visibility_set_t.

shapelets

Functions to create shapelet basis functions for use in WODEN

shapelets.calc_basis_func_1D_numpy(n: int, x: float | ndarray, beta=1) ndarray[source]

Calculate shapelet basis function values to use in WODEN. These values work with models fitted using SHAMFI https://github.com/JLBLine/SHAMFI

See Line et al. 2020 https://doi.org/10.1017/pasa.2020.18 for more information on shapelet fitting

Parameters:
  • n (int) – Order of shapelet basis function to calculate

  • x (Union[float, np.ndarray]) – Coordinate(s) to evaluate the basis function at

  • beta (int, optional) – The x-coord scaling factor, should be 1 when used with WODEN, by default 1

Returns:

The basis function values

Return type:

np.ndarray

shapelets.create_sbf(precision='double', sbf_N=101, sbf_c=5000, sbf_dx=0.01)[source]

Creates a ctypes array of float or doubles, containing shapelet basis functions to feed into run_woden.

All settings default to settings hard-coded into libwoden_double.so, so only mess with them if you know what you’re doing. A future iteration of WODEN could have sbf_N, sbf_c, sbf_dx put into woden_settings to allow for on-the-fly basis function adjustment.

With the defaults listed below, each basis function will be calculate over a range of x = -50 to x = 50, with a resolution of x = 0.01 (for a total of 10001 x values per basis function).

The final array is 1D, populated by basis function n = 0 for all x values, up to basis function n = (sbf_N - 1).

Parameters:
  • precision (str, optional) – Precision to return. If set to ‘float’, uses c_float, if set to double uses c_double. By default set to “double”.

  • sbf_N (int, optional) – Sets what order of basis function to generate up to, by default 101

  • sbf_c (int, optional) – Sets the central array value, where x = 0 will be, by default 5000

  • sbf_dx (float, optional) – The x resolution of each array element, by default 0.01

Returns:

All of the basis functions stored in a 1D array of len = 2*sbf_c + 1

Return type:

c_float_Array or c_double_Array

shapelets.numpy_eval_hermite(n: int, x: float | ndarray) float | ndarray[source]

This function duplicates what scipy.special.eval_hermite does:

Evaluate physicist’s Hermite polynomial at a point.

Have found that installing scipy on some clusters can be problematic (looking at you Pawsey) so implement a numpy version to sidestep needed scipy.

See https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.eval_hermite.html#scipy-special-eval-hermite for more detail

Parameters:
  • n (int) – Order of hermite polynomial

  • x (Union[float, np.ndarray]) – Coordinate(s) to evaluate the polynomial at

Returns:

The evaulated polynomial values

Return type:

Union[float, np.ndarray]

skymodel_structs

Functions and Classes to setup the source catalogue and components. Eventually these things are passed to the C/C++/GPU code, so many functions here to set up the data structures, and convert from Python native to ctypes types.

class skymodel_structs.Components_Ctypes

A class structured equivalently to a components_t struct, used by the C and CUDA code in libwoden_float.so or libwoden_double.so.

Created by the function create_components_struct, which sets user_precision_t to either c_float or c_double.

Variables:
  • ras (POINTER(double)) – COMPONENT right ascensions (radians)

  • decs (POINTER(double)) – COMPONENT declinations (radians)

  • power_ref_freqs (POINTER(double)) – COMPONENT Flux density reference frequencies (Hz)

  • power_ref_stokesI (POINTER(user_precision_t)) – COMPONENT Stokes I reference flux density (Jy)

  • power_ref_stokesQ (POINTER(user_precision_t)) – COMPONENT Stokes Q reference flux density (Jy)

  • power_ref_stokesU (POINTER(user_precision_t)) – COMPONENT Stokes U reference flux density (Jy)

  • power_ref_stokesV (POINTER(user_precision_t)) – COMPONENT Stokes V reference flux density (Jy)

  • power_SIs (POINTER(user_precision_t)) – COMPONENT spectral indexes

  • curve_ref_freqs (POINTER(double)) – COMPONENT Flux density reference frequencies (Hz)

  • curve_ref_stokesI (POINTER(user_precision_t)) – COMPONENT Stokes I reference flux density (Jy)

  • curve_ref_stokesQ (POINTER(user_precision_t)) – COMPONENT Stokes Q reference flux density (Jy)

  • curve_ref_stokesU (POINTER(user_precision_t)) – COMPONENT Stokes U reference flux density (Jy)

  • curve_ref_stokesV (POINTER(user_precision_t)) – COMPONENT Stokes V reference flux density (Jy)

  • curve_SIs (POINTER(user_precision_t)) – COMPONENT spectral indexes

  • curve_qs (POINTER(user_precision_t)) – COMPONENT curvature

  • power_comp_inds (POINTER(int)) – The indexes of all power-law models w.r.t ra,dec

  • curve_comp_inds (POINTER(int)) – The indexes of all curved power-law models w.r.t ra,dec

  • list_comp_inds (POINTER(int)) – The indexes of all list models w.r.t ra,dec

  • list_freqs (POINTER(double)) – COMPONENT Flux density references frequencies (Hz)

  • list_stokesI (POINTER(user_precision_t)) – COMPONENT Stokes I list flux density (Jy)

  • list_stokesQ (POINTER(user_precision_t)) – COMPONENT Stokes Q list flux density (Jy)

  • list_stokesU (POINTER(user_precision_t)) – COMPONENT Stokes U list flux density (Jy)

  • list_stokesV (POINTER(user_precision_t)) – COMPONENT Stokes V list flux density (Jy)

  • num_list_values (POINTER(int)) – How many freq/flux values are in each COMPONENT lis

  • list_start_indexes (POINTER(int)) – How many freq/flux values are in each COMPONENT lis

  • total_num_flux_entires (POINTER(int)) – The total number of freq/flux values are in all lists combine

  • extrap_stokesI (POINTER(user_precision_t)) – extrapolated COMPONENT Stokes I flux densities (Jy)

  • extrap_stokesQ (POINTER(user_precision_t)) – extrapolated COMPONENT Stokes Q flux densities (Jy)

  • extrap_stokesU (POINTER(user_precision_t)) – extrapolated COMPONENT Stokes U flux densities (Jy)

  • extrap_stokesV (POINTER(user_precision_t)) – extrapolated COMPONENT Stokes V flux densities (Jy)

  • shape_coeffs (POINTER(user_precision_t)) – Scaling coefficients for SHAPELET basis functions

  • n1s (POINTER(user_precision_t)) – 1st basis function order for SHAPELET basis functions

  • n2s (POINTER(user_precision_t)) – 2nd basis function order for SHAPELET basis functions

  • majors (POINTER(user_precision_t)) – GAUSSIAN/SHAPELET major axis (beta1, radians)

  • minors (POINTER(user_precision_t)) – GAUSSIAN/SHAPELET minor axis (beta2, radians)

  • pas (POINTER(user_precision_t)) – GAUSSIAN/SHAPELET position angles (radians)

  • param_indexes (POINTER(user_precision_t)) – An index value to match each coeff, n1, and n2 to the correct ra, dec, major, minor, pa for a SHAPELET

  • azs (POINTER(user_precision_t)) – Azimuth angles for all time steps

  • zas (POINTER(user_precision_t)) – Zenith angles for all time steps

  • para_angles (POINTER(user_precision_t)) – Parallactic angles for all time steps

  • beam_has (POINTER(double)) – Hour angle of COMPONENTs for all time steps, used for beam calculations

  • beam_decs (POINTER(double)) – Declinations of COMPONENTs for all time steps, used for beam calculations

  • num_primarybeam_values (POINTER(int)) – Number of beam calculations needed for COMPONENTs

  • gxs (POINTER(user_precision_complex_t)) – North-South Beam gain values for all directions, frequencies, and times for these COMPONENT

  • Dxs (POINTER(user_precision_complex_t)) – North-South Beam leakage values for all directions, frequencies, and times for these COMPONENT

  • Dys (POINTER(user_precision_complex_t)) – East-West Beam leakage values for all directions, frequencies, and times for these COMPONENT

  • gys (POINTER(user_precision_complex_t)) – East-West Beam gain values for all directions, frequencies, and times for these COMPONENT

  • ls (POINTER(double)) – Device memory l cosine direction coords for these COMPONENTs

  • ms (POINTER(double)) – Device memory m cosine direction coords for these COMPONENTs

  • ns (POINTER(double)) – Device memory n cosine direction coords for these COMPONENTs

  • stokesV_pol_fracs (POINTER(c_float)) – Stokes V polarisation fractions

  • stokesV_pol_frac_comp_inds (POINTER(c_int)) – The indexes of all Stokes V polarisation fraction models w.r.t ra,dec

  • stokesV_power_ref_flux (POINTER(c_float)) – Stokes V reference flux for power-law

  • stokesV_power_SIs (POINTER(c_float)) – Stokes V spectral index for power-law

  • stokesV_power_comp_inds (POINTER(c_int)) – The indexes of all Stokes V power-law models w.r.t ra,dec

  • stokesV_curve_ref_flux (POINTER(c_float)) – Stokes V reference flux for curved power-law

  • stokesV_curve_SIs (POINTER(c_float)) – Stokes V spectral index for curved power-law

  • stokesV_curve_qs (POINTER(c_float)) – Stokes V q param for curved power-law

  • stokesV_curve_comp_inds (POINTER(c_int)) – The indexes of Stokes V curved power-law models w.r.t ra,dec

  • linpol_pol_fracs (POINTER(c_float)) – Linear polarisation polarisation fractions

  • linpol_pol_frac_comp_inds (POINTER(c_int)) – The indexes of all linear polarisation fraction models w.r.t ra,dec

  • linpol_power_ref_flux (POINTER(c_float)) – Linear polarisation reference flux for power-law

  • linpol_power_SIs (POINTER(c_float)) – Linear polarisation spectral index for power-law

  • linpol_power_comp_inds (POINTER(c_int)) – The indexes of all linear polarisation power-law models w.r.t ra,dec

  • linpol_curve_ref_flux (POINTER(c_float)) – Linear polarisation reference flux for curved power-law

  • linpol_curve_SIs (POINTER(c_float)) – Linear polarisation spectral index for curved power-law

  • linpol_curve_qs (POINTER(c_float)) – Linear polarisation q param for curved power-law

  • linpol_curve_comp_inds (POINTER(c_int)) – The indexes of all linear polarisation curved power-law models w.r.t ra,dec

  • rm_values (POINTER(c_float)) – Linear polarisation rotation measures

  • intr_pol_angle (POINTER(c_float)) – Linear polarisation instrinsic polarisation angles

  • linpol_angle_inds (POINTER(c_int)) – The indexes of all RM/intrinsic polarisation angles w.r.t ra,dec

  • n_stokesV_pol_frac (c_int) – The number of Stokes V polarisation fraction models

  • n_stokesV_power (c_int) – The number of Stokes V power-law models

  • n_stokesV_curve (c_int) – The number of V curved power-law models

  • n_linpol_pol_frac (c_int) – The number of linear polarisation fraction models

  • n_linpol_power (c_int) – The number of linear polarisation power-law models

  • n_linpol_curve (c_int) – The number of linear polarisation curved power-law models

  • n_linpol_angles (c_int) – The number of RM/intrinsic polarisation angles

  • do_QUV (c_int) – Set if doing any polarised information

class skymodel_structs.Components_Python[source]

A class structured equivalently to a components_t struct but using Python native data types. This can be pickled and therefore fed to Python multiprocessing functions. Needed as ctypes pointers cannot be pickled, and therefore cannot be passed to Python multiprocessing functions.

class skymodel_structs.Source_Catalogue

A class structured equivalent to a source_t struct, used by the C/GPU code

num_sources

The number of sources in the catalogue

Type:

int

num_shapelets

The total number of shapelets components in the catalogue

Type:

int

sources

A pointer to an array of Source_Float objects representing the sources in the catalogue

Type:

POINTER(Source_Ctypes)

class skymodel_structs.Source_Ctypes

A class structured equivalent to a source_t struct, used by the C and CUDA code in libwoden_double.so

Variables:
  • name (c_char*32) – Source name

  • n_comps (c_int) – Total number of COMPONENTs in source

  • n_points (c_int) – Number of POINT source COMPONENTs

  • n_point_lists (c_int) – Number of POINTs with LIST type flux

  • n_point_powers (c_int) – Number of POINTs with POWER_LAW type flux

  • n_point_curves (c_int) – Number of POINTs with CURVED_POWER_LAW type flux

  • n_gauss (c_int) – Number of GAUSSIAN source COMPONENTs

  • n_gauss_lists (c_int) – Number of GAUSSIANs with LIST type flux

  • n_gauss_powers (c_int) – Number of GAUSSIANs with POWER_LAW type flux

  • n_gauss_curves (c_int) – Number of GAUSSIANs with CURVED_POWER_LAW type flux

  • n_shapes (c_int) – Number of SHAPELET source COMPONENTs

  • n_shape_lists (c_int) – Number of SHAPELETs with LIST type flux

  • n_shape_powers (c_int) – Number of SHAPELETs with POWER_LAW type flux

  • n_shape_curves (c_int) – Number of SHAPELETs with CURVED_POWER_LAW type flux

  • n_shape_coeffs (c_int) – Total number of SHAPELET coefficients

  • point_components (Components_Ctypes_Double) – Components_Ctypes holding component information for all POINT COMPONENTs in this SOURCE

  • gauss_components (Components_Ctypes_Double) – Components_Ctypes holding component information for all GAUSSIAN COMPONENTs in this SOURCE

  • shape_components (Components_Ctypes_Double) – Components_Ctypes holding component information for all SHAPELET COMPONENTs in this SOURCE

class skymodel_structs.Source_Python[source]

A class structured equivalent to a source_t struct, but using Python native data types. This can be pickled and therefore fed to Python multiprocessing functions. Needed as ctypes pointers cannot be pickled, and therefore cannot be passed to Python multiprocessing functions.

class skymodel_structs.c_double_complex[source]

ctypes doesn’t have a built-in complex type, define one here. Thanks to random internet person for this code. https://stackoverflow.com/questions/13373291/complex-number-in-ctypes

Note you could use python complex types, and some wrapper functions inside C, but I’d keep C code as simple as possible

class skymodel_structs.c_float_complex[source]

ctypes doesn’t have a built-in complex type, define one here. Thanks to random internet person for this code. https://stackoverflow.com/questions/13373291/complex-number-in-ctypes

Note you could use python complex types, and some wrapper functions inside C, but I’d keep C code as simple as possible

skymodel_structs.copy_python_components_to_ctypes(python_comps: Components_Python, ctypes_comps: Components_Ctypes, comp_type: CompTypes, n_powers: int, n_curves: int, n_lists: int, beamtype: int, precision='double')[source]

Copies data from python_comps to ctypes_comps ctypes structures for use in C libraries. Handles memory allocation itself via the np.ndarray.ctypes.data_as() method, combined with the precision as specified by precision`

Parameters:
  • python_comps (Components_Python) – The Python components containing the data to be copied.

  • ctypes_comps (Components_Ctypes) – The ctypes components where the data will be copied to.

  • comp_type (CompTypes) – The type of components being copied (e.g., POINT, GAUSSIAN, SHAPELET).

  • n_powers (int) – Number of power components.

  • n_curves (int) – Number of curve components.

  • n_lists (int) – Number of list components.

  • beamtype (int) – The type of beam being used.

  • precision (str, optional) – Precision of the data (‘float’ or ‘double’, default is ‘double’).

skymodel_structs.copy_python_source_to_ctypes(python_source: Source_Python, ctypes_source: Source_Ctypes, beamtype: int, precision: str = 'double')[source]

Copies data from a Python source object to a ctypes source object, which can be fed to the C/GPU code. Handles memory allocation itself via the np.ndarray.ctypes.data_as() method, combined with the precision as specified by precision`

Parameters:
  • python_source (Source_Python) – The source object containing data in Python format.

  • ctypes_source (Source_Ctypes) – The source object to be populated with data in ctypes format.

  • beamtype (int) – The type of beam to be used.

  • precision (str, optional) – The precision of the data to be copied, either ‘float’ or ‘double’; default is ‘double’.

Notes

This function transfers various attributes from the Python source object to the ctypes source object, including the number of points, Gaussian components, and shapelet components. It also calls copy_python_components_to_ctypes to copy the components of each type if they exist in the Python source object.

skymodel_structs.create_components_struct(precision='double')[source]

Creates a Components_Ctypes class structured equivalently to a components_t struct in the C/CUDA code. Created dynamically based on the precision, to match the compile time precision flag -DUSE_DOUBLE in the C code.

Parameters:

precision (str, optional) – Either “float” or “double:, by default “double”

Returns:

The Components_Ctypes class structured equivalently to a components_t struct

Return type:

Components_Ctypes

skymodel_structs.create_source_catalogue_struct(Source_Ctypes: Source_Ctypes)[source]

Creates a Source_Catalogue class structured equivalent to a source_catalogue_t struct, used by the C and CUDA code. The Source_Ctypes class is passed in as the Source_Ctypes class is created dynamically depending on the required precision.

Parameters:

Source_Ctypes (Source_Ctypes) – The Source_Ctypes class structured equivalent to a source_t struct

Returns:

The Source_Catalogue class structured equivalent to a source_catalogue_t struct

Return type:

Source_Catalogue

skymodel_structs.create_source_struct(Components_Ctypes: Components_Ctypes)[source]

Creates a Source_Ctypes class structured equivalent to a source_t struct, used by the C and CUDA code in libwoden_double.so. The Components_Ctypes class is passed in as the Components_Ctypes class is created dynamically depending on the required precision.

Parameters:

Components_Ctypes (Components_Ctypes) – The Components_Ctypes class structured equivalently to a components_t struct

Returns:

The Source_Ctypes class structured equivalent to a source_t struct

Return type:

Source_Ctypes

skymodel_structs.setup_chunked_source(chunked_source: Source_Python, chunk_map: Skymodel_Chunk_Map, num_freqs: int, num_times: int, num_beams: int, beamtype: int, precision='double') Source_Python[source]

Sets up chunked_source, which will be entually be copied to a ctypes struct and then passed to the C/GPU functions. Allocates the correct amount of memory, based on whether the precision is either ‘double’ or ‘float’, as well as what is detailed in the chunk_map.

Parameters:
  • chunked_source (Source_Python) – Object to contain the chunked source information.

  • chunk_map (Skymodel_Chunk_Map) – Object containing information about the chunk of the sky model.

  • num_freqs (int) – The number of frequency channels.

  • num_times (int) – The number of time samples.

  • num_beams (int) – Number of beams to be calculated (only used for certain beam types). If using one beam for all station/tiles, num_beams=1, otherwise num_beams=num_ants.

  • beamtype (int) – The type of primary beam.

  • precision (str, optional) – The precision to use. Can be either “float” or “double. Defaults to “double”.

Returns:

chunked_source – The chunked_source that was passed in, but now with all the necessary components allocated.

Return type:

Source_Python

skymodel_structs.setup_components(chunk_map: Skymodel_Chunk_Map, chunked_source: Source_Python, num_freqs: int, num_times: int, num_beams: int, comp_type: CompTypes, beamtype: int, precision: str = 'double') None[source]

Given the mapping information in chunk_map, initialise the necessary components in chunked_source for the given comp_type, this being one of

  • chunked_source.point_components

  • chunked_source.gaussion_components

  • chunked_source.shape_components

This setup includes allocating numpy arrays of specific precision for the components, depending on what type of chunked_source is passed in.

Parameters:
  • chunk_map (Skymodel_Chunk_Map) – Object containing information about the chunk of the sky model.

  • chunked_source (Union[Source_Ctypes, Source_Python]) – Object containing the chunked source information.

  • num_freqs (int) – Number of frequencies

  • num_times (int) – Number of times

  • num_beams (int) – Number of beams to be calculated (only used for certain beam types). If using one beam for all station/tiles, num_beams=1, otherwise num_beams=num_ants.

  • comp_type (CompTypes) – enum representing the type of component.

  • beamtype (int) – representing the type of beam.

  • precision (str) – Either “float” or “double”, default “double”.

skymodel_structs.setup_source_catalogue(Source_Ctypes: Source_Ctypes, Source_Catalogue: Source_Catalogue, num_sources: int, num_shapelets: int, precision='double') Source_Catalogue[source]

Setups a Source_Catalogue with the specified number of sources and shapelets. Sets source_catalogue.sources as an array of Source_Ctypes objects of length num_sources

As Source_Ctypes/Source_Catalogue are created dynamically based on the precision, this function takes them as arguments rather than creating them within the function.

These classes should be created once via wodenpy.use_libwoden.create_woden_struct_classes.Woden_Struct_Classes and called from there e.g.

woden_struct_classes = Woden_Struct_Classes() Source_Catalogue = woden_struct_classes.Source_Catalogue

Parameters:
  • Source_Ctypes (Source_Ctypes) – The Source_Ctypes class structured equivalent to a source_t struct.

  • Source_Catalogue (Source_Catalogue) – The Source_Catalogue class structured equivalent to a source_catalogue_t struct.

  • num_sources (int) – The number of sources in the catalogue.

  • num_shapelets (int) – The number of shapelets for each source.

  • precision (str) – The precision of the source catalogue. Can be “float” or “double”. Default is “double”.

Returns:

source_catalogue – The initialised source_catalogue object.

Return type:

Source_Catalogue

use_libwoden

Functions to load in the WODEN C/C++/GPU code via a dynamic library, with the required precision (either load libwoden_float.so or libwoden_double.so).

use_libwoden.check_for_everybeam(woden_lib_path: str) bool[source]

Checks if libwoden*.so has been compiled against EveryBeam (via a flag -DHAVE_EVERYBEAM which was set via CMake during compilation).

Returns True if it has, False otherwise.

This function calls :func:~`worker_check_for_everybeam` in a separate process to avoid clashing with python-casacore. See :func:~`worker_check_for_everybeam` docs for more details.

Parameters:

woden_lib_path (str) – The file path to the WODEN library (either /some/path/libwoden_float.so or /some/path/libwoden_double.so).

Returns:

True if the ‘EveryBeam’ feature is compiled in the WODEN library, False otherwise.

Return type:

bool

use_libwoden.load_in_run_woden(woden_lib: CDLL, woden_struct_classes: Woden_Struct_Classes)[source]

Load in and define the C wrapper function run_woden, which runs the C/C++/GPU code. woden_lib is the ctypes object which has loaded in the WODEN library via ctypes.cdll.LoadLibrary(woden_lib_path).

Here woden_lib_path is the path to the WODEN library, which is either libwoden_float.so or libwoden_double.so, depending on the precision.

Parameters:
  • woden_lib (ctypes.CDLL) – The ctypes object which has loaded in the WODEN library

  • woden_struct_classes (Woden_Struct_Classes) – This holds all the various ctype structure classes that are equivalent to the C/CUDA structs. Should have been initialised with the correct precision (“float” or “double”).

Returns:

run_woden – The C wrapper function run_woden, which runs the C/CUDA code. This function takes the following args, where sbf_pointer is either ctypes.POINTER(ctypes.c_float) or ctypes.POINTER(ctypes.c_double), depending on the woden_struct_classes.precision:

  • ctypes.POINTER(woden_struct_classes.Woden_Settings)

  • ctypes.POINTER(woden_struct_classes.Visi_Set)

  • ctypes.POINTER(woden_struct_classes.Source_Catalogue)

  • ctypes.POINTER(Array_Layout)

  • sbf_pointer

Return type:

_NamedFuncPointer

use_libwoden.worker_check_for_everybeam(woden_lib_path: str, q: Queue)[source]

Checks if libwoden*.so has been compiled against EveryBeam (via a flag -DHAVE_EVERYBEAM which was set via CMake during compilation). Puts True into the queue q, if it has, False otherwise.

This function is run in a separate process to avoid clashing with python-casacore. python-casacore and libwoden*.so can be linked to different versions of casacore. When loaded, both create dependency paths and global variables in a persisting c++ state. This causes much explosions and segfaults. Wrapping in a separate process isolates the state of the c++ code. This is a hot-fix.

Todo

Replace all calls to python-casacore with calls to casacore directly, via libuse_everybeam.so. It’s also possible that using pybind11 to call c++ instead of ctypes would be better?

Parameters:
  • woden_lib_path (str) – The file path to the WODEN library (either /some/path/libwoden_float.so or /some/path/libwoden_double.so).

  • q (Queue) – A multiprocessing queue to store the result of the check.

visibility_set

Functions to create and manipulate visibility sets in WODEN

class visibility_set.Visi_Set

A class structured equivalently to a visi_set struct, used by the C/C++/GPU code in libwoden_*.so

Variables:
  • us_metres (POINTER(c_user_precision)) – Output \(u\) for all time steps, frequency steps, and baselines

  • vs_metres (POINTER(c_user_precision)) – Output \(v\) for all time steps, frequency steps, and baselines

  • ws_metres (POINTER(c_user_precision)) – Output \(w\) for all time steps, frequency steps, and baselines

  • allsteps_sha0s (POINTER(c_user_precision)) – Sine of hour angle of phase centre for all time steps, frequency steps, and baselines

  • allsteps_cha0s (POINTER(c_user_precision)) – Cosine of hour angle of phase centre for all time steps, frequency steps, and baselines

  • allsteps_lsts (POINTER(c_user_precision)) – Local sidereal time for all time steps, frequency steps, and baselines (radians)

  • allsteps_wavelengths (POINTER(c_user_precision)) – Wavelengths for all time steps, frequency steps, and baselines (metres)

  • channel_frequencies (POINTER(c_user_precision)) – Frequencies for all frequency steps (Hz)

  • sum_visi_XX_real (POINTER(c_user_precision)) – Real values for XX polarisation for all time steps, frequency steps, and baselines

  • sum_visi_XX_imag (POINTER(c_user_precision)) – Imaginary values for XX polarisation for all time steps, frequency steps, and baselines

  • sum_visi_XY_real (POINTER(c_user_precision)) – Real values for XY polarisation for all time steps, frequency steps, and baselines

  • sum_visi_XY_imag (POINTER(c_user_precision)) – Imaginary values for XY polarisation for all time steps, frequency steps, and baselines

  • sum_visi_YX_real (POINTER(c_user_precision)) – Real values for YX polarisation for all time steps, frequency steps, and baselines

  • sum_visi_YX_imag (POINTER(c_user_precision)) – Imaginary values for YX polarisation for all time steps, frequency steps, and baselines

  • sum_visi_YY_real (POINTER(c_user_precision)) – Real values for YY polarisation for all time steps, frequency steps, and baselines

  • sum_visi_YY_imag (POINTER(c_user_precision)) – Imaginary values for YY polarisation for all time steps, frequency steps, and baselines

class visibility_set.Visi_Set_Python[source]

A class structured equivalently to a visibility_set_t struct, used by the C/C++/GPU code in libwoden_*.so. This class is used in the Python code to pass around easily (and can be pickled)

visibility_set.create_visi_set_struct(precision='double')[source]

Creates a Visi_Set class structured equivalently to a visibility_set_t struct in the C/CUDA code. Created dynamically based on the precision, to match the compile time precision flag -DUSE_DOUBLE in the C code.

Parameters:

precision (str, optional) – Either “float” or “double:, by default “double”

Returns:

The Visi_Set class structured equivalently to a visibility_set_t struct

Return type:

Visi_Set

visibility_set.load_visibility_set(visibility_set: Visi_Set_Python, num_baselines: int, num_freq_channels: int, num_time_steps: int, num_ants: int, precision: str = 'double', do_autos: bool = False)[source]

Read the contents of visibility_set (a Visi_Set_Python object), ready to be put into a uvfits file. visibility_set is a list of Visi_Set_Python objects, each of which contains the visibility data for a single band and thread. It should have the shape (num_bands, num_threads).

By default, WODEN only outputs cross-correlations. In this case, the output binary is ordered by baseline (fastest changing), frequency, and time (slowest changing). Visibility coords and data are read in, with the visi data output into an array of shape=(num_time_steps*num_baselines,1,1,num_freq_channels,4,3)), which is appropriate for a uvfits file. Needs to know whether WODEN was run with ‘float’ (32 bit) or ‘double’ (64 bit) precision to read in the data correctly.

If WODEN was run with do_autos=True, then auto correlations are also in the output binary. These are stored AFTER the cross-correlations, and orders by antenna (fastest changing), frequency, and time (slowest changing). In this case the data are output into an array of shape=(num_time_steps*(num_baselines+num_ants),1,1,num_freq_channels,4,3)), where we say a baseline is only defined between to different antennas. The visibilities are output to match the BASELINE array, which orders the autos and crosses via antenna pairs as (1,1), (1,2), (1,3) .. (2,2), (2,3) etc etc meaning the autos and crosses are mixed.

Parameters:
  • visibility_set (Visi_Set_Python) – The visibility set to load the data into

  • num_baselines (int) – Number of baselines

  • num_freq_channels (int) – Number of frequencies

  • num_time_steps (int) – Number of time steps

  • num_ants (int) – Number of antennas (a.k.a. stations/tiles, e.g. 128 for MWA)

  • precision (string) – Precision WODEN was run with - either ‘float’ or ‘double’

  • do_autos (Boolean) – if True, data has auto-correlations in

Returns:

  • uus (float array) – The \(u\) coordinates (seconds). These are zero for auto-correlations.

  • vvs (float array) – The \(v\) coordinates (seconds). These are zero for auto-correlations.

  • wws (float array) – The \(w\) coordinates (seconds). These are zero for auto-correlations.

  • v_container (float array) – Visibility data with shape=(num_time_steps*num_baselines,1,1,num_freq_channels,4,3))

visibility_set.setup_visi_set(visibility_set: Visi_Set, num_visis: int, precision='double') Structure[source]

Does ctypes memory allocation in visibility_set for the number of visibilities num_visis and returns the visibility_set with the memory allocated.

Parameters:
  • visibility_set (Visi_Set) – An initialised Visi_Set class

  • num_visis (int) – Number of visibilities to assign memory for

  • precision (str, optional) – Precision to be used, either ‘float’ or ‘double. Defaults to ‘double’

Returns:

visibility_setvisibility_set with all necessary memory allocated

Return type:

Visi_Set

visibility_set.setup_visi_set_array(Visi_Set: Visi_Set, num_bands: int, num_visis: int, precision='double') Structure[source]

We feed an array of visibility_sets to woden.c, this sets up the array and populates with empty visibility_sets of the correct precision

Parameters:
  • Visi_Set (Visi_Set) – The Visi_Set class; NOT initialised, just the Class type

  • num_bands (int) – Number of bands to assign memory for

  • num_visis (int) – Number of visibilities to assign memory for

  • precision (str, optional) – Precision to be used, either ‘float’ or ‘double. Defaults to ‘double’

Returns:

An initialised array of num_bands times Visi_Set class, compatible with libwoden_float.so or libwoden_double.so.

Return type:

ctypes.Structure

woden_settings

Functions/Classes to create and populate a Woden_Settings class structured equivalently to a woden_settings_t struct in the C/C++/GPU code. Created dynamically based on the required precision.

class woden_settings.Woden_Settings

A class structured equivalently to a woden_settings_t struct, used by the C and CUDA code in libwoden_float.so or libwoden_double.so.

Created by the function create_woden_settings_struct, which sets user_precision_t to either c_float or c_double.

Variables:
  • lst_base (c_double) – Local sidereal time for first time step (radians)

  • lst_obs_epoch_base (c_double) – Local sidereal time for first time step (radians) for the observation epoch (e.g. in 2020 for a 2020 obs)

  • ra0 (c_double) – Right ascension of phase centre (radians)

  • dec0 (c_double) – Declination of phase centre (radians)

  • sdec0 (c_double) – Sine of Declination of phase centre (radians)

  • cdec0 (c_double) – Cosine of Declination of phase centre (radians)

  • num_baselines (c_int) – Number of baselines this array layout has

  • num_ants (c_int) – Number of antennas this array layout has (MWA calls this number of tiles)

  • num_freqs (c_int) – Number of frequencies per coarse band

  • frequency_resolution (c_double) – Frequency resolution of a fine channel (Hz)

  • base_low_freq (c_double) – The lowest fine channel frequency of band 1

  • num_time_steps (c_int) – Number of time steps to simulate

  • time_res (c_double) – Time resolution of simulation (seconds)

  • num_bands (c_int) – Number of coarse frequency bands to simulate

  • band_nums (POINTER(c_int)) – Which number coarse bands to simulate (e.g 1,4,6)

  • sky_crop_type (c_int) – Whether to crop sky models by SOURCE or COMPONENT

  • beamtype (c_int) – What type of primary beam to simulate with

  • gauss_beam_FWHM (c_user_precision) – FWHM of Gaussian primary beam (degrees)

  • gauss_beam_ref_freq (c_double) – Reference frequency for given Gaussian primary beam FWHM

  • chunking_size (c_uint64) – Maximum number of COMPONENTs to include in a single chunk

  • hdf5_beam_path (POINTER(c_char)) – Path to *.hf file containing MWA FEE beam spherical harmonic information

  • jd_date (c_double) – Julian date at beginning of simulation

  • array_layout_file (c_int) – Do we have a path to the array layout or not

  • array_layout_file_path (POINTER(c_char)) – ath to file containing E,N,H coords of array layout

  • latitude (c_double) – Latitude of the array to simulate (radians)

  • latitude_obs_epoch_base (c_double) – Latitude of the array at the observation epoch (radians)

  • longitude (c_user_precision) – Longitude of the array to simulate (radians)

  • FEE_ideal_delays (POINTER(c_int)) – Delay values specifying the pointing for the MWA FEE beam model

  • coarse_band_width (c_double) – Frequency bandwidth of a single coarse band (Hz)

  • gauss_ra_point (c_double) – The initial Right Ascension to point the Gaussian beam at (radians)

  • gauss_dec_point (c_double) – The initial Declination to point the Gaussian beam at (radians)

  • num_cross (c_int) – Total number of cross-correlations to simulate, so freqs*times*baselines

  • num_autos (c_int) – Total number of auto-correlations to simulate, so freqs*times*baselines

  • num_visis (c_int) – Total number of visibilities to simulate, so num_cross + num_autos

  • base_band_freq (c_double) – The lowest fine channel frequency in the current band being simulated

  • do_precession (c_int) – Boolean of whether to apply precession to the array layout or not

  • lsts (POINTER(c_double)) – Array to hold LSTs for all time centroids (these are different when precession is happening)

  • latitudes (POINTER(c_double)) – Array to hold latitudes for all time centroids (these are different when precession is happening)

  • mjds (POINTER(c_double)) – Array to hold modified julian dates for all time centroids

  • do_autos (c_int) – Boolean of whether to simulate autos or not (0 False, 1 True)

  • use_dipamps (c_int) – Boolean of whether to use dipole amplitudes, so have an individual beam per tile (0 False, 1 True)

  • mwa_dipole_amps (POINTER(c_double)) – Bespoke MWA dipole amplitudes for each antenna(tile). Should be 2*num_ants*16 long

  • single_everybeam_station (c_int) – If using everybeam, add this to say we are only using a single station

  • off_cardinal_dipoles (c_int) – Boolean of whether to use off-cardinal dipole equations to apply the beams gains to the Stokes IQUV parameters

  • use_gpu (c_int) – Boolean of whether to use the GPU or not (0 False, 1 True)

  • verbose (c_int) – Boolean of whether to do verbose logging or not (0 False, 1 True)

  • normalise_primary_beam (c_int) – Boolean of whether to normalise the primary beam (0 False, 1 True)

  • beam_ms_path (POINTER(c_char)) – Path to the beam model MS file for everybeam simulations

  • eb_beam_ra0 (c_double) – Right ascension to lock the EveryBeam primary beam centre to (radians)

  • eb_beam_dec0 (c_double) – Declination to lock the EveryBeam primary beam centre to (radians)

class woden_settings.Woden_Settings_Python[source]

A class structured equivalently to a woden_settings_t struct, used by the C/C++/GPU code in libwoden_float.so or libwoden_double.so. Retain a copy of the settings in Python for easy access and manipulation.

woden_settings.command(cmd)[source]

Runs the command string cmd using subprocess.call

Parameters:

cmd (string) – The command to run on the command line

woden_settings.convert_woden_settings_to_ctypes(woden_settings_python: Woden_Settings_Python, woden_settings_ctypes: Woden_Settings) Woden_Settings[source]

Converts Woden settings from a Python object to a ctypes object. :param woden_settings_python: The Woden settings in Python object format. :type woden_settings_python: Woden_Settings_Python :param woden_settings_ctypes: The Woden settings in ctypes object format to be populated. :type woden_settings_ctypes: Woden_Settings

Returns:

The populated Woden settings in ctypes object format.

Return type:

Woden_Settings

woden_settings.create_woden_settings_struct(precision: str = 'double')[source]

Creates a Woden_Settings class structured equivalently to a woden_settings_t struct in the C/CUDA code. Created dynamically based on the precision, to match the compile time precision flag -DUSE_DOUBLE in the C code.

Parameters:

precision (str, optional) – Either “float” or “double:, by default “double”

Returns:

The Woden_Settings class structured equivalently to a woden_settings_t struct

Return type:

Woden_Settings

woden_settings.fill_woden_settings_python(args: Namespace, jd_date: float, lst: float)[source]

Given the parsed and checked arguments in args, populate a woden_settings ctypes.Structure that can be passed into libwoden_float.so or libwoden_double.so, depending on the desired precision.

Parameters:
  • woden_settings (Woden_Settings) – An initialised Woden_Settings class struct

  • args (argparse.Namespace) – The populated arguments args = parser.parse_args()` as returned from the parser given by check_args()

  • jd_date (float) – The julian date of the first time step of the observation

  • lst (float) – The LST of the first time step of the observation (degrees)

Returns:

woden_settings – Populated Woden_Settings_Python class

Return type:

Woden_Settings_Python

woden_settings.setup_lsts_and_phase_centre(woden_settings_python: Woden_Settings_Python, logger: Logger = False) ndarray[source]

Calculate the Local Sidereal Time (LST) for each time step of an observation, and set the phase centre coordinates. If woden_settings.do_precession == True, the returned LSTs are precessed back to J2000.

Parameters:
  • woden_settings_python (Woden_Settings_Python) – A populated Woden_Settings object containing the observation parameters.

  • logger (Logger, optional) – A logger object for logging messages, by default False. If False, a simple logger is created.

Returns:

  • lsts (np.ndarray:) – An array of LST values, one for each time step of the observation.

  • latitudes (np.ndarray:) – An array of latitude values, one for each time step of the observation (these should be the same if precession is not applied, and even if applied there should be tiny differences).