Skip to content

Commit

Permalink
Adds minimum duration request for sscweb
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Jeandet <[email protected]>
  • Loading branch information
jeandet committed Apr 18, 2021
1 parent d415d3a commit b1c959e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions spwc/sscweb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import os
from typing import Optional
from datetime import datetime
from datetime import datetime, timedelta
import requests
from ..cache import _cache, Cacheable
from ..common.variable import SpwcVariable
Expand Down Expand Up @@ -62,11 +62,13 @@ def version(self, product):
@Proxyfiable(GetProduct, get_parameter_args)
def get_orbit(self, product: str, start_time: datetime, stop_time: datetime, coordinate_system: str = 'gse',
debug=False) -> Optional[SpwcVariable]:
if stop_time - start_time < timedelta(days=1):
stop_time += timedelta(days=1)
url = f"{self.__url}/locations/{product}/{start_time.strftime('%Y%m%dT%H%M%SZ')},{stop_time.strftime('%Y%m%dT%H%M%SZ')}/{coordinate_system}/"
if debug:
print(url)
res = requests.get(url, headers={"Accept": "application/json"})
orbit = res.json()
if res.ok and _is_valid(orbit):
return _variable(orbit)
return _variable(orbit)[start_time:stop_time]
return None
14 changes: 13 additions & 1 deletion tests/test_sscweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Tests for `spwc` package."""
import unittest
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta
from spwc import sscweb
from ddt import ddt, data

Expand Down Expand Up @@ -31,6 +31,16 @@ def tearDown(self):
"product": "mms1",
"start_time": datetime(2021, 1, 8, 1, 0, 0, tzinfo=timezone.utc),
"stop_time": datetime(2021, 1, 8, 10, 0, 0, tzinfo=timezone.utc)
},
{
"product": "mms1",
"start_time": datetime(2021, 1, 8, 1, 0, 0, tzinfo=timezone.utc),
"stop_time": datetime(2021, 1, 8, 1, 0, 0, tzinfo=timezone.utc)
},
{
"product": "mms1",
"start_time": datetime(2021, 1, 8, 1, 0, 0, tzinfo=timezone.utc),
"stop_time": datetime(2021, 1, 8, 1, 0, 1, tzinfo=timezone.utc)
}
)
def test_get_orbit(self, kw):
Expand All @@ -40,6 +50,8 @@ def test_get_orbit(self, kw):
disable_proxy=True)
self.assertIsNotNone(result)
self.assertGreater(len(result), 0)
self.assertGreater(60., kw["start_time"].timestamp() - result.time[0])
self.assertGreater(60., kw["stop_time"].timestamp() - result.time[-1])

def test_get_observatories(self):
obs_list = self.ssc.get_observatories()
Expand Down

0 comments on commit b1c959e

Please sign in to comment.