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

Functions to help chop large sky models into smaller chunks for processing

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 for all power-law components w.r.t to the original sky model.

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

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

  • 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 (int) – 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.

  • num_v_pol_fracs (int) – Number of Stokes V fractional polarisation types.

  • num_v_powers (int) – Number of Stokes V power-law components.

  • num_v_curves (int) – Number of Stokes V curved power-law components.

  • v_pol_frac_orig_inds (bool) – Relative indexes for all Stokes V fractional polarisation components w.r.t the original sky model.

  • v_power_orig_inds (bool) – Relative indexes for all Stokes V power-law components w.r.t the original sky model

  • v_curve_orig_inds (bool) – Relative indexes for all Stokes V curved power-law components w.r.t the original sky model

  • num_lin_pol_fracs (int) – Number of Linear polarisation fractional polarisation types.

  • num_lin_powers (int) – Number of Linear polarisation power-law components.

  • num_lin_curves (int) – Number of Linear polarisation curved power-law components.

  • num_lin_angles (int) – Total number of Linear polarisation angle components (num_lin_pol_fracs + num_lin_powers + num_lin_curves).

  • lin_pol_frac_orig_inds (bool) – Relative indexes for all Linear polarisation fractional polarisation components w.r.t the original sky model.

  • lin_power_orig_inds (bool) – Relative indexes for all Linear polarisation power-law components w.r.t the original sky model

  • lin_curve_orig_inds (bool) – Relative indexes for all Linear polarisation curved power-law components w.r.t the original sky model

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.

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, num_threads: int = 1, beamtype_value: int = 8, max_dirs: int = 0, max_chunks_per_set: int = 64, text_file=False) ndarray[tuple[Any, ...], dtype[List[Skymodel_Chunk_Map]]][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. As the sky model reading is split across num_threads, in parallel, ensure that the chunks are split evenly across the threads. Even distribution across threads only really important when calculating the primary beam on the CPU.

Returns an array of shape (num_sets, num_threads), where each element is a list of Skymodel_Chunk_Map objects. Each list contains chunk maps that should evenly distribute the work across the threads for each set.

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. If max_dirs isn’t set, max_num_visibilities is used to calculate max_dirs.

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

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

  • beamtype_value (int) – The type of beam to use for the calculation (default EB_MWA).

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

  • num_threads (int) – The number of threads to use for parallel processing (default 1).

  • max_dirs (int) – The maximum number of directions to include in each chunk. This should be set if calculating the primary beam on the CPU, to try and balance the length of time spent on CPU and GPU for optimal efficiency (default 0).

  • max_chunks_per_set (int) – The maximum number of chunks to include in each set. Each set is sent to the GPU for processing, and iterated over. Again, can use this to balance the length of time spent on CPU and GPU for optimal efficiency. (default 64)

  • 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.fill_chunk_map_polarised_info(comp_type: CompTypes, chunk_map: Skymodel_Chunk_Map, cropped_comp_counter: Component_Type_Counter) Skymodel_Chunk_Map[source]

Fill in all the polarisation information for a given chunk.

This should be called within map_chunk_pointgauss or map_chunk_shapelet, as a bunch of things should be filled

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

  • chunk_map (Skymodel_Chunk_Map) – A Skymodel_Chunk_Map object that contains mapping information about the components in the chunk.

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

Returns:

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

Return type:

Skymodel_Chunk_Map

chunk_sky_model.find_num_dirs_per_chunk(num_directions: int, max_directions_per_chunk: int, num_threads: int) int[source]

Given the number of directions in the sky model num_directions, the maximum number of directions per chunk max_directions_per_chunk, and the number of threads num_threads, this function calculates the number of directions per chunk to evenly distribute the number of directions across the threads. This calculated number must be less than or equal to max_directions_per_chunk.

Parameters:
  • num_directions (int) – The number of directions in the sky model.

  • max_directions_per_chunk (int) – The maximum number of directions per chunk.

  • num_threads (int) – The number of threads.

Returns:

num_dirs_per_chunk – The number of directions per chunk.

Return type:

int

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, coeffs_per_chunk: int, num_shape_dirs: int = 100000.0)[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.

  • num_shape_dirs (int = 1e+5) – The maximum number of shapelet directions to include in each chunk; useful to limit when calculating primary beams on CPU. By default set to 1e+5 in the assumption the limiting factor should be coeffs_per_chunk.

Return type:

None

chunk_sky_model.reshape_chunked_skymodel_map_sets(chunked_skymodel_map_sets: ndarray[tuple[Any, ...], dtype[List[Skymodel_Chunk_Map]]], num_threads: int, max_chunks_per_set: int = 64) ndarray[tuple[Any, ...], dtype[List[Skymodel_Chunk_Map]]][source]

Reshapes the chunked sky model map sets into a 2D array of shape (num_sets, num_threads). num_sets is found by filling the threads in each set, up to the maximum number of chunks per set.

Parameters:
  • chunked_skymodel_map_sets (NDArray[List[Skymodel_Chunk_Map]]) – An array containing information about the chunked sky model.

  • num_threads (int) – The number of threads used to chunk the sky model.

  • max_chunks_per_set (int) – The maximum number of chunks per set. Default is 64.

Returns:

A 2D array of shape (num_sets, num_threads) where each element is a list of Skymodel_Chunk_Map objects.

Return type:

NDArray[List[Skymodel_Chunk_Map]]

read_fits_skymodel

Functions to read in a LoBES/hyperdrive/WODEN FITS sky model file. Functionality includes: - Checking that the FITS file contains all the necessary information to be read in correctly. - Counting the number of components of each type and their properties. - Reading the FITS file sky model and storing the information in a Component_Type_Counter object. - Given chunk maps, reading specific component information to facilitate lazy-loading.

read_fits_skymodel.add_fits_info_to_source_catalogue(comp_type: ~wodenpy.skymodel.woden_skymodel.CompTypes, main_table: ~astropy.table.table.Table, shape_table: ~astropy.table.table.Table, chunk_source: ~wodenpy.use_libwoden.skymodel_structs.create_source_struct.<locals>.Source_Ctypes, chunk_map: ~wodenpy.skymodel.chunk_sky_model.Skymodel_Chunk_Map, beamtype: int, lsts: ~numpy.ndarray[float], latitudes: ~numpy.ndarray[float], v_table: ~astropy.table.table.Table = False, q_table: ~astropy.table.table.Table = False, u_table: ~astropy.table.table.Table = False, p_table: ~astropy.table.table.Table = False, uvbeam_objs: ~numpy.ndarray[~pyuvdata.uvbeam.uvbeam.UVBeam] = False, all_freqs: ~numpy.ndarray = False, logger: ~logging.Logger = False)[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, and polarisation information if it is present.

Furthermore, if beamtype is in wodenpy.use_libwoden.beam_settings.BeamGroups.python_calc_beams, the function will call the relevant beam model and calculate beam values.

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 (Source_Ctypes) – The ctypes Source_Ctypes 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.

  • latitudes (np.ndarray) – Latitudes for all time steps for this simulation.

  • v_table (Table, optional) – The Table containing the Stokes V information, by default False.

  • q_table (Table, optional) – The Table containing the Stokes Q information, by default False.

  • u_table (Table, optional) – The Table containing the Stokes U information, by default False.

  • p_table (Table, optional) – The Table containing the linear polarisation information, by default False.

  • uvbeam_objs (np.ndarray[UVBeam], optional) – The initialised UVBeam objects if calculating primary beams via UVBeam.

  • all_freqs (np.ndarray, optional) – The frequencies to calculate the primary beam response to (only needed if calculating primary beams)

  • logger (Logger, optional) – The logger object to log information to, by default False. If False, make a new logger object.

read_fits_skymodel.add_list_flux_info(mod_type: CompTypes, n_lists: int, key_prepend: str, list_table: Table, map_components: Components_Map, source_components: Components_Python, main_table: Table = False, comp_orig_inds: ndarray = False, list_comp_ind_offset: int = 0)[source]

Given a list of components, and a table containing list flux information, add the list flux information to the components. This is done by matching the component names in the main table with the list table, and then extracting the flux information for each component.

Parameters:
  • mod_type (CompTypes) – The component type, e.g. CompTypes.V_LIST.

  • n_lists (int) – The number of list-type components.

  • key_prepend (str) – The prepend value for the flux columns in the list table e.g. ‘V_INT_FLX’.

  • list_table (Table) – The table containing the list flux information.

  • map_components (Components_Map) – The Components_Map object containing the mapping between the main table and the list table.

  • source_components (Components_Python) – The Components_Python object containing the source component information.

  • main_table (Table, optional) – The main table containing the component information, by default False.

  • comp_orig_inds (np.ndarray, optional) – The original indexes of the components in the main table, by default False.

  • list_comp_ind_offset (int, optional) – The offset to apply to the list component indexes, by default 0.

read_fits_skymodel.check_columns_fits(fits_path: str)[source]

Checks that the FITS file at fits_path contains all the necessary information to be read in correctly. Also checks for optional columns, and certain combinations that must be present e.g. if there are shapelets specified in COMP_TYPE, then there must be a second shapelet HDU.

Any problems and the function errors out with a helpful error message.

Parameters:

fits_path (str) – Path to FITS sky model file.

read_fits_skymodel.count_num_list_fluxes(flux_mod_col_name: str, flux_col_prepend: str, num_list_fluxes: ndarray, main_table: Table, comp_counter: Component_Type_Counter, model_type='nan', optional_table: Table = False)[source]

Counts the number of list-type fluxes for a given model type. Default is to look for Stokes I fluxes in the main table, but can be one of the optional HDUs like V_LIST_FLUXES; point optional_table to correct table if needed. Fills num_list_fluxes with the number of list-type fluxes for each component of the given model type.

Also checks that the number of references to that model type (e.g. ‘nan’ in the MOD_TYPE column) matches the number of rows in the table that have list fluxes. If they don’t match, the function exits.

Parameters:
  • flux_mod_col_name (str) – The model column name, e.g. ‘MOD_TYPE’ or V_MOD_TYPE.

  • flux_col_prepend (str) – Prepend that flux columns start with, e.g. ‘INT_FLX’ or ‘V_INT_FLX’.

  • num_list_fluxes (np.ndarray) – Array to fill with the number of list-type fluxes for each component (e.g. comp_counter.num_list_fluxes).

  • main_table (Table) – The main table (e.g. Table.read(fits_path, hdu=1))

  • comp_counter (Component_Type_Counter) – _description_

  • model_type (str, optional) – _description_, by default ‘nan’

  • optional_table (Table, optional) – _description_, by default False

read_fits_skymodel.find_all_indexes_of_x_in_y(x: ndarray, y: ndarray) ndarray[source]

Given two arrays x and y, find the indexes of matching elements from y in x.

See here https://stackoverflow.com/questions/8251541/numpy-for-every-element-in-one-array-find-the-index-in-another-array for the origins of this function (github copypasta)

Parameters:
  • x (np.ndarray) – Array of elements to find in y.

  • y (np.ndarray) – Array to search for elements in x.

Returns:

Array of indexes of y that match the elements in x.

Return type:

np.ndarray

read_fits_skymodel.read_fits_radec_count_components(fits_path: str) Component_Type_Counter[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(args: Namespace, main_table: Table, shape_table: Table, chunked_skymodel_maps: list, num_freqs: int, num_time_steps: int, beamtype: int, j2000_lsts: ndarray, j2000_latitudes: ndarray, v_table: Table = False, q_table: Table = False, u_table: Table = False, p_table: Table = False, precision: str = 'double', uvbeam_objs: ndarray[UVBeam] = False, logger: Logger = False) List[Source_Python][source]

Uses Tables read from a FITS file and returns a list of populated Source_Python classes. Uses the maps in chunked_skymodel_maps to determine which components to read in.

This function is run in parallel by run_woden.py, and Python multiprocessing requires everything to be picklable. This means we can’t use ctypes, so we can’t use Woden_Settings, hence we have to pass in all the relevant information as arguments.

If beamtype is in wodenpy.use_libwoden.beam_settings.BeamGroups.python_calc_beams, this function will call the relevant beam model and calculate beam values (via add_fits_info_to_source_catalogue).

Parameters:
  • args (argparse.Namespace) – The args object from run_woden.py.

  • 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.

  • j2000_lsts (np.ndarray) – The LSTs matching the precessed latitudes in J2000

  • j2000_latitudes (np.ndarray) – Latitude of the array as precessed back to J2000. Should be precessed for each time step in the simulation.

  • v_table (Table, optional) – The Table containing the Stokes V information, by default False.

  • q_table (Table, optional) – The Table containing the Stokes Q information, by default False.

  • u_table (Table, optional) – The Table containing the Stokes U information, by default False.

  • p_table (Table, optional) – The Table containing the linear polarisation information, by default False.

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

  • uvbeam_objs (np.ndarray[UVBeam], optional) – The initialised UVBeam objects if calculating primary beams via UVBeam.

  • logger (Logging, optional) – The logger object to use, by default False. If False, makes a new logger.

Returns:

A list of populated Source_Python classes.

Return type:

List[Source_Python]

read_text_skymodel

Functions to read in the deprecated WODEN text sky model format and convert it to the LoBES-style FITS sky model format.

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

Functions to read in the mwa_hyperdrive yaml sky model format and convert it to the LoBES-style FITS sky model format.

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

A function to centralise reading all sky model formats, and converting to the FITS format. Also a function to convert Python source objects in a ctypes Source_Catalogue object.

read_skymodel.create_source_catalogue_from_python_sources(python_sources: List[Source_Python], woden_struct_classes: Woden_Struct_Classes, beamtype: int, precision: str = 'double') Source_Catalogue[source]

Create a Source_Catalogue object from a list of Source_Python objects. This is the main function to convert from the Python source objects to the C source objects. The Source_Catalogue object is a ctypes object that is directly fed into the C/GPU code.

Parameters:
  • python_sources (list) – A list of Source_Python objects.

  • woden_struct_classes (Woden_Struct_Classes) – A Woden_Struct_Classes object that contains the ctypes classes for the Source_Catalogue object.

  • beamtype (int) – The beam type of the sources. This is used to determine what information needs to be copied from the Source_Python objects to the Source_Catalogue, e.g. azimuth/altitude, or actual complex beam values etc.

  • precision (str) – The precision of the source catalogue. Either ‘single’ or ‘double’. Default is ‘double’.

Returns:

source_catalogue – A Source_Catalogue object that contains all of the source information in a format that can be fed directly into the C/GPU code.

Return type:

Source_Catalogue

read_skymodel.get_skymodel_tables(skymodel_path: str) tuple[source]

Read the contents of a sky model file into a set of astropy Tables. If the sky model is a .fits file, the tables are read in directly. If the sky model is a .yaml or .txt file, the file is read in an converted into Tables. As the yaml and text formats are deprecated, they never return any polarisation infomration.

Parameters:

skymodel_path (str) – The path to the sky model file. Must end in .fits, .yaml, or .txt.

Returns:

A tuple containing the following elements: - main_table (Table): The main table read from the first HDU. - shape_table (Table or str): The shapelet table if present, otherwise ‘no_shape_table’. - v_table (Table or bool): The V_LIST_FLUXES table if present, otherwise False. - q_table (Table or bool): The Q_LIST_FLUXES table if present, otherwise False. - u_table (Table or bool): The U_LIST_FLUXES table if present, otherwise False. - p_table (Table or bool): The P_LIST_FLUXES table if present, otherwise False.

Return type:

tuple

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

woden_skymodel

Functions/Classes to read in a sky model file, count the number of components, discard components below the horizon, and model reference fluxes to 200MHz

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

info_string()[source]

Return a string with the total counts of all components

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, logger: Logger = False, 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.

  • logger (Logger, optional) – A logger object for logging information. Default is False, in which case a basic logger is made to log to instead.

  • 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.