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

Make sure integer data arrays can be coregistered #775

Merged
merged 1 commit into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Version 2.0.0.dev21 (in development)

* Make sure integer data variables can be coregistered [#770](https://github.com/CCI-Tools/cate/issues/770)

## Version 2.0.0.dev20

* Changed order and names of new `data_frame_subset` operation inputs.
Expand Down
2 changes: 1 addition & 1 deletion cate/ops/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def _downsample_2d(src, mask, use_mask, method, fill_value, mode_rank, out):
else:
out[out_y, out_x] = (wvv_sum * w_sum - wv_sum * wv_sum) / w_sum / w_sum
if method == DS_STD:
out = np.sqrt(out)
out = np.sqrt(out).astype(out.dtype)
else:
raise ValueError('invalid downsampling method')

Expand Down
68 changes: 68 additions & 0 deletions test/ops/test_coregistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,71 @@ def test_2D(self):
ds_coarse_resampled = coregister(ds_fine, ds_coarse)

assert_almost_equal(ds_coarse_resampled['first'].values, slice_exp)

def test_int_array(self):
"""
Test coregistration on integer arrays
"""
ds_fine = xr.Dataset({
'first': (['time', 'lat', 'lon'], np.array([np.eye(4, 8), np.eye(4, 8)], dtype='int32')),
'second': (['time', 'lat', 'lon'], np.array([np.eye(4, 8), np.eye(4, 8,)])),
'lat': np.linspace(-67.5, 67.5, 4),
'lon': np.linspace(-157.5, 157.5, 8),
'time': np.array([1, 2])}).chunk(chunks={'lat': 2, 'lon': 4})

ds_coarse = xr.Dataset({
'first': (['time', 'lat', 'lon'], np.array([np.eye(3, 6), np.eye(3, 6)], dtype='int32')),
'second': (['time', 'lat', 'lon'], np.array([np.eye(3, 6), np.eye(3, 6)])),
'lat': np.linspace(-60, 60, 3),
'lon': np.linspace(-150, 150, 6),
'time': np.array([1, 2])}).chunk(chunks={'lat': 3, 'lon': 3})

# Test that the coarse dataset has been resampled onto the grid
# of the finer dataset.
ds_coarse_resampled = coregister(ds_fine, ds_coarse, method_us='nearest')

expected = xr.Dataset({
'first': (['time', 'lat', 'lon'], np.array([[[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0]],
[[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0]]])),
'second': (['time', 'lat', 'lon'], np.array([[[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0]],
[[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0]]])),
'lat': np.linspace(-67.5, 67.5, 4),
'lon': np.linspace(-157.5, 157.5, 8),
'time': np.array([1, 2])})
assert_almost_equal(ds_coarse_resampled['first'].values, expected['first'].values)

# Test that the fine dataset has been resampled (aggregated)
# onto the grid of the coarse dataset.
ds_fine_resampled = coregister(ds_coarse, ds_fine, method_ds='mode')
expected = xr.Dataset({
'first': (['time', 'lat', 'lon'], np.array([[[1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0]],

[[1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0]]])),
'second': (['time', 'lat', 'lon'], np.array([[[1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0]],

[[1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0]]])),
'lat': np.linspace(-60, 60, 3),
'lon': np.linspace(-150, 150, 6),
'time': np.array([1, 2])})

assert_almost_equal(ds_fine_resampled['first'].values, expected['first'].values)