voxcity.ioΒΆ
Persistence functions for VoxCity models and simulation results.
Provides:
- save_voxcity / load_voxcity β pickle-based VoxCity model I/O
- save_h5 / load_h5 β HDF5-based VoxCity model I/O (recommended)
- save_results_h5 / load_results_h5 β HDF5-based combined model + results I/O
FunctionsΒΆ
|
Load a VoxCity instance from a file. |
|
Save a VoxCity instance to disk. |
|
Save a VoxCity model to an HDF5 file (no simulation results). |
|
Load a VoxCity model from an HDF5 file. |
|
Save a VoxCity model and simulation results to an HDF5 file. |
|
Load a VoxCity model and simulation results from an HDF5 file. |
Module ContentsΒΆ
- voxcity.io.load_voxcity(input_path, *, trusted: bool = False)[source]ΒΆ
Load a VoxCity instance from a file.
The format is detected automatically based on the file extension:
.h5/.hdf5β safe HDF5 format (no warning).Anything else (e.g.
.pkl) β legacy pickle format.
Warning
Pickle files can execute arbitrary code on load. Only load files you created yourself or received from a trusted source. Pass
trusted=Trueto suppress this warning.- Parameters:
input_path (str or Path) β Path to the file.
trusted (bool, default False) β (Pickle only) Set to
Trueto acknowledge the security implications of loading a pickle file and suppress the warning.
- Return type:
- voxcity.io.save_voxcity(output_path, city)[source]ΒΆ
Save a VoxCity instance to disk.
The format is chosen automatically based on the file extension:
.h5/.hdf5β safe HDF5 format (recommended).Anything else (e.g.
.pkl) β legacy pickle format.
- Parameters:
output_path (str or Path) β Destination file path.
city (VoxCity) β The model to save.
- voxcity.io.save_h5(output_path, city)[source]ΒΆ
Save a VoxCity model to an HDF5 file (no simulation results).
This is the recommended alternative to
save_voxcity()(pickle-based) because HDF5 files cannot execute arbitrary code on load.- Parameters:
output_path (str or Path) β Destination file path (e.g.
"model.h5").city (VoxCity) β The VoxCity model instance.
See also
load_h5Load a VoxCity model from an HDF5 file.
save_results_h5Save a VoxCity model together with simulation results.
- voxcity.io.load_h5(input_path)[source]ΒΆ
Load a VoxCity model from an HDF5 file.
This is the safe counterpart to
load_voxcity()(pickle-based). Works with files written by eithersave_h5()orsave_results_h5()β simulation result groups are simply ignored.- Parameters:
input_path (str or Path) β Path to the HDF5 file.
- Returns:
The reconstructed VoxCity model.
- Return type:
See also
save_h5Save a VoxCity model to an HDF5 file.
load_results_h5Load a VoxCity model together with simulation results.
- voxcity.io.save_results_h5(output_path, city, ground_results=None, building_results=None, simulation_results=None)[source]ΒΆ
Save a VoxCity model and simulation results to an HDF5 file.
- Parameters:
output_path (str) β Destination file path (e.g.
"results.h5").city (VoxCity) β The VoxCity model instance.
ground_results (dict, optional) β
Ground-level simulation results. Keys whose values are
numpy.ndarrayare stored as HDF5 datasets (with gzip compression); all other JSON-serializable values are stored as group attributes.Typical keys produced by the GPU solar integration module:
{ 'sunlight_hours': np.ndarray (ny, nx), 'cumulative_global': np.ndarray (ny, nx), 'svf': np.ndarray (ny, nx), 'potential_sunlight_hours': float, 'mode': str, ... }
If the input numpy array carries a
.metadatadict (e.g.ArrayWithMetadata), those metadata entries are also persisted as sub-attributes.building_results (dict, optional) β
Building-surface simulation results. The dict must contain a
'mesh'key whose value is a Trimesh object. Per-face data arrays are taken either from the'metadata'sub-dict or directly from the Trimeshβs.metadataattribute.Typical keys produced by the GPU solar integration module:
{ 'mesh': trimesh.Trimesh, 'metadata': { 'irradiance_direct': np.ndarray (n_faces,), 'irradiance_diffuse': np.ndarray (n_faces,), 'sunlight_hours': np.ndarray (n_faces,), 'potential_sunlight_hours': float, ... }, }
If
'metadata'is not provided explicitly, the function falls back tomesh.metadata.simulation_results (dict, optional) β
Multiple named simulation results grouped by simulation type. The recommended structure is:
{ 'ground': { 'solar_cumulative': {'cumulative_global': array, ...}, 'sunlight_hours_dsh': {'sunlight_hours': array, ...}, }, 'building_surface': { 'solar_cumulative': trimesh_obj, 'sky_view_factor': {'mesh': trimesh_obj, 'metadata': {...}}, }, }
Supported simulation types are
'ground'and'building_surface'. The legacyground_resultsandbuilding_resultsarguments remain supported for saving one unnamed/default result of each type.
Notes
Requires the
h5pypackage (pip install h5py).The file is self-contained β no pickle dependency at load time.
Datasets use
compression='gzip'by default for compact files.
- voxcity.io.load_results_h5(input_path)[source]ΒΆ
Load a VoxCity model and simulation results from an HDF5 file.
- Parameters:
input_path (str) β Path to the HDF5 file created by
save_results_h5().- Returns:
A dictionary with the following keys:
'voxcity'The reconstructed
VoxCityinstance.'ground'(if present)dict mapping dataset names to numpy arrays, plus scalar metadata entries.
'building'(if present)dict with
'mesh_vertices','mesh_faces','mesh_face_normals'(numpy arrays) and per-face data arrays / scalar metadata.'simulations'(if present)nested dict of named simulation results grouped by simulation type, e.g.
data['simulations']['ground']['solar_cumulative']ordata['simulations']['building_surface']['sky_view_factor']. Legacy top-level'ground'and'building'groups are also exposed as'default'entries in this nested structure.'meta'dict with
'crs','meshsize','bounds'.
- Return type:
dict
Notes
The returned
'voxcity'object is a fully reconstructedVoxCitydataclass β it can be passed directly to any simulator or visualizer function.