wodenpy.skymodel

Methods for reading and writing sky models.

wodenpy.skymodel is a collection of methods for reading and writing sky models. The sky models are stored in a variety of formats, including FITS, YAML, and text.

chunk_sky_model

class chunk_sky_model.Components_Map[source]

Mapping information for a set of components, of either POINT, GAUSSIAN or SHAPELET type.

Variables:
  • power_orig_inds (bool) – Relative indexes w.r.t all power-law components in the original sky model for power components.

  • curve_orig_inds (bool) – Relative indexes w.r.t all curved power-law components in the original sky model for curve components.

  • list_orig_inds (bool) – Relative indexes w.r.t all list-type components in the original sky model for list components.

  • power_shape_basis_inds (bool) – Index of a basis function entry relative to its component for power components.

  • curve_shape_basis_inds (bool) – Index of a basis function entry relative to its component for curve components.

  • list_shape_basis_inds (bool) – Index of a basis function entry relative to its component for list components.

  • lowest_file_num (float) – The line in the original sky model file that each component appears in. Ignore all lines before the smallest line number for all components in this chunk, makes reading faster.

  • total_num_flux_entires (int) – Number of flux list entries there are in total so we can allocate correct amount when reading in full information.

  • total_shape_coeffs (int) – Number of shapelet basis functions that are in total so we can allocate correct amount when reading in full information.

class chunk_sky_model.Skymodel_Chunk_Map(n_point_powers=0, n_point_curves=0, n_point_lists=0, n_gauss_powers=0, n_gauss_curves=0, n_gauss_lists=0, n_shape_powers=0, n_shape_curves=0, n_shape_lists=0, n_shape_coeffs=0)[source]

A class representing a chunk of a sky model, containing information about the number of point, Gaussian, and shape components, as well as their respective power-law, curved power-law, or list type flux info. This class also provides methods for consolidating component and flux types into one array of original component indexes, and for printing information about the chunk.

Variables:
  • n_point_lists (int) – Number of POINT list-type components.

  • n_point_powers (int) – Number of POINT power-law components.

  • n_point_curves (int) – Number of POINT curved power-law components.

  • n_gauss_lists (int) – Number of GAUSSIAN list-type components.

  • n_gauss_powers (int) – Number of GAUSSIAN power-law components.

  • n_gauss_curves (int) – Number of GAUSSIAN curved power-law components.

  • n_shape_lists (int) – Number of SHAPELET list-type components.

  • n_shape_powers (int) – Number of SHAPELET power-law components.

  • n_shape_curves (int) – Number of SHAPELET curved power-law components.

  • n_shape_coeffs (int) – Number of SHAPELET coefficients.

  • n_points (int) – Number of POINT components

  • n_gauss (int) – Number of GAUSSIAN components

  • n_shapes (int) – Number of SHAPELET components

  • n_comps (int) – Number of all components

  • point_components (Components_Map) – Mapping object for POINT components.

  • gauss_components (Components_Map) – Mapping object for GAUSSIAN components.

  • shape_components (Components_Map) – Mapping object for SHAPELET components.

make_all_orig_inds_array()[source]

Look through all component and flux types and consolidate into one array self.all_orig_inds of original component indexes. Use this when reading in full information from the sky model

print_info()[source]

Prints information about the ChunkSkyModel object, including the number of points, Gaussians, and shapes, as well as the number of powers, curves, lists, and coefficients associated with each type of object.

chunk_sky_model.create_shape_basis_maps(cropped_comp_counter: Component_Type_Counter)[source]

Creates maps that associate each shape basis function with its corresponding original component index, component type, and parameter index.

Parameters:

cropped_comp_counterComponent_Type_Counter

An instance of the Component_Type_Counter class that contains information about the number of shape coefficients for each component type and the corresponding indices of the components in the original component list.

Returns:

shape_basis_to_orig_comp_index_mapnumpy.ndarray

An array that maps each shape basis function to its corresponding original component index.

shape_basis_to_comp_type_mapnumpy.ndarray

An array that maps each shape basis function to its corresponding component type.

shape_basis_param_indexnumpy.ndarray

An array that maps each shape basis function to its corresponding parameter index within its component.

chunk_sky_model.create_skymodel_chunk_map(comp_counter: Component_Type_Counter, max_num_visibilities: int, num_baselines: int, num_freqs: int, num_time_steps: int, text_file=False) list[source]

Given all the information in comp_counter, make a map of how to split the whole sky model up into manageable chunks to fit in memory. The purpose of this function is to record what to ‘malloc’ in each Components_t and Source_t ctype class before we lazy-load all the values into them directly from the skymodel.

Parameters:
  • comp_counter (Component_Type_Counter) – object that contains information about the number of components of each type in the sky model.

  • max_num_visibilities (int) – The maximum number of visibilities that can be loaded into memory at once.

  • num_baselines (int) – The number of baselines in the observation.

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

  • num_time_steps (int) – The number of time steps in the observation.

  • text_file (Boolean) – A boolean flag indicating whether to we are reading in from text file or not (default False)

Returns:

A list of dictionaries containing information about the chunked sky model.

Return type:

list

chunk_sky_model.fill_chunk_component(comp_type: CompTypes, cropped_comp_counter: Component_Type_Counter, power_iter: int, num_chunk_power: int, curve_iter: int, num_chunk_curve: int, list_iter: int, num_chunk_list: int) Skymodel_Chunk_Map[source]

Fills in the relevant fields inside a Skymodel_Chunk_Map based on the given component type and the number of components of each type that are required in the chunk. The function returns a Skymodel_Chunk_Map in prepartion to read a number of chunks from the skymodel

Parameters:
  • comp_type (CompTypes) – The type of component to be filled in the chunk.

  • cropped_comp_counter (Component_Type_Counter) – The counter object that contains the indices of the cropped components.

  • power_iter (int) – The starting index of the power components in the cropped component counter.

  • num_chunk_power (int) – The number of power components to be included in the chunk.

  • curve_iter (int) – The starting index of the curve components in the cropped component counter.

  • num_chunk_curve (int) – The number of curve components to be included in the chunk.

  • list_iter (int) – The starting index of the list components in the cropped component counter.

  • num_chunk_list (int) – The number of list components to be included in the chunk.

Returns:

chunk_map – A Skymodel_Chunk_Map object that contains the filled-in Components_Map.

Return type:

Skymodel_Chunk_Map

chunk_sky_model.increment_flux_type_counters(power_iter: int, curve_iter: int, list_iter: int, num_chunk_power: int, num_chunk_curve: int, num_chunk_list: int, num_power: int, num_curve: int, num_list: int, comps_per_chunk: int, lower_comp_ind: int, upper_comp_ind: int)[source]

Here, given the overall lower and upper index in a given type of components, work out how many of each flux type we have and increment the counters as appropriate

Always order things as POWER_LAW, CURVED_POWER_LAW, LIST

Parameters:
  • power_iter (int) – The current iteration of the power law flux type.

  • curve_iter (int) – The current iteration of the curved power law flux type.

  • list_iter (int) – The current iteration of the list flux type.

  • num_chunk_power (int) – The number of power law flux types in the current chunk.

  • num_chunk_curve (int) – The number of curved power law flux types in the current chunk.

  • num_chunk_list (int) – The number of list flux types in the current chunk.

  • num_power (int) – The total number of power law flux types.

  • num_curve (int) – The total number of curved power law flux types.

  • num_list (int) – The total number of list flux types.

  • comps_per_chunk (int) – The number of components per chunk.

  • lower_comp_ind (int) – The lower index of the current chunk.

  • upper_comp_ind (int) – The upper index of the current chunk.

Returns:

The updated values of power_iter, curve_iter, list_iter, num_chunk_power, num_chunk_curve, num_chunk_list.

Return type:

Tuple of integers

chunk_sky_model.map_chunk_pointgauss(cropped_comp_counter: Component_Type_Counter, chunk_ind: int, comps_per_chunk: int, point_source=False, gaussian_source=False) Components_Map[source]

For a given chunk index chunk_ind, work out how many of each type of COMPONENT to fit in the chunk, and then map specifics across to that one chunk

Parameters:
  • cropped_comp_counter (Component_Type_Counter) – A cropped component counter object that contains information about the components to use in the chunk.

  • chunk_ind (int) – The index of the chunk.

  • comps_per_chunk (int) – The number of components per chunk.

  • point_source (bool) – Whether to use point sources. Default is False.

  • gaussian_source (bool) – Whether to use gaussian sources. Default is False.

Returns:

chunk_map – A Components_Map object that contains mapping information about the components in the chunk.

Return type:

Components_Map

chunk_sky_model.map_chunk_shapelets(cropped_comp_counter: Component_Type_Counter, shape_basis_to_orig_comp_index_map: ndarray, shape_basis_to_orig_type_map: ndarray, shape_basis_param_index: ndarray, chunk_ind: int, coeffs_per_chunk: int)[source]

Maps the shapelet components in a chunk of the sky model to their corresponding indices in the original sky model. This function is used to create a mapping between the shapelet components in the cropped sky model and their corresponding components in the original sky model. This mapping is used to extract the correct shapelet coefficients from the original sky model when creating a chunked sky model.

Parameters:
  • cropped_comp_counter (Component_Type_Counter) – A Component_Type_Counter object containing information about the components in the cropped sky model.

  • shape_basis_to_orig_comp_index_map (np.ndarray) – An array mapping the indices of the shapelet basis functions in the cropped sky model to their corresponding indices in the original sky model.

  • shape_basis_to_orig_type_map (np.ndarray) – An array mapping the indices of the shapelet basis functions in the cropped sky model to their corresponding component types in the original sky model.

  • shape_basis_param_index (np.ndarray) – An array containing the indices of the shapelet basis functions in the original sky model.

  • chunk_ind (int) – The index of the chunk being mapped.

  • coeffs_per_chunk (int) – The number of shapelet coefficients in each chunk.

Return type:

None

read_fits_skymodel

read_fits_skymodel.add_fits_info_to_source_catalogue(comp_type: CompTypes, main_table: Table, shape_table: Table, chunk_source: Source_Float | Source_Double, chunk_map: Skymodel_Chunk_Map, beamtype: int, lsts: ndarray, latitude: float)[source]

Given the desired components as detailed in the chunk_map, add the relevant information from the FITS file main_table, shape_table objects to the chunk_source object. As well as the skymodel information, this function adds either az/za or ha/dec information, depending on the beamtype.

Parameters:
  • comp_type (CompTypes) – The type of component we are adding information for.

  • main_table (Table) – The main Table (with RA,Dec etc) from the FITS file.

  • shape_table (Table) – The shapelet Table from the FITS file.

  • chunk_source (Union[Source_Float, Source_Double]) – The ctypes Source object to add information to.

  • chunk_map (Skymodel_Chunk_Map) – The map object containing information about components for this chunk.

  • beamtype (int) – The type of beam used (BeamTypes)

  • lsts (np.ndarray) – LSTs for all time steps for this simulation.

  • latitude (float) – Latitude of the array

read_fits_skymodel.read_fits_radec_count_components(fits_path: str)[source]

Reads a FITS file sky model. Reads just the ra, dec, and counts how many POINT/GAUSS/SHAPE and POWER/CURVE/LIST, consolidating the information into a Component_Type_Counter object.

Parameters:

fits_path (str) – The path to the FITS file containing the sky model information.

Returns:

comp_counter – A Component_Type_Counter object that counts the number of components of each type and their properties.

Return type:

Component_Type_Counter

read_fits_skymodel.read_fits_skymodel_chunks(main_table: Table, shape_table: Table, chunked_skymodel_maps: list, num_freqs: int, num_time_steps: int, beamtype: int, lsts: ndarray, latitude: float, precision='double') Source_Catalogue_Float | Source_Catalogue_Double[source]

Uses Tables read from a FITS file and returns a source catalogue that can be used by C/CUDA code to calculate visibilities. Uses the maps in chunked_skymodel_maps to determine which components to read in and add to the source_catalogue

Parameters:
  • main_table (Table) – The main Table (with RA,Dec etc) from the FITS file.

  • shape_table (Table) – The shapelet Table from the FITS file.

  • chunked_skymodel_maps (list) – List of ChunkedSkyModelMap objects, each representing a chunk of the sky model.

  • num_freqs (int) – Number of frequency channels in the sky model.

  • num_time_steps (int) – Number of time steps in the sky model.

  • beamtype (int) – Type of beam used in the sky model.

  • lsts (np.ndarray) – Array of LST values for each time step in the sky model.

  • latitude (float) – Latitude of the observation site.

  • precision (str, optional) – Precision of the source catalogue (either “float” or “double”), by default “double”.

Returns:

source_catalogue – A source catalogue that can be used by C/CUDA code to calculate visibilities.

Return type:

Union[Source_Catalogue_Float, Source_Catalogue_Double]

read_text_skymodel

read_text_skymodel.read_full_text_into_fitstable(text_path: str) Tuple[Table, Table][source]

Read in an old-school WODEN style text sky model and convert it into the LoBES-style FITS sky model format. Can then be read in by read_fits_skymodel.read_fits_skymodel_chunks.

Parameters:

text_path (str) – Path to the text sky model

Returns:

The main_table and shape_table to be used by during lazy loading

Return type:

Tuple(Table, Table)

read_text_skymodel.read_text_radec_count_components(text_path: str)[source]

Reads a text file sky model. Reads just the ra, dec, and counts how many POINT/GAUSS/SHAPE and POWER/CURVE/LIST, consolidating the information into a Component_Type_Counter object.

Parameters:

text_path (str) – The path to the text file containing the sky model information.

Returns:

comp_counter – A Component_Type_Counter object that counts the number of components of each type and their properties.

Return type:

Component_Type_Counter

read_yaml_skymodel

read_yaml_skymodel.read_full_yaml_into_fitstable(yaml_path: str) Tuple[Table, Table][source]

Read in a hyperdrive style yaml sky model and convert it into the LoBES-style FITS sky model format. Can then be read in by read_fits_skymodel.read_fits_skymodel_chunks.

Parameters:

yaml_path (str) – Path to the yaml sky model

Returns:

The main_table and shape_table to be used by during lazy loading

Return type:

Tuple(Table, Table)

read_yaml_skymodel.read_yaml_radec_count_components(yaml_path: str)[source]

Reads a yaml file sky model. Reads just the ra, dec, and counts how many POINT/GAUSS/SHAPE and POWER/CURVE/LIST, consolidating the information into a Component_Type_Counter object.

Parameters:

yaml_path (str) – The path to the yaml file containing the sky model information.

Returns:

comp_counter – A Component_Type_Counter object that counts the number of components of each type and their properties.

Return type:

Component_Type_Counter

read_skymodel

read_skymodel.read_radec_count_components(skymodel_path: str) Component_Type_Counter[source]

Reads basic info from a sky model. Checks whether the sky model is a .fits, .yaml, or .txt file, and errors if not. Then calls the appropriate function if so. Reads just the ra, dec, and counts how many POINT/GAUSS/SHAPE and POWER/CURVE/LIST, consolidating the information into a Component_Type_Counter object.

Parameters:

skymodel_path (str) – The path to the sky model file.

Returns:

comp_counter – A Component_Type_Counter object that counts the number of components of each type and their properties.

Return type:

Component_Type_Counter

read_skymodel.read_skymodel_chunks(skymodel_path: str, chunked_skymodel_maps: list, num_freqs: int, num_time_steps: int, beamtype: int, lsts: ndarray, latitude: float, precision='double') Source_Catalogue_Float | Source_Catalogue_Double[source]

Lazy loads chunks of a sky model at skymodel_path into a Source_Catalogue object, as mapped by chunked_skymodel_maps. If the sky model isn’t already a FITS file, it is converted to one. The resultant can be passed into C/CUDA code to calculate visibilities.

Parameters:
  • skymodel_path (str) – The path to the sky model file.

  • chunked_skymodel_maps (list) – List of ChunkedSkyModelMap objects, each representing a chunk of the sky model.

  • num_freqs (int) – Number of frequency channels in the sky model.

  • num_time_steps (int) – Number of time steps in the sky model.

  • beamtype (int) – Type of beam used in the sky model.

  • lsts (np.ndarray) – Array of LST values for each time step in the sky model.

  • latitude (float) – Latitude of the observation site.

  • precision (str, optional) – Precision of the source catalogue (either “float” or “double”), by default “double”.

Returns:

source_catalogue – A source catalogue that can be used by C/CUDA code to calculate visibilities.

Return type:

Union[Source_Catalogue_Float, Source_Catalogue_Double]

woden_skymodel

class woden_skymodel.CompTypes(value)[source]

That’s right, C-style enum inside Python This Class let’s us label the component/flux type combinations with a unique name, 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

Variables:
  • POINT (auto()) – point source

  • GAUSSIAN (auto()) – gaussian source

  • SHAPELET (auto()) – shapelet source

  • POINT_POWER (auto()) – point source + power law

  • POINT_CURVE (auto()) – point source + curved power law

  • POINT_LIST (auto()) – point source + list type law

  • GAUSS_POWER (auto()) – gaussian source + power law

  • GAUSS_CURVE (auto()) – gaussian source + curved power law

  • GAUSS_LIST (auto()) – gaussian source + list type law

  • SHAPE_POWER (auto()) – shapelet source + power law

  • SHAPE_CURVE (auto()) – shapelet source + curved power law

  • SHAPE_LIST (auto()) – shapelet source + list type law

class woden_skymodel.Component_Info[source]

A class that stores information about a sky model component.

Variables:
  • comp_type (int) – The type of component, given by values in CompTypes().

  • ra (float) – The right ascension of the component in radians.

  • dec (float) – The declination of the component in radians.

  • point (int) – Used to set the component type during reading.

  • gaussian (int) – Used to set the component type during reading.

  • shapelet (int) – Used to set the component type during reading.

  • flux_power (int) – Used to select flux type during reading.

  • flux_curve (int) – Used to select flux type during reading.

  • flux_list (int) – Used to select flux type during reading.

  • major (float) – The major axis of the component in radians.

  • minor (float) – The minor axis of the component in radians.

  • pa (float) – The position angle of the component in radians.

  • n1s (list) – A list of shapelet basis function n1 values.

  • n2s (list) – A list of shapelet basis function n2 values.

  • coeffs (list) – A list of shapelet basis function coefficients.

  • si (float) – The spectral index of the component.

  • curve_q (float) – The curvature of the component spectrum.

  • freqs (list) – A list of frequencies at which the flux is defined (Hz).

  • fluxes (list) – A list of Stokes vectors defining the flux (Jy).

  • num_fluxes (int) – The number of frequencies that have been added.

  • num_shape_basis (int) – The number of shapelet basis functions.

  • source_name (str) – The name of the parent source.

  • norm_comp_pl (float) – The reference flux of the power-law component at 200MHz (Jy)

  • norm_comp_cpl (float) – The reference flux of the curved power-law component at 200MHz (Jy)

class woden_skymodel.Component_Type_Counter(initial_size=100000)[source]

Holds counts for the various types of components in a source list, including type (point, gaaussian, shapelet) and flux model (power law, curved power law, list). Contains methods to count properties of current source being read in, and then to add that component

Does a large amount of book keeping on indexes of components within the original sky model, so that we can pull out the correct information when lazy loading chunks of sky model.

This is used by read_radec_count_components and the functions within.

add_component_reset_counters()[source]

Add the current component to overall counts, and reset the current component values for the next component

count_list_flux()[source]

Count an entry to the current number of flux entries for a list type flux, if the component has a list type flux model

initiate_component()[source]

Starting a new component, so need to iterate the component index and capture the current source index. Make arrays bigger if necessary

new_file_line()[source]

Iterates the line in the file that we are on

new_source()[source]

Iterates the source index if we are in a new source

print_info()[source]

Print out the totals of everything

remove_array_padding()[source]

Once everything is read in, we can shrink down the arrays to however much information was read in (we keep doubling array size as needed)

total_components()[source]

Create final total counts once all information has been read in

woden_skymodel.calc_cpl_norm_at_200MHz(component: Component_Info) Component_Info[source]

The FITS style sky model references everything to 200MHz, so extrap a curved power-law model reference flux to 200MHz, and set frequency to 200MHz

Parameters:

component (Component_Info) – A populated Component_Info instance with curved power law info

Returns:

Updated component info with curved power law extrapolated to 200MHz

Return type:

Component_Info

woden_skymodel.calc_pl_norm_at_200MHz(component: Component_Info) Component_Info[source]

The FITS style sky model references everything to 200MHz, so extrap a power-law model reference flux to 200MHz, and set frequency to 200MHz

Parameters:

component (Component_Info) – A populated Component_Info instance with power law info

Returns:

Updated component info with power law extrapolated to 200MHz

Return type:

Component_Info

woden_skymodel.crop_below_horizon(lst: float, latitude: float, comp_counter: Component_Type_Counter, crop_by_component=True) Component_Type_Counter[source]

Crop a Component_Type_Counter to only include components above the horizon, given the local sidereal time and latitude of the array

Parameters:
  • lst (float) – The local sidereal time (in radians).

  • latitude (float) – The array latitude (in radians).

  • comp_counter (Component_Type_Counter) – An object containing information about the components in the sky model.

  • crop_by_component (bool, optional) – If True, crop components individually. If False, crop sources as a whole. Default is True.

Returns:

comp_counter – An updated version of the input comp_counter object, with only the components above the horizon included.

Return type:

Component_Type_Counter

Notes

This function crops a sky model to only include components above the horizon. It uses the input lst and latitude to calculate the azimuth and elevation of each component in the sky model, and then includes only those components with elevation greater than or equal to zero.

If crop_by_component is True, each component is cropped individually. If False, sources are cropped as a whole. In the latter case, all components belonging to a source are included if at least one of them is above the horizon.

The input comp_counter object is updated in place, and the updated object is returned.