Spatio-Temporal Interpolation
Spatio-temporal interpolation module.
Support function to perform interpolation in various ways
interpolate(location_in=None, time_in=None, values_in=None, location_out=None, time_out=None, **kwargs)
Interpolates data based on input.
Interpolation using scipy.griddata function. Which in turn uses linear barycentric interpolation.
It is assumed that the shape of location_in, time_in and values_in is consistent
When time_out has the same size as number of rows of location_out, it is assumed these are aligned and be treated as consistent, hence the output will be a column vector. If this is not the case an interpolation will be performed for all combinations of rows in location out with times of time_out and output wil be shaped as [nof_location_values x dimension]
If location_out == None, we only perform temporal (1D) interpolation. If time_out == None we only perform spatial interpolation
If linear interpolation is not possible for spatio or spatiotemporal interpolation, we use nearest neighbor interpolation, a warning will be displayed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location_in
|
ndarray
|
Array of size [nof_values x dimension] with locations to interpolate from |
None
|
time_in
|
Union[ndarray, DatetimeArray]
|
Array of size [nof_values x 1] with timestamps or some form of time values (seconds) to interpolate from |
None
|
values_in
|
ndarray
|
Array of size [nof_values x 1] with values to interpolate from |
None
|
location_out
|
ndarray
|
Array of size [nof_location_values x dimension] with locations to interpolate to |
None
|
time_out
|
Union[ndarray, DatetimeArray]
|
Array of size [nof_time_values x 1] with timestamps or some form of time values (seconds) to interpolate to |
None
|
**kwargs
|
dict
|
Other keyword arguments which get passed into the griddata interpolation function |
{}
|
Returns:
Name | Type | Description |
---|---|---|
result |
ndarray
|
Array of size [nof_location_values x nof_time_values] with interpolated values |
Source code in src/pyelq/support_functions/spatio_temporal_interpolation.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
_sense_check_interpolate_inputs(location_in, time_in, values_in, location_out, time_out)
Helper function to sense check inputs and raise errors when applicable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location_in
|
ndarray
|
Array of size [nof_values x dimension] with locations to interpolate from |
required |
time_in
|
Union[ndarray, DatetimeArray]
|
Array of size [nof_values x 1] with timestamps or some form of time values (seconds) to interpolate from |
required |
values_in
|
ndarray
|
Array of size [nof_values x 1] with values to interpolate from |
required |
location_out
|
ndarray
|
Array of size [nof_location_values x dimension] with locations to interpolate to |
required |
time_out
|
Union[ndarray, DatetimeArray]
|
Array of size [nof_time_values x 1] with |
required |
Raises:
Type | Description |
---|---|
ValueError
|
When inputs do not match up. |
Source code in src/pyelq/support_functions/spatio_temporal_interpolation.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
_griddata(points_in, values, points_out, **kwargs)
Wrapped function to handle special cases around the gridded interpolate.
Will try nearest neighbour method when few enough points that spatial cases fail.
Syntax like scipy.griddata
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points_in
|
ndarray
|
2-D ndarray of floats with shape (n, D), or length D tuple of 1-D |
required |
values
|
ndarray
|
_ndarray of float or complex, shape (n,). Data values |
required |
points_out
|
ndarray
|
2-D ndarray of floats with shape (m, D), or length D tuple of nd-arrays broadcastable to the same shape. Points at which to interpolate data. |
required |
Returns:
Name | Type | Description |
---|---|---|
ndarray |
Array of interpolated values. |
Source code in src/pyelq/support_functions/spatio_temporal_interpolation.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
temporal_resampling(time_in, values_in, time_bin_edges, aggregate_function='mean', side='center')
Resamples data into a set of time bins.
Checks which values of time_in are withing 2 consecutive values of time_bin_edges and performs the aggregate function on the corresponding values from values_in. time_in values outside the time_bin_edges are ignored. Empty bins will be assigned a 'NaN' value.
When 'time_in' is a sequence of time stamps, a DatetimeArray should be used. Otherwise, a np.ndarray should be used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_in
|
Union[ndarray, DatetimeArray]
|
A vector of times which correspond to values_in. |
required |
values_in
|
ndarray
|
A vector of the values to be resampled. |
required |
time_bin_edges
|
Union[ndarray, DatetimeArray]
|
A vector of times which define the edges of the bins into which the data will be resampled. |
required |
aggregate_function
|
str
|
The function which is used to aggregate the data after it has been sorted into bins. Defaults to mean. |
'mean'
|
side
|
str
|
Which side of the time bins should be used to generate times_out. Possible values are: 'left', 'center', and 'right'. Defaults to 'center'. |
'center'
|
Returns:
Name | Type | Description |
---|---|---|
time_out |
Union[ndarray, DatetimeArray]
|
Vector-like object containing the times of the resampled values consistent with time_in dtype and side input argument. |
values_out |
ndarray
|
A vector of resampled values, according to the time bins and the aggregate function. |
Raises:
Type | Description |
---|---|
ValueError
|
If any of the input arguments are not of the correct type or shape, this error is raised. |
Source code in src/pyelq/support_functions/spatio_temporal_interpolation.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|