Commit 4f6bb624 authored by jfpiolle's avatar jfpiolle
Browse files

Merge branch 'master' of https://git.cersat.fr/cerbere/cerinterp

parents acb6d906 f6d660dc
......@@ -57,8 +57,8 @@ def instantiate_features(srcproduct,
product file.
targetmapperclass (:class:AbstractMapper): mapper class for the target
product file.
srcslices (str, optional): slices for
targetslices (str, optional): full path to the target product file.
srcslices (, optional): slices for source file extraction
targetslices (, optional): slices for target file extraction
srcmapper_args (dict): additional input arguments for source mapper
instantiation.
targetmapper_args (dict): additional input arguments for target mapper
......@@ -89,6 +89,8 @@ def resample(srcfeature,
filename=None,
use_source_time=False,
mask=None,
copy=False,
attrs=None,
**kwargs
):
"""Resample source product on a target
......@@ -109,8 +111,12 @@ def resample(srcfeature,
This is meant for instance to mask land data over which
interpolation may have been performed in the resampling
process.
copy (bool): if True, make a copy of the target feature and add
the resampled source fields into it.
"""
if copy:
targetfeature = targetfeature.extract_subset()
# resampling
if fields is None:
resampled_fields = srcfeature.get_fieldnames()
......@@ -131,7 +137,7 @@ def resample(srcfeature,
targetfeature,
fields=resampled_fields,
radius=radius,
new=True,
new=not copy,
add_reference=True,
**kwargs
)
......@@ -161,6 +167,7 @@ def resample(srcfeature,
if outfeature:
# set global attributes
globalattrs = {}
globalattrs.update(attrs)
timevals = srcfeature.get_times()
time0 = timevals.min()
time1 = timevals.max()
......@@ -168,6 +175,7 @@ def resample(srcfeature,
maxtime = num2date(time1, srcfeature.get_time_units())
globalattrs['time_coverage_start'] = mintime.strftime('%Y%m%dT%H%M%S')
globalattrs['time_coverage_stop'] = maxtime.strftime('%Y%m%dT%H%M%S')
if method[0] == 'closest_neighbour':
globalattrs['spatial_colocation_radius_in_km'] = radius / 1000.
# set time
......@@ -440,6 +448,17 @@ if __name__ == "__main__":
mask_field = options.target_mask.split('/')[0]
mask_value = int(options.target_mask.split('/')[1])
mask = (targetfeature.get_values(mask_field) != mask_value)
# creates automatically a copy of target if slicing is required
copy = target_slices is not None
# output global attributes
attrs = {}
attrs['source_filename'] = srcfeature.get_mapper().get_basename()
attrs['target_filename'] = targetfeature.get_mapper().get_basename()
attrs['source_subset_slices'] = str(source_slices)
attrs['target_subset_slices'] = str(target_slices)
if srcfeature.__class__.__name__ == 'GridTimeSeries' and timestep is None:
for grid in srcfeature:
date = grid.get_datetimes()[0]
......@@ -455,7 +474,8 @@ if __name__ == "__main__":
outdir=output,
filename=filename,
use_source_time=use_source_time,
mask=mask
mask=mask,
attrs=attrs
)
else:
if srcfeature.__class__.__name__ == 'GridTimeSeries':
......@@ -468,5 +488,7 @@ if __name__ == "__main__":
method=method,
outdir=output,
use_source_time=use_source_time,
mask=mask
mask=mask,
copy=copy,
attrs=attrs
)
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