ARTS
2.2.66
|
Interpolation routines for special purposes. More...
#include <cmath>
#include <iostream>
#include <stdexcept>
#include "auto_md.h"
#include "check_input.h"
#include "math_funcs.h"
#include "messages.h"
#include "special_interp.h"
Go to the source code of this file.
Functions | |
void | interp_atmfield_gp2itw (Matrix &itw, const Index &atmosphere_dim, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon) |
interp_atmfield_gp2itw More... | |
void | interp_atmfield_by_itw (VectorView x, const Index &atmosphere_dim, ConstTensor3View x_field, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, ConstMatrixView itw) |
interp_atmfield_by_itw More... | |
void | interp_atmfield_by_gp (VectorView x, const Index &atmosphere_dim, ConstTensor3View x_field, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon) |
interp_atmfield_by_gp More... | |
Numeric | interp_atmfield_by_gp (const Index &atmosphere_dim, ConstTensor3View x_field, const GridPos &gp_p, const GridPos &gp_lat, const GridPos &gp_lon) |
interp_atmfield_by_gp More... | |
void | interp_cloudfield_gp2itw (VectorView itw, GridPos &gp_p_out, GridPos &gp_lat_out, GridPos &gp_lon_out, const GridPos &gp_p_in, const GridPos &gp_lat_in, const GridPos &gp_lon_in, const Index &atmosphere_dim, const ArrayOfIndex &cloudbox_limits) |
interp_cloudfield_gp2itw More... | |
void | interp_atmsurface_gp2itw (Matrix &itw, const Index &atmosphere_dim, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon) |
interp_atmsurface_gp2itw More... | |
void | interp_atmsurface_by_itw (VectorView x, const Index &atmosphere_dim, ConstMatrixView x_surface, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, ConstMatrixView itw) |
interp_atmsurface_by_itw More... | |
void | interp_atmsurface_by_gp (VectorView x, const Index &atmosphere_dim, ConstMatrixView x_surface, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon) |
interp_atmsurface_by_gp More... | |
Numeric | interp_atmsurface_by_gp (const Index &atmosphere_dim, ConstMatrixView x_surface, const GridPos &gp_lat, const GridPos &gp_lon) |
interp_atmsurface_by_gp More... | |
void | itw2p (VectorView p_values, ConstVectorView p_grid, const ArrayOfGridPos &gp, ConstMatrixView itw) |
itw2p More... | |
void | p2gridpos (ArrayOfGridPos &gp, ConstVectorView old_pgrid, ConstVectorView new_pgrid, const Numeric &extpolfac) |
p2gridpos More... | |
void | p2gridpos_poly (ArrayOfGridPosPoly &gp, ConstVectorView old_pgrid, ConstVectorView new_pgrid, const Index order, const Numeric &extpolfac) |
p2gridpos_poly More... | |
void | rte_pos2gridpos (GridPos &gp_p, GridPos &gp_lat, GridPos &gp_lon, const Index &atmosphere_dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View z_field, ConstVectorView rte_pos) |
rte_pos2gridpos More... | |
void | z_at_lat_2d (VectorView z, ConstVectorView p_grid, ConstVectorView lat_grid, ConstMatrixView z_field, const GridPos &gp_lat) |
z_at_lat_2d More... | |
void | z_at_latlon (VectorView z, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View z_field, const GridPos &gp_lat, const GridPos &gp_lon) |
z_at_latlon More... | |
void | complex_n_interp (MatrixView n_real, MatrixView n_imag, const GriddedField3 &complex_n, const String &varname, ConstVectorView f_grid, ConstVectorView t_grid) |
complex_n_interp More... | |
Interpolation routines for special purposes.
This file contains functions connected to interpolation of non-general character. The total general interpolation routines are found in interpolation.cc.
These interpolation functions interpolate a atmospheric/surface fields to a set of points, such as the points of a propagation path. That is, "blue" interpolation. The functions assume that the grid positions are at hand. If several atmospheric fields shall be interpolated, the functions to use are interp_atmfield_gp2itw and interp_atmfield_by_itw*, where the first function is called once and the second is called for each field to be interpolated. If only one field shall be interpolated, the function interp_atmfield_by_gp* is a shortcut for calling both functions above. There exist an identical set of functions for interpolating surface-type variables, with names where atmfield is replaced with atmsurface.
Possible surface-type variables are z_surface and one page of z_field.
To convert a geometric altitude to a pressure results in an interpolation of the pressure grid, or more exactly the log of the p_grid*. Such functions are placed in this file for that reason. These functions have names ending with "2p", for example itw2p.
Definition in file special_interp.cc.
void complex_n_interp | ( | MatrixView | n_real, |
MatrixView | n_imag, | ||
const GriddedField3 & | complex_n, | ||
const String & | varname, | ||
ConstVectorView | f_grid, | ||
ConstVectorView | t_grid | ||
) |
complex_n_interp
General function for interpolating data of complex n type.
See documentation of comples_refr_index for format of complex_n-.
n_real | Out: Real part [nf,nt] |
n_imag | Out: Imaginary part [nf,nt] |
complex_n | Complex refracton index data. |
varname | The name of complex_n to use in error message. |
f_grid | Output frequency grid [nf] |
t_grid | Output temperature grid [nt] |
Definition at line 880 of file special_interp.cc.
References GriddedField3::checksize_strict(), chk_griddedfield_gridname(), chk_interpolation_grids(), GriddedField3::data, GriddedField::get_numeric_grid(), gridpos(), interp(), interpweights(), joker, ConstTensor3View::ncols(), ConstMatrixView::ncols(), ConstVectorView::nelem(), ConstTensor3View::npages(), ConstTensor3View::nrows(), and ConstMatrixView::nrows().
Referenced by scat_data_arrayFromMeta(), and surfaceFlatRefractiveIndex().
void interp_atmfield_by_gp | ( | VectorView | x, |
const Index & | atmosphere_dim, | ||
ConstTensor3View | x_field, | ||
const ArrayOfGridPos & | gp_p, | ||
const ArrayOfGridPos & | gp_lat, | ||
const ArrayOfGridPos & | gp_lon | ||
) |
interp_atmfield_by_gp
Interpolates an atmospheric field given the grid positions.
The function performs the interpolation for a number of positions. The return variable (x) is accordingly a vector. The vector must be set to have the same length as the grid position arrays before calling the function.
The input atmospheric field is checked to be consistent with the atmosphere_dim*, p_grid, lat_grid and lon_grid. The length of the grid position arrays are asserted to be the identical, or for dimensions not used, that the length is zero.
x | Output: Values obtained by the interpolation. |
atmosphere_dim | As the WSV with the same name. |
x_field | The atmospheric field to be interpolated. |
gp_p | Pressure grid positions. |
gp_lat | Latitude grid positions. |
gp_lon | Longitude grid positions. |
Definition at line 215 of file special_interp.cc.
References interp_atmfield_by_itw(), and interp_atmfield_gp2itw().
Referenced by interp_atmfield_by_gp(), InterpAtmFieldToPosition(), and mcPathTraceIPA().
Numeric interp_atmfield_by_gp | ( | const Index & | atmosphere_dim, |
ConstTensor3View | x_field, | ||
const GridPos & | gp_p, | ||
const GridPos & | gp_lat, | ||
const GridPos & | gp_lon | ||
) |
interp_atmfield_by_gp
As the function above but return-numeric version.
Definition at line 240 of file special_interp.cc.
References gridpos_copy(), and interp_atmfield_by_gp().
void interp_atmfield_by_itw | ( | VectorView | x, |
const Index & | atmosphere_dim, | ||
ConstTensor3View | x_field, | ||
const ArrayOfGridPos & | gp_p, | ||
const ArrayOfGridPos & | gp_lat, | ||
const ArrayOfGridPos & | gp_lon, | ||
ConstMatrixView | itw | ||
) |
interp_atmfield_by_itw
Interpolates an atmospheric field with pre-calculated weights by interp_atmfield_gp2itw.
The function performs the interpolation for a number of positions. The return variable (x) is accordingly a vector. The vector must be set to have the same length as the grid position arrays before calling the function.
The input atmospheric field is checked to be consistent with the atmosphere_dim*, p_grid, lat_grid and lon_grid. The length of the grid position arrays are asserted to be the identical, or for dimensions not used, that the length is zero.
x | Output: Values obtained by the interpolation. |
atmosphere_dim | As the WSV with the same name. |
x_field | The atmospheric field to be interpolated. |
gp_p | Pressure grid positions. |
gp_lat | Latitude grid positions. |
gp_lon | Longitude grid positions. |
itw | Interpolation weights from interp_atmfield_gp2itw. |
Definition at line 159 of file special_interp.cc.
References interp(), joker, ConstMatrixView::ncols(), Array< base >::nelem(), and ConstVectorView::nelem().
Referenced by clear_rt_vars_at_gp(), cloud_atm_vars_by_gp(), get_ppath_atmvars(), get_ppath_ext(), interp_atmfield_by_gp(), and iy_auxFillParticleVariables().
void interp_atmfield_gp2itw | ( | Matrix & | itw, |
const Index & | atmosphere_dim, | ||
const ArrayOfGridPos & | gp_p, | ||
const ArrayOfGridPos & | gp_lat, | ||
const ArrayOfGridPos & | gp_lon | ||
) |
interp_atmfield_gp2itw
Converts atmospheric grid positions to weights for interpolation of an atmospheric field.
The function is intended for "blue" interpolation, that is, interpolation for a set of positions.
The output matrix for interpolation weights are resized inside the function.
The input atmospheric grids are checked to be consistent.
itw | Output: Interpolation weights. |
atmosphere_dim | As the WSV with the same name. |
gp_p | Pressure grid positions. |
gp_lat | Latitude grid positions. |
gp_lon | Longitude grid positions. |
Definition at line 99 of file special_interp.cc.
References interpweights(), Array< base >::nelem(), and Matrix::resize().
Referenced by clear_rt_vars_at_gp(), cloud_atm_vars_by_gp(), get_ppath_atmvars(), and interp_atmfield_by_gp().
void interp_atmsurface_by_gp | ( | VectorView | x, |
const Index & | atmosphere_dim, | ||
ConstMatrixView | x_surface, | ||
const ArrayOfGridPos & | gp_lat, | ||
const ArrayOfGridPos & | gp_lon | ||
) |
interp_atmsurface_by_gp
Interpolates a surface-type variable given the grid positions.
The function performs the interpolation for a number of positions. The return variable (x) is accordingly a vector. The vector must be set to have the same length as the grid position arrays before calling the function.
The input surface-type variable is checked to be consistent with the atmosphere_dim*, lat_grid and lon_grid. The length of the grid position arrays are asserted to be the identical, or for dimensions not used, that the length is zero.
x | Output: Values obtained by the interpolation. |
atmosphere_dim | As the WSV with the same name. |
x_surface | The atmospheric field to be interpolated. |
gp_lat | Latitude grid positions. |
gp_lon | Longitude grid positions. |
Definition at line 481 of file special_interp.cc.
References interp_atmsurface_by_itw(), and interp_atmsurface_gp2itw().
Referenced by interp_atmsurface_by_gp(), and InterpSurfaceFieldToPosition().
Numeric interp_atmsurface_by_gp | ( | const Index & | atmosphere_dim, |
ConstMatrixView | x_surface, | ||
const GridPos & | gp_lat, | ||
const GridPos & | gp_lon | ||
) |
interp_atmsurface_by_gp
As the function above, but return-numeric version.
Definition at line 504 of file special_interp.cc.
References gridpos_copy(), and interp_atmsurface_by_gp().
void interp_atmsurface_by_itw | ( | VectorView | x, |
const Index & | atmosphere_dim, | ||
ConstMatrixView | x_surface, | ||
const ArrayOfGridPos & | gp_lat, | ||
const ArrayOfGridPos & | gp_lon, | ||
ConstMatrixView | itw | ||
) |
interp_atmsurface_by_itw
Interpolates a surface-type variable with pre-calculated weights by interp_atmsurface_gp2itw.
The function performs the interpolation for a number of positions. The return variable (x) is accordingly a vector. The vector must be set to have the same length as the grid position arrays before calling the function.
The input surface-type variable is checked to be consistent with the atmosphere_dim*, lat_grid and lon_grid. The length of the grid position arrays are asserted to be the identical, or for dimensions not used, that the length is zero.
x | Output: Values obtained by the interpolation. |
atmosphere_dim | As the WSV with the same name. |
x_surface | The atmospheric field to be interpolated. |
gp_lat | Latitude grid positions. |
gp_lon | Longitude grid positions. |
itw | Interpolation weights from interp_atmsurface_gp2itw. |
Definition at line 427 of file special_interp.cc.
References interp(), joker, ConstMatrixView::ncols(), Array< base >::nelem(), and ConstVectorView::nelem().
Referenced by interp_atmsurface_by_gp().
void interp_atmsurface_gp2itw | ( | Matrix & | itw, |
const Index & | atmosphere_dim, | ||
const ArrayOfGridPos & | gp_lat, | ||
const ArrayOfGridPos & | gp_lon | ||
) |
interp_atmsurface_gp2itw
Converts atmospheric grid positions to weights for interpolation of a surface-type variable.
The function is intended for "blue" interpolation, that is, interpolation for a set of positions.
The output matrix for interpolation weights are resized inside the function.
The input atmospheric grids are checked to be consistent.
itw | Output: Interpolation weights. |
atmosphere_dim | As the WSV with the same name. |
gp_lat | Latitude grid positions. |
gp_lon | Longitude grid positions. |
Definition at line 371 of file special_interp.cc.
References interpweights(), Array< base >::nelem(), and Matrix::resize().
Referenced by interp_atmsurface_by_gp().
void interp_cloudfield_gp2itw | ( | VectorView | itw, |
GridPos & | gp_p_out, | ||
GridPos & | gp_lat_out, | ||
GridPos & | gp_lon_out, | ||
const GridPos & | gp_p_in, | ||
const GridPos & | gp_lat_in, | ||
const GridPos & | gp_lon_in, | ||
const Index & | atmosphere_dim, | ||
const ArrayOfIndex & | cloudbox_limits | ||
) |
interp_cloudfield_gp2itw
Converts atmospheric a grid position to weights for interpolation of a field defined ONLY inside the cloudbox.
That is, as interp_atmfield_gp2itw, but for cloudbox only variables.
The input grid position shall be with respect to total grids. If grid positions already refer to grid parts inside the cloudbox, you can use interp_atmfield_gp2itw.
The output grid positions are created by the function, to match the cloudbox field, and can be used for later calls of e.g. interp_atmfield_by_itw
itw | Output: Interpolation weights. Vector must be given correct size before call of function. |
gp_p_out | Output: Pressure cloudbox grid position. |
gp_lat_out | Output: Latitude cloudbox grid positionn. |
gp_lon_out | Output: Longitude cloudbox grid position. |
gp_p_in | Pressure grid position. |
gp_lat_in | Latitude grid position. |
gp_lon_in | Longitude grid position. |
atmosphere_dim | As the WSV with the same name. |
cloudbiox_limits | As the WSV with the same name. |
Definition at line 301 of file special_interp.cc.
References gridpos_copy(), gridpos_upperend_check(), GridPos::idx, interpweights(), and ConstVectorView::nelem().
Referenced by get_ppath_ext(), and iy_auxFillParticleVariables().
void itw2p | ( | VectorView | p_values, |
ConstVectorView | p_grid, | ||
const ArrayOfGridPos & | gp, | ||
ConstMatrixView | itw | ||
) |
itw2p
Converts interpolation weights to pressures.
The function takes interpolation weights calculated with respect to the vertical dimension, and determines the corresponding pressures. This function can be used when a geometrical altitude is known and the pressure for that altitude shall be determined. The interpolation weights are then calculated using the geometrical altitudes for the pressure levels for the position of concern.
This can be seen as a 1D "blue" interpolation. That means that the number of columns of itw shall be 2.
p_values | Output: Found pressure values. |
p_grid | As the WSV with the same name. |
gp | Altitude grid positions. |
itw | Interpolation weights |
Definition at line 561 of file special_interp.cc.
References interp(), ConstMatrixView::ncols(), ConstVectorView::nelem(), ConstMatrixView::nrows(), and transform().
Referenced by clear_rt_vars_at_gp(), cloud_atm_vars_by_gp(), cloud_ppath_update3D(), get_ppath_atmvars(), get_refr_index_1d(), get_refr_index_2d(), get_refr_index_3d(), and interp_cloud_coeff1D().
void p2gridpos | ( | ArrayOfGridPos & | gp, |
ConstVectorView | old_pgrid, | ||
ConstVectorView | new_pgrid, | ||
const Numeric & | extpolfac | ||
) |
p2gridpos
Calculates grid positions for pressure values.
This function works as gridpos, but is adapted to handle pressure grids. The ARTS defintions result in that pressures shall not be interpolated directly, it is the log of the pressure that shall be interpolated. This means that if some values shall be interpolated to some given pressures, the grid positions shall be calculated with this function. The interpolation can then be performed as usual.
[out] | gp | Output: Grid position Array. |
[in] | old_pgrid | The original pressure grid. |
[in] | new_pgrid | The new pressure grid. |
[in] | extpolfac | Extrapolation factor. Default value is 0.5, which means that extrapolation of half of the last grid distance is allowed. You don't have to specify this. |
Definition at line 608 of file special_interp.cc.
References gridpos(), ConstVectorView::nelem(), and transform().
Referenced by atm_fields_compactAddSpecies(), diy_from_path_to_rgrids(), doit_i_fieldSetClearsky(), get_perturbation_gridpos(), pnd_fieldCalc(), and z_fieldFromHSE().
void p2gridpos_poly | ( | ArrayOfGridPosPoly & | gp, |
ConstVectorView | old_pgrid, | ||
ConstVectorView | new_pgrid, | ||
const Index | order, | ||
const Numeric & | extpolfac | ||
) |
p2gridpos_poly
Calculates grid positions for pressure values - higher order interpolation.
This function is similar to p2gridpos, but for higher order interpolation.
[out] | gp | Output: Grid position Array. |
[in] | old_pgrid | The original pressure grid. |
[in] | new_pgrid | The new pressure grid. |
[in] | order | Interpolation order (1=linear, 2=quadratic, etc.) |
[in] | extpolfac | Extrapolation factor. Default value is 0.5, which means that extrapolation of half of the last grid distance is allowed. You don't have to specify this. |
Definition at line 643 of file special_interp.cc.
References gridpos_poly(), ConstVectorView::nelem(), and transform().
Referenced by AtmFieldsCalc(), and GriddedFieldPRegridHelper().
void rte_pos2gridpos | ( | GridPos & | gp_p, |
GridPos & | gp_lat, | ||
GridPos & | gp_lon, | ||
const Index & | atmosphere_dim, | ||
ConstVectorView | p_grid, | ||
ConstVectorView | lat_grid, | ||
ConstVectorView | lon_grid, | ||
ConstTensor3View | z_field, | ||
ConstVectorView | rte_pos | ||
) |
rte_pos2gridpos
Converts a geographical position (rte_pos) to grid positions for p, lat and lon.
The function calculates the altitude, latitude and longitude in rte_pos to matching grid positions. The conversion is straightforwatd for latitude and longitude. The altitude shall be converted pressure grid position which requires an interpolation of z_field.
Handles 1D, 2D and 3D (gp_lat and gp_lon untouched if not used).
Note that the function performs several checks of runtime error type.
gp_p | Output: Pressure grid position. |
gp_lat | Output: Latitude grid position. |
gp_lon | Output: Longitude grid position. |
atmosphere_dim | As the WSV with the same name. |
p_grid | As the WSV with the same name. |
lat_grid | As the WSV with the same name. |
lon_grid | As the WSV with the same name. |
z_field | As the WSV with the same name. |
rte_pos | As the WSV with the same name. |
Definition at line 688 of file special_interp.cc.
References chk_interpolation_grids(), chk_rte_pos(), gridpos(), gridpos_1to1(), interp(), interpweights(), joker, and ConstVectorView::nelem().
Referenced by InterpAtmFieldToPosition(), iyInterpCloudboxField(), iyInterpCloudboxField2(), iyInterpPolyCloudboxField(), ppath_start_stepping(), and ppathFromRtePos2().
void z_at_lat_2d | ( | VectorView | z, |
ConstVectorView | p_grid, | ||
ConstVectorView | lat_grid, | ||
ConstMatrixView | z_field, | ||
const GridPos & | gp_lat | ||
) |
z_at_lat_2d
Returns the geomtrical altitudes of p_grid for one latitude.
The latitude is specified by its grid position, in an ArrayOfGridPos of length 1. The altitude field (z_field) is then interpolated to that latitude.
z | Out: Found altitudes. |
p_grid | As the WSV with the same name. |
lat_grid | As the WSV with the same name. |
z_field | The pressure and latitude part of the WSV with the same name (that is, the first column). |
gp_lat | Latitude grid position. |
Definition at line 770 of file special_interp.cc.
References gridpos(), gridpos_copy(), interp(), interpweights(), joker, and ConstVectorView::nelem().
Referenced by get_refr_index_2d().
void z_at_latlon | ( | VectorView | z, |
ConstVectorView | p_grid, | ||
ConstVectorView | lat_grid, | ||
ConstVectorView | lon_grid, | ||
ConstTensor3View | z_field, | ||
const GridPos & | gp_lat, | ||
const GridPos & | gp_lon | ||
) |
z_at_latlon
Returns the geomtrical altitudes of p_grid for one latitude and one longitude.
The latitude and longitude are specified by their grid position, in an ArrayOfGridPos of length 1. The altitude field (z_field) is then interpolated to that latitude and longitude.
z | Out: Found altitudes. |
p_grid | As the WSV with the same name. |
lat_grid | As the WSV with the same name. |
lon_grid | As the WSV with the same name. |
z_field | As the WSV with the same name. |
gp_lat | Latitude grid positions. |
gp_lon | Longitude grid positions. |
Definition at line 822 of file special_interp.cc.
References gridpos(), gridpos_copy(), interp(), interpweights(), joker, and ConstVectorView::nelem().
Referenced by get_refr_index_3d(), and mcPathTraceIPA().