Package References¶
Base class¶
-
class
hydrointerp.
Interp
(grid_data=None, grid_time_name=None, grid_x_name=None, grid_y_name=None, grid_data_name=None, grid_crs=None, point_data=None, point_time_name=None, point_x_name=None, point_y_name=None, point_data_name=None, point_crs=None)¶ Base Interp class to prepare the input data for the interpolation functions.
- Parameters
data (DataFrame or Dataset) – A pandas DataFrame containing four columns as shown in the below parameters or an Xarray Dataset.
time_name (str) – If grid is a DataFrame, then time_name is the time column name. If grid is a Dataset, then time_name is the time coordinate name.
x_name (str) – If grid is a DataFrame, then x_name is the x column name. If grid is a Dataset, then x_name is the x coordinate name.
y_name (str) – If grid is a DataFrame, then y_name is the y column name. If grid is a Dataset, then y_name is the y coordinate name.
data_name (str) – If grid is a DataFrame, then data_name is the data column name. If grid is a Dataset, then data_name is the data variable name.
from_crs (int or str or None) –
The projection info for the input data if the result should be reprojected to the to_crs projection (either a proj4 str or epsg int).
- returns
- rtype
Interp object
Nan interpolator¶
-
Interp.
_grid_interp_na
(method='linear', min_val=None, inplace=True)¶ Function to fill nan’s in the grid_data to make it complete. Necessary for grid_to_* functions.
- Parameters
method (str) – The scipy griddata interpolation method to be applied. Options are ‘nearest’, ‘linear’, and ‘cubic’. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html for more details.
min_val (int, float, or None) – The minimum value for the results. All results below min_val will be assigned min_val.
inplace (bool) – Should the new grid overwrite the grid_data from initialisation?
- Returns
- Return type
Xarray Dataset
Base interpolators¶
-
Interp.
_grid_to_grid
(grid_res, to_crs=None, bbox=None, order=3, extrapolation='constant', fill_val=nan, digits=2, min_val=None)¶ Function to interpolate regularly or irregularly spaced values over many time stamps. Each time stamp of spatial values are interpolated independently (2D interpolation as opposed to 3D interpolation). Returns an xarray Dataset with the 3 dimensions. Uses the scipy interpolation function called map_coordinates.
- Parameters
grid_res (int or float) – The resulting grid resolution in the unit of the final projection (usually meters or decimal degrees).
to_crs (int or str or None) – The projection for the output data similar to from_crs.
bbox (tuple of int or float) – The bounding box for the output interpolation in the to_crs projection. None will return a similar grid extent as the input. The tuple should contain four ints or floats in the following order: (x_min, x_max, y_min, y_max)
order (int) – The order of the spline interpolation, default is 3. The order has to be in the range 0-5. An order of 1 is linear interpolation.
extrapolation (str) – The equivalent of ‘mode’ in the map_coordinates function. Options are: ‘constant’, ‘nearest’, ‘reflect’, ‘mirror’, and ‘wrap’. Most reseaonable options for this function will be either ‘constant’ or ‘nearest’. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html for more details.
fill_val (int or float) – If ‘constant’ if passed to the extrapolation parameter, fill_val assigns the value outside of the boundary. Defaults to numpy.nan.
digits (int) – The number of digits to round the output.
min_val (int, float, or None) – The minimum value for the results. All results below min_val will be assigned min_val.
- Returns
- Return type
xarray Dataset
-
Interp.
_points_to_grid
(grid_res, to_crs=None, bbox=None, method='linear', extrapolation='contstant', fill_val=nan, digits=2, min_val=None)¶ Function to take a dataframe of point value inputs (df) and interpolate to a grid. Uses the scipy griddata function for interpolation.
- Parameters
grid_res (int or float) – The resulting grid resolution in the unit of the final projection (usually meters or decimal degrees).
to_crs (int or str or None) – The projection for the output data similar to from_crs.
bbox (tuple of int or float) – The bounding box for the output interpolation in the to_crs projection. None will return a similar grid extent as the input. The tuple should contain four ints or floats in the following order: (x_min, x_max, y_min, y_max)
method (str) –
The scipy griddata interpolation method to be applied. Options are ‘nearest’, ‘linear’, and ‘cubic’. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html for more details.
extrapolation (str) – Either ‘constant’ or ‘nearest’.
fill_val (int or float) – If ‘constant’ if passed to the extrapolation parameter, fill_val assigns the value outside of the boundary. Defaults to numpy.nan.
digits (int) – The number of digits to round the output.
min_val (int, float, or None) –
The minimum value for the results. All results below min_val will be assigned min_val.
- returns
- rtype
xarray Dataset
-
Interp.
_grid_to_points
(point_data, to_crs=None, bbox=None, order=3, digits=2, min_val=None)¶ Function to take a dataframe of point value inputs (df) and interpolate to other points (point_data). Uses the scipy griddata function for interpolation.
- Parameters
point_data (str or DataFrame) – Path to geometry file of points to be interpolated (e.g. shapefile). Can be any file type that fiona/gdal can open. It can also be a DataFrame with ‘x’ and ‘y’ columns and the crs must be the same as to_crs.
to_crs (int or str or None) – The projection for the output data similar to from_crs.
bbox (tuple of int or float) – The bounding box for the output interpolation in the to_crs projection. None will return a similar grid extent as the input. The tuple should contain four ints or floats in the following order: (x_min, x_max, y_min, y_max)
order (int) – The order of the spline interpolation, default is 3. The order has to be in the range 0-5. An order of 1 is linear interpolation.
digits (int) – The number of digits to round the output.
min_val (int, float, or None) – The minimum value for the results. All results below min_val will be assigned min_val.
- Returns
- Return type
DataFrame
-
Interp.
_points_to_points
(point_data, to_crs=None, method='linear', digits=2, min_val=None)¶ Function to interpolate regularly or irregularly spaced values over many time stamps. Each time stamp of spatial values are interpolated independently (2D interpolation as opposed to 3D interpolation). Returns an xarray Dataset with the 3 dimensions. Uses the scipy interpolation function called map_coordinates.
- Parameters
point_data (str or DataFrame) – Path to geometry file of points to be interpolated (e.g. shapefile). Can be any file type that fiona/gdal can open. It can also be a DataFrame with ‘x’ and ‘y’ columns and the crs must be the same as to_crs.
to_crs (int or str or None) – The projection for the output data similar to from_crs.
method (str) – The scipy griddata interpolation method to be applied. Options are ‘nearest’, ‘linear’, and ‘cubic’.
digits (int) – The number of digits to round the output.
min_val (int, float, or None) – The minimum value for the results. All results below min_val will be assigned min_val.
- Returns
- Return type
DataFrame
Adjust grid from points¶
-
Interp.
_adjust_grid_from_points
(grid_res=None, to_crs=None, order=2, method='linear', digits=2, min_val=0)¶ Method to adjust a grid by forcing it through point data.
- Parameters
grid_res (int, float, or None) – The resulting grid resolution in the unit of the final projection (usually meters or decimal degrees).
to_crs (int or str or None) – The projection for the output data similar to from_crs.
order (int) – The order of the spline interpolation, default is 3. The order has to be in the range 0-5. An order of 1 is linear interpolation.
method (str) –
The scipy griddata interpolation method to be applied. Options are ‘nearest’, ‘linear’, and ‘cubic’. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html for more details.
digits (int) – The number of digits to round the output.
min_val (int, float, or None) – The minimum value for the results. All results below min_val will be assigned min_val.
- Returns
- Return type
Dataset
-
Interp.
_validate_grid_from_points
(test_perc=0.1, grid_res=None, to_crs=None, order=2, method='linear', digits=2, min_val=0)¶ Method to validate a grid created by the adjust_grid_from_points method.
- Parameters
grid_res (int, float, or None) – The resulting grid resolution in the unit of the final projection (usually meters or decimal degrees).
to_crs (int or str or None) – The projection for the output data similar to from_crs.
order (int) – The order of the spline interpolation, default is 3. The order has to be in the range 0-5. An order of 1 is linear interpolation.
method (str) –
The scipy griddata interpolation method to be applied. Options are ‘nearest’, ‘linear’, and ‘cubic’. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html for more details.
digits (int) – The number of digits to round the output.
min_val (int, float, or None) – The minimum value for the results. All results below min_val will be assigned min_val.
- Returns
- Return type
DataFrame