smash.PrecipitationIndices.to_numpy#
- PrecipitationIndices.to_numpy(axis=0)[source]#
Convert the
PrecipitationIndicesobject to anumpy.ndarray.The attribute arrays are stacked along a user-specified axis of the resulting array in alphabetical order based on the names of the precipitation indices (
'd1','d2','hg','std','vg').- Parameters:
- axisint, default 0
The axis along which the precipitation arrays will be joined.
- Returns:
- res
numpy.ndarray It returns the
PrecipitationIndicesobject as anumpy.ndarray.
- res
Examples
>>> from smash.factory import load_dataset >>> setup, mesh = load_dataset("cance") >>> model = smash.Model(setup, mesh)
Compute precipitation indices
>>> prcp_ind = smash.precipitation_indices(model)
Convert the result to a
numpy.ndarray>>> prcp_ind_np = prcp_ind.to_numpy(axis=-1) >>> prcp_ind_np array([[[nan, nan, nan, nan, nan], [nan, nan, nan, nan, nan], [nan, nan, nan, nan, nan], ..., [nan, nan, nan, nan, nan], [nan, nan, nan, nan, nan], [nan, nan, nan, nan, nan]]], dtype=float32)
>>> prcp_ind_np.shape (3, 1440, 5)
Access a specific precipitation indice
>>> prcp_ind_keys = sorted(["std", "d1", "d2", "vg", "hg"]) >>> ind = prcp_ind_keys.index("d1") >>> ind 0
>>> prcp_ind_np[..., ind] array([[nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan]], dtype=float32)