erddapy 3.3.0__tar.gz → 3.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {erddapy-3.3.0 → erddapy-3.3.2}/PKG-INFO +5 -7
- {erddapy-3.3.0 → erddapy-3.3.2}/README.md +2 -2
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/core/url.py +7 -6
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/erddapy.py +30 -3
- erddapy-3.3.2/erddapy/xarray_erddap.py +57 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy.egg-info/SOURCES.txt +0 -2
- {erddapy-3.3.0 → erddapy-3.3.2}/pyproject.toml +39 -10
- erddapy-3.3.0/erddapy/xarray_erddap.py +0 -51
- erddapy-3.3.0/requirements-dev.txt +0 -27
- erddapy-3.3.0/requirements.txt +0 -2
- {erddapy-3.3.0 → erddapy-3.3.2}/CHANGES.txt +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/LICENSE.txt +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/MANIFEST.in +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/__init__.py +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/core/__init__.py +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/core/griddap.py +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/core/interfaces.py +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/core/netcdf.py +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/multiple_server_search.py +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/servers/__init__.py +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/servers/erddaps.json +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/erddapy/servers/servers.py +0 -0
- {erddapy-3.3.0 → erddapy-3.3.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: erddapy
|
|
3
|
-
Version: 3.3.
|
|
3
|
+
Version: 3.3.2
|
|
4
4
|
Summary: Python interface for ERDDAP
|
|
5
5
|
Maintainer-email: Alex Kerney <akerney@gmri.org>, Callum Rollo <c.rollo@outlook.com>, Filipe Fernandes <ocefpaf+erddapy@gmail.com>
|
|
6
6
|
License: Copyright 2017 Filipe Fernandes
|
|
@@ -32,18 +32,16 @@ License: Copyright 2017 Filipe Fernandes
|
|
|
32
32
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
|
33
33
|
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
34
34
|
|
|
35
|
-
Project-URL: documentation, https://ioos.github.io/erddapy
|
|
36
|
-
Project-URL: homepage, https://github.com/ioos/erddapy
|
|
37
|
-
Project-URL: repository, https://github.com/ioos/erddapy
|
|
38
35
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
39
36
|
Classifier: Programming Language :: Python :: 3.11
|
|
40
37
|
Classifier: Programming Language :: Python :: 3.12
|
|
41
38
|
Classifier: Programming Language :: Python :: 3.13
|
|
42
39
|
Classifier: Programming Language :: Python :: 3.14
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
43
41
|
Requires-Python: >=3.11
|
|
44
42
|
Description-Content-Type: text/markdown
|
|
45
43
|
License-File: LICENSE.txt
|
|
46
|
-
Requires-Dist: pandas
|
|
44
|
+
Requires-Dist: pandas
|
|
47
45
|
Requires-Dist: requests
|
|
48
46
|
Dynamic: license-file
|
|
49
47
|
|
|
@@ -69,7 +67,7 @@ erddapy: ERDDAP + Python.
|
|
|
69
67
|
<img src="https://img.shields.io/github/contributors/ioos/erddapy.svg"
|
|
70
68
|
alt="# contributors" /></a>
|
|
71
69
|
<a href="https://zenodo.org/badge/latestdoi/104919828">
|
|
72
|
-
<img src="https://zenodo.org/badge/
|
|
70
|
+
<img src="https://zenodo.org/badge/DOI/10.5281/zenodo.latest.svg"
|
|
73
71
|
alt="zenodo" /></a>
|
|
74
72
|
<a href="https://pypi.org/project/erddapy">
|
|
75
73
|
<img src="https://img.shields.io/pypi/pyversions/erddapy.svg"
|
|
@@ -79,7 +77,7 @@ erddapy: ERDDAP + Python.
|
|
|
79
77
|
alt="pre-commit.ci status" /></a>
|
|
80
78
|
|
|
81
79
|
<a href="https://github.com/ioos/erddapy/actions">
|
|
82
|
-
<img src="https://github.com/ioos/erddapy/actions/workflows/tests.yml/badge.svg"
|
|
80
|
+
<img src="https://github.com/ioos/erddapy/actions/workflows/tests-full.yml/badge.svg"
|
|
83
81
|
alt="GHA-tests" /></a>
|
|
84
82
|
|
|
85
83
|
|
|
@@ -20,7 +20,7 @@ erddapy: ERDDAP + Python.
|
|
|
20
20
|
<img src="https://img.shields.io/github/contributors/ioos/erddapy.svg"
|
|
21
21
|
alt="# contributors" /></a>
|
|
22
22
|
<a href="https://zenodo.org/badge/latestdoi/104919828">
|
|
23
|
-
<img src="https://zenodo.org/badge/
|
|
23
|
+
<img src="https://zenodo.org/badge/DOI/10.5281/zenodo.latest.svg"
|
|
24
24
|
alt="zenodo" /></a>
|
|
25
25
|
<a href="https://pypi.org/project/erddapy">
|
|
26
26
|
<img src="https://img.shields.io/pypi/pyversions/erddapy.svg"
|
|
@@ -30,7 +30,7 @@ erddapy: ERDDAP + Python.
|
|
|
30
30
|
alt="pre-commit.ci status" /></a>
|
|
31
31
|
|
|
32
32
|
<a href="https://github.com/ioos/erddapy/actions">
|
|
33
|
-
<img src="https://github.com/ioos/erddapy/actions/workflows/tests.yml/badge.svg"
|
|
33
|
+
<img src="https://github.com/ioos/erddapy/actions/workflows/tests-full.yml/badge.svg"
|
|
34
34
|
alt="GHA-tests" /></a>
|
|
35
35
|
|
|
36
36
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""URL handling."""
|
|
2
2
|
|
|
3
3
|
import copy
|
|
4
|
-
import datetime
|
|
4
|
+
import datetime as dt
|
|
5
5
|
import functools
|
|
6
6
|
import io
|
|
7
7
|
from collections import OrderedDict
|
|
@@ -244,7 +244,7 @@ def _is_quoted(url: str) -> bool:
|
|
|
244
244
|
|
|
245
245
|
|
|
246
246
|
def parse_dates(
|
|
247
|
-
date_time:
|
|
247
|
+
date_time: dt.datetime | str,
|
|
248
248
|
*,
|
|
249
249
|
dayfirst: bool = False,
|
|
250
250
|
yearfirst: bool = False,
|
|
@@ -255,6 +255,7 @@ def parse_dates(
|
|
|
255
255
|
strings or seconds since 1970, but internally ERDDAPY uses datetime-like
|
|
256
256
|
objects. `timestamp` returns the expected strings in seconds since 1970.
|
|
257
257
|
|
|
258
|
+
This function will shift any tz-aware, and convert naive datetimes, to UTC.
|
|
258
259
|
"""
|
|
259
260
|
if isinstance(date_time, str):
|
|
260
261
|
parse_date_time = to_datetime(
|
|
@@ -267,14 +268,14 @@ def parse_dates(
|
|
|
267
268
|
|
|
268
269
|
# Naive datetimes tzinfo must be replaced, tz-aware should be converted.
|
|
269
270
|
if not parse_date_time.tzinfo:
|
|
270
|
-
parse_date_time = parse_date_time.replace(tzinfo=
|
|
271
|
+
parse_date_time = parse_date_time.replace(tzinfo=dt.UTC)
|
|
271
272
|
else:
|
|
272
|
-
parse_date_time = parse_date_time.astimezone(
|
|
273
|
+
parse_date_time = parse_date_time.astimezone(dt.UTC)
|
|
273
274
|
|
|
274
275
|
return parse_date_time.timestamp()
|
|
275
276
|
|
|
276
277
|
|
|
277
|
-
def get_search_url( # noqa: PLR0913
|
|
278
|
+
def get_search_url( # noqa: PLR0913, PLR0917
|
|
278
279
|
server: str,
|
|
279
280
|
response: str = "html",
|
|
280
281
|
search_for: str | None = None,
|
|
@@ -350,7 +351,7 @@ def get_search_url( # noqa: PLR0913
|
|
|
350
351
|
search_for = parse.quote_plus(search_for)
|
|
351
352
|
base += "&searchFor={searchFor}"
|
|
352
353
|
|
|
353
|
-
# Convert dates from
|
|
354
|
+
# Convert dates from dt.datetime to secs since 1970-01-01T00:00:00Z.
|
|
354
355
|
min_time = kwargs.pop("min_time", "")
|
|
355
356
|
max_time = kwargs.pop("max_time", "")
|
|
356
357
|
if min_time and not _check_substrings(min_time):
|
|
@@ -4,11 +4,13 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import functools
|
|
6
6
|
import hashlib
|
|
7
|
+
import re
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
from typing import TYPE_CHECKING, Any
|
|
9
10
|
from urllib.request import urlretrieve
|
|
10
11
|
|
|
11
12
|
import pandas as pd
|
|
13
|
+
import requests
|
|
12
14
|
|
|
13
15
|
from erddapy.core.griddap import (
|
|
14
16
|
_griddap_check_constraints,
|
|
@@ -121,9 +123,6 @@ class ERDDAP:
|
|
|
121
123
|
_servers = servers()
|
|
122
124
|
if server.lower() in _servers:
|
|
123
125
|
server = _servers[server.lower()].url
|
|
124
|
-
else:
|
|
125
|
-
msg = f"Cannot initialize {server=}."
|
|
126
|
-
raise ValueError(msg)
|
|
127
126
|
self.server = server.rstrip("/")
|
|
128
127
|
self.protocol = protocol
|
|
129
128
|
self.response = response
|
|
@@ -144,6 +143,34 @@ class ERDDAP:
|
|
|
144
143
|
# quicker access, will be overridden when requesting a new dataset_id.
|
|
145
144
|
self._dataset_id: str | None = None
|
|
146
145
|
self._variables: dict = {}
|
|
146
|
+
self._build_info = functools.lru_cache(maxsize=128)(
|
|
147
|
+
self._build_info_uncached,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
def _build_info_uncached(self) -> tuple[str | None, str | None]:
|
|
151
|
+
"""ERDDAP server build_info."""
|
|
152
|
+
build_info: tuple[str | None, str | None] = (None, None)
|
|
153
|
+
metrics = f"{self.server}/metrics"
|
|
154
|
+
try:
|
|
155
|
+
ret = urlopen(metrics)
|
|
156
|
+
text = ret.read()
|
|
157
|
+
for line in text.decode().splitlines():
|
|
158
|
+
if line.strip().startswith("ERDDAP_build_info"):
|
|
159
|
+
break
|
|
160
|
+
match = re.search(
|
|
161
|
+
r'deployment_info="([^"]+)".*?version_full="([^"]+)"',
|
|
162
|
+
line,
|
|
163
|
+
)
|
|
164
|
+
if match:
|
|
165
|
+
build_info = match.group(2), match.group(1)
|
|
166
|
+
except (
|
|
167
|
+
requests.exceptions.HTTPError,
|
|
168
|
+
requests.exceptions.ConnectionError,
|
|
169
|
+
requests.exceptions.ReadTimeout,
|
|
170
|
+
):
|
|
171
|
+
pass
|
|
172
|
+
|
|
173
|
+
return build_info
|
|
147
174
|
|
|
148
175
|
@property
|
|
149
176
|
def dataset_id(self) -> str | None:
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""ERDDAPyBackendEntrypoint."""
|
|
2
|
+
|
|
3
|
+
import urllib.parse
|
|
4
|
+
from collections.abc import Iterable
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
import xarray as xr
|
|
8
|
+
from xarray.backends.common import T_PathFileOrDataStore
|
|
9
|
+
|
|
10
|
+
XARRAY_IMPORT = True
|
|
11
|
+
except ImportError:
|
|
12
|
+
XARRAY_IMPORT = False
|
|
13
|
+
|
|
14
|
+
from erddapy.core.interfaces import to_xarray
|
|
15
|
+
from erddapy.core.url import _is_netcdf, _is_url
|
|
16
|
+
|
|
17
|
+
if XARRAY_IMPORT:
|
|
18
|
+
|
|
19
|
+
def _make_opendap(url: str) -> str:
|
|
20
|
+
parts = urllib.parse.urlparse(url)
|
|
21
|
+
opendap_url = urllib.parse.urlunparse(
|
|
22
|
+
[parts.scheme, parts.netloc, parts.path, "", "", ""],
|
|
23
|
+
)
|
|
24
|
+
return opendap_url.split(".nc")[0]
|
|
25
|
+
|
|
26
|
+
class ERDDAPyBackendEntrypoint(xr.backends.BackendEntrypoint):
|
|
27
|
+
"""Erddapy backend entrypoint for xarray."""
|
|
28
|
+
|
|
29
|
+
def open_dataset(
|
|
30
|
+
self,
|
|
31
|
+
filename_or_obj: T_PathFileOrDataStore,
|
|
32
|
+
*,
|
|
33
|
+
drop_variables: str | Iterable[str] | None = None, # noqa: ARG002
|
|
34
|
+
) -> xr.Dataset:
|
|
35
|
+
"""Open ERDDAP URLs as xarray datasets."""
|
|
36
|
+
return open_erddap_dataset(filename_or_obj)
|
|
37
|
+
|
|
38
|
+
open_dataset_parameters = ("filename_or_obj", "drop_variables")
|
|
39
|
+
|
|
40
|
+
description = "Load ERDDAP URLs in xarray."
|
|
41
|
+
|
|
42
|
+
def open_erddap_dataset(
|
|
43
|
+
filename_or_obj: T_PathFileOrDataStore,
|
|
44
|
+
) -> xr.Dataset:
|
|
45
|
+
"""Open an ERDDAP URL response as an xarray object."""
|
|
46
|
+
if not _is_url(filename_or_obj):
|
|
47
|
+
msg = f"Expected an ERDDAP URL, got {filename_or_obj!r}."
|
|
48
|
+
raise ValueError(msg)
|
|
49
|
+
|
|
50
|
+
url = str(filename_or_obj)
|
|
51
|
+
if _is_netcdf(url):
|
|
52
|
+
response = "nc"
|
|
53
|
+
else:
|
|
54
|
+
filename_or_obj = _make_opendap(url)
|
|
55
|
+
response = "opendap"
|
|
56
|
+
|
|
57
|
+
return to_xarray(url, response=response)
|
|
@@ -19,24 +19,53 @@ classifiers = [
|
|
|
19
19
|
"Programming Language :: Python :: 3.12",
|
|
20
20
|
"Programming Language :: Python :: 3.13",
|
|
21
21
|
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Programming Language :: Python :: 3.15",
|
|
22
23
|
]
|
|
23
|
-
dynamic = [
|
|
24
|
-
|
|
25
|
-
"
|
|
24
|
+
dynamic = [ "version" ]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"pandas",
|
|
27
|
+
"requests",
|
|
28
|
+
]
|
|
29
|
+
entry-points."xarray.backends".erddapy = "erddapy.xarray_erddap:ERDDAPyBackendEntrypoint"
|
|
30
|
+
|
|
31
|
+
[dependency-groups]
|
|
32
|
+
dev = [
|
|
33
|
+
"pooch",
|
|
34
|
+
"prek",
|
|
35
|
+
"pytest",
|
|
36
|
+
"pytest-cov",
|
|
37
|
+
"pytest-recording",
|
|
38
|
+
"xarray",
|
|
39
|
+
]
|
|
40
|
+
docs = [
|
|
41
|
+
"cartopy>=0.21",
|
|
42
|
+
"geopandas",
|
|
43
|
+
"joblib",
|
|
44
|
+
"nbclassic",
|
|
45
|
+
"nbconvert",
|
|
46
|
+
"nbsphinx",
|
|
47
|
+
"regionmask>=0.9",
|
|
48
|
+
"sphinx",
|
|
49
|
+
{ include-group = "dev" },
|
|
50
|
+
{ include-group = "objects" },
|
|
51
|
+
{ include-group = "extras" },
|
|
52
|
+
]
|
|
53
|
+
extras = [
|
|
54
|
+
"joblib",
|
|
55
|
+
]
|
|
56
|
+
objects = [
|
|
57
|
+
"dask",
|
|
58
|
+
"netcdf4",
|
|
59
|
+
"scitools-iris>=3.3",
|
|
60
|
+
"xarray",
|
|
26
61
|
]
|
|
27
62
|
urls.documentation = "https://ioos.github.io/erddapy"
|
|
28
63
|
urls.homepage = "https://github.com/ioos/erddapy"
|
|
29
64
|
urls.repository = "https://github.com/ioos/erddapy"
|
|
30
|
-
entry-points."xarray.backends".erddapy = "erddapy.xarray_erddap:ERDDAPyBackendEntrypoint"
|
|
31
65
|
|
|
32
66
|
[tool.setuptools]
|
|
33
|
-
packages = [
|
|
34
|
-
"erddapy",
|
|
35
|
-
]
|
|
67
|
+
packages = [ "erddapy" ]
|
|
36
68
|
include-package-data = true
|
|
37
|
-
dynamic.dependencies = { file = [
|
|
38
|
-
"requirements.txt",
|
|
39
|
-
] }
|
|
40
69
|
|
|
41
70
|
[tool.setuptools_scm]
|
|
42
71
|
tag_regex = "^(?P<prefix>v)?(?P<version>[^\\+]+)(?P<suffix>.*)?$"
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"""ERDDAPyBackendEntrypoint."""
|
|
2
|
-
|
|
3
|
-
import urllib.parse
|
|
4
|
-
from collections.abc import Iterable
|
|
5
|
-
|
|
6
|
-
import xarray as xr
|
|
7
|
-
from xarray.backends.common import T_PathFileOrDataStore
|
|
8
|
-
|
|
9
|
-
from erddapy.core.interfaces import to_xarray
|
|
10
|
-
from erddapy.core.url import _is_netcdf, _is_url
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def _make_opendap(url: str) -> str:
|
|
14
|
-
parts = urllib.parse.urlparse(url)
|
|
15
|
-
opendap_url = urllib.parse.urlunparse(
|
|
16
|
-
[parts.scheme, parts.netloc, parts.path, "", "", ""],
|
|
17
|
-
)
|
|
18
|
-
return opendap_url.split(".nc")[0]
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class ERDDAPyBackendEntrypoint(xr.backends.BackendEntrypoint):
|
|
22
|
-
"""Erddapy backend entrypoint for xarray."""
|
|
23
|
-
|
|
24
|
-
def open_dataset(
|
|
25
|
-
self,
|
|
26
|
-
filename_or_obj: T_PathFileOrDataStore,
|
|
27
|
-
*,
|
|
28
|
-
drop_variables: str | Iterable[str] | None = None, # noqa: ARG002
|
|
29
|
-
) -> xr.Dataset:
|
|
30
|
-
"""Open ERDDAP URLs as xarray datasets."""
|
|
31
|
-
return open_erddap_dataset(filename_or_obj)
|
|
32
|
-
|
|
33
|
-
open_dataset_parameters = ("filename_or_obj", "drop_variables")
|
|
34
|
-
|
|
35
|
-
description = "Load ERDDAP URLs in xarray."
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def open_erddap_dataset(filename_or_obj: T_PathFileOrDataStore) -> xr.Dataset:
|
|
39
|
-
"""Open an ERDDAP URL with a netcdf-like response as an xarray object."""
|
|
40
|
-
if not _is_url(filename_or_obj):
|
|
41
|
-
msg = f"Expected an ERDDAP URL, got {filename_or_obj!r}."
|
|
42
|
-
raise ValueError(msg)
|
|
43
|
-
|
|
44
|
-
url = str(filename_or_obj)
|
|
45
|
-
if _is_netcdf(url):
|
|
46
|
-
response = "nc"
|
|
47
|
-
else:
|
|
48
|
-
filename_or_obj = _make_opendap(url)
|
|
49
|
-
response = "opendap"
|
|
50
|
-
|
|
51
|
-
return to_xarray(url, response=response)
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
cartopy>=0.21
|
|
2
|
-
cartopy_offlinedata
|
|
3
|
-
check-manifest
|
|
4
|
-
geopandas
|
|
5
|
-
interrogate
|
|
6
|
-
joblib
|
|
7
|
-
jupyter
|
|
8
|
-
mypy
|
|
9
|
-
nbclassic
|
|
10
|
-
nbconvert
|
|
11
|
-
nbsphinx
|
|
12
|
-
netcdf4
|
|
13
|
-
pandas-stubs
|
|
14
|
-
pendulum>=2.0.1
|
|
15
|
-
pooch
|
|
16
|
-
pytest
|
|
17
|
-
pytest-cov
|
|
18
|
-
pytest-recording
|
|
19
|
-
pytest-sugar
|
|
20
|
-
regionmask>=0.9
|
|
21
|
-
scitools-iris>=3.3.0
|
|
22
|
-
setuptools_scm
|
|
23
|
-
sphinx
|
|
24
|
-
twine
|
|
25
|
-
types-requests
|
|
26
|
-
wheel
|
|
27
|
-
xarray
|
erddapy-3.3.0/requirements.txt
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|