Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- presumably fixed bug #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 11 additions & 8 deletions src/basinex/geoarray/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import numpy as np

# precision for rounding to avoid numerical instabilities
PRECISION = 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add this as an optional argument to the config yaml file.



class SpatialMixin(object):
def trim(self):
Expand Down Expand Up @@ -83,10 +86,10 @@ def shrink(self, ymin=None, ymax=None, xmin=None, xmax=None):
}

cellsize = [float(abs(cs)) for cs in self.cellsize]
top = floor((self.bbox["ymax"] - bbox["ymax"]) / cellsize[0])
left = floor((bbox["xmin"] - self.bbox["xmin"]) / cellsize[1])
bottom = floor((bbox["ymin"] - self.bbox["ymin"]) / cellsize[0])
right = floor((self.bbox["xmax"] - bbox["xmax"]) / cellsize[1])
top = floor(round((self.bbox["ymax"] - bbox["ymax"]) / cellsize[0], PRECISION))
left = floor(round((bbox["xmin"] - self.bbox["xmin"]) / cellsize[1], PRECISION))
bottom = floor(round((bbox["ymin"] - self.bbox["ymin"]) / cellsize[0], PRECISION))
right = floor(round((self.bbox["xmax"] - bbox["xmax"]) / cellsize[1], PRECISION))

return self.removeCells(
max(top, 0), max(left, 0), max(bottom, 0), max(right, 0)
Expand Down Expand Up @@ -175,10 +178,10 @@ def enlarge(self, ymin=None, ymax=None, xmin=None, xmax=None):

cellsize = [float(abs(cs)) for cs in self.cellsize]

top = ceil((bbox["ymax"] - self.bbox["ymax"]) / cellsize[0])
left = ceil((self.bbox["xmin"] - bbox["xmin"]) / cellsize[1])
bottom = ceil((self.bbox["ymin"] - bbox["ymin"]) / cellsize[0])
right = ceil((bbox["xmax"] - self.bbox["xmax"]) / cellsize[1])
top = ceil(round((bbox["ymax"] - self.bbox["ymax"]) / cellsize[0], PRECISION))
left = ceil(round((self.bbox["xmin"] - bbox["xmin"]) / cellsize[1], PRECISION))
bottom = ceil(round((self.bbox["ymin"] - bbox["ymin"]) / cellsize[0], PRECISION))
right = ceil(round((bbox["xmax"] - self.bbox["xmax"]) / cellsize[1], PRECISION))

return self.addCells(max(top, 0), max(left, 0), max(bottom, 0), max(right, 0))

Expand Down
2 changes: 1 addition & 1 deletion src/basinex/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def writeReport(bpath, mask, scaling_factor, gauge):


def maskData(data, mask):
if all(x == y for x, y in zip(mask.cellsize, data.cellsize)):
if all(np.isclose(x, y) for x, y in zip(mask.cellsize, data.cellsize)):
return data.setMask(mask.mask)

enlarged_mask = mask.enlarge(**data.bbox).astype(float)
Expand Down