Commit 4daf221a authored by PIOLLE's avatar PIOLLE
Browse files

added options for subsetting

parent 2d5de7c8
......@@ -36,34 +36,32 @@ def instantiate_features(srcproduct,
targetmodelclass,
srcmapperclass,
targetmapperclass,
srcargs):
srcslices=None,
targetslices=None,
**kwargs):
"""Instantiate source and target feature objects from model, mapper and
file path.
Args:
srcproduct (str): full path to the source product file.
targetproduct (str): full path to the target product file.
srcmodelclass (:class:AbstractFeature): data model class of source
feature.
targetmodelclass (:class:AbstractFeature): data model class of target
feature.
srcmapperclass (:class:AbstractMapper): mapper class for the source
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.
srcargs (dict): additional input arguments for source mapper
instantiation.
"""
source = srcmodelclass()
target = targetmodelclass()
srcmapper = srcmapperclass(url=srcproduct,
**srcargs)
**kwargs)
targetmapper = targetmapperclass(url=targetproduct)
# detect if grid file is centered on meridian 180
# TODO: to be improved by using a more flexible interpolator
......@@ -71,8 +69,17 @@ def instantiate_features(srcproduct,
is_centered_on_180(srcmapperclass, srcproduct):
srcmapper.center_on_greenwhich = True
source.load(srcmapper)
target.load(targetmapper)
source.load(srcmapper, view=srcslices)
#if srcslices:
# source = source.extract_subset(slices=srcslices)
print "SLICES", srcslices, targetslices
target.load(targetmapper, view=targetslices)
#target.load(targetmapper)
#if targetslices:
# target = target.extract_subset(slices=targetslices)
print source.get_geolocation_dimsizes()
print target.get_geolocation_dimsizes()
return source, target
......@@ -251,6 +258,19 @@ def get_options():
" data in the remapped file where VALUE is set"
" (slash separated)"
)
parser.add_argument("-s", "--source_subset",
action="store",
dest="source_slices",
help="slices (in cerbere syntax) for the source feature "
"Only the subset defined by this slices will be "
"extracted and resampled.")
parser.add_argument("-S", "--target_subset",
action="store",
dest="target_slices",
help="slices (in cerbere syntax) for the target feature "
"Only the subset defined by this slices will be "
"extracted.")
options = parser.parse_args()
......@@ -379,6 +399,17 @@ if __name__ == "__main__":
'%Y%m%dT%H%M%S')
else:
timestep = None
# slices
if options.source_slices:
value = options.source_slices
source_slices = eval(value)
else:
source_slices = None
if options.target_slices:
value = options.target_slices
target_slices = eval(value)
else:
target_slices = None
# instantiate features
srcfeature, targetfeature = instantiate_features(
......@@ -388,7 +419,9 @@ if __name__ == "__main__":
targetmodelclass=target_datamodel,
srcmapperclass=source_mapper,
targetmapperclass=target_mapper,
srcargs=input_args
srcslices=source_slices,
targetslices=target_slices,
**input_args
)
if not options.target_mask:
mask = None
......
......@@ -18,3 +18,5 @@ Resampling a scatterometer swath (ASCAT) over a altimeter track (AltiKa)
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.
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. -S '{"time": slice(1000, 2000, 1)}'
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