Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Aug 19, 2024
1 parent c6b9002 commit 7bfdbb1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 10 additions & 6 deletions dask_geomodeling/raster/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
__all__ = ["MemorySource", "RasterFileSource"]


def utc_from_ms_timestamp(timestamp):
"""Returns naive UTC datetime from ms timestamp"""
return datetime.fromtimestamp(timestamp / 1000, tz=timezone.utc).replace(tzinfo=None)

class MemorySource(RasterBlock):
"""A raster source that interfaces data from memory.
Expand Down Expand Up @@ -174,9 +178,9 @@ def period(self):
if len(self) == 0:
return
elif len(self) == 1:
return (datetime.fromtimestamp(self.time_first / 1000, tz=timezone.utc)) * 2
return (utc_from_ms_timestamp(self.time_first),) * 2
else:
first = datetime.fromtimestamp(self.time_first / 1000, tz=timezone.utc)
first = utc_from_ms_timestamp(self.time_first)
last = first + (len(self) - 1) * self.timedelta
return first, last

Expand Down Expand Up @@ -206,7 +210,7 @@ def get_sources_and_requests(self, **request):
start, stop, first_i, last_i = utils.snap_start_stop(
request.get("start"),
request.get("stop"),
datetime.fromtimestamp(self.time_first / 1000, tz=timezone.utc),
utc_from_ms_timestamp(self.time_first),
self.timedelta,
len(self),
)
Expand Down Expand Up @@ -398,9 +402,9 @@ def period(self):
if len(self) == 0:
return
elif len(self) == 1:
return (datetime.fromtimestamp(self.time_first / 1000, tz=timezone.utc)) * 2
return (utc_from_ms_timestamp(self.time_first)) * 2
else:
first = datetime.fromtimestamp(self.time_first / 1000, tz=timezone.utc)
first = utc_from_ms_timestamp(self.time_first)
last = first + (len(self) - 1) * self.timedelta
return first, last

Expand All @@ -427,7 +431,7 @@ def get_sources_and_requests(self, **request):
start, stop, first_i, last_i = utils.snap_start_stop(
request.get("start"),
request.get("stop"),
datetime.fromtimestamp(self.time_first / 1000, tz=timezone.utc),
utc_from_ms_timestamp(self.time_first),
self.timedelta,
len(self),
)
Expand Down
2 changes: 2 additions & 0 deletions dask_geomodeling/raster/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ def period(self):

@property
def timedelta(self):
if self.frequency is None:
return None
try:
return pd.Timedelta(to_offset(self.frequency)).to_pytimedelta()
except ValueError:
Expand Down

0 comments on commit 7bfdbb1

Please sign in to comment.