Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
No_op in case geospatial defintion is the same
Browse files Browse the repository at this point in the history
In case master and slave/replica already have the same geospatial
definition, don't do anything, or do only a subset

Closes #805
  • Loading branch information
Jānis Gailis committed Nov 8, 2018
1 parent e818763 commit 7e4576b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cate/ops/coregistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def coregister(ds_master: xr.Dataset,
' pixel-registered, can not perform'
' coregistration'.format(array[0]))

# Don't do anything if datasets already have the same spatial definition
if np.array_equal(ds_master['lat'].values, ds_slave['lat'].values) and \
np.array_equal(ds_master['lon'].values, ds_slave['lon'].values):
return ds_slave

# Co-register
methods_us = {'nearest': 10, 'linear': 11}
methods_ds = {'first': 50, 'last': 51, 'mean': 54, 'mode': 56, 'var': 57, 'std': 58}
Expand Down Expand Up @@ -309,6 +314,11 @@ def _resample_dataset(ds_master: xr.Dataset, ds_slave: xr.Dataset, method_us: in
lat = ds_master['lat'].sel(lat=lat_slice)
ds_slave = ds_slave.sel(lon=lon_slice, lat=lat_slice)

if np.array_equal(lon.values, ds_slave['lon'].values) and \
np.array_equal(lat.values, ds_slave['lat'].values):
# The original grids already have the same spatial definition
return ds_slave

with monitor.starting("coregister dataset", len(ds_slave.data_vars)):
kwargs = {'lon': lon, 'lat': lat, 'method_us': method_us, 'method_ds': method_ds, 'parent_monitor': monitor}
retset = ds_slave.apply(_resample_array, keep_attrs=True, **kwargs)
Expand Down

0 comments on commit 7e4576b

Please sign in to comment.