erddapy 3.3.1__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.1 → erddapy-3.3.2}/PKG-INFO +3 -27
- {erddapy-3.3.1 → erddapy-3.3.2}/README.md +2 -2
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/core/url.py +6 -5
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/erddapy.py +30 -0
- erddapy-3.3.2/erddapy/xarray_erddap.py +57 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/pyproject.toml +14 -6
- erddapy-3.3.1/erddapy/xarray_erddap.py +0 -51
- {erddapy-3.3.1 → erddapy-3.3.2}/CHANGES.txt +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/LICENSE.txt +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/MANIFEST.in +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/__init__.py +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/core/__init__.py +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/core/griddap.py +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/core/interfaces.py +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/core/netcdf.py +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/multiple_server_search.py +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/servers/__init__.py +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/servers/erddaps.json +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy/servers/servers.py +0 -0
- {erddapy-3.3.1 → erddapy-3.3.2}/erddapy.egg-info/SOURCES.txt +0 -0
- {erddapy-3.3.1 → 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,9 +32,6 @@ 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
|
|
@@ -46,27 +43,6 @@ Description-Content-Type: text/markdown
|
|
|
46
43
|
License-File: LICENSE.txt
|
|
47
44
|
Requires-Dist: pandas
|
|
48
45
|
Requires-Dist: requests
|
|
49
|
-
Requires-Dist: xarray
|
|
50
|
-
Provides-Extra: dev
|
|
51
|
-
Requires-Dist: dask; extra == "dev"
|
|
52
|
-
Requires-Dist: pooch; extra == "dev"
|
|
53
|
-
Requires-Dist: prek; extra == "dev"
|
|
54
|
-
Requires-Dist: pytest; extra == "dev"
|
|
55
|
-
Requires-Dist: pytest-cov; extra == "dev"
|
|
56
|
-
Requires-Dist: pytest-recording; extra == "dev"
|
|
57
|
-
Provides-Extra: docs
|
|
58
|
-
Requires-Dist: cartopy>=0.21; extra == "docs"
|
|
59
|
-
Requires-Dist: geopandas; extra == "docs"
|
|
60
|
-
Requires-Dist: joblib; extra == "docs"
|
|
61
|
-
Requires-Dist: nbclassic; extra == "docs"
|
|
62
|
-
Requires-Dist: nbconvert; extra == "docs"
|
|
63
|
-
Requires-Dist: nbsphinx; extra == "docs"
|
|
64
|
-
Requires-Dist: regionmask>=0.9; extra == "docs"
|
|
65
|
-
Requires-Dist: sphinx; extra == "docs"
|
|
66
|
-
Provides-Extra: extras
|
|
67
|
-
Requires-Dist: joblib; extra == "extras"
|
|
68
|
-
Requires-Dist: netcdf4; extra == "extras"
|
|
69
|
-
Requires-Dist: scitools-iris>=3.3; extra == "extras"
|
|
70
46
|
Dynamic: license-file
|
|
71
47
|
|
|
72
48
|
<h1 align="center" style="margin:1em;">
|
|
@@ -91,7 +67,7 @@ erddapy: ERDDAP + Python.
|
|
|
91
67
|
<img src="https://img.shields.io/github/contributors/ioos/erddapy.svg"
|
|
92
68
|
alt="# contributors" /></a>
|
|
93
69
|
<a href="https://zenodo.org/badge/latestdoi/104919828">
|
|
94
|
-
<img src="https://zenodo.org/badge/
|
|
70
|
+
<img src="https://zenodo.org/badge/DOI/10.5281/zenodo.latest.svg"
|
|
95
71
|
alt="zenodo" /></a>
|
|
96
72
|
<a href="https://pypi.org/project/erddapy">
|
|
97
73
|
<img src="https://img.shields.io/pypi/pyversions/erddapy.svg"
|
|
@@ -101,7 +77,7 @@ erddapy: ERDDAP + Python.
|
|
|
101
77
|
alt="pre-commit.ci status" /></a>
|
|
102
78
|
|
|
103
79
|
<a href="https://github.com/ioos/erddapy/actions">
|
|
104
|
-
<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"
|
|
105
81
|
alt="GHA-tests" /></a>
|
|
106
82
|
|
|
107
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,9 +268,9 @@ 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
|
|
|
@@ -350,7 +351,7 @@ def get_search_url( # noqa: PLR0913, PLR0917
|
|
|
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,
|
|
@@ -141,6 +143,34 @@ class ERDDAP:
|
|
|
141
143
|
# quicker access, will be overridden when requesting a new dataset_id.
|
|
142
144
|
self._dataset_id: str | None = None
|
|
143
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
|
|
144
174
|
|
|
145
175
|
@property
|
|
146
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)
|
|
@@ -25,17 +25,19 @@ dynamic = [ "version" ]
|
|
|
25
25
|
dependencies = [
|
|
26
26
|
"pandas",
|
|
27
27
|
"requests",
|
|
28
|
-
"xarray",
|
|
29
28
|
]
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
entry-points."xarray.backends".erddapy = "erddapy.xarray_erddap:ERDDAPyBackendEntrypoint"
|
|
30
|
+
|
|
31
|
+
[dependency-groups]
|
|
32
|
+
dev = [
|
|
32
33
|
"pooch",
|
|
33
34
|
"prek",
|
|
34
35
|
"pytest",
|
|
35
36
|
"pytest-cov",
|
|
36
37
|
"pytest-recording",
|
|
38
|
+
"xarray",
|
|
37
39
|
]
|
|
38
|
-
|
|
40
|
+
docs = [
|
|
39
41
|
"cartopy>=0.21",
|
|
40
42
|
"geopandas",
|
|
41
43
|
"joblib",
|
|
@@ -44,16 +46,22 @@ optional-dependencies.docs = [
|
|
|
44
46
|
"nbsphinx",
|
|
45
47
|
"regionmask>=0.9",
|
|
46
48
|
"sphinx",
|
|
49
|
+
{ include-group = "dev" },
|
|
50
|
+
{ include-group = "objects" },
|
|
51
|
+
{ include-group = "extras" },
|
|
47
52
|
]
|
|
48
|
-
|
|
53
|
+
extras = [
|
|
49
54
|
"joblib",
|
|
55
|
+
]
|
|
56
|
+
objects = [
|
|
57
|
+
"dask",
|
|
50
58
|
"netcdf4",
|
|
51
59
|
"scitools-iris>=3.3",
|
|
60
|
+
"xarray",
|
|
52
61
|
]
|
|
53
62
|
urls.documentation = "https://ioos.github.io/erddapy"
|
|
54
63
|
urls.homepage = "https://github.com/ioos/erddapy"
|
|
55
64
|
urls.repository = "https://github.com/ioos/erddapy"
|
|
56
|
-
entry-points."xarray.backends".erddapy = "erddapy.xarray_erddap:ERDDAPyBackendEntrypoint"
|
|
57
65
|
|
|
58
66
|
[tool.setuptools]
|
|
59
67
|
packages = [ "erddapy" ]
|
|
@@ -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)
|
|
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
|
|
File without changes
|