Commit de6f06dd authored by PIOLLE's avatar PIOLLE
Browse files

more doc

parent 168387ef
# -*- coding: utf-8 -*-
"""
cerinterp.resampler
=======================
.. module::cerinterp.resampler
Class for the resampling of features
A module for the resampling of `cerbere` observation features
:copyright: Copyright 2013 Ifremer / Cersat.
:license: Released under GPL v3 license, see :ref:`license`.
:license: Released under GPL v3 license
.. sectionauthor:: Jeff Piolle <jfpiolle@ifremer.fr>
.. codeauthor:: Jeff Piolle <jfpiolle@ifremer.fr>
......@@ -32,7 +31,7 @@ try:
except ImportError:
logging.warning(
"This cerbere instance doesn't include a compiled Cython "
"module 'pyx'. This is probalby because you are running "
"module 'pyx'. This is probably because you are running "
"cerbere from a repository, and not as an installed package. "
"Building 'pyx' implace...")
import pyximport
......@@ -43,6 +42,12 @@ except ImportError:
class Resampler(object):
"""A toolbox for the resampling of cerbere features on top of each others.
It provides several methods for resampling or interpolation.
"""
def __init__(self):
pass
@classmethod
def __monotonic(cls, longitudes):
......@@ -65,10 +70,10 @@ class Resampler(object):
"""Fill in missing values with a mean of the neighbours.
Args:
data (MaskedArray): array to fill in.
extrapolation (int): number of iterations of the extrapolation process
(how far we want to extrapolate).
copy (boolean): copy the result in a new array.
data (:class:`numpy.ma.MaskedArray`): array to fill in.
extrapolation (optional, int): number of iterations of the
extrapolation process (how far to extrapolate).
copy (optional, boolean): if True, copy the result in a new array.
"""
# Get array filled with NaN and mask
# NOTE : in a global case, it is possible here to duplicate the fist/last
......@@ -143,12 +148,12 @@ class Resampler(object):
(cerbere convention is to express longitudes between -180/180).
Args:
source (:class:Grid): source grid.
source (:class:`cerbere.datamodel.grid.Grid`): source grid.
fieldname (string or list of string): name of the field(s) to
interpolate.
target (:class:Grid): target grid.
target (:class:`cerbere.datamodel.grid.Grid`): target grid.
extrapolation (int): if different from 0, extrapolate values of
source over edges (gaps, land, sea-ice,...). Default is 0. The
......@@ -161,10 +166,11 @@ class Resampler(object):
argument (for instance water freezing temperature when
interpolating SST along sea ice edges).
mask (bool ndarray): if not None, mask the interpolated values. The
mask must match the dimensions of the target grid. This is
meant for instance to mask land data over which interpolation
may have been performed in the resampling.
mask (ndarray): a boolean mask to apply on the interpolated
values after they have been calculated. The mask must match the
dimensions of the target grid. This is meant for instance to
mask land data over which interpolation may have been performed
in the resampling.
"""
if fields is None:
logging.warning("No field names were provided")
......
resampler Package
cerinterp Package
=================
:mod:`resampler` Package
:mod:`resampler` Module
------------------------
.. automodule:: cerinterp.resampler
......
......@@ -3,36 +3,59 @@
=======================================================
*cerresample* is a command line utility to resample a data feature (swath,
grid,...) on top of another data feature.
*cerresample* is a command line utility to resample a :package:`cerbere` feature (swath,
grid,...) on top of another :package:`cerbere` feature.
Usage
=====
The `cerresample` tool can be called with the following arguments.::
optional arguments:
-h, --help show this help message and exit
-p FILE, --source FILE
full path to the source file (file to be resampled)
-P FILE, --target FILE
full path to the target file (on which the source is
resampled)
-f string, --fields string
name of the field(s) to resample, slash separated (all
by defaults)
-o DIR, --output DIR
full path to the output directory
-m string, --source-mapper-class string
mapper for the source data file (default: NCFile)
-d string, --source-model-class string
data model for the source file (default: Grid)
-M string, --target-mapper-class string
mapper for the target data file (default: NCFile)
-D string, --target-model-class string
data model for the target file (default: Grid)
-a string, --method string
Resampling method
The `cerresample` tool can be called with the following arguments.:
.. code-block:: bash
-h, --help show this help message and exit
-p FILE, --source FILE
full path to the source file (file to be resampled)
-P FILE, --target FILE
full path to the target file (on which the source is
resampled)
-f FIELD1/FIELD2/..., --fields FIELD1/FIELD2/...
name of the field(s) to resample, slash separated (all
by defaults)
-o OUTPUT_DIR, --output OUTPUT_DIR
full path to the output directory
-m MAPPER, --source-mapper-class MAPPER
mapper for the source data file (default: NCFile)
-d MODEL, --source-model-class MODEL
data model for the source file (default: Grid)
-M MAPPER, --target-mapper-class MAPPER
mapper for the target data file (default: NCFile)
-D MODEL, --target-model-class MODEL
data model for the target file (default: Grid)
-a string, --method string
Resampling method
-u, --use-source-time
Use the time of the source to fill the time of the
produced file (used when the target is only used as
for the pattern definition)
-k FIELD/VALUE, --use-target-mask FIELD/VALUE
Use a FIELD from the target file to mask invalid data
in the remapped file where VALUE is set (slash
separated)
-s SOURCE_SLICES, --source_subset SOURCE_SLICES
slices (in cerbere syntax) for the source feature Only
the subset defined by this slices will be extracted
and resampled.
-S TARGET_SLICES, --target_subset TARGET_SLICES
slices (in cerbere syntax) for the target feature Only
the subset defined by this slices will be extracted.
.. note::
when similar arguments can be used for the source and the target,
we use lower case convention (`-p`) for the source, upper case convention
(`-P`) for the target.
Here are a few examples::
......@@ -49,8 +72,47 @@ Here are a few examples::
More examples and details on how to use it are provided in the following
sections.
Special resampling arguments
============================
Tutorial
========
Suppose we want to reproject a swath observation (an AMSR2 file from JAXA) feature over
a another swath (a MODIS file from PODAAC) :
.. code-block:: bash
cerresample -p 20100506-AMSRE-REMSS-L2P-amsr_l2b_v05_r42588.dat-v01.nc $
-P 20100506-MODIS_A-JPL-L2P-A2010126170000.L2_LAC_GHRSST_D-v01.nc $
-d Swath -D Grid
-m GHRSSTNCFile -M GHRSSTNCFile $
-o test/
What did we just provide as arguments?
* a path to the source product (the one we reproject) with `-p` option
* a path to the target product (the one on which we reproject the source
product) with `-p` option
* the mapper to read the source product is provided with `-m` (here we used
the generic mapper for GHRSST products : `GHRSSTNCFile`)
* similarly, a mapper for the target file (`-P`), which happens to be in this example
a GHRSST file too.
* the type of observation pattern (datamodel) of the source, provided with
`-d` argument. Here our source is a swath (:class:`Swath` in cerbere)
* the type of observation pattern (datamodel) of the target, provided with
`-d` argument. Here our source is a grid (:class:`Grid` in cerbere)
* the output repository, provided with `-o` option
So we basically described what were our source and target objects, without too
much details on how to perform the resampling.
.. important::
The default method used for resampling is the closest neighbour. This method
works with any kind of feature.
So here closest neighbour resampling was used as we did not explicitely specify
anything.
In addition to the `method` argument, additional keywords can be provided
(separated by `&`) to further refine the resampling process. They are dependant
......
......@@ -330,13 +330,25 @@ class Mock(object):
else:
return Mock()
MOCK_MODULES = ['numpy',
'scipy',
'gdal',
MOCK_MODULES = [
'cerinterp.fastregrid',
'numpy',
'scipy',
'scipy.spatial',
'scipy.stats',
'gdal',
'cerbere',
'cerbere.datamodel',
'cerbere.datamodel.field',
'cerbere.datamodel.variable',
'cerbere.datamodel.swath',
'cerbere.datamodel.grid',
'cerbere.datamodel.image',
'cerbere.datamodel.trajectory',
'Cython',
'Cython.Distutils',
'Cython.Distutils.build_ext',
'gdalconst'
]
'gdalconst'
]
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment