Skip to content

Commit

Permalink
Do not change dtype of data during resampling.
Browse files Browse the repository at this point in the history
Fix #82
  • Loading branch information
Christoph Paulik committed Mar 22, 2016
1 parent 5248a83 commit 78b7b81
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -6,6 +6,7 @@
* Add recursive calculation of Pearson correlation coefficent.
* Change H-SAF reading interface to use pygeobase consistently.
* H07 reader now returns more variables.
* Resampling interface now respects dtype of input data.


# v0.3.6, 2015-12-10
Expand Down
4 changes: 2 additions & 2 deletions pytesmo/grid/resample.py
Expand Up @@ -160,9 +160,9 @@ def resample_to_grid(input_data, src_lon, src_lat, target_lon, target_lat,
# construct arrays in output grid form
if fill_value is not None:
output_array = np.zeros(
output_swath.shape, dtype=np.float64) + fill_value
output_swath.shape, dtype=data.dtype) + fill_value
else:
output_array = np.zeros(output_swath.shape, dtype=np.float64)
output_array = np.zeros(output_swath.shape, dtype=data.dtype)
output_array = np.ma.array(output_array, mask=mask)

neigh_slice = slice(None, None, None)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_grid/test_resample.py
Expand Up @@ -70,6 +70,33 @@ def test_resample_to_zero_dot_one_deg(self):
assert resampled_data[key].shape == lons_grid.shape


def test_resample_dtypes():
"""
Test if dtypes stay the same when resampling.
"""

data = {'testint8': np.array([5, 5], dtype=np.int8),
'testfloat16': np.array([5, 5], dtype=np.float16)}

fill_values = {'testint8': 0,
'testfloat16': 999.}
lons = np.array([0, 0.1])
lats = np.array([0, 0.1])
# lets resample to a 0.1 degree grid
# define the grid points in latitude and longitude
lats_dim = np.arange(-1, 1, 0.1)
lons_dim = np.arange(-1, 1, 0.1)
# make 2d grid out the 1D grid spacing
lons_grid, lats_grid = np.meshgrid(lons_dim, lats_dim)

resampled_data = resample.resample_to_grid(data, lons, lats,
lons_grid, lats_grid,
fill_values=fill_values)

for key in data:
assert resampled_data[key].shape == lons_grid.shape
assert resampled_data[key].dtype == data[key].dtype

if __name__ == "__main__":
# import sys;sys.argv = ['', 'Test.testName']
unittest.main()

0 comments on commit 78b7b81

Please sign in to comment.