GLODAP 0.1__tar.gz → 0.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,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
- Name: GLODAP
3
- Version: 0.1
4
- Summary: GLODAP downloader and importer in Python
2
+ Name: glodap
3
+ Version: 0.3
4
+ Summary: GLODAP downloader and importer in Python
5
5
  Classifier: Development Status :: 4 - Beta
6
6
  Classifier: Programming Language :: Python :: 3.10
7
7
  Classifier: Programming Language :: Python :: 3.11
@@ -23,6 +23,12 @@ Dynamic: license-file
23
23
 
24
24
  # glodap
25
25
 
26
+ [![Tests](https://github.com/mvdh7/glodap/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mvdh7/glodap/actions)
27
+ [![pypi badge](https://img.shields.io/pypi/v/glodap.svg?style=popout)](https://pypi.org/project/glodap/)
28
+ [![Conda Version](https://img.shields.io/conda/vn/conda-forge/glodap.svg)](https://anaconda.org/conda-forge/glodap)
29
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
30
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
31
+
26
32
  Download [GLODAP](https://glodap.info) datasets and import them as pandas DataFrames.
27
33
 
28
34
  ## Install
@@ -42,8 +48,8 @@ df_atlantic = glodap.atlantic()
42
48
  Files are saved by default at `"~/.glodap"`, but this can be controlled with the
43
49
  kwarg `gpath`. See the function docstrings for more information.
44
50
 
45
- The columns of the imported DataFrames are renamed so that they can be passed
46
- directly into [PyCO2SYS v2](https://github.com/mvdh7/PyCO2SYS):
51
+ The columns of the imported DataFrames can be passed
52
+ directly into [PyCO2SYS v2](https://mvdh.xyz/PyCO2SYS):
47
53
 
48
54
  ```python
49
55
  import PyCO2SYS as pyco2
@@ -51,22 +57,20 @@ co2s_atlantic = pyco2.sys(data=df_atlantic, nitrite=None)
51
57
  ```
52
58
 
53
59
  Note `nitrite=None` - this means PyCO2SYS will ignore the `"nitrite"` column,
54
- which is necessary because PyCO2SYS includes the nitrite-nitrous acid
55
- equilibrium but its equilibrium constant is valid only under lab conditions.
60
+ which is necessary because while PyCO2SYS includes the nitrite-nitrous acid
61
+ equilibrium, its equilibrium constant is valid only under lab conditions.
62
+
63
+ Because of how the columns are named, when passing the DataFrame directly to
64
+ PyCO2SYS as above, the system will be solved from DIC and alkalinity, not pH.
56
65
 
57
66
  The columns are the same as in the original GLODAP .mat files available from [glodap.info](https://glodap.info), except:
58
67
  * The `"G2"` at the start of each parameter has been removed.
59
68
  * Flags end with `"_f"` instead of just `"f"`.
60
69
  * There is a `"datetime"` column, which combines the `"year"`, `"month"` and `"day"` but NOT the `"hour"` and `"minute"` (because some of these are missing).
61
- * For compatibility with PyCO2SYS:
62
- - `"tco2"` => `"dic"`
63
- - `"talk"` => `"alkalinity"`
64
- - `"phts25p0"` => `"ph_lab"`
65
- - `"phtsinsitutp"` => `"ph_insitu"`
66
-
67
- Therefore when passing the DataFrame directly to PyCO2SYS as in the example
68
- above, the system will be solved from DIC and alkalinity, not pH.
69
70
 
70
71
  The functions `download` and `read` can also be used for finer control, such as
71
72
  specifying a particular GLODAP version rather than using the latest one. See
72
73
  their function docstrings for more information.
74
+
75
+ The .mat files from the GEOMAR mirrors are downloaded, and the SHA256 checksum
76
+ of each downloaded file is checked before the file is written to disk.
@@ -7,6 +7,11 @@ GLODAP.egg-info/dependency_links.txt
7
7
  GLODAP.egg-info/requires.txt
8
8
  GLODAP.egg-info/top_level.txt
9
9
  glodap/__init__.py
10
+ glodap.egg-info/PKG-INFO
11
+ glodap.egg-info/SOURCES.txt
12
+ glodap.egg-info/dependency_links.txt
13
+ glodap.egg-info/requires.txt
14
+ glodap.egg-info/top_level.txt
10
15
  tests/test_import.py
11
16
  tests/test_regions.py
12
17
  tests/test_response.py
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
- Name: GLODAP
3
- Version: 0.1
4
- Summary: GLODAP downloader and importer in Python
2
+ Name: glodap
3
+ Version: 0.3
4
+ Summary: GLODAP downloader and importer in Python
5
5
  Classifier: Development Status :: 4 - Beta
6
6
  Classifier: Programming Language :: Python :: 3.10
7
7
  Classifier: Programming Language :: Python :: 3.11
@@ -23,6 +23,12 @@ Dynamic: license-file
23
23
 
24
24
  # glodap
25
25
 
26
+ [![Tests](https://github.com/mvdh7/glodap/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mvdh7/glodap/actions)
27
+ [![pypi badge](https://img.shields.io/pypi/v/glodap.svg?style=popout)](https://pypi.org/project/glodap/)
28
+ [![Conda Version](https://img.shields.io/conda/vn/conda-forge/glodap.svg)](https://anaconda.org/conda-forge/glodap)
29
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
30
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
31
+
26
32
  Download [GLODAP](https://glodap.info) datasets and import them as pandas DataFrames.
27
33
 
28
34
  ## Install
@@ -42,8 +48,8 @@ df_atlantic = glodap.atlantic()
42
48
  Files are saved by default at `"~/.glodap"`, but this can be controlled with the
43
49
  kwarg `gpath`. See the function docstrings for more information.
44
50
 
45
- The columns of the imported DataFrames are renamed so that they can be passed
46
- directly into [PyCO2SYS v2](https://github.com/mvdh7/PyCO2SYS):
51
+ The columns of the imported DataFrames can be passed
52
+ directly into [PyCO2SYS v2](https://mvdh.xyz/PyCO2SYS):
47
53
 
48
54
  ```python
49
55
  import PyCO2SYS as pyco2
@@ -51,22 +57,20 @@ co2s_atlantic = pyco2.sys(data=df_atlantic, nitrite=None)
51
57
  ```
52
58
 
53
59
  Note `nitrite=None` - this means PyCO2SYS will ignore the `"nitrite"` column,
54
- which is necessary because PyCO2SYS includes the nitrite-nitrous acid
55
- equilibrium but its equilibrium constant is valid only under lab conditions.
60
+ which is necessary because while PyCO2SYS includes the nitrite-nitrous acid
61
+ equilibrium, its equilibrium constant is valid only under lab conditions.
62
+
63
+ Because of how the columns are named, when passing the DataFrame directly to
64
+ PyCO2SYS as above, the system will be solved from DIC and alkalinity, not pH.
56
65
 
57
66
  The columns are the same as in the original GLODAP .mat files available from [glodap.info](https://glodap.info), except:
58
67
  * The `"G2"` at the start of each parameter has been removed.
59
68
  * Flags end with `"_f"` instead of just `"f"`.
60
69
  * There is a `"datetime"` column, which combines the `"year"`, `"month"` and `"day"` but NOT the `"hour"` and `"minute"` (because some of these are missing).
61
- * For compatibility with PyCO2SYS:
62
- - `"tco2"` => `"dic"`
63
- - `"talk"` => `"alkalinity"`
64
- - `"phts25p0"` => `"ph_lab"`
65
- - `"phtsinsitutp"` => `"ph_insitu"`
66
-
67
- Therefore when passing the DataFrame directly to PyCO2SYS as in the example
68
- above, the system will be solved from DIC and alkalinity, not pH.
69
70
 
70
71
  The functions `download` and `read` can also be used for finer control, such as
71
72
  specifying a particular GLODAP version rather than using the latest one. See
72
73
  their function docstrings for more information.
74
+
75
+ The .mat files from the GEOMAR mirrors are downloaded, and the SHA256 checksum
76
+ of each downloaded file is checked before the file is written to disk.
@@ -1,5 +1,11 @@
1
1
  # glodap
2
2
 
3
+ [![Tests](https://github.com/mvdh7/glodap/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mvdh7/glodap/actions)
4
+ [![pypi badge](https://img.shields.io/pypi/v/glodap.svg?style=popout)](https://pypi.org/project/glodap/)
5
+ [![Conda Version](https://img.shields.io/conda/vn/conda-forge/glodap.svg)](https://anaconda.org/conda-forge/glodap)
6
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
7
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
8
+
3
9
  Download [GLODAP](https://glodap.info) datasets and import them as pandas DataFrames.
4
10
 
5
11
  ## Install
@@ -19,8 +25,8 @@ df_atlantic = glodap.atlantic()
19
25
  Files are saved by default at `"~/.glodap"`, but this can be controlled with the
20
26
  kwarg `gpath`. See the function docstrings for more information.
21
27
 
22
- The columns of the imported DataFrames are renamed so that they can be passed
23
- directly into [PyCO2SYS v2](https://github.com/mvdh7/PyCO2SYS):
28
+ The columns of the imported DataFrames can be passed
29
+ directly into [PyCO2SYS v2](https://mvdh.xyz/PyCO2SYS):
24
30
 
25
31
  ```python
26
32
  import PyCO2SYS as pyco2
@@ -28,22 +34,20 @@ co2s_atlantic = pyco2.sys(data=df_atlantic, nitrite=None)
28
34
  ```
29
35
 
30
36
  Note `nitrite=None` - this means PyCO2SYS will ignore the `"nitrite"` column,
31
- which is necessary because PyCO2SYS includes the nitrite-nitrous acid
32
- equilibrium but its equilibrium constant is valid only under lab conditions.
37
+ which is necessary because while PyCO2SYS includes the nitrite-nitrous acid
38
+ equilibrium, its equilibrium constant is valid only under lab conditions.
39
+
40
+ Because of how the columns are named, when passing the DataFrame directly to
41
+ PyCO2SYS as above, the system will be solved from DIC and alkalinity, not pH.
33
42
 
34
43
  The columns are the same as in the original GLODAP .mat files available from [glodap.info](https://glodap.info), except:
35
44
  * The `"G2"` at the start of each parameter has been removed.
36
45
  * Flags end with `"_f"` instead of just `"f"`.
37
46
  * There is a `"datetime"` column, which combines the `"year"`, `"month"` and `"day"` but NOT the `"hour"` and `"minute"` (because some of these are missing).
38
- * For compatibility with PyCO2SYS:
39
- - `"tco2"` => `"dic"`
40
- - `"talk"` => `"alkalinity"`
41
- - `"phts25p0"` => `"ph_lab"`
42
- - `"phtsinsitutp"` => `"ph_insitu"`
43
-
44
- Therefore when passing the DataFrame directly to PyCO2SYS as in the example
45
- above, the system will be solved from DIC and alkalinity, not pH.
46
47
 
47
48
  The functions `download` and `read` can also be used for finer control, such as
48
49
  specifying a particular GLODAP version rather than using the latest one. See
49
50
  their function docstrings for more information.
51
+
52
+ The .mat files from the GEOMAR mirrors are downloaded, and the SHA256 checksum
53
+ of each downloaded file is checked before the file is written to disk.
@@ -14,35 +14,35 @@ downloading the file if it's not already saved locally. For example:
14
14
  Files are saved by default at "~/.glodap", but this can be controlled with the
15
15
  kwarg `gpath`. See the function docstrings for more information.
16
16
 
17
- The columns of the imported DataFrames are renamed so that they can be passed
18
- directly into PyCO2SYS v2:
17
+ The columns of the imported DataFrames can be passed directly into PyCO2SYS v2:
19
18
 
20
19
  >>> import PyCO2SYS as pyco2
21
20
  >>> co2s_atlantic = pyco2.sys(data=df_atlantic, nitrite=None)
22
21
 
23
22
  Note `nitrite=None` - this means PyCO2SYS will ignore the "nitrite" column,
24
- which is necessary because PyCO2SYS includes the nitrite-nitrous acid
25
- equilibrium but its equilibrium constant is valid only under lab conditions.
23
+ which is necessary because while PyCO2SYS includes the nitrite-nitrous acid
24
+ equilibrium, its equilibrium constant is valid only under lab conditions.
25
+
26
+ Because of how the columns are named, when passing the DataFrame directly to
27
+ PyCO2SYS as above, the system will be solved from DIC and alkalinity, not pH.
26
28
 
27
29
  The columns are the same as in the original GLODAP .mat files, except:
28
30
  * The "G2" at the start of each parameter has been removed.
29
31
  * Flags end with "_f" instead of just "f".
30
32
  * There is a "datetime" column, which combines the "year", "month" and "day"
31
33
  but NOT the "hour" and "minute" (because some of these are missing).
32
- * For compatibility with PyCO2SYS:
33
- "tco2" => "dic"
34
- "talk" => "alkalinity"
35
- "phts25p0" => "ph_lab"
36
- "phtsinsitutp" => "ph_insitu"
37
- Therefore when passing the DataFrame directly to PyCO2SYS as in the example
38
- above, the system will be solved from DIC and alkalinity, not pH.
39
34
 
40
35
  The functions `download` and `read` can also be used for finer control, such as
41
36
  specifying a particular GLODAP version rather than using the latest one. See
42
37
  their function docstrings for more information.
38
+
39
+ The .mat files from the GEOMAR mirrors are downloaded, and the SHA256 checksum
40
+ of each downloaded file is checked before the file is written to disk.
43
41
  """
44
42
 
43
+ import hashlib
45
44
  import os
45
+ import tempfile
46
46
  from warnings import warn
47
47
 
48
48
  import pandas as pd
@@ -52,38 +52,76 @@ from scipy.io import loadmat
52
52
 
53
53
  # Package metadata
54
54
  __author__ = "Humphreys, Matthew P."
55
- __version__ = "0.1"
55
+ __version__ = "0.3"
56
56
 
57
57
  # GLODAP metadata
58
58
  version_latest = "v2.2023"
59
59
  versions = ["v2.2023", "v2.2022", "v2.2021", "v2.2020", "v2.2019"]
60
- regions_full = {
60
+ regions = {
61
61
  "arctic": "Arctic_Ocean",
62
62
  "atlantic": "Atlantic_Ocean",
63
63
  "indian": "Indian_Ocean",
64
64
  "pacific": "Pacific_Ocean",
65
- "global": "Merged_Master_File",
66
65
  "world": "Merged_Master_File",
67
66
  }
68
- regions = regions_full.copy()
69
- for k, v in regions_full.items():
70
- regions[k[:3]] = v
67
+ regions_full = regions.copy()
68
+ for k, v in regions.items():
69
+ regions_full[k[:3]] = v
70
+ checksums = {
71
+ "v2.2023": {
72
+ "arc": "a998a8d99db84e9357b21a7e345bbfde62eae77870e651119b4c1929a2f1e2fd",
73
+ "atl": "a3ff7bc4f4ff3a1b0f540886a0eb7c9b3ec52aa4eae2dea57d47ae61f56da56f",
74
+ "ind": "8c9c21d4af9db506b09fdec79e2a311c2dbbf41b8fc4e6a7a855d1d50b3ccb51",
75
+ "pac": "9891160dba6211d2f13923171564a06bbea34cda799f3091148061c32fc6070c",
76
+ "wor": "002881fa71923d15c1bd5aca3b99bc220ad5d1c77a90f130ba1ff0d3910d8766",
77
+ },
78
+ "v2.2022": {
79
+ "arc": "b2cdeeebfb3ff75701ccc15edb22b5c8e1153623aefc6463f9699ae8780edf15",
80
+ "atl": "cffdb28aca195e189b16834a4f9711b90a995ea2b99d95bc6fe498049f975631",
81
+ "ind": "00381b0542ed4e8a39c33ee071fcb2388c1e3b3fb13f76c75fc342b26f4c8a13",
82
+ "pac": "4037f093d89ea422aa62524273ab40ca147934e34637496372e83f2e34fe9a66",
83
+ "wor": "3d7ba5bcf59b0c1f513b6fa8140df0618d984fa7b320899e7f188dd7c6cef565",
84
+ },
85
+ "v2.2021": {
86
+ "arc": "21e511e808b9cc9f5b8532bf3b1c6754bb4ad6c344adb4a498b71967a0b6d217",
87
+ "atl": "22731e474a33d10c3efd3cc6748aafca7e1488495acefe1bbbd26b4105973a21",
88
+ "ind": "d3c43da540e606091a981958b4ce674dbe1ef9777ffee4c90de29bcc74f010a2",
89
+ "pac": "925cf0424f4cd1caad30cfbe57bdc19740c85e715bee06bd298893915cfc5a01",
90
+ "wor": "8329acd8722a3c198455642f8fca29b05f460b149e178fef9e1041f2caa19453",
91
+ },
92
+ "v2.2020": {
93
+ "arc": "de52e1086b61f68d46cb0142e4bcffae18b578f41c2a00bda40a8960959a94b7",
94
+ "atl": "e927d87d873e089311ed5b747195aa150880f59559831bab27a54dcc0ff7ff69",
95
+ "ind": "1d8dfbefb820541d9b10f73d3785dae8653e67166b94666dbb433d3ddfa4e255",
96
+ "pac": "9a75bf66b38341117afaae947af465f8f7e4082a9f773355c1fbadf26484d544",
97
+ "wor": "51e1000101aa61712edb9c0074289bb83c105d17ee8cea575f8e18fa05bde953",
98
+ },
99
+ "v2.2019": {
100
+ "arc": "f972a835601a5b00ac5ffc5093414d5fd2a520bbc7b1c7ff0a7d343852302284",
101
+ "atl": "6ac0826bacbaa43a9813fe18bcb84b1786efb44538b7a2d24e8a0c993ff23193",
102
+ "ind": "aa6695b715cce7658f94911d38a344f1e835ff6bbed8f9dc1548b167983a2967",
103
+ "pac": "88df995e272dd63db55421b911be1f99bfec4cac6f97a73e017c9e275bf29db2",
104
+ "wor": "4637ce5eb560fe020e9fccf0370156bfe19498fc74c2e8b66dee190cc44cff63",
105
+ },
106
+ }
71
107
 
72
108
 
73
109
  def _get_paths(region, version, gpath):
74
- assert region in regions, "`region` not valid!"
110
+ assert region in regions_full, "`region` not valid!"
75
111
  if version is None:
76
112
  version = version_latest
113
+ version = version.lower()
77
114
  assert version in versions, "`version` not valid!"
78
115
  if gpath is None:
79
116
  gpath = os.path.join(os.path.expanduser("~"), ".glodap")
80
- fileregion = regions[region.lower()]
117
+ fileregion = regions_full[region.lower()]
81
118
  filename = f"{fileregion}_{version}.mat"
82
119
  return gpath, fileregion, filename, version
83
120
 
84
121
 
85
- def download(region="world", version=None, gpath=None, do_download=True):
86
- """Download a GLODAP data file and save it locally.
122
+ def download(region="world", version=None, gpath=None, chunk_size=8192):
123
+ """Download a GLODAP data file and save it locally, after checking that it
124
+ has the expected checksum (SHA256).
87
125
 
88
126
  Parameters
89
127
  ----------
@@ -95,7 +133,6 @@ def download(region="world", version=None, gpath=None, do_download=True):
95
133
  "indian" "ind" Indian Ocean
96
134
  "pacific" "pac" Pacific Ocean
97
135
  "world" "wor" Merged Master File
98
- "global" "glo" Merged Master File
99
136
  version : str or None, optional
100
137
  Which GLODAP version to download, by default `None`, in which case the
101
138
  most recent version is downloaded. The options are:
@@ -103,13 +140,8 @@ def download(region="world", version=None, gpath=None, do_download=True):
103
140
  gpath : str of None, optional
104
141
  Where to save the downloaded file, by default `None`, in which case the
105
142
  file is saved at "~/.glodap".
106
- do_download : bool, optional
107
- Whether to actually download the file, by default `True`.
108
-
109
- Returns
110
- -------
111
- int
112
- The status code from the URL request; 200 indicates success.
143
+ chunk_size : int, optional
144
+ Chunk size for streamed file download, by default 8192.
113
145
  """
114
146
  gpath, fileregion, filename, version = _get_paths(region, version, gpath)
115
147
  if not os.path.isdir(gpath):
@@ -118,19 +150,23 @@ def download(region="world", version=None, gpath=None, do_download=True):
118
150
  f"https://glodap.info/glodap_files/{version}/"
119
151
  + f"GLODAP{version}_{fileregion}.mat"
120
152
  )
121
- if do_download:
122
- r = requests.get(url)
123
- if r.status_code == 200:
124
- with open(os.path.join(gpath, filename), "wb") as file:
125
- file.write(r.content)
126
- else:
127
- warn(f"Could not download file - status code {r.status_code}")
128
- else:
129
- r = requests.head(url)
130
- return r.status_code
131
-
132
-
133
- def read(region="world", version=None, gpath=None, rename_pyco2=True):
153
+ hasher = hashlib.new("sha256")
154
+ checksum = checksums[version][region[:3].lower()]
155
+ with tempfile.TemporaryDirectory() as tdir:
156
+ temp_path = os.path.join(tdir, filename)
157
+ with requests.get(url, stream=True) as r:
158
+ r.raise_for_status()
159
+ with open(temp_path, "wb") as f:
160
+ for chunk in r.iter_content(chunk_size=chunk_size):
161
+ f.write(chunk)
162
+ hasher.update(chunk)
163
+ if hasher.hexdigest() == checksum:
164
+ os.rename(temp_path, os.path.join(gpath, filename))
165
+ else:
166
+ warn("File checksum not as expected - download failed.")
167
+
168
+
169
+ def read(region="world", version=None, gpath=None):
134
170
  """Import a GLODAP data file as a pandas DataFrame, downloading it first
135
171
  if it's not already available locally.
136
172
 
@@ -144,7 +180,6 @@ def read(region="world", version=None, gpath=None, rename_pyco2=True):
144
180
  "indian" "ind" Indian Ocean
145
181
  "pacific" "pac" Pacific Ocean
146
182
  "world" "wor" Merged Master File
147
- "global" "glo" Merged Master File
148
183
  version : str or None, optional
149
184
  Which GLODAP version to import, by default `None`, in which case the
150
185
  most recent version is imported. The options are:
@@ -152,8 +187,6 @@ def read(region="world", version=None, gpath=None, rename_pyco2=True):
152
187
  gpath : str of None, optional
153
188
  Where to the downloaded file is or should be saved, by default `None`,
154
189
  in which case the file is imported from or saved at "~/.glodap".
155
- rename_pyco2 : bool, optional
156
- Whether to rename the columns to work with PyCO2SYS, by default `True`.
157
190
 
158
191
  Returns
159
192
  -------
@@ -221,20 +254,8 @@ def read(region="world", version=None, gpath=None, rename_pyco2=True):
221
254
  for k in keys_integers + keys_flags:
222
255
  df[k] = df[k].astype(int)
223
256
  # Rename columns for PyCO2SYS, if requested
224
- if rename_pyco2:
225
- renamer_pyco2 = {
226
- "tco2": "dic",
227
- "talk": "alkalinity",
228
- "phts25p0": "ph_lab",
229
- "phtsinsitutp": "ph_insitu",
230
- }
231
- renamer_flags = {
232
- k: renamer_pyco2[k[:-1]] + "_f"
233
- if k[:-1] in renamer_pyco2
234
- else k[:-1] + "_f"
235
- for k in keys_flags
236
- }
237
- df = df.rename(columns=renamer_pyco2).rename(columns=renamer_flags)
257
+ renamer_flags = {k: k[:-1] + "_f" for k in keys_flags}
258
+ df = df.rename(columns=renamer_flags)
238
259
  # Calculate datetime for convenience - don't include hour and minute
239
260
  # because some are missing
240
261
  df["datetime"] = pd.to_datetime(
@@ -251,101 +272,131 @@ def read(region="world", version=None, gpath=None, rename_pyco2=True):
251
272
  return df
252
273
 
253
274
 
254
- def arctic(gpath=None, rename_pyco2=True):
275
+ def arctic(version=None, gpath=None):
255
276
  """Import the latest version of the GLODAP Arctic Ocean dataset,
256
277
  downloading it first if it's not already available locally.
257
278
 
258
279
  Parameters
259
280
  ----------
281
+ version : str or None, optional
282
+ Which GLODAP version to import, by default `None`, in which case the
283
+ most recent version is imported. The options are:
284
+ "v2.2023", "v2.2022", "v2.2021", "v2.2020", "v2.2019"
260
285
  gpath : str of None, optional
261
286
  Where to the downloaded file is or should be saved, by default `None`,
262
287
  in which case the file is imported from or saved at "~/.glodap".
263
- rename_pyco2 : bool, optional
264
- Whether to rename the columns to work with PyCO2SYS, by default `True`.
265
288
 
266
289
  Returns
267
290
  -------
268
291
  pd.DataFrame
269
292
  The GLODAP Arctic Ocean dataset as a pandas DataFrame.
270
293
  """
271
- return read(region="arctic", gpath=gpath, rename_pyco2=rename_pyco2)
294
+ return read(
295
+ region="arctic",
296
+ version=version,
297
+ gpath=gpath,
298
+ )
272
299
 
273
300
 
274
- def atlantic(gpath=None, rename_pyco2=True):
301
+ def atlantic(version=None, gpath=None):
275
302
  """Import the latest version of the GLODAP Atlantic Ocean dataset,
276
303
  downloading it first if it's not already available locally.
277
304
 
278
305
  Parameters
279
306
  ----------
307
+ version : str or None, optional
308
+ Which GLODAP version to import, by default `None`, in which case the
309
+ most recent version is imported. The options are:
310
+ "v2.2023", "v2.2022", "v2.2021", "v2.2020", "v2.2019"
280
311
  gpath : str of None, optional
281
312
  Where to the downloaded file is or should be saved, by default `None`,
282
313
  in which case the file is imported from or saved at "~/.glodap".
283
- rename_pyco2 : bool, optional
284
- Whether to rename the columns to work with PyCO2SYS, by default `True`.
285
314
 
286
315
  Returns
287
316
  -------
288
317
  pd.DataFrame
289
318
  The GLODAP Atlantic Ocean dataset as a pandas DataFrame.
290
319
  """
291
- return read(region="atlantic", gpath=gpath, rename_pyco2=rename_pyco2)
320
+ return read(
321
+ region="atlantic",
322
+ version=version,
323
+ gpath=gpath,
324
+ )
292
325
 
293
326
 
294
- def indian(gpath=None, rename_pyco2=True):
327
+ def indian(version=None, gpath=None):
295
328
  """Import the latest version of the GLODAP Indian Ocean dataset,
296
329
  downloading it first if it's not already available locally.
297
330
 
298
331
  Parameters
299
332
  ----------
333
+ version : str or None, optional
334
+ Which GLODAP version to import, by default `None`, in which case the
335
+ most recent version is imported. The options are:
336
+ "v2.2023", "v2.2022", "v2.2021", "v2.2020", "v2.2019"
300
337
  gpath : str of None, optional
301
338
  Where to the downloaded file is or should be saved, by default `None`,
302
339
  in which case the file is imported from or saved at "~/.glodap".
303
- rename_pyco2 : bool, optional
304
- Whether to rename the columns to work with PyCO2SYS, by default `True`.
305
340
 
306
341
  Returns
307
342
  -------
308
343
  pd.DataFrame
309
344
  The GLODAP Indian Ocean dataset as a pandas DataFrame.
310
345
  """
311
- return read(region="indian", gpath=gpath, rename_pyco2=rename_pyco2)
346
+ return read(
347
+ region="indian",
348
+ version=version,
349
+ gpath=gpath,
350
+ )
312
351
 
313
352
 
314
- def pacific(gpath=None, rename_pyco2=True):
353
+ def pacific(version=None, gpath=None):
315
354
  """Import the latest version of the GLODAP Pacific Ocean dataset,
316
355
  downloading it first if it's not already available locally.
317
356
 
318
357
  Parameters
319
358
  ----------
359
+ version : str or None, optional
360
+ Which GLODAP version to import, by default `None`, in which case the
361
+ most recent version is imported. The options are:
362
+ "v2.2023", "v2.2022", "v2.2021", "v2.2020", "v2.2019"
320
363
  gpath : str of None, optional
321
364
  Where to the downloaded file is or should be saved, by default `None`,
322
365
  in which case the file is imported from or saved at "~/.glodap".
323
- rename_pyco2 : bool, optional
324
- Whether to rename the columns to work with PyCO2SYS, by default `True`.
325
366
 
326
367
  Returns
327
368
  -------
328
369
  pd.DataFrame
329
370
  The GLODAP Pacific Ocean dataset as a pandas DataFrame.
330
371
  """
331
- return read(region="pacific", gpath=gpath, rename_pyco2=rename_pyco2)
372
+ return read(
373
+ region="pacific",
374
+ version=version,
375
+ gpath=gpath,
376
+ )
332
377
 
333
378
 
334
- def world(gpath=None, rename_pyco2=True):
379
+ def world(version=None, gpath=None):
335
380
  """Import the latest version of the GLODAP Merged Master File dataset,
336
381
  downloading it first if it's not already available locally.
337
382
 
338
383
  Parameters
339
384
  ----------
385
+ version : str or None, optional
386
+ Which GLODAP version to import, by default `None`, in which case the
387
+ most recent version is imported. The options are:
388
+ "v2.2023", "v2.2022", "v2.2021", "v2.2020", "v2.2019"
340
389
  gpath : str of None, optional
341
390
  Where to the downloaded file is or should be saved, by default `None`,
342
391
  in which case the file is imported from or saved at "~/.glodap".
343
- rename_pyco2 : bool, optional
344
- Whether to rename the columns to work with PyCO2SYS, by default `True`.
345
392
 
346
393
  Returns
347
394
  -------
348
395
  pd.DataFrame
349
396
  The GLODAP Merged Master File as a pandas DataFrame dataset.
350
397
  """
351
- return read(region="world", gpath=gpath, rename_pyco2=rename_pyco2)
398
+ return read(
399
+ region="world",
400
+ version=version,
401
+ gpath=gpath,
402
+ )
@@ -5,8 +5,8 @@ requires = [
5
5
  build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
- name = "GLODAP"
9
- description = "GLODAP downloader and importer in Python "
8
+ name = "glodap"
9
+ description = "GLODAP downloader and importer in Python"
10
10
  readme = "README.md"
11
11
  requires-python = ">= 3.10"
12
12
  dependencies = [
@@ -4,8 +4,8 @@ import glodap
4
4
 
5
5
  def test_region_names():
6
6
  # Check that the first 3 letters of each region name are unique
7
- regions_short = {k[:3] for k in glodap.regions_full}
8
- assert len(regions_short) == len(glodap.regions_full)
7
+ regions_short = {k[:3] for k in glodap.regions}
8
+ assert len(regions_short) == len(glodap.regions)
9
9
 
10
10
 
11
11
  # test_region_names()
@@ -0,0 +1,17 @@
1
+ # %%
2
+ import itertools
3
+ import tempfile
4
+
5
+ import glodap
6
+
7
+
8
+ def test_response():
9
+ with tempfile.TemporaryDirectory() as tdir:
10
+ for region, version in itertools.product(
11
+ glodap.regions, glodap.versions
12
+ ):
13
+ print(region, version)
14
+ glodap.download(region=region, version=version, gpath=tdir)
15
+
16
+
17
+ # test_response()
@@ -1,15 +0,0 @@
1
- # %%
2
- import itertools
3
-
4
- import glodap
5
-
6
-
7
- def test_responses():
8
- for region, version in itertools.product(glodap.regions, glodap.versions):
9
- status = glodap.download(
10
- region=region, version=version, do_download=False
11
- )
12
- assert status == 200, f"Failed on {region} {version}"
13
-
14
-
15
- # test_responses()
File without changes
File without changes
File without changes
File without changes
File without changes