LocalSkyModel

class ska_sdp_datamodels.global_sky_model.LocalSkyModel(column_names: list[str], num_rows: int, max_vector_len: int = 5, vector_columns: Sequence[str] | None = None)

Bases: object

The LocalSkyModel class provides methods to load and save CSV files, and access local sky model data in memory.

Load a formatted CSV sky model file using the load() method, passing the filename to load as a string. For example:

from ska_sdp_datamodels.global_sky_model import LocalSkyModel

local_sky_model = LocalSkyModel.load("sky_model.csv")

Alternatively, an empty sky model can be created by passing the column names and the number of rows to the constructor. For example:

column_names = ["ra_deg", "dec_deg", "i_pol_jy"]
num_rows = 1234
local_sky_model = LocalSkyModel(column_names, num_rows)

Access data values by dereferencing the sky model first by a string containing the column name, and then the integer row/component index. If required, this can also be used to set values into the sky model. For example:

flux = local_sky_model["i_pol_jy"][0]
local_sky_model["i_pol_jy"][0] = flux

If required, the column names and the number of rows can be accessed using the column_names and num_components attributes, respectively:

print(local_sky_model.column_names)
print(local_sky_model.num_components)

The local sky model can be saved to a CSV file using the save() method, passing the filename as a string. For example:

local_sky_model.save("another_sky_model.csv")

Attributes Summary

column_names

Return a list of column names in the sky model.

num_components

Return the number of components (or number of rows) in the sky model.

Methods Summary

get_value_str(name, row_index)

Returns a string containing a single value for a single component.

load(path[, max_vector_len, vector_columns])

Load a sky model CSV text file into the data model.

save(path)

Save this sky model to a CSV text file.

set_header(header)

Set header key, value pairs.

set_row(row_index, row_data)

Sets all parameters for a single component.

set_value(name, row_index, value)

Sets a single parameter for a single component.

tokenize_line(line)

Split a line into tokens, assuming commas as separators, while respecting quotes and bracketed vectors.

Attributes Documentation

column_names

Return a list of column names in the sky model.

Returns:

List of column names.

Return type:

list[str]

num_components

Return the number of components (or number of rows) in the sky model.

Returns:

Number of components in the sky model.

Return type:

int

Methods Documentation

get_value_str(name: str, row_index: int) str

Returns a string containing a single value for a single component. Called by the save() method.

Parameters:
  • name (str) – Column name for which to return data.

  • row_index (int) – Row index of component to return.

Returns:

String containing specified component data.

Return type:

str

classmethod load(path: str, max_vector_len: int = 5, vector_columns: Sequence[str] | None = None) LocalSkyModel

Load a sky model CSV text file into the data model.

Parameters:
  • path (str) – Path to CSV text file to load.

  • max_vector_len (int) – Maximum vector length for vector column types.

  • vector_columns (Sequence[str] or None) – Names of columns that may contain vectors.

Returns:

Sky model data structure.

Return type:

LocalSkyModel

save(path: str) None

Save this sky model to a CSV text file.

Parameters:

path (str) – Path of CSV text file to write.

set_header(header: dict[str, Any]) None

Set header key, value pairs. These are written to the file as comments.

Parameters:

header (dict[str, Any]) – Header data to set.

set_row(row_index: int, row_data: dict[str, Any]) None

Sets all parameters for a single component.

Parameters:
  • row_index (int) – Row index of component to set.

  • row_data (dict[str, Any]) – Data to set for this row.

set_value(name: str, row_index: int, value: Any) None

Sets a single parameter for a single component.

Parameters:
  • name (str) – Column name to set.

  • row_index (int) – Row index of component to set.

  • value (Any) – Value to set for parameter. Use ‘None’ for ‘missing’.

static tokenize_line(line: str) list[str]

Split a line into tokens, assuming commas as separators, while respecting quotes and bracketed vectors.

Parameters:

line (str) – String to split up.

Returns:

List of tokens.

Return type:

list[str]