Skip to content

Commit

Permalink
fixing fminimum method in raster class
Browse files Browse the repository at this point in the history
  • Loading branch information
wbierbower committed Apr 30, 2015
1 parent c000d9b commit 1301280
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions fauxgeo/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ def minimum(self, raster):
# Implement broadcast operation
def min_closure(nodata):
def mini(x):
def f(x): return np.where((np.minimum(x, raster)), x, raster)
def f(x): return np.where(np.not_equal(x, raster), np.minimum(x, raster), np.minimum(x, raster))
return np.where((np.not_equal(x, nodata)), f(x), nodata)
return mini
return self.local_op(raster, min_closure, broadcast=True)
else:
def min_closure(nodata):
def mini(x, y):
def f(x, y): return np.where((np.minimum(x, y)), x, y)
def f(x, y): return np.where(np.not_equal(x, y), np.minimum(x, y), np.minimum(x, y))
return np.where((np.not_equal(x, nodata)) & (np.not_equal(y, nodata)), f(x, y), nodata)
return mini
return self.local_op(raster, min_closure)
Expand All @@ -306,15 +306,15 @@ def fminimum(self, raster):
# Implement broadcast operation
def min_closure(nodata):
def mini(x):
def f(x): return np.where((np.fmin(x, raster)), x, raster)
def f(x): return np.where(np.not_equal(x, raster), np.fmin(x, raster), np.fmin(x, raster))
return np.where((np.not_equal(x, nodata)), f(x), nodata)
return mini
return self.local_op(raster, min_closure, broadcast=True)
else:
def min_closure(nodata):
def mini(x, y):
def f(x, y): return np.where((np.fmin(x, y)), x, y)
return np.where((np.not_equal(x, nodata)) | (np.not_equal(y, nodata)), f(x, y), nodata)
def f(x, y): return np.where((np.not_equal(x, y)), np.fmin(x, y), np.fmin(x, y))
return np.where((np.not_equal(x, nodata)) & (np.not_equal(y, nodata)), f(x, y), nodata)
return mini
return self.local_op(raster, min_closure)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ def test_minimum(self):
assert(min_raster.get_band(1).data[0, 1] == -9999)

def test_fminimum(self):
raster1 = self.factory.alternating(1.0, 2.0)
raster2 = self.factory.alternating(2.0, -9999)
raster1 = self.factory.alternating(2.0, float('NaN'))
raster2 = self.factory.alternating(1.0, 2.0)
min_raster = raster1.fminimum(raster2)
assert(min_raster.get_band(1).data[0, 0] == 1)
assert(min_raster.get_band(1).data[0, 1] == 2)
Expand Down

0 comments on commit 1301280

Please sign in to comment.