Skip to content

Commit

Permalink
Merge pull request #92 from nens/verkerk-do-not-mess-with-elemwise
Browse files Browse the repository at this point in the history
Revert changes to elemwise.
  • Loading branch information
arjanverkerk committed Feb 4, 2022
2 parents 9efab77 + afa0249 commit 903592d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog of dask-geomodeling
2.3.6 (unreleased)
------------------

- Nothing changed yet.
- Reverted changes to elemwise.


2.3.5 (2022-02-02)
Expand Down
21 changes: 6 additions & 15 deletions dask_geomodeling/raster/elemwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,17 @@ def _sources(self):
return [arg for arg in self.args if isinstance(arg, RasterBlock)]

def get_sources_and_requests(self, **request):

period = self.period
process_kwargs = {
"dtype": self.dtype.name, "fillvalue": self.fillvalue,
}
if period is None:
return [(process_kwargs, None)]

# limit request to self.period so that resulting data is aligned
start = request.get("start", None)
stop = request.get("stop", None)
if start is not None:
if stop is not None:

if start is not None and stop is not None:
# limit request to self.period so that resulting data is aligned
period = self.period
if period is not None:
request["start"] = max(start, period[0])
request["stop"] = min(stop, period[1])
else: # stop is None but start isn't
request["start"] = min(max(start, period[0]), period[1])
else: # start and stop are both None
request["start"] = period[1]

process_kwargs = {"dtype": self.dtype.name, "fillvalue": self.fillvalue}
sources_and_requests = [(source, request) for source in self.args]

return [(process_kwargs, None)] + sources_and_requests
Expand Down
30 changes: 30 additions & 0 deletions dask_geomodeling/raster/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,36 @@ def __init__(self, *args):
raise TypeError("'{}' object is not allowed".format(type(arg)))
super().__init__(*args)

def get_sources_and_requests(self, **request):
"""
This method is more strict than the one from BaseElementWise, it is not
possible to get data from this block when its period is None, meaning
that either the sources have no common period, or one of the sources'
periods is None.
"""
period = self.period
process_kwargs = {
"dtype": self.dtype.name, "fillvalue": self.fillvalue,
}
if period is None:
return [(process_kwargs, None)]

# limit request to self.period so that resulting data is aligned
start = request.get("start", None)
stop = request.get("stop", None)
if start is not None:
if stop is not None:
request["start"] = max(start, period[0])
request["stop"] = min(stop, period[1])
else: # stop is None but start isn't
request["start"] = min(max(start, period[0]), period[1])
else: # start and stop are both None
request["start"] = period[1]

sources_and_requests = [(source, request) for source in self.args]

return [(process_kwargs, None)] + sources_and_requests

@property
def extent(self):
""" Boundingbox of combined contents in WGS84 projection. """
Expand Down

0 comments on commit 903592d

Please sign in to comment.