Commit 168387ef authored by PIOLLE's avatar PIOLLE
Browse files

specific arguments can now be used for source and target mappers

parent b5288c83
......@@ -21,6 +21,7 @@ import importlib
from datetime import datetime
import random
import string
import ast
from netCDF4 import num2date
......@@ -40,7 +41,8 @@ def instantiate_features(srcproduct,
targetmapperclass,
srcslices=None,
targetslices=None,
**kwargs):
srcmapper_args=None,
targetmapper_args=None):
"""Instantiate source and target feature objects from model, mapper and
file path.
......@@ -57,14 +59,17 @@ def instantiate_features(srcproduct,
product file.
srcslices (str, optional): slices for
targetslices (str, optional): full path to the target product file.
srcargs (dict): additional input arguments for source mapper
srcmapper_args (dict): additional input arguments for source mapper
instantiation.
targetmapper_args (dict): additional input arguments for target mapper
instantiation.
"""
source = srcmodelclass()
target = targetmodelclass()
srcmapper = srcmapperclass(url=srcproduct,
**kwargs)
targetmapper = targetmapperclass(url=targetproduct)
**srcmapper_args)
targetmapper = targetmapperclass(url=targetproduct,
**targetmapper_args)
# detect if grid file is centered on meridian 180
# TODO: to be improved by using a more flexible interpolator
if source.__class__.__name__ == 'Grid' and\
......@@ -321,7 +326,7 @@ if __name__ == "__main__":
else:
method = 'closest_neighbour'
# source mapper
input_args = {}
src_args = {}
if not options.source_mapper:
source_mapper = getattr(
importlib.import_module(
......@@ -335,9 +340,9 @@ if __name__ == "__main__":
# additional arguments
fields = mapper.split('/')
mapper = fields[0]
input_args = {f.split('=')[0]: f.split('=')[1] for f in fields[1:]}
src_args = {f.split('=')[0]: f.split('=')[1] for f in fields[1:]}
if 'fillvalue' in input_args:
input_args['fillvalue'] = float(input_args['fillvalue'])
input_args['fillvalue'] = float(src_args['fillvalue'])
source_mapper = getattr(
importlib.import_module(
'cerbere.mapper.' + mapper.lower()
......@@ -359,6 +364,7 @@ if __name__ == "__main__":
options.source_datamodel
)
# target
target_args = {}
if not options.target_mapper:
target_mapper = getattr(
importlib.import_module(
......@@ -367,11 +373,18 @@ if __name__ == "__main__":
'NCFile'
)
else:
mapper = options.target_mapper
if '/' in mapper:
# additional arguments
fields = mapper.split('/')
mapper = fields[0]
target_args = {f.split('=')[0]: ast.literal_eval(f.split('=')[1])
for f in fields[1:]}
target_mapper = getattr(
importlib.import_module(
'cerbere.mapper.' + options.target_mapper.lower()
'cerbere.mapper.' + mapper.lower()
),
options.target_mapper
mapper
)
if not options.target_datamodel:
target_datamodel = getattr(
......@@ -418,7 +431,8 @@ if __name__ == "__main__":
targetmapperclass=target_mapper,
srcslices=source_slices,
targetslices=target_slices,
**input_args
srcmapper_args=src_args,
targetmapper_args=target_args,
)
if not options.target_mask:
mask = None
......
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