smash.sparse_vector_to_matrix#

smash.sparse_vector_to_matrix(mesh, vector)[source]#

Convert a NumPy 1D array respecting the order of the sparse storage to a 2D array.

Note

To avoid a memory overflow, the atmospheric forcings and simulated discharges can be sparse stored by precising it in the Model initialization setup dictionary (sparse_storage = True). It allows to store for each time step a 1D array whose size is the number of active cells instead of storing the whole rectangular domain. O(nrow * ncol) -> O(nac) with nac < nrow * ncol.

Parameters:
meshMeshDT, the Model mesh attributes (see Model.mesh).
vectorNumPy 1D array.

The 1D array respecting the order of the sparse storage of shape (nac).

Returns:
matrixNumPy 2D array.

The 2D array of shape (nrow, ncol). Non active cells are filled in with NaN.

Examples

>>> setup, mesh = smash.load_dataset("cance")

Precise the sparse storage in the setup.

>>> setup["sparse_storage"] = True
>>> model = smash.Model(setup, mesh)

Access to the precipitation at time step 0 with sparse storing.

>>> sparse_prcp = model.input_data.sparse_prcp[:,0]
>>> sparse_prcp.size, sparse_prcp.shape, model.mesh.nac
(383, (383,), 383)

Convert to a 2D array.

>>> prcp = smash.sparse_vector_to_matrix(model.mesh, sparse_prcp)
>>> prcp.size, prcp.shape, model.mesh.nrow * model.mesh.ncol
(784, (28, 28), 784)