Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3DView support #80

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ astropy
pyistp
astroquery
tqdm
suds
matplotlib
sphinx!=5.2.0.post0
sphinx-rtd-theme
Expand Down
14 changes: 14 additions & 0 deletions docs/user/3DView/3dview.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
3D View
=======

.. toctree::
:maxdepth: 1

`3DView <http://3dview.irap.omp.eu/>`__ is one of the main data providers handled by speasy. All products are either available using directly the 3DView module or using :meth:`speasy.get_data()`.
:meth:`speasy.get_data()` usage should be preferred over 3DView module methods since it is more flexible and it's interface is guaranteed to be more stable.
The following documentation will focus on 3DView module specific usage.


Basics: Getting data from 3DView module
---------------------------------------

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ requires = ["flit_core"]
name = 'speasy'
version = "1.1.1"
description = "A simple Python package to deal with main Space Physics WebServices (CDA, CSA, AMDA and SSC)."
keywords= ["satellite", "plasma-physics", "nasa-data", "amda", "cdpp", "CDF"]
keywords = ["satellite", "plasma-physics", "nasa-data", "amda", "cdpp", "CDF"]
authors = [
{name = "Alexis Jeandet", email = "alexis.jeandet@member.fsf.org" }
{ name = "Alexis Jeandet", email = "alexis.jeandet@member.fsf.org" }
]

maintainers = [
{name = "Alexis Jeandet", email = "alexis.jeandet@member.fsf.org" }
{ name = "Alexis Jeandet", email = "alexis.jeandet@member.fsf.org" }
]

requires-python=">=3.7"
Expand All @@ -31,7 +31,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
]
dependencies = ['requests', 'pandas', 'diskcache', 'appdirs', 'numpy', 'packaging', 'python-dateutil',
'astropy', 'astroquery', 'pyistp', 'tqdm', 'matplotlib', 'urllib3>=1.26.0']
'astropy', 'astroquery', 'pyistp', 'tqdm', 'matplotlib', 'urllib3>=1.26.0', 'suds']
[project.urls]
homepage = "https://github.com/SciQLop/speasy"

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ astropy
pyistp
astroquery
tqdm
matplotlib
matplotlib
suds
3 changes: 2 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ pytest-cov
pyistp
astroquery
tqdm
matplotlib
matplotlib
suds
2 changes: 1 addition & 1 deletion speasy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from speasy.core.inventory.indexes import SpeasyIndex
from .products import SpeasyVariable, Catalog, Event, Dataset, TimeTable, MaybeAnyProduct
from typing import List
from .core.requests_scheduling.request_dispatch import get_data, list_providers, amda, cda, csa, ssc
from .core.requests_scheduling.request_dispatch import get_data, list_providers, amda, cda, csa, ssc, cdpp3dview


# @TODO implement me, this function should be able to look inside all servers
Expand Down
9 changes: 9 additions & 0 deletions speasy/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ def remove_entry(entry: ConfigEntry):
"default": "ASCII"}
)

cdpp_3dview = ConfigSection("3DView",
cache_retention={"default": 900,
"description": "3DView cache retention for non trajectories requests in seconds.",
"type_ctor": int
},
wsld_url={
"default": "http://3dview.irap.omp.eu/CdppServices?wsdl"}
)

inventories = ConfigSection("INVENTORIES",
cache_retention_days={
"default": 2,
Expand Down
2 changes: 1 addition & 1 deletion speasy/core/dataprovider.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from datetime import datetime
from functools import wraps
from typing import Callable, List, Optional
from threading import Lock
from typing import Callable, List, Optional

from speasy.core.datetime_range import DateTimeRange
from speasy.core.inventory import ProviderInventory
Expand Down
2 changes: 1 addition & 1 deletion speasy/core/proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

log = logging.getLogger(__name__)
PROXY_ALLOWED_KWARGS = ['disable_proxy']
MINIMUM_REQUIRED_PROXY_VERSION = Version("0.8.0")
MINIMUM_REQUIRED_PROXY_VERSION = Version("0.9.0")
_CURRENT_PROXY_SERVER_VERSION = None

if proxy_cfg.url() == "" or proxy_cfg.enabled() == False:
Expand Down
19 changes: 13 additions & 6 deletions speasy/core/requests_scheduling/request_dispatch.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import sys
from datetime import datetime
from typing import Iterable, List, Optional, Tuple, Union, overload
import sys

import numpy as np

from .. import is_collection, progress_bar
from ..datetime_range import DateTimeRange
from ..inventory.indexes import (CatalogIndex, ComponentIndex,
DatasetIndex, ParameterIndex,
SpeasyIndex, TimetableIndex)

from ...config import core as core_cfg
from ...products import *
from ...webservices import (AMDA_Webservice, CDA_Webservice, CSA_Webservice,
SSC_Webservice)
from .. import is_collection, progress_bar
from ..datetime_range import DateTimeRange
from ...config import core as core_cfg
SSC_Webservice, CDPP_3DView_Webservice)

TimeT = Union[str, datetime, float, np.datetime64]
TimeRangeT = Union[DateTimeRange, Tuple[TimeT, TimeT]]
Expand All @@ -24,6 +24,7 @@
csa = None
cda = None
ssc = None
cdpp3dview = None

if 'amda' not in core_cfg.disabled_providers():
amda = AMDA_Webservice()
Expand All @@ -47,6 +48,12 @@
PROVIDERS['ssc'] = ssc
PROVIDERS['sscweb'] = ssc

if not core_cfg.disabled_providers().intersection({'CDPP_3DView', '3DView'}):
cdpp3dview = CDPP_3DView_Webservice()
sys.modules[__name__].cdpp3dview = cdpp3dview
PROVIDERS['CDPP_3DView'] = cdpp3dview
PROVIDERS['3DView'] = cdpp3dview


def list_providers() -> List[str]:
return list(PROVIDERS.keys())
Expand Down
1 change: 1 addition & 0 deletions speasy/webservices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .cda import CDA_Webservice
from .ssc import SSC_Webservice
from .csa import CSA_Webservice
from .cdpp_3dview import CDPP_3DView_Webservice
49 changes: 49 additions & 0 deletions speasy/webservices/cdpp_3dview/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

"""CDPP_3DView_Webservice package for Speasy."""

__author__ = """Alexis Jeandet"""
__email__ = 'alexis.jeandet@member.fsf.org'
__version__ = '0.1.0'

import logging
from typing import List, Dict

from speasy.core.dataprovider import (DataProvider)
from speasy.core.inventory.indexes import ParameterIndex, SpeasyIndex
from .ws import _WS_impl, Body

log = logging.getLogger(__name__)


def _to_indexes(provider_name: str, bodies: List[Body]) -> Dict[str, ParameterIndex]:
return {
b.name: ParameterIndex(name=b.name, provider=provider_name, uid=str(b.naif_id), meta={
"body_type": str(b.body_type),
"coverage": str(b.coverage),
"model_id": str(b.model_id),
"naif_id": str(b.naif_id),
"preferred_center": str(b.preferred_center),
"preferred_frame": str(b.preferred_frame),
"preferred_star_subset": str(b.preferred_star_subset)
}) for b in bodies
}


class CDPP_3DView_Webservice(DataProvider):
def __init__(self):
self._impl = _WS_impl()
DataProvider.__init__(self, provider_name='CDPP_3DView', provider_alt_names=['3DView'])

def build_inventory(self, root: SpeasyIndex):
root.Asteroids = SpeasyIndex(name='Asteroids', provider=self.provider_name, uid='Asteroids',
meta=_to_indexes(self.provider_name, self._impl.get_asteroid_list()))
root.Comets = SpeasyIndex(name='Comets', provider=self.provider_name, uid='Comets',
meta=_to_indexes(self.provider_name, self._impl.get_comet_list()))
root.Planets = SpeasyIndex(name='Planets', provider=self.provider_name, uid='Planets',
meta=_to_indexes(self.provider_name, self._impl.get_planet_list()))
root.Satellites = SpeasyIndex(name='Satellites', provider=self.provider_name, uid='Satellites',
meta=_to_indexes(self.provider_name, self._impl.get_satellite_list()))
root.Spacecrafts = SpeasyIndex(name='Spacecrafts', provider=self.provider_name, uid='Spacecrafts',
meta=_to_indexes(self.provider_name, self._impl.get_spacecraft_list()))
return root
30 changes: 30 additions & 0 deletions speasy/webservices/cdpp_3dview/trajectory_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import Optional, Collection

import numpy as np
from astropy.io import votable

from speasy.core.http import urlopen_with_retry
from ...products import SpeasyVariable, VariableTimeAxis, DataContainer


def _to_datetime(dt: str) -> np.datetime64:
return np.datetime64(dt, 'ns')


def _to_datetime_array(time_vec: Collection[str]) -> np.ndarray:
return np.array(list(map(_to_datetime, time_vec)))


def load_trajectory(path: str) -> Optional[SpeasyVariable]:
with urlopen_with_retry(path) as f:
import io
traj = votable.parse_single_table(io.BytesIO(f.read())).to_table()
if traj and len(traj):
arr = np.empty((len(traj), 3))
arr[:, 0] = traj['col2']
arr[:, 1] = traj['col3']
arr[:, 2] = traj['col4']
return SpeasyVariable(axes=[VariableTimeAxis(values=_to_datetime_array(traj['col1']))],
values=DataContainer(values=arr, meta={'UNITS': 'km'}),
columns=["x", "y", "z"])
return None
Loading