Pyresample can be used to resample a swath dataset to a grid, a grid to a swath or a swath to another swath.
Resampling can be done using nearest neighbour method, Guassian weighting, weighting with an arbitrary radial function.

Changed in version 1.8.0: SwathDefinition no longer checks the validity of the provided longitude
and latitude coordinates to improve performance. Longitude arrays are
expected to be between -180 and 180 degrees, latitude -90 to 90 degrees.
This also applies to all geometry definitions that are provided longitude
and latitude arrays on initialization. Use
pyresample.utils.check_and_wrap to preprocess your arrays.

If the arguments swath_def and area_def where switched (and data matched the dimensions of area_def) the grid of area_def
would be resampled to the swath defined by swath_def.

Note the keyword arguments:

radius_of_influence: The radius around each grid pixel in meters to search for neighbours in the swath.

epsilon: The distance to a found value is guaranteed to be no further than (1 + eps) times the distance to the correct neighbour. Allowing for uncertanty decreases execution time.

If data is a masked array the mask will follow the neighbour pixel assignment.

If there are multiple channels in the dataset the data argument should be of the shape of the lons and lat arrays
with the channels along the last axis e.g. (rows, cols, channels). Note: the convention of pyresample < 0.7.4 is to pass
data in the form of (number_of_data_points, channels) is still accepted.

Function for resampling using nearest Gussian weighting. The Gauss weigh function is defined as exp(-dist^2/sigma^2).
Note the pyresample sigma is not the standard deviation of the gaussian.
Example showing how to resample a generated swath dataset to a grid using Gaussian weighting:

Uncertainty estimates in the form of weighted standard deviation can be obtained from the resample_custom and resample_gauss functions.
By default the functions return the result of the resampling as a single numpy array. If the functions are given the keyword argument with_uncert=True
then the following list of numpy arrays will be returned instead: (result, stddev, count). result is the usual result. stddev is the weighted standard deviation for each element in the result. count is the number of data values used in the weighting for each element in the result.

The principle is to view the calculated value for each element in the result as a weighted average of values sampled from a statistical variable.
An estimate of the standard deviation of the distribution is calculated using the unbiased weighted estimator given as
stddev = sqrt((V1 / (V1 ** 2 + V2)) * sum(wi * (xi - result) ** 2)) where result is the result of the resampling. xi is the value of a contributing neighbour
and wi is the corresponding weight. The coefficients are given as V1 = sum(wi) and V2 = sum(wi ** 2). The standard deviation is only calculated for elements in
the result where more than one neighbour has contributed to the weighting. The count numpy array can be used for filtering at a higher number of contributing neigbours.

Usage only differs in the number of return values from resample_gauss and resample_custom. E.g.:

First get arrays containing information about the nearest neighbours to each grid point.
Then use these arrays to retrive the resampling result.

This approch can be useful if several datasets based on the same swath are to be resampled. The computational
heavy task of calculating the neighbour information can be done once and the result can be used to
retrieve the resampled data from each of the datasets fast.

Note the keyword argument neighbours=1. This specifies only to consider one neighbour for each
grid point (the nearest neighbour). Also note distance_array is not a required argument for
get_sample_from_neighbour_info when using nearest neighbour resampling

Whenever a resampling function takes the keyword argument segments the number of segments to split the resampling process in can be specified. This affects the memory footprint of pyresample. If the value of segments is left to default pyresample will estimate the number of segments to use.

Use this information to resample several datasets between these two
areas/swaths

Only the first step is computationally expensive operation, so by
re-using this information the overall processing time is reduced
significantly. This is also done internally by the
resample_bilinear function, but separating these steps makes it
possible to cache the coefficients if the same transformation is done
over and over again. This is very typical in operational
geostationary satellite image processing. Note that the output shape is now
defined so that the result is reshaped to correct shape. This reshaping
is done internally in resample_bilinear.

Pyresample makes it possible to resample swath data to a uniform grid
using an Elliptical Weighted Averaging algorithm or EWA for short.
This algorithm behaves differently than the KDTree based resampling
algorithms that pyresample provides. The KDTree-based algorithms
process each output grid pixel by searching for all “nearby” input
pixels and applying a certain interpolation (nearest neighbor, gaussian, etc).
The EWA algorithm processes each input pixel mapping it to one or more output
pixels. Once each input pixel has been analyzed the intermediate results are
averaged to produce the final gridded result.

The EWA algorithm also has limitations on how the input data is structured
compared to the generic KDTree algorithms. EWA assumes that data in the array
is organized geographically; adjacent data in the array is adjacent data
geographically. The algorithm uses this to configure parameters based on the
size and location of the swath pixels.

The EWA algorithm consists of two
steps: ll2cr and fornav. The algorithm was originally part of the
MODIS Swath to Grid Toolbox (ms2gt) created by the
NASA National Snow & Ice Data Center (NSIDC). Its default parameters
work best with MODIS L1B data, but it has been proven to produce high
quality images from VIIRS and AVHRR data with the right parameters.

Note

This code was originally part of the Polar2Grid project. This
documentation and the API documentation for this algorithm may still
use references or concepts from Polar2Grid until everything can
be updated.

The first step is called ‘ll2cr’ which stands for “longitude/latitude to
column/row”. This step maps the pixel location (lon/lat space) into area (grid)
space. Areas in pyresample are defined by a PROJ.4 projection specification.
An area is defined by the following parameters:

The second step of EWA remapping is called “fornav”, short for
“forward navigation”. This EWA algorithm processes one input scan line
at a time. The algorithm weights the effect of an input pixel on an output
pixel based on its location in the scan line and other calculated
coefficients. It can also handle swaths that are not scan based by specifying
rows_per_scan as the number of rows in the entire swath.
How the algorithm treats the data can be configured with various
keyword arguments, see the API documentation for more information.
Both steps provide additional information to inform the user how much data
was used in the result. The first returned value of ll2cr tells you how many
of the input swath pixels overlap the grid. The first returned value of fornav
tells you how many grid points have valid data values in them.