Skip to content

Commit

Permalink
Update sscweb Json schema
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Jeandet <[email protected]>
  • Loading branch information
jeandet committed Apr 17, 2024
1 parent 9a0a754 commit 60cdc57
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions speasy/webservices/ssc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@
from speasy.products.variable import SpeasyVariable, VariableTimeAxis, DataContainer
from ...core import AllowedKwargs, http

log = logging.getLogger(__name__)


def _make_datetime(dt: str) -> np.datetime64:
'''
Hack to support python 3.6, once 3.6 support removed then go back to:
datetime.strptime(v[1], '%Y-%m-%dT%H:%M:%S.%f%z').timestamp()
'''
return np.datetime64(dt[:-6], 'ns')


def _variable(orbit: dict) -> Optional[SpeasyVariable]:
data = orbit['Result']['Data'][1][0]['Coordinates'][1][0]
keys = list(data.keys())
keys.remove('CoordinateSystem')
data = orbit['Result'][1]['Data'][1][0][1]['Coordinates'][1][0][1]
time = orbit['Result'][1]['Data'][1][0][1]['Time'][1]
values = np.array([data['X'][1], data['Y'][1], data['Z'][1]]).transpose()

# this is damn slow!
time_axis = np.array([_make_datetime(v[1]) for v in
orbit['Result']['Data'][1][0]['Time'][1]])
time_axis = np.array([_make_datetime(v[1]) for v in time])
return SpeasyVariable(
axes=[VariableTimeAxis(values=time_axis)],
values=DataContainer(values, meta={'CoordinateSystem': data['CoordinateSystem'], 'UNITS': 'km'}),
columns=['X', 'Y', 'Z']
)


log = logging.getLogger(__name__)


def _make_datetime(dt: str) -> np.datetime64:
'''
Hack to support python 3.6, once 3.6 support removed then go back to:
datetime.strptime(v[1], '%Y-%m-%dT%H:%M:%S.%f%z').timestamp()
'''
return np.datetime64(dt[:-6], 'ns')


def _is_valid(orbit: dict):
return orbit['Result']['StatusCode'] == 'SUCCESS' and orbit['Result']['StatusSubCode'] == 'SUCCESS'
return orbit['Result'][1]['StatusCode'] == 'SUCCESS' and orbit['Result'][1]['StatusSubCode'] == 'SUCCESS'


def _make_cache_entry_name(prefix: str, product: str, start_time: str, **kwargs):
Expand Down Expand Up @@ -86,7 +86,7 @@ def get_observatories(self):
res = http.get(f"{self.__url}/observatories", headers={"Accept": "application/json"})
if not res.ok:
return None
return res.json()['Observatory'][1]
return list(map(lambda x: x[1], res.json()[1]['Observatory'][1]))

def version(self, product):
return 2
Expand Down Expand Up @@ -138,7 +138,7 @@ def _get_orbit(self, product: str, start_time: datetime, stop_time: datetime, co
if extra_http_headers is not None:
headers.update(extra_http_headers)
res = http.get(url, headers=headers)
orbit = res.json()
orbit = res.json()[1]
if res.ok and _is_valid(orbit):
return _variable(orbit)[start_time:stop_time]
return None

0 comments on commit 60cdc57

Please sign in to comment.