amisc.compression
Module for compression methods.
Especially useful for field quantities with high dimensions.
Includes:
Compression— an interface for specifying a compression method for field quantities.SVD— a Singular Value Decomposition (SVD) compression method.
Compression(fields=list(), method='svd', coords=None, interpolate_method='rbf', interpolate_opts=dict(), _map_computed=False)
dataclass
Bases: PickleSerializable, ABC
Base class for compression methods. Compression methods should:
compute_map- compute the compression map from provided datacompress- compress data into a latent spacereconstruct- reconstruct the compressed data back into the full spacelatent_size- return the size of the latent spaceestimate_latent_ranges- estimate the range of the latent space coefficients
Specifying fields
The fields attribute is a list of strings that specify the field quantities to compress. For example, for
3D velocity data, the fields might be ['ux', 'uy', 'uz']. The length of the
fields attribute is used to determine the number of quantities of interest at each grid point in coords.
Note that interpolation to/from the compression grid will assume a shape of (num_pts, num_qoi) for the
states on the grid, where num_qoi is the length of fields and num_pts is the length of coords. When
constructing the compression map, this important fact should be considered when passing data to
compute_map.
In order to use a Compression object, you must first call compute_map to compute the compression map, which
should set the private value self._map_computed=True. The coords of the compression grid must also be
specified. The coords should have the shape (num_pts, dim) where num_pts is the number of points in the
compression grid and dim is the number of spatial dimensions. If coords is a 1d array, then the dim is
assumed to be 1.
| ATTRIBUTE | DESCRIPTION |
|---|---|
fields |
list of field quantities to compress
TYPE:
|
method |
the compression method to use (only svd is supported for now)
TYPE:
|
coords |
the coordinates of the compression grid
TYPE:
|
interpolate_method |
the interpolation method to use to interpolate to/from the compression grid (only
TYPE:
|
interpolate_opts |
additional options to pass to the interpolation method
TYPE:
|
_map_computed |
whether the compression map has been computed
TYPE:
|
dim
property
Number of physical grid coordinates for the field quantity, (i.e. x,y,z spatial dims)
dof
property
Total degrees of freedom in the compression grid (i.e. num_pts * num_qoi).
map_exists
property
All compression methods should have coords when their map has been constructed.
num_pts
property
Number of physical points in the compression grid.
num_qoi
property
Number of quantities of interest at each grid point, (i.e. ux, uy, uz for 3d velocity data).
compress(data)
abstractmethod
Compress the data into a latent space.
| PARAMETER | DESCRIPTION |
|---|---|
data |
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
|
Source code in src/amisc/compression.py
compute_map(**kwargs)
abstractmethod
Compute and store the compression map. Must set the value of coords and _is_computed. Should
use the same normalization as the parent Variable object.
Note
You should pass any required data to compute_map with the assumption that the data will be used in the
shape (num_pts, num_qoi) where num_qoi is the length of fields and num_pts is the length of
coords. This is the shape that the compression map should be constructed in.
Source code in src/amisc/compression.py
estimate_latent_ranges()
abstractmethod
from_dict(spec)
classmethod
Construct a Compression object from a spec dictionary.
Source code in src/amisc/compression.py
interpolate_from_grid(states, new_coords)
Interpolate the states on the compression grid to new coordinates.
| PARAMETER | DESCRIPTION |
|---|---|
states |
TYPE:
|
new_coords |
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in src/amisc/compression.py
interpolate_to_grid(field_coords, field_values)
Interpolate the field values at given coordinates to the compression grid. An array of nan is returned for any coordinates or field values that are empty or None.
| PARAMETER | DESCRIPTION |
|---|---|
field_coords |
TYPE:
|
field_values |
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in src/amisc/compression.py
interpolator()
The interpolator to use during compression and reconstruction. Interpolator expects to be used as:
xg = np.ndarray # (num_pts, dim) grid coordinates
yg = np.ndarray # (num_pts, ...) scalar values on grid
xp = np.ndarray # (Q, dim) evaluation points
interp = interpolate_method(xg, yg, **interpolate_opts)
yp = interp(xp) # (Q, ...) interpolated values
Source code in src/amisc/compression.py
latent_size()
abstractmethod
reconstruct(compressed)
abstractmethod
Reconstruct the compressed data back into the full dof space.
| PARAMETER | DESCRIPTION |
|---|---|
compressed |
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
|
Source code in src/amisc/compression.py
SVD(fields=list(), method='svd', coords=None, interpolate_method='rbf', interpolate_opts=dict(), _map_computed=False, data_matrix=None, projection_matrix=None, rank=None, energy_tol=None, reconstruction_tol=None)
dataclass
Bases: Compression
A Singular Value Decomposition (SVD) compression method. The SVD will be computed on initialization if the
data_matrix is provided.
| ATTRIBUTE | DESCRIPTION |
|---|---|
data_matrix |
TYPE:
|
projection_matrix |
TYPE:
|
rank |
the rank of the SVD decomposition
TYPE:
|
energy_tol |
the energy tolerance of the SVD decomposition
TYPE:
|
reconstruction_tol |
the reconstruction error tolerance of the SVD decomposition
TYPE:
|
compute_map(data_matrix, rank=None, energy_tol=None, reconstruction_tol=None)
Compute the SVD compression map from the data matrix. Recall that dof is the total number of degrees of
freedom, equal to the number of grid points num_pts times the number of quantities of interest num_qoi
at each grid point.
Rank priority: if rank is provided, then it will be used. Otherwise, if reconstruction_tol is provided,
then the rank will be chosen to meet this reconstruction error level. Finally, if energy_tol is provided,
then the rank will be chosen to meet this energy fraction level (sum of squared singular values).
| PARAMETER | DESCRIPTION |
|---|---|
data_matrix |
TYPE:
|
rank |
the rank of the SVD decomposition
TYPE:
|
energy_tol |
the energy tolerance of the SVD decomposition (defaults to 0.95)
TYPE:
|
reconstruction_tol |
the reconstruction error tolerance of the SVD decomposition
TYPE:
|