Skip to content

Commit

Permalink
Use masked_array() to read by envelope
Browse files Browse the repository at this point in the history
  • Loading branch information
bkg committed Aug 12, 2015
1 parent 0e34bd0 commit d212185
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions greenwich/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,9 @@ def _mask(self, geom):
# Without a simple envelope, this becomes a masking operation rather
# than a crop.
if not geom.Equals(env.polygon):
arr = self.ds.ReadAsArray(*readargs)
m = np.ma.masked_array(arr)
m = self.masked_array(env)
# This will broadcast whereas np.ma.masked_array() does not.
m.mask = geom_to_array(geom, dims, affine)
if self.nodata is not None:
m = np.ma.masked_values(m, self.nodata, copy=False)
pixbuf = bytes(np.getbuffer(m.filled()))
else:
pixbuf = self.ds.ReadRaster(*readargs)
Expand All @@ -548,9 +545,9 @@ def masked_array(self, envelope=()):
envelope -- coordinate extent tuple or Envelope
"""
arr = self.array(envelope)
if self.nodata is None:
return np.ma.masked_array(arr)
return np.ma.masked_values(arr, self.nodata)
if self.nodata is not None:
return np.ma.masked_values(arr, self.nodata, copy=False)
return np.ma.masked_array(arr)

@property
def nodata(self):
Expand Down

0 comments on commit d212185

Please sign in to comment.