Commit 2d5de7c8 authored by PIOLLE's avatar PIOLLE
Browse files

fixed import + better error control

parent 8c98beec
......@@ -22,7 +22,7 @@ from datetime import datetime
from netCDF4 import num2date
from cerbereutils.resampling.resampler import Resampler
from cerinterp.resampler import Resampler
from cerbere.mapper.ncfile import NCFile
from cerbere.mapper.abstractmapper import AbstractMapper, WRITE_NEW
......@@ -116,10 +116,11 @@ def resample(srcfeature,
for k in method.split('/')[1:]}
if method_name == 'closest_neighbour':
if 'radius' in method_kwargs:
radius = method_kwargs['radius']
radius = float(method_kwargs['radius'])
else:
# 1.5 = approx. sqrt(2)
# value is converted from degree to meter
# !!!! TODO: THERE IS INCONSISTENCY HERE BETWEEN RES IN KM OR DEG
radius = srcfeature.get_spatial_resolution() / 2. * 150000
outfeature = Resampler.closest_neighbour(srcfeature,
targetfeature,
......@@ -171,9 +172,7 @@ def resample(srcfeature,
field.set_values(
srcfeature.get_geolocation_field('time').get_values().copy()
)
print srcfeature.get_geolocation_field('time').get_values()
outfeature._geolocation_fields['time'] = field
print outfeature.get_geolocation_field('time').get_values()
# save file
if not os.path.exists(outdir):
os.makedirs(outdir)
......@@ -254,8 +253,16 @@ def get_options():
)
options = parser.parse_args()
assert options.resampling_method.split('/')[0] in RESAMPLING_METHODS,\
'Unknown resampling method'
if options.resampling_method:
if '/' in options.resampling_method:
methodname = options.resampling_method.split('/')[0]
else:
methodname = options.resampling_method
if methodname not in RESAMPLING_METHODS:
raise Exception("Resampling method must be closest_neighbour or"
"bilinear. You provided a bad expression: %s",
options.resampling_method)
return options
......@@ -266,7 +273,6 @@ def is_centered_on_180(srcmapperclass, srcproduct):
lons = mapper.read_values('lon')
res = False
if lons[0] > lons[-1]:
print "IS CNTERED"
res = True
mapper.close()
return res
......@@ -293,7 +299,10 @@ if __name__ == "__main__":
use_source_time = True
else:
use_source_time = False
method = options.resampling_method
if options.resampling_method:
method = options.resampling_method
else:
method = 'closest_neighbour'
# source mapper
input_args = {}
if not options.source_mapper:
......@@ -408,6 +417,7 @@ if __name__ == "__main__":
if srcfeature.__class__.__name__ == 'GridTimeSeries':
if timestep is not None:
srcfeature = srcfeature.extract_grid(time=timestep)
resample(srcfeature,
targetfeature,
fields=fieldnames,
......
......@@ -345,7 +345,7 @@ class Resampler(object):
valid_input_index, valid_output_index, index_array, distance_array\
= kd_tree.get_neighbour_info(source_def,
target_def,
radius,
radius_of_influence=float(radius),
reduce_data=False,
neighbours=1
)
......@@ -380,7 +380,7 @@ class Resampler(object):
valid_input_index, valid_output_index, index_array, distance_array\
= Resampler.__get_closest_neighbour_info(source_def,
target_def,
radius)
radius_of_influence=radius)
if not valid_input_index.any():
# return None if no source data can be resampled on the
# target
......
========
Examples
========
This section provides various examples of resampling of features over other
features, using the ``cerresample`` command line tool.
Swath on Trajectory
===================
Only closest_neighbour resampling method is possible here.
Resampling a scatterometer swath (ASCAT) over a altimeter track (AltiKa)
------------------------------------------------------------------------
.. code-block:: bash
cerresample --source /export/home/sumba/git/naiad/test/data/ascat_a/ascat_20150101_095100_metopa_42560_eps_o_125_2300_ovw.l2.nc --target /export/home/sumba/git/naiad/test/data/saral/SRL_OPRSSHA_2PTS019_0809_20150101_114518_20150101_132355.EUM.nc -d Swath -D Trajectory -m NCFile -M Cryosat2NCFile -o . -a closest_neighbour/radius=25000.
......@@ -28,3 +28,4 @@ Utilities
:maxdepth: 2
cerresample
examples
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