ebas-plot 0.2.3__tar.gz → 0.2.5__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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ebas-plot
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Plotting utilities for EBAS netCDF datasets.
5
5
  Author-email: Lise Eder Murberg <lemu@nilu.no>, Marthe Brevig <mbre@nilu.no>, Jonathan Elias Holme <jhol@nilu.no>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ebas-plot
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Plotting utilities for EBAS netCDF datasets.
5
5
  Author-email: Lise Eder Murberg <lemu@nilu.no>, Marthe Brevig <mbre@nilu.no>, Jonathan Elias Holme <jhol@nilu.no>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -8,7 +8,7 @@ import requests
8
8
  from netCDF4 import date2num, num2date
9
9
  import pandas as pd
10
10
 
11
- __version__ = "0.2.3"
11
+ __version__ = "0.2.5"
12
12
 
13
13
 
14
14
  class DatasetAccessError(Exception):
@@ -182,6 +182,10 @@ def open_dataset(
182
182
  return _slice_time(ds, *bounds) if any(bounds) else ds
183
183
 
184
184
 
185
+ # Known hosts only: the user's Bearer token is forwarded to the dataset host.
186
+ _THREDDS_HOSTS = ("https://thredds.nilu.no", "https://dev-thredds.nilu.no")
187
+
188
+
185
189
  def _open_dataset(url: str, token: str | None) -> xr.Dataset:
186
190
  if not url.startswith("http"): # local file
187
191
  ds = validate_dataset(url)
@@ -190,9 +194,9 @@ def _open_dataset(url: str, token: str | None) -> xr.Dataset:
190
194
  return ds
191
195
  elif url.startswith("https://doi.nilu.no/doi/") or url.startswith("https://doi.org/"): # DOI link
192
196
  opendap_url = _doi_to_opendap_url(url.split("/")[-1])
193
- elif url.startswith("https://thredds.nilu.no/thredds/fileServer/ebas_doi/"): # Download link, convert to OPeNDAP
197
+ elif any(url.startswith(f"{h}/thredds/fileServer/ebas_doi/") for h in _THREDDS_HOSTS): # Download link, convert to OPeNDAP
194
198
  opendap_url = url.replace("fileServer", "dodsC")
195
- elif url.startswith("https://thredds.nilu.no/thredds/dodsC/ebas_doi/"): # direct OPeNDAP link
199
+ elif any(url.startswith(f"{h}/thredds/dodsC/ebas_doi/") for h in _THREDDS_HOSTS): # direct OPeNDAP link
196
200
  opendap_url = url
197
201
  else:
198
202
  raise ValueError(f"Unsupported dataset URL: {url}")
@@ -206,6 +210,9 @@ def _open_dataset(url: str, token: str | None) -> xr.Dataset:
206
210
  raise DatasetAccessError(503, f"OPeNDAP server unreachable: {exc}") from exc
207
211
  if probe.status_code in (401, 403):
208
212
  raise DatasetAccessError(probe.status_code, "Dataset is restricted")
213
+ if probe.status_code == 404:
214
+ # netCDF-C retries a missing dataset for ~50s before giving up.
215
+ raise DatasetAccessError(404, "Dataset not found on the OPeNDAP server")
209
216
  if probe.status_code >= 500:
210
217
  raise DatasetAccessError(503, f"OPeNDAP server error ({probe.status_code})")
211
218
 
@@ -1055,4 +1062,4 @@ def main() -> None:
1055
1062
 
1056
1063
 
1057
1064
  if __name__ == "__main__":
1058
- main()
1065
+ main()
File without changes
File without changes
File without changes
File without changes