Skip to content

Commit 1a3bb80

Browse files
author
Cristian Lussana
committed
added structure functions and R_optimal_... functions
1 parent 1acb6dc commit 1a3bb80

File tree

5 files changed

+820
-19
lines changed

5 files changed

+820
-19
lines changed

include/gridpp.h

Lines changed: 106 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,36 @@ namespace gridpp {
293293
int max_points,
294294
bool allow_extrapolation=true);
295295

296+
/** Optimal interpolation for an ensemble point field (R bindings)
297+
* See Lussana et al 2019 (DOI: 10.1002/qj.3646)
298+
* @param bpoints Points of background field
299+
* @param background 2D vector of background values (L, E)
300+
* @param obs_points Observation points
301+
* @param obs 1D vector of observations
302+
* @param obs_standard_deviations 1D vector of observation standard deviations
303+
* @param background_at_points 2D vector of background at observation points (L, E)
304+
* @param which_structfun structure function to use (0=Barnes;1=MixA)
305+
* @param dh length scale for the horizontal structure function
306+
* @param dz length scale for the vertical structure function
307+
* @param dw minimum value of the correlation coefficient for laf structure function
308+
* @param max_points Maximum number of observations to use inside localization zone; Use 0 to disable
309+
* @param allow_extrapolation Allow OI to extrapolate increments outside increments at observations
310+
* @returns 2D vector of analised values (L, E)
311+
*/
312+
vec2 R_optimal_interpolation_ensi(const Points& bpoints,
313+
const vec2& background,
314+
const Points& obs_points,
315+
const vec& obs,
316+
const vec& obs_standard_deviations,
317+
const vec2& background_at_points,
318+
/* const StructureFunction& structure, */
319+
int which_structfun,
320+
float dh,
321+
float dz,
322+
float dw,
323+
int max_points,
324+
bool allow_extrapolation=true);
325+
296326
/** Optimal interpolation for an ensemble gridded field (alternative version)
297327
* Work in progress
298328
* @param bgrid Grid of background field
@@ -324,33 +354,35 @@ namespace gridpp {
324354
int max_points,
325355
bool allow_extrapolation=true); */
326356

327-
/** Optimal interpolation for an ensemble gridded field (alternative version)
357+
/** Optimal interpolation for an ensemble gridded field (alternative version that works with R bindings)
328358
* Work in progress
329-
* @param bgrid Grid of background field
330-
* @param background 3D vector of (left) background values to update (Y, X, E)
331-
* @param background 3D vector of (LEFT) background values (Y, X, E) used to compute correlations
332-
* @param obs_points observation points
333-
* @param obs 2D vector of perturbed observations (S, E)
334-
* @param background 3D vector of (right) background values used to compute innovations (Y, X, E)
335-
* @param background 3D vector of (RIGHT) background values (Y, X, E) used to compute correlations
336-
* @param dh structure Structure function par 1
337-
* @param dz structure Structure function par 2
338-
* @param dw structure Structure function par 3
359+
* @param bpoints Points of background field
360+
* @param background 2D vector of (left) background values to update (M, E) M=num. grid points
361+
* @param background 2D vector of (LEFT) background values (M, E) used to compute correlations
362+
* @param obs_points Observation points
363+
* @param obs 2D vector of perturbed observations (S, E) S=num. obs points
364+
* @param background 2D vector of (right) background values used to compute innovations (S, E)
365+
* @param background 2D vector of (RIGHT) background values (S, E) used to compute correlations
366+
* @param which_structfun structure function to use (0=Barnes;1=MixA)
367+
* @param dh length scale for the horizontal structure function
368+
* @param dz length scale for the vertical structure function
369+
* @param dw minimum value of the correlation coefficient for laf structure function
339370
* @param variance_ratio (ratio of observation to right background error variance)
340371
* @param standard deviation ratio (ratio of left to right background error standard deviation)
341372
* @param weight given to the analysis increment
342373
* @param max_points Maximum number of observations to use inside localization zone; Use 0 to disable
343374
* @param allow_extrapolation Allow OI to extrapolate increments outside increments at observations
344-
* @returns 3D vector of analised values (Y, X, E)
375+
* @returns 2D vector of analised values (M, E)
345376
*/
346-
vec2 optimal_interpolation_ensi_lr(const Points& bpoints,
377+
vec2 R_optimal_interpolation_ensi_lr(const Points& bpoints,
347378
const vec2& background_l,
348379
const vec2& background_L,
349380
const Points& obs_points,
350381
const vec2& obs,
351382
const vec2& pbackground_r,
352383
const vec2& pbackground_R,
353384
/* const StructureFunction& structure, */
385+
int which_structfun,
354386
float dh,
355387
float dz,
356388
float dw,
@@ -2000,6 +2032,34 @@ namespace gridpp {
20002032
* @returns Cressman rho
20012033
*/
20022034
float cressman_rho(float dist, float length) const;
2035+
2036+
/** Compactly supported second-order autoregressive correlation function
2037+
* @param dist Distance between points. Same units as 'length'
2038+
* @param length Length scale
2039+
* @returns SOAR rho
2040+
*/
2041+
float soar_rho(float dist, float length) const;
2042+
2043+
/** Compactly supported third-order autoregressive correlation function
2044+
* @param dist Distance between points. Same units as 'length'
2045+
* @param length Length scale
2046+
* @returns TOAR rho
2047+
*/
2048+
float toar_rho(float dist, float length) const;
2049+
2050+
/** Powerlaw correlation function
2051+
* @param dist Distance between points. Same units as 'length'
2052+
* @param length Length scale
2053+
* @returns powerlaw rho
2054+
*/
2055+
float powerlaw_rho(float dist, float length) const;
2056+
2057+
/** Linear correlation function
2058+
* @param normdist Normalized distance between points. Must be in the range -1 to 1.
2059+
* @param min Minimum allowed value for the correlation (if less than 0, the return 1)
2060+
* @returns linear rho
2061+
*/
2062+
float linear_rho(float normdist, float min) const;
20032063
float m_localization_distance;
20042064
};
20052065
class MultipleStructure: public StructureFunction {
@@ -2052,6 +2112,39 @@ namespace gridpp {
20522112
bool m_is_spatial;
20532113
};
20542114

2115+
/** Mix of structure functions based on distance(SOAR), elevation(Gauss), and land area fraction(linear) */
2116+
class MixAStructure: public StructureFunction {
2117+
public:
2118+
/** Structure function SOAR - Gaussian - Linear
2119+
* @param h: Horizontal decorrelation length >=0 [m] (SOAR)
2120+
* @param v: Vertical decorrelation length >=0 [m] (Gaussian). If 0, disable decorrelation.
2121+
* @param w: Land/sea decorrelation length >=0 [1] (Linear). If 0, disable decorrelation.
2122+
* @param hmax: Truncate horizontal correlation beyond this length [m]. If undefined, 3.64 * h.
2123+
*/
2124+
MixAStructure(float h, float v=0, float w=0, float hmax=MV);
2125+
2126+
/** MixA structure function where decorrelation varyies spatially
2127+
* @param grid: Grid of decorrelation field
2128+
* @param h: 2D vector of horizontal decorrelation lengths >=0 (SOAR) , same size as grid [m]
2129+
* @param v: 2D vector of Vertical decorrelation lengths >=0 [m] (Gaussian). Set all to 0 to disable decorrelation.
2130+
* @param w: 2D vector of land/sea decorrelation lengths >=0 [1] (Linear). Set all to 0 to disable decorrelation.
2131+
* @param min_rho: Truncate horizontal correlation when rho is less than this value [m].
2132+
*/
2133+
MixAStructure(Grid grid, vec2 h, vec2 v, vec2 w, float min_rho=StructureFunction::default_min_rho);
2134+
float corr(const Point& p1, const Point& p2) const;
2135+
vec corr(const Point& p1, const std::vector<Point>& p2) const;
2136+
StructureFunctionPtr clone() const;
2137+
float localization_distance(const Point& p) const;
2138+
private:
2139+
float localization_distance(float h) const;
2140+
Grid m_grid;
2141+
vec2 mH;
2142+
vec2 mV;
2143+
vec2 mW;
2144+
float m_min_rho;
2145+
bool m_is_spatial;
2146+
};
2147+
20552148
/** Simple structure function based on distance, elevation, and land area fraction */
20562149
class CressmanStructure: public StructureFunction {
20572150
public:

0 commit comments

Comments
 (0)