Commit 414102be authored by PIOLLE's avatar PIOLLE
Browse files

creates a new file is slicing is requested on the target

parent b5288c83
......@@ -55,8 +55,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
targetslices (, optional):
srcargs (dict): additional input arguments for source mapper
instantiation.
"""
......@@ -84,6 +84,8 @@ def resample(srcfeature,
filename=None,
use_source_time=False,
mask=None,
copy=False,
attrs=None,
**kwargs
):
"""Resample source product on a target
......@@ -104,8 +106,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()
......@@ -126,7 +132,7 @@ def resample(srcfeature,
targetfeature,
fields=resampled_fields,
radius=radius,
new=True,
new=not copy,
add_reference=True,
**kwargs
)
......@@ -156,6 +162,7 @@ def resample(srcfeature,
if outfeature:
# set global attributes
globalattrs = {}
globalattrs.update(attrs)
timevals = srcfeature.get_times()
time0 = timevals.min()
time1 = timevals.max()
......@@ -163,6 +170,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
......@@ -426,6 +434,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]
......@@ -441,7 +460,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':
......@@ -454,5 +474,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