Skip to content

Commit

Permalink
fix mask for loading in data
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Dec 11, 2019
1 parent 770b0ba commit 9f56b9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rioxarray/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def read(self, window, out_shape, *args, **kwargs) -> numpy.ma.array:
if numpy.isnan(nodata):
mask = numpy.isnan(data_window)
elif nodata is not None:
mask = data_window != nodata
mask = data_window == nodata
fill_value = nodata

return numpy.ma.array(
Expand Down
9 changes: 5 additions & 4 deletions test/integration/test_integration_merge.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import pytest
from numpy import nansum
from numpy.testing import assert_almost_equal

from rioxarray import open_rasterio
Expand Down Expand Up @@ -50,12 +51,12 @@ def test_merge_arrays():
assert sorted(merged.coords) == ["band", "spatial_ref", "x", "y"]
assert merged.rio.crs == rds.rio.crs
assert merged.attrs == rds.attrs
assert_almost_equal(merged.sum(), -1158377472)
assert_almost_equal(merged.sum(), 11368261)


def test_merge_arrays__res():
dem_test = os.path.join(TEST_INPUT_DATA_DIR, "MODIS_ARRAY.nc")
with open_rasterio(dem_test) as rds:
with open_rasterio(dem_test, masked=True) as rds:
rds.attrs = {
"_FillValue": rds.rio.nodata,
"grid_mapping": "spatial_ref",
Expand Down Expand Up @@ -85,7 +86,7 @@ def test_merge_arrays__res():
assert sorted(merged.coords) == ["band", "spatial_ref", "x", "y"]
assert merged.rio.crs == rds.rio.crs
assert merged.attrs == rds.attrs
assert_almost_equal(merged.sum(), -688844800)
assert_almost_equal(nansum(merged), 13767944)


@pytest.mark.xfail(os.name == "nt", reason="On windows the merged data is different.")
Expand Down Expand Up @@ -187,4 +188,4 @@ def test_merge_datasets__res():
base_attrs = dict(rds.attrs)
base_attrs["grid_mapping"] = "spatial_ref"
assert merged.attrs == base_attrs
assert_almost_equal(merged[data_var].sum(), 973667940761024)
assert_almost_equal(merged[data_var].sum(), 974565970607345)

0 comments on commit 9f56b9b

Please sign in to comment.