Skip to content

Commit

Permalink
ModisSmoothH5: correct last_collected to look at archive of raw collects
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob committed Mar 17, 2021
1 parent 308df13 commit 1fd1f3e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
13 changes: 11 additions & 2 deletions modape/modis/smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,17 @@ def smooth(self,


@property
def last_collected(self):
"""Last collected date in file"""
def last_collected_in_raw(self):
"""Last collected date in raw file"""
with h5py.File(self.rawfile, "r") as h5f_raw:
dates = h5f_raw.get("rawdates")
last_date = dates[-1].decode()

return last_date


def last_smoothed(self):
"""Last smoothed date in file"""
assert self.exists, "File doesn't exist!"

with h5py.File(self.filename, "r") as h5_open:
Expand Down
10 changes: 5 additions & 5 deletions modape/scripts/modis_smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ def _worker(rawfile: str,
smt_h5.create()

if last_collected is not None:
last_collected_infile = smt_h5.last_collected
last_collected_in_rawfile = smt_h5.last_collected_in_raw

if not last_collected_infile:
raise ValueError(f"No last_collected recorded in {smt_h5.filename}")
if not last_collected_in_rawfile:
raise ValueError(f"No last_collected recorded in {smt_h5.rawfile}")

assert last_collected == last_collected_infile, \
f"Last collected date in file is {last_collected_infile} not {last_collected}"
assert last_collected == last_collected_in_rawfile, \
f"Last collected date in {smt_h5.rawfile} is {last_collected_in_rawfile} not {last_collected}"

smt_h5.smooth(**kwargs)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_modis.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ def test_create(self):
dates = hdf5_file.get("dates")
self.assertTrue(dates)

self.assertNotEqual(smtH5.last_collected, "2002201")
self.assertEqual(smtH5.last_collected, "2002209")
self.assertNotEqual(smtH5.last_smoothed, "2002201")
self.assertEqual(smtH5.last_smoothed, "2002209")

smtH5.filename.unlink()

Expand Down

0 comments on commit 1fd1f3e

Please sign in to comment.