artist.io.h5_columnar_heliostats ================================ .. py:module:: artist.io.h5_columnar_heliostats Attributes ---------- .. autoapisummary:: artist.io.h5_columnar_heliostats.required_fields artist.io.h5_columnar_heliostats.optional_fields artist.io.h5_columnar_heliostats.string_fields artist.io.h5_columnar_heliostats.rigid_body_deviations artist.io.h5_columnar_heliostats.linear_actuator_parameters Exceptions ---------- .. autoapisummary:: artist.io.h5_columnar_heliostats.ColumnarLayoutError Functions --------- .. autoapisummary:: artist.io.h5_columnar_heliostats.is_columnar artist.io.h5_columnar_heliostats.heliostat_columns artist.io.h5_columnar_heliostats._component_columns artist.io.h5_columnar_heliostats._to_numpy artist.io.h5_columnar_heliostats._to_str artist.io.h5_columnar_heliostats.write_columnar_heliostats artist.io.h5_columnar_heliostats.read_legacy_heliostats artist.io.h5_columnar_heliostats.read_heliostat_columns artist.io.h5_columnar_heliostats.read_kinematics_deviations artist.io.h5_columnar_heliostats.read_actuator_parameters artist.io.h5_columnar_heliostats.convert_scenario_to_columnar Module Contents --------------- .. py:data:: required_fields The parameters every heliostat, facet, kinematics, and actuator must have, per component. .. py:data:: optional_fields The group of scalar parameters per component that may be missing, which are stored as NaN. .. py:data:: string_fields The parameters that are stored as strings. .. py:data:: rigid_body_deviations Index and name of each translation and each rotation deviation parameter of the rigid body kinematics. .. py:data:: linear_actuator_parameters Index and name of each non-optimizable and each optimizable linear actuator parameter. .. py:exception:: ColumnarLayoutError Bases: :py:obj:`ValueError` Initialize self. See help(type(self)) for accurate signature. .. py:function:: is_columnar(heliostats_config: h5py.Group) -> bool Check whether the heliostats of a scenario file are stored in the columnar layout. Parameters ---------- heliostats_config : h5py.Group The heliostat group of the scenario file. Returns ------- bool Whether the heliostats are stored in the columnar layout. .. py:function:: 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 ---------- heliostats : Sequence[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. .. py:function:: _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 ---------- component : str The component, i.e., ``""`` for heliostat-level parameters, surface, kinematics, or actuators. rows : list[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. .. py:function:: _to_numpy(value: Any) -> numpy.ndarray Convert a parameter value, i.e., a tensor, NumPy array, or Python scalar, to a NumPy array. Parameters ---------- value : Any The value. Returns ------- np.ndarray The value as a NumPy array. .. py:function:: _to_str(value: Any) -> str Convert a string parameter value, which may be stored as bytes or a NumPy scalar, to a string. Parameters ---------- value : Any The value. Returns ------- str The value as a string. .. py:function:: 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_config : h5py.Group The empty heliostat group of the scenario file. columns : dict[str, np.ndarray] The path of each dataset relative to the heliostat group and its data. .. py:function:: 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_config : h5py.Group The heliostat group of the scenario file. Returns ------- list[tuple[str, dict[str, Any]]] The name and the flattened parameters of each heliostat. .. py:function:: 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_config : h5py.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. .. py:function:: 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 ---------- columns : dict[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]``. .. py:function:: 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 ---------- columns : dict[str, np.ndarray] The heliostat columns. actuator_type : str 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]``. .. py:function:: 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_path : pathlib.Path | str The scenario file with heliostats in the legacy layout. output_path : pathlib.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.