artist.io.h5_columnar_heliostats

Attributes

required_fields

The parameters every heliostat, facet, kinematics, and actuator must have, per component.

optional_fields

The group of scalar parameters per component that may be missing, which are stored as NaN.

string_fields

The parameters that are stored as strings.

rigid_body_deviations

Index and name of each translation and each rotation deviation parameter of the rigid body kinematics.

linear_actuator_parameters

Index and name of each non-optimizable and each optimizable linear actuator parameter.

Exceptions

ColumnarLayoutError

Initialize self. See help(type(self)) for accurate signature.

Functions

is_columnar(heliostats_config) → bool

Check whether the heliostats of a scenario file are stored in the columnar layout.

heliostat_columns(heliostats) → dict[str, numpy.ndarray]

Arrange the parameters of all heliostats in the columnar layout.

_component_columns(component, rows) → dict[str, numpy.ndarray]

Arrange the parameters of one component of all heliostats that have it in the columnar layout.

_to_numpy(value) → numpy.ndarray

Convert a parameter value, i.e., a tensor, NumPy array, or Python scalar, to a NumPy array.

_to_str(value) → str

Convert a string parameter value, which may be stored as bytes or a NumPy scalar, to a string.

write_columnar_heliostats(heliostats_config, columns) → None

Write heliostats arranged by heliostat_columns() into an empty HDF5 group and mark its layout.

read_legacy_heliostats(heliostats_config) → list[tuple[str, dict[str, Any]]]

Read all heliostats stored in the legacy layout, with one HDF5 group per heliostat, as flattened parameters.

read_heliostat_columns(heliostats_config) → list[dict[str, numpy.ndarray]]

Read the heliostats of a scenario file in the columnar layout, whichever layout the file uses.

read_kinematics_deviations(columns) → tuple[torch.Tensor, torch.Tensor, dict[str, torch.Tensor]]

Read the rigid body deviations of all heliostats with individual kinematics onto the CPU.

read_actuator_parameters(columns, actuator_type) → tuple[torch.Tensor, torch.Tensor, dict[str, torch.Tensor]]

Read the parameters of all heliostats with individual actuators onto the CPU, as actuators of one type.

convert_scenario_to_columnar(input_path, output_path) → None

Convert a scenario file with heliostats in the legacy layout to the columnar layout.

Module Contents

artist.io.h5_columnar_heliostats.required_fields

The parameters every heliostat, facet, kinematics, and actuator must have, per component.

artist.io.h5_columnar_heliostats.optional_fields

The group of scalar parameters per component that may be missing, which are stored as NaN.

artist.io.h5_columnar_heliostats.string_fields

The parameters that are stored as strings.

artist.io.h5_columnar_heliostats.rigid_body_deviations

Index and name of each translation and each rotation deviation parameter of the rigid body kinematics.

artist.io.h5_columnar_heliostats.linear_actuator_parameters

Index and name of each non-optimizable and each optimizable linear actuator parameter.

exception artist.io.h5_columnar_heliostats.ColumnarLayoutError

Bases: ValueError

Initialize self. See help(type(self)) for accurate signature.

artist.io.h5_columnar_heliostats.is_columnar(heliostats_config: h5py.Group) → bool

Check whether the heliostats of a scenario file are stored in the columnar layout.

Parameters

heliostats_configh5py.Group

The heliostat group of the scenario file.

Returns

bool

Whether the heliostats are stored in the columnar layout.

artist.io.h5_columnar_heliostats.heliostat_columns(heliostats: collections.abc.Sequence[tuple[str, dict[str, Any]]]) → dict[str, numpy.ndarray]

Arrange the parameters of all heliostats in the columnar layout.

Every heliostat parameter is stored in one dataset for all heliostats, with the heliostats as the first dimension, sorted by name. Facets and actuators are sorted by name as well, as HDF5 sorts the members of a group. Individual surfaces, kinematics, and actuators are only stored for the heliostats that have them, together with the indices of these heliostats. Missing kinematics deviations and actuator parameters are stored as NaN.

Parameters

heliostatsSequence[tuple[str, dict[str, Any]]]

The name and the flattened parameters of each heliostat, as stored in the legacy layout, e.g., {"position": ..., "surface/facets/facet_1/control_points": ...}.

Raises

ColumnarLayoutError

If the heliostats cannot be stored in the columnar layout. Nothing is silently left out: parameters that differ in shape between heliostats, or that the layout does not know, raise this error.

Returns

dict[str, np.ndarray]

The path of each dataset relative to the heliostat group and its data.

artist.io.h5_columnar_heliostats._component_columns(component: str, rows: list[tuple[int, str, dict[str, dict[str, Any]]]]) → dict[str, numpy.ndarray]

Arrange the parameters of one component of all heliostats that have it in the columnar layout.

Parameters

componentstr

The component, i.e., "" for heliostat-level parameters, surface, kinematics, or actuators.

rowslist[tuple[int, str, dict[str, dict[str, Any]]]]

The index, name, and the parameters of each item (facet or actuator) of every heliostat with the component.

Raises

ColumnarLayoutError

If a parameter is missing, unknown, not scalar where it must be, or differs in shape between heliostats.

Returns

dict[str, np.ndarray]

The path of each dataset relative to the heliostat group and its data.

artist.io.h5_columnar_heliostats._to_numpy(value: Any) → numpy.ndarray

Convert a parameter value, i.e., a tensor, NumPy array, or Python scalar, to a NumPy array.

Parameters

valueAny

The value.

Returns

np.ndarray

The value as a NumPy array.

artist.io.h5_columnar_heliostats._to_str(value: Any) → str

Convert a string parameter value, which may be stored as bytes or a NumPy scalar, to a string.

Parameters

valueAny

The value.

Returns

str

The value as a string.

artist.io.h5_columnar_heliostats.write_columnar_heliostats(heliostats_config: h5py.Group, columns: dict[str, numpy.ndarray]) → None

Write heliostats arranged by heliostat_columns() into an empty HDF5 group and mark its layout.

Parameters

heliostats_configh5py.Group

The empty heliostat group of the scenario file.

columnsdict[str, np.ndarray]

The path of each dataset relative to the heliostat group and its data.

artist.io.h5_columnar_heliostats.read_legacy_heliostats(heliostats_config: h5py.Group) → list[tuple[str, dict[str, Any]]]

Read all heliostats stored in the legacy layout, with one HDF5 group per heliostat, as flattened parameters.

Parameters

heliostats_configh5py.Group

The heliostat group of the scenario file.

Returns

list[tuple[str, dict[str, Any]]]

The name and the flattened parameters of each heliostat.

artist.io.h5_columnar_heliostats.read_heliostat_columns(heliostats_config: h5py.Group) → list[dict[str, numpy.ndarray]]

Read the heliostats of a scenario file in the columnar layout, whichever layout the file uses.

Heliostats in the legacy layout are arranged in columns while reading. If their parameters differ in shape, e.g., because their surfaces have different numbers of control points, each heliostat is arranged on its own.

Parameters

heliostats_configh5py.Group

The heliostat group of the scenario file.

Raises

ColumnarLayoutError

If a heliostat in the legacy layout contains parameters that are missing or unknown.

Returns

list[dict[str, np.ndarray]]

One or more sets of columns, each mapping the path of a dataset relative to the heliostat group to its data. Together they contain all heliostats, sorted by name.

artist.io.h5_columnar_heliostats.read_kinematics_deviations(columns: dict[str, numpy.ndarray]) → tuple[torch.Tensor, torch.Tensor, dict[str, torch.Tensor]]

Read the rigid body deviations of all heliostats with individual kinematics onto the CPU.

Missing deviations default to zero.

Parameters

columnsdict[str, np.ndarray]

The heliostat columns.

Returns

torch.Tensor

The translation deviations. Shape is [number_of_heliostats_with_kinematics, 9].

torch.Tensor

The rotation deviations. Shape is [number_of_heliostats_with_kinematics, 4].

dict[str, torch.Tensor]

For each deviation, which heliostats with individual kinematics miss it. Shape is [number_of_heliostats_with_kinematics].

artist.io.h5_columnar_heliostats.read_actuator_parameters(columns: dict[str, numpy.ndarray], actuator_type: str) → tuple[torch.Tensor, torch.Tensor, dict[str, torch.Tensor]]

Read the parameters of all heliostats with individual actuators onto the CPU, as actuators of one type.

Missing parameters default to zero. For linear actuators, the initial angle of the first actuator is corrected for the orientation of the surface, as in h5_scenario_parser.linear_actuators().

Parameters

columnsdict[str, np.ndarray]

The heliostat columns.

actuator_typestr

The actuator type.

Raises

ValueError

If the actuator type is unknown.

Returns

torch.Tensor

The non-optimizable parameters. Shape is [number_of_heliostats_with_actuators, number_of_parameters, number_of_actuators].

torch.Tensor

The optimizable parameters. Shape is [number_of_heliostats_with_actuators, 2, number_of_actuators] for linear actuators.

dict[str, torch.Tensor]

For each linear actuator parameter, which actuators of the heliostats miss it. Shape is [number_of_heliostats_with_actuators, number_of_actuators].

artist.io.h5_columnar_heliostats.convert_scenario_to_columnar(input_path: pathlib.Path | str, output_path: pathlib.Path | str) → None

Convert a scenario file with heliostats in the legacy layout to the columnar layout.

Everything apart from the heliostats is copied unchanged. Scenarios in the columnar layout load faster, especially for large heliostat fields, and yield exactly the same scenario.

Parameters

input_pathpathlib.Path | str

The scenario file with heliostats in the legacy layout.

output_pathpathlib.Path | str

The file to write the converted scenario to. It must differ from the input file.

Raises

ValueError

If the heliostats of the input file are already stored in the columnar layout, or input and output are the same file.

ColumnarLayoutError

If the heliostats cannot be stored in the columnar layout.