special_interp.cc File Reference

Interpolation routines for special purposes. More...

#include <cmath>
#include <iostream>
#include <stdexcept>
#include "check_input.h"
#include "interpolation.h"
#include "math_funcs.h"
#include "messages.h"
#include "special_interp.h"

Include dependency graph for special_interp.cc:

Go to the source code of this file.

Functions

void fix_gridpos_at_boundary (ArrayOfGridPos &gp, const Index grid_size)
 fix_gridpos_at_boundary
void interp_atmfield_gp2itw (Matrix &itw, const Index &atmosphere_dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
 interp_atmfield_gp2itw
void interp_atmfield_by_itw (VectorView x, const Index &atmosphere_dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View x_field, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, ConstMatrixView itw)
 interp_atmfield_by_itw
void interp_atmfield_by_gp (VectorView x, const Index &atmosphere_dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View x_field, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
 interp_atmfield_by_gp
Numeric interp_atmfield_by_gp (const Index &atmosphere_dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View x_field, const GridPos &gp_p, const GridPos &gp_lat, const GridPos &gp_lon)
 interp_atmfield_by_gp
void interp_atmsurface_gp2itw (Matrix &itw, const Index &atmosphere_dim, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
 interp_atmsurface_gp2itw
void interp_atmsurface_by_itw (VectorView x, const Index &atmosphere_dim, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstMatrixView x_surface, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, ConstMatrixView itw)
 interp_atmsurface_by_itw
void interp_atmsurface_by_gp (VectorView x, const Index &atmosphere_dim, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstMatrixView x_surface, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
 interp_atmsurface_by_gp
Numeric interp_atmsurface_by_gp (const Index &atmosphere_dim, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstMatrixView x_surface, const GridPos &gp_lat, const GridPos &gp_lon)
 interp_atmsurface_by_gp
void interp_gfield3 (Numeric &value, const GField3 &gfield3, const Index &effective_dim, const Numeric &x, const Numeric &y, const Numeric &z, const String &dim0, const String &dim1, const String &dim2)
 interp_gfield3
void itw2p (VectorView p_values, ConstVectorView p_grid, const ArrayOfGridPos &gp, ConstMatrixView itw)
 itw2p
void p2gridpos (ArrayOfGridPos &gp, ConstVectorView old_pgrid, ConstVectorView new_pgrid, const Numeric &extpolfac)
 p2gridpos
void z_at_lat_2d (VectorView z, ConstVectorView p_grid, ConstVectorView lat_grid, ConstMatrixView z_field, const GridPos &gp_lat)
 z_at_lat_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


Detailed Description

Interpolation routines for special purposes.

Author:
Patrick Eriksson <Patrick.Eriksson@rss.chalmers.se>
Date:
2002-11-14
This file contains functions connected to interpolation of non-general character. The total general interpolation routines are found in interpolation.cc.

These interpolation functions interpolates a field or a surface 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. The exists an identical set of functions for interpolating surfaces, with names where _atmfield_ is replaced with _atmsurface_.

Possible atmospheric surfaces are *r_geoid*, *z_ground* 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.

See below to find what functions that exist.

Definition in file special_interp.cc.


Function Documentation

void fix_gridpos_at_boundary ( ArrayOfGridPos gp,
const Index  grid_size 
)

fix_gridpos_at_boundary

This function fixes grid positions on the boundaries of the grids, on which one wants to interpolate.

The use of the function can be demonstrated using an example, the interpolation of the *pnd_field* on a propagation path inside the cloudbox. The gridpositions calculated in the ppath_agenda are given with respect to the atmospheric grids (p_grid, lat_grid, lon_grid), whereas the pnd_field* is defined on a subset of these grids, only inside the cloudbox. Hence the gridpositions need to be transformed. If a point is exactly at the lower boundary of the cloudbox, the gridposition index can be either cloudbox_limits[0] or cloudbox_limits[0]-1, depending on random numerical errors. To transform the gridpositions, cloudbox_limits[0] is substracted from the original gridposition index, which results in a new gridpostion index of -1. This is of coarse not allowed in the interpolation routines.

A more precise example: If a point is exactly on the lower boundary (say p-index = 12) of cloudbox the gridpositions can be gp.idx = 12, gp.fd[0] = 1, gp.fd[1] = 0 or gp.idx = 11, gp.fd[0] = 0, gp.fd[1] = 1 In the second case gp_cloud.idx will be -1 which gives an error.

Parameters:
gp An array of gridpositions
grid_size Length of the data grid
Author:
Claudia Emde
Date:
2005-05-27

Definition at line 108 of file special_interp.cc.

References abs, Array< base >::nelem(), and out1.

Referenced by cloud_atm_vars_by_gp(), and cloud_ppath_update3D().

Numeric interp_atmfield_by_gp ( const Index atmosphere_dim,
ConstVectorView  p_grid,
ConstVectorView  lat_grid,
ConstVectorView  lon_grid,
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.

Author:
Patrick Eriksson
Date:
2002-11-13

Definition at line 340 of file special_interp.cc.

References gridpos_copy(), and interp_atmfield_by_gp().

void interp_atmfield_by_gp ( VectorView  x,
const Index atmosphere_dim,
ConstVectorView  p_grid,
ConstVectorView  lat_grid,
ConstVectorView  lon_grid,
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.

Parameters:
x Output: Values obtained by the interpolation.
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.
x_field The atmospheric field to be interpolated.
gp_p Pressure grid positions.
gp_lat Latitude grid positions.
gp_lon Longitude grid positions.
Author:
Patrick Eriksson
Date:
2002-11-13

Definition at line 311 of file special_interp.cc.

References interp_atmfield_by_itw(), and interp_atmfield_gp2itw().

Referenced by interp_atmfield_by_gp(), InterpAtmFieldToRteGps(), and mcPathTraceIPA().

void interp_atmfield_by_itw ( VectorView  x,
const Index atmosphere_dim,
ConstVectorView  p_grid,
ConstVectorView  lat_grid,
ConstVectorView  lon_grid,
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.

Parameters:
x Output: Values obtained by the interpolation.
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.
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.
Author:
Patrick Eriksson
Date:
2002-11-13

Definition at line 246 of file special_interp.cc.

References chk_atm_field(), interp(), joker, ConstMatrixView::ncols(), Array< base >::nelem(), and ConstVectorView::nelem().

Referenced by clear_rt_vars_at_gp(), cloud_atm_vars_by_gp(), interp_atmfield_by_gp(), iy_calc(), and opt_depth_calc().

void interp_atmfield_gp2itw ( Matrix itw,
const Index atmosphere_dim,
ConstVectorView  p_grid,
ConstVectorView  lat_grid,
ConstVectorView  lon_grid,
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.

Parameters:
itw Output: Interpolation weights.
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.
gp_p Pressure grid positions.
gp_lat Latitude grid positions.
gp_lon Longitude grid positions.
Author:
Patrick Eriksson
Date:
2002-11-13

Definition at line 178 of file special_interp.cc.

References chk_atm_grids(), interpweights(), Array< base >::nelem(), and Matrix::resize().

Referenced by clear_rt_vars_at_gp(), cloud_atm_vars_by_gp(), interp_atmfield_by_gp(), iy_calc(), and opt_depth_calc().

Numeric interp_atmsurface_by_gp ( const Index atmosphere_dim,
ConstVectorView  lat_grid,
ConstVectorView  lon_grid,
ConstMatrixView  x_surface,
const GridPos gp_lat,
const GridPos gp_lon 
)

interp_atmsurface_by_gp

As the function above, but return-numeric version.

Author:
Patrick Eriksson
Date:
2002-11-13

Definition at line 543 of file special_interp.cc.

References gridpos_copy(), and interp_atmsurface_by_gp().

void interp_atmsurface_by_gp ( VectorView  x,
const Index atmosphere_dim,
ConstVectorView  lat_grid,
ConstVectorView  lon_grid,
ConstMatrixView  x_surface,
const ArrayOfGridPos gp_lat,
const ArrayOfGridPos gp_lon 
)

interp_atmsurface_by_gp

Interpolates an atmospheric surface 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 surface 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.

Parameters:
x Output: Values obtained by the interpolation.
atmosphere_dim 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.
x_surface The atmospheric field to be interpolated.
gp_lat Latitude grid positions.
gp_lon Longitude grid positions.
Author:
Patrick Eriksson
Date:
2002-11-13

Definition at line 517 of file special_interp.cc.

References interp_atmsurface_by_itw(), and interp_atmsurface_gp2itw().

Referenced by interp_atmsurface_by_gp(), and InterpSurfaceFieldToRteGps().

void interp_atmsurface_by_itw ( VectorView  x,
const Index atmosphere_dim,
ConstVectorView  lat_grid,
ConstVectorView  lon_grid,
ConstMatrixView  x_surface,
const ArrayOfGridPos gp_lat,
const ArrayOfGridPos gp_lon,
ConstMatrixView  itw 
)

interp_atmsurface_by_itw

Interpolates an atmospheric surface 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 atmospheric surface 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.

Parameters:
x Output: Values obtained by the interpolation.
atmosphere_dim 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.
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.
Author:
Patrick Eriksson
Date:
2002-11-13

Definition at line 455 of file special_interp.cc.

References chk_atm_surface(), 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 an atmospheric surface.

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.

Parameters:
itw Output: Interpolation weights.
atmosphere_dim As the WSV with the same name.
gp_lat Latitude grid positions.
gp_lon Longitude grid positions.
Author:
Patrick Eriksson
Date:
2002-11-13

Definition at line 397 of file special_interp.cc.

References interpweights(), Array< base >::nelem(), and Matrix::resize().

Referenced by interp_atmsurface_by_gp().

void interp_gfield3 ( Numeric value,
const GField3 gfield3,
const Index effective_dim,
const Numeric x,
const Numeric y,
const Numeric z,
const String dim0,
const String dim1,
const String dim2 
)

interp_gfield3

Single point interpolation of a GField3.

Data where not all dimensions are effectively used can be handled. For example, if the last dimension is not ysed, effective_dim* is set to 2.

"First dimension" refers to the left-most dimension.

Parameters:
value Output: Obtained value.
gfield3 Field to interpolate
effective_dim Effective dimension of gfield. See above.
x First dimension position of interpolation point.
y Second dimension position of interpolation point.
z Third dimension position of interpolation point.
dim0 Expected name of grid for first dimension
dim1 Expected name of grid for second dimension
dim2 Expected name of grid for third dimension
Author:
Patrick Eriksson
Date:
2008-10-01

Definition at line 598 of file special_interp.cc.

References chk_if_in_range(), chk_if_increasing(), GField::get_grid_name(), GField::get_numeric_grid(), gridpos(), interp(), interpweights(), joker, last(), ConstTensor3View::ncols(), and ConstTensor3View::nrows().

Referenced by InterpSurfaceEmissivityFieldIncLatLon().

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 surfaces 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.

Parameters:
p_values Output: Found pressure values.
p_grid As the WSV with the same name.
gp Altitude grid positions.
itw Interpolation weights
Author:
Patrick Eriksson
Date:
2002-11-13

Definition at line 780 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_refr_index_1d(), get_refr_index_2d(), get_refr_index_3d(), interp_cloud_coeff1D(), iy_calc(), and opt_depth_calc().

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.

Parameters:
gp Output: Grid position Array.
old_pgrid The original pressure grid.
new_pgrid The new pressure grid.
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.
Author:
Patrick Eriksson
Date:
2003-01-20
Author:
Stefan Buehler
Date:
2008-03-03

Definition at line 827 of file special_interp.cc.

References gridpos(), ConstVectorView::nelem(), and transform().

Referenced by AtmFieldsCalc(), doit_i_fieldSetClearsky(), get_perturbation_gridpos(), jacobian_from_path_to_rgrids(), pnd_fieldCalc(), and refr_indexFieldAndGradients().

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.

Parameters:
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.
Author:
Patrick Eriksson
Date:
2002-11-18

Definition at line 866 of file special_interp.cc.

References gridpos(), gridpos_copy(), interp(), interpweights(), joker, and ConstVectorView::nelem().

Referenced by get_refr_index_2d(), ppath_start_stepping(), and refr_indexFieldAndGradients().

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.

Parameters:
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.
Author:
Patrick Eriksson
Date:
2002-12-31

Definition at line 918 of file special_interp.cc.

References gridpos(), gridpos_copy(), interp(), interpweights(), joker, and ConstVectorView::nelem().

Referenced by cloudbox_ppath_start_stepping(), get_refr_index_3d(), mcPathTraceIPA(), ppath_start_stepping(), and refr_indexFieldAndGradients().


Generated on Mon Mar 23 14:06:52 2009 for ARTS by  doxygen 1.5.6