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:
objectThe 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_namesandnum_componentsattributes, 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
Return a list of column names in the sky model.
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.
- 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:
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.
- 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:
- Returns:
Sky model data structure.
- Return type:
- 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.