Skip to content

Commit

Permalink
Fixes few minor issues in AMDA module
Browse files Browse the repository at this point in the history
- Since we added new inventory entries there could be some code path
where inventory was cached but with missing entries.
- Given a time range a downloaded parameter won't match exactly start
time and end time but should contain the first data at or after start
time to the last data before stop time.

Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
  • Loading branch information
jeandet committed Aug 5, 2021
1 parent ddb5a71 commit e107171
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions speasy/amda/amda.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def __init__(self, wsdl: str = 'AMDA/public/wsdl/Methods_AMDA.wsdl', server_url:
self.catalog = {}
if "AMDA/inventory" in _cache:
self._unpack_inventory(_cache["AMDA/inventory"])
if any(map(lambda d: d == {},
[self.parameter, self.mission, self.observatory, self.instrument, self.dataset,
self.datasetGroup, self.component, self.dataCenter, self.folder, self.timeTable,
self.catalog])):
self.update_inventory()
else:
self.update_inventory()

Expand Down
9 changes: 6 additions & 3 deletions tests/test_amda_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import unittest
import os
from datetime import datetime, timezone
from datetime import datetime, timedelta
from speasy.amda import AMDA, load_csv
from speasy.common.variable import SpeasyVariable
from ddt import ddt, data
Expand Down Expand Up @@ -43,8 +43,11 @@ def test_time_datatype(self):
self.assertTrue(self.data.time.dtype == float)

def test_time_range(self):
self.assertTrue(datetime.utcfromtimestamp(self.data.time[0]) == self.start)
self.assertTrue(datetime.utcfromtimestamp(self.data.time[-1]) == self.stop)
min_dt = min(self.data.time[1:] - self.data.time[:-1])
self.assertTrue(
self.start <= datetime.utcfromtimestamp(self.data.time[0]) < self.start + timedelta(seconds=min_dt))
self.assertTrue(
self.stop > datetime.utcfromtimestamp(self.data.time[-1]) >= self.stop - timedelta(seconds=min_dt))

def test_dataset_not_none(self):
self.assertIsNotNone(self.dataset)
Expand Down

0 comments on commit e107171

Please sign in to comment.