erddapy 3.3.1__tar.gz → 3.3.3__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.
@@ -1,37 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: erddapy
3
- Version: 3.3.1
3
+ Version: 3.3.3
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
- License: Copyright 2017 Filipe Fernandes
7
-
8
-
9
- Redistribution and use in source and binary forms,
10
- with or without modification,
11
- are permitted provided that the following conditions are met:
12
-
13
- 1. Redistributions of source code must retain the above copyright notice,
14
- this list of conditions and the following disclaimer.
15
-
16
- 2. Redistributions in binary form must reproduce the above copyright notice,
17
- this list of conditions and the following disclaimer in the documentation
18
- and/or other materials provided with the distribution.
19
-
20
- 3. Neither the name of the copyright holder nor the names of its contributors
21
- may be used to endorse or promote products derived from this software
22
- without specific prior written permission.
23
-
24
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32
- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
33
- WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
-
6
+ License-Expression: BSD-3-Clause
35
7
  Project-URL: documentation, https://ioos.github.io/erddapy
36
8
  Project-URL: homepage, https://github.com/ioos/erddapy
37
9
  Project-URL: repository, https://github.com/ioos/erddapy
@@ -46,27 +18,15 @@ Description-Content-Type: text/markdown
46
18
  License-File: LICENSE.txt
47
19
  Requires-Dist: pandas
48
20
  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"
21
+ Provides-Extra: all
22
+ Requires-Dist: erddapy[extras,objects]; extra == "all"
66
23
  Provides-Extra: extras
67
24
  Requires-Dist: joblib; extra == "extras"
68
- Requires-Dist: netcdf4; extra == "extras"
69
- Requires-Dist: scitools-iris>=3.3; extra == "extras"
25
+ Provides-Extra: objects
26
+ Requires-Dist: dask; extra == "objects"
27
+ Requires-Dist: netcdf4; extra == "objects"
28
+ Requires-Dist: scitools-iris>=3.3; extra == "objects"
29
+ Requires-Dist: xarray; extra == "objects"
70
30
  Dynamic: license-file
71
31
 
72
32
  <h1 align="center" style="margin:1em;">
@@ -91,7 +51,7 @@ erddapy: ERDDAP + Python.
91
51
  <img src="https://img.shields.io/github/contributors/ioos/erddapy.svg"
92
52
  alt="# contributors" /></a>
93
53
  <a href="https://zenodo.org/badge/latestdoi/104919828">
94
- <img src="https://zenodo.org/badge/104919828.svg"
54
+ <img src="https://zenodo.org/badge/DOI/10.5281/zenodo.latest.svg"
95
55
  alt="zenodo" /></a>
96
56
  <a href="https://pypi.org/project/erddapy">
97
57
  <img src="https://img.shields.io/pypi/pyversions/erddapy.svg"
@@ -101,7 +61,7 @@ erddapy: ERDDAP + Python.
101
61
  alt="pre-commit.ci status" /></a>
102
62
 
103
63
  <a href="https://github.com/ioos/erddapy/actions">
104
- <img src="https://github.com/ioos/erddapy/actions/workflows/tests.yml/badge.svg"
64
+ <img src="https://github.com/ioos/erddapy/actions/workflows/tests-full.yml/badge.svg"
105
65
  alt="GHA-tests" /></a>
106
66
 
107
67
 
@@ -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/104919828.svg"
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
 
@@ -20,8 +20,7 @@ def _griddap_get_constraints(
20
20
  xmlns = "https://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2"
21
21
 
22
22
  ncml_url = f"{dataset_url}.ncml"
23
- res = urlopen(ncml_url)
24
- xml = res.read().decode("utf-8")
23
+ xml = urlopen(ncml_url).read().decode("utf-8")
25
24
  root = ET.fromstring(xml) # noqa: S314
26
25
 
27
26
  variables = root.findall(f"{{{xmlns}}}variable")
@@ -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
@@ -232,9 +232,7 @@ def _check_substrings(constraint: str) -> bool:
232
232
  """Extend the OPeNDAP with extra strings."""
233
233
  # The `now` doesn't need this check, it works both quoted and unquoted.
234
234
  substrings = ["now+", "now-", "min(", "max("]
235
- return any(
236
- True for substring in substrings if substring in str(constraint)
237
- )
235
+ return any(True for substring in substrings if substring in constraint)
238
236
 
239
237
 
240
238
  def _is_quoted(url: str) -> bool:
@@ -244,7 +242,7 @@ def _is_quoted(url: str) -> bool:
244
242
 
245
243
 
246
244
  def parse_dates(
247
- date_time: datetime.datetime | str,
245
+ date_time: dt.datetime | str,
248
246
  *,
249
247
  dayfirst: bool = False,
250
248
  yearfirst: bool = False,
@@ -255,6 +253,7 @@ def parse_dates(
255
253
  strings or seconds since 1970, but internally ERDDAPY uses datetime-like
256
254
  objects. `timestamp` returns the expected strings in seconds since 1970.
257
255
 
256
+ This function will shift any tz-aware, and convert naive datetimes, to UTC.
258
257
  """
259
258
  if isinstance(date_time, str):
260
259
  parse_date_time = to_datetime(
@@ -267,9 +266,9 @@ def parse_dates(
267
266
 
268
267
  # Naive datetimes tzinfo must be replaced, tz-aware should be converted.
269
268
  if not parse_date_time.tzinfo:
270
- parse_date_time = parse_date_time.replace(tzinfo=datetime.UTC)
269
+ parse_date_time = parse_date_time.replace(tzinfo=dt.UTC)
271
270
  else:
272
- parse_date_time = parse_date_time.astimezone(datetime.UTC)
271
+ parse_date_time = parse_date_time.astimezone(dt.UTC)
273
272
 
274
273
  return parse_date_time.timestamp()
275
274
 
@@ -350,7 +349,7 @@ def get_search_url( # noqa: PLR0913, PLR0917
350
349
  search_for = parse.quote_plus(search_for)
351
350
  base += "&searchFor={searchFor}"
352
351
 
353
- # Convert dates from datetime.datetime to secs since 1970-01-01T00:00:00Z.
352
+ # Convert dates from dt.datetime to secs since 1970-01-01T00:00:00Z.
354
353
  min_time = kwargs.pop("min_time", "")
355
354
  max_time = kwargs.pop("max_time", "")
356
355
  if min_time and not _check_substrings(min_time):
@@ -569,7 +568,7 @@ def get_download_url( # noqa: PLR0913
569
568
  if constraints:
570
569
  _constraints = copy.copy(constraints)
571
570
  for k, v in _constraints.items():
572
- if _check_substrings(v):
571
+ if _check_substrings(str(v)):
573
572
  continue
574
573
  # The valid operators are =, != (not equals),
575
574
  # =~ (a regular expression test), <, <=, >, and >=
@@ -2,13 +2,16 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import copy
5
6
  import functools
6
7
  import hashlib
8
+ import re
7
9
  from pathlib import Path
8
10
  from typing import TYPE_CHECKING, Any
9
11
  from urllib.request import urlretrieve
10
12
 
11
13
  import pandas as pd
14
+ import requests
12
15
 
13
16
  from erddapy.core.griddap import (
14
17
  _griddap_check_constraints,
@@ -141,6 +144,34 @@ class ERDDAP:
141
144
  # quicker access, will be overridden when requesting a new dataset_id.
142
145
  self._dataset_id: str | None = None
143
146
  self._variables: dict = {}
147
+ self._build_info = functools.lru_cache(maxsize=128)(
148
+ self._build_info_uncached,
149
+ )
150
+
151
+ def _build_info_uncached(self) -> tuple[str, str]:
152
+ """ERDDAP server build_info."""
153
+ build_info: tuple[str, str] = ("", "")
154
+ metrics = f"{self.server}/metrics"
155
+ try:
156
+ ret = urlopen(metrics)
157
+ text = ret.read()
158
+ for line in text.decode().splitlines():
159
+ if line.strip().startswith("ERDDAP_build_info"):
160
+ break
161
+ version_full = re.findall(r'version_full="([^"]+)"|$', line)[0]
162
+ deployment_info = re.findall(
163
+ r'deployment_info="([^"]+)".*?|$',
164
+ line,
165
+ )[0]
166
+ build_info = version_full, deployment_info
167
+ except (
168
+ requests.exceptions.HTTPError,
169
+ requests.exceptions.ConnectionError,
170
+ requests.exceptions.ReadTimeout,
171
+ ):
172
+ pass
173
+
174
+ return build_info
144
175
 
145
176
  @property
146
177
  def dataset_id(self) -> str | None:
@@ -532,7 +563,7 @@ class ERDDAP:
532
563
  var = variables[vname]
533
564
  for k, v in kwargs.items():
534
565
  # Attributes must always be a string.
535
- _k = str(k)
566
+ _k = copy.copy(k)
536
567
  if callable(v):
537
568
  has_value_flag = v(var.get(_k, None))
538
569
  if not has_value_flag:
@@ -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)
@@ -6,7 +6,8 @@ requires = [ "setuptools>=42", "setuptools-scm" ]
6
6
  name = "erddapy"
7
7
  description = "Python interface for ERDDAP"
8
8
  readme = "README.md"
9
- license = { file = "LICENSE.txt" }
9
+ license = "BSD-3-Clause"
10
+ license-files = [ "LICENSE.txt" ]
10
11
  maintainers = [
11
12
  { name = "Alex Kerney", email = "akerney@gmri.org" },
12
13
  { name = "Callum Rollo", email = "c.rollo@outlook.com" },
@@ -25,17 +26,32 @@ dynamic = [ "version" ]
25
26
  dependencies = [
26
27
  "pandas",
27
28
  "requests",
28
- "xarray",
29
29
  ]
30
- optional-dependencies.dev = [
30
+ optional-dependencies.all = [ "erddapy[extras,objects]" ]
31
+ optional-dependencies.extras = [
32
+ "joblib",
33
+ ]
34
+ optional-dependencies.objects = [
31
35
  "dask",
36
+ "netcdf4",
37
+ "scitools-iris>=3.3",
38
+ "xarray",
39
+ ]
40
+ urls.documentation = "https://ioos.github.io/erddapy"
41
+ urls.homepage = "https://github.com/ioos/erddapy"
42
+ urls.repository = "https://github.com/ioos/erddapy"
43
+ entry-points."xarray.backends".erddapy = "erddapy.xarray_erddap:ERDDAPyBackendEntrypoint"
44
+
45
+ [dependency-groups]
46
+ dev = [
32
47
  "pooch",
33
48
  "prek",
34
49
  "pytest",
35
50
  "pytest-cov",
36
51
  "pytest-recording",
52
+ "xarray",
37
53
  ]
38
- optional-dependencies.docs = [
54
+ docs = [
39
55
  "cartopy>=0.21",
40
56
  "geopandas",
41
57
  "joblib",
@@ -44,16 +60,11 @@ optional-dependencies.docs = [
44
60
  "nbsphinx",
45
61
  "regionmask>=0.9",
46
62
  "sphinx",
47
- ]
48
- optional-dependencies.extras = [
49
- "joblib",
50
- "netcdf4",
51
- "scitools-iris>=3.3",
63
+ { include-group = "dev" },
52
64
  ]
53
65
  urls.documentation = "https://ioos.github.io/erddapy"
54
66
  urls.homepage = "https://github.com/ioos/erddapy"
55
67
  urls.repository = "https://github.com/ioos/erddapy"
56
- entry-points."xarray.backends".erddapy = "erddapy.xarray_erddap:ERDDAPyBackendEntrypoint"
57
68
 
58
69
  [tool.setuptools]
59
70
  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