physoce-datasets 0.1.0__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.
@@ -0,0 +1,192 @@
1
+ # ignore data files
2
+ *.nc
3
+ data/*
4
+
5
+ # Python-generated files
6
+ __pycache__/
7
+ *.py[oc]
8
+ build/
9
+ dist/
10
+ wheels/
11
+ *.egg-info
12
+
13
+ # Virtual environments
14
+ .venv
15
+
16
+ # Created with easyignore
17
+ # Created by https://www.toptal.com/developers/gitignore/api/python
18
+ # Edit at https://www.toptal.com/developers/gitignore?templates=python
19
+
20
+ ### Python ###
21
+ # Byte-compiled / optimized / DLL files
22
+ __pycache__/
23
+ *.py[cod]
24
+ *$py.class
25
+
26
+ # C extensions
27
+ *.so
28
+
29
+ # Distribution / packaging
30
+ .Python
31
+ build/
32
+ develop-eggs/
33
+ dist/
34
+ downloads/
35
+ eggs/
36
+ .eggs/
37
+ lib/
38
+ lib64/
39
+ parts/
40
+ sdist/
41
+ var/
42
+ wheels/
43
+ share/python-wheels/
44
+ *.egg-info/
45
+ .installed.cfg
46
+ *.egg
47
+ MANIFEST
48
+
49
+ # PyInstaller
50
+ # Usually these files are written by a python script from a template
51
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
52
+ *.manifest
53
+ *.spec
54
+
55
+ # Installer logs
56
+ pip-log.txt
57
+ pip-delete-this-directory.txt
58
+
59
+ # Unit test / coverage reports
60
+ htmlcov/
61
+ .tox/
62
+ .nox/
63
+ .coverage
64
+ .coverage.*
65
+ .cache
66
+ nosetests.xml
67
+ coverage.xml
68
+ *.cover
69
+ *.py,cover
70
+ .hypothesis/
71
+ .pytest_cache/
72
+ cover/
73
+
74
+ # Translations
75
+ *.mo
76
+ *.pot
77
+
78
+ # Django stuff:
79
+ *.log
80
+ local_settings.py
81
+ db.sqlite3
82
+ db.sqlite3-journal
83
+
84
+ # Flask stuff:
85
+ instance/
86
+ .webassets-cache
87
+
88
+ # Scrapy stuff:
89
+ .scrapy
90
+
91
+ # Sphinx documentation
92
+ docs/_build/
93
+
94
+ # PyBuilder
95
+ .pybuilder/
96
+ target/
97
+
98
+ # Jupyter Notebook
99
+ .ipynb_checkpoints
100
+
101
+ # IPython
102
+ profile_default/
103
+ ipython_config.py
104
+
105
+ # pyenv
106
+ # For a library or package, you might want to ignore these files since the code is
107
+ # intended to run in multiple environments; otherwise, check them in:
108
+ # .python-version
109
+
110
+ # pipenv
111
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
112
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
113
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
114
+ # install all needed dependencies.
115
+ #Pipfile.lock
116
+
117
+ # poetry
118
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
119
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
120
+ # commonly ignored for libraries.
121
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
122
+ #poetry.lock
123
+
124
+ # pdm
125
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
126
+ #pdm.lock
127
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
128
+ # in version control.
129
+ # https://pdm.fming.dev/#use-with-ide
130
+ .pdm.toml
131
+
132
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
133
+ __pypackages__/
134
+
135
+ # Celery stuff
136
+ celerybeat-schedule
137
+ celerybeat.pid
138
+
139
+ # SageMath parsed files
140
+ *.sage.py
141
+
142
+ # Environments
143
+ .env
144
+ .venv
145
+ env/
146
+ venv/
147
+ ENV/
148
+ env.bak/
149
+ venv.bak/
150
+
151
+ # Spyder project settings
152
+ .spyderproject
153
+ .spyproject
154
+
155
+ # Rope project settings
156
+ .ropeproject
157
+
158
+ # mkdocs documentation
159
+ /site
160
+
161
+ # mypy
162
+ .mypy_cache/
163
+ .dmypy.json
164
+ dmypy.json
165
+
166
+ # Pyre type checker
167
+ .pyre/
168
+
169
+ # pytype static type analyzer
170
+ .pytype/
171
+
172
+ # Cython debug symbols
173
+ cython_debug/
174
+
175
+ # PyCharm
176
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
177
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
178
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
179
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
180
+ #.idea/
181
+
182
+ ### Python Patch ###
183
+ # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
184
+ poetry.toml
185
+
186
+ # ruff
187
+ .ruff_cache/
188
+
189
+ # LSP config files
190
+ pyrightconfig.json
191
+
192
+ # End of https://www.toptal.com/developers/gitignore/api/python
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: physoce-datasets
3
+ Version: 0.1.0
4
+ Summary: A Python package and CLI for downloading various physical oceanographic datasets.
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: cdsapi>=0.7.7
7
+ Requires-Dist: cfgrib>=0.9.15.1
8
+ Requires-Dist: click>=8.2.1
9
+ Requires-Dist: copernicusmarine>=2.3.0
10
+ Requires-Dist: ecmwf-datastores-client>=0.5.1
11
+ Requires-Dist: gcsfs>=2026.3.0
12
+ Requires-Dist: h5py>=3.16.0
13
+ Requires-Dist: ipykernel>=7.2.0
14
+ Requires-Dist: metpy>=1.7.1
15
+ Requires-Dist: numpy>=2.4.4
16
+ Requires-Dist: pycoare>=0.4.0
17
+ Requires-Dist: python-dotenv>=1.2.2
18
+ Requires-Dist: xarray[accel,io,parallel]>=2026.2.0
19
+ Description-Content-Type: text/markdown
20
+
21
+ # physoce-datasets
22
+
23
+ A Python package and CLI for downloading various physical oceanographic datasets.
24
+
25
+ ## Install
26
+
27
+ Clone the package and navigate to the directory:
28
+
29
+ ```bash
30
+ git clone https://github.com/andrew-s28/physoce-datasets.git
31
+ cd physoce-datasets
32
+ ```
33
+
34
+ ### uv
35
+
36
+ `uv` is the preferred way to manage this package. Please refer to the [uv installation instructions](https://docs.astral.sh/uv/getting-started/installation/). Once uv is installed, you can initialize a virtual environment with `uv sync` or you can run any commands directly with `uv run` and `uv` will handle the `venv` creation and activation auto-magically.
37
+
38
+ ### pip
39
+
40
+ Of course, you can also use the classic `pip`, but you have to handle creating and activating the `venv` yourself:
41
+
42
+ ```bash
43
+ python -m venv .venv
44
+ source .venv/bin/activate
45
+ pip install -e .
46
+ ```
47
+
48
+ ## Credentials
49
+
50
+ Upon usage, this package may prompt for credentials to various data stores. Please refer to their documentation for how to access credentials and how credentials are stored:
51
+
52
+ - [Copernicus Marine Services](https://toolbox-docs.marine.copernicus.eu/en/stable/usage/login-usage.html)
53
+ - [Copernicus Climate Data Store](https://cds.climate.copernicus.eu/how-to-api)
54
+
55
+ ## CLI usage
56
+
57
+ Run the CLI with uv:
58
+
59
+ ```bash
60
+ uv run datasets.py --help
61
+ ```
62
+
63
+ Note that if you prefer the `pip` environment management, activate your environment according to the above and replace all `uv run` commands with `python`, e.g.:
64
+
65
+ ```bash
66
+ python datasets.py --help
67
+ ```
68
+
69
+ Available commands:
70
+
71
+ - `eke`: Download altimetry-derived geostrophic velocities and compute eddy kinetic energy from Copernicus Marine Services.
72
+ - `era5`: ERA5 workflow group with `submit` and `download` subcommands.
73
+
74
+ Show command help:
75
+
76
+ ```bash
77
+ uv run datasets.py eke --help
78
+ ```
79
+
80
+ ### Options
81
+
82
+ All commands share the same base options:
83
+
84
+ - `--save-dir`: Directory where the dataset file is written. If not set, defaults to the package `data/` directory.
85
+ - `--start-date`: Start date in `YYYY-MM-DD` format. If not set, uses the earliest available date.
86
+ - `--end-date`: End date in `YYYY-MM-DD` format. If not set, uses the latest available date
87
+
88
+ Run `eke` download with defaults:
89
+
90
+ ```bash
91
+ uv run datasets.py eke
92
+ ```
93
+
94
+ Submit ERA5 jobs with explicit options:
95
+
96
+ ```bash
97
+ uv run datasets.py era5 submit --save-dir data --start-date 2020-01-01 --end-date 2020-01-31 --max-active-requests 10
98
+ ```
99
+
100
+ Download and process ERA5 files once all remote jobs are successful:
101
+
102
+ ```bash
103
+ uv run datasets.py era5 download --save-dir data
104
+ ```
105
+
106
+ The ERA5 workflow writes its progress to `submitted_requests.csv` inside the save directory. If the script exits or is interrupted, rerun the same command to resume from saved state.
@@ -0,0 +1,86 @@
1
+ # physoce-datasets
2
+
3
+ A Python package and CLI for downloading various physical oceanographic datasets.
4
+
5
+ ## Install
6
+
7
+ Clone the package and navigate to the directory:
8
+
9
+ ```bash
10
+ git clone https://github.com/andrew-s28/physoce-datasets.git
11
+ cd physoce-datasets
12
+ ```
13
+
14
+ ### uv
15
+
16
+ `uv` is the preferred way to manage this package. Please refer to the [uv installation instructions](https://docs.astral.sh/uv/getting-started/installation/). Once uv is installed, you can initialize a virtual environment with `uv sync` or you can run any commands directly with `uv run` and `uv` will handle the `venv` creation and activation auto-magically.
17
+
18
+ ### pip
19
+
20
+ Of course, you can also use the classic `pip`, but you have to handle creating and activating the `venv` yourself:
21
+
22
+ ```bash
23
+ python -m venv .venv
24
+ source .venv/bin/activate
25
+ pip install -e .
26
+ ```
27
+
28
+ ## Credentials
29
+
30
+ Upon usage, this package may prompt for credentials to various data stores. Please refer to their documentation for how to access credentials and how credentials are stored:
31
+
32
+ - [Copernicus Marine Services](https://toolbox-docs.marine.copernicus.eu/en/stable/usage/login-usage.html)
33
+ - [Copernicus Climate Data Store](https://cds.climate.copernicus.eu/how-to-api)
34
+
35
+ ## CLI usage
36
+
37
+ Run the CLI with uv:
38
+
39
+ ```bash
40
+ uv run datasets.py --help
41
+ ```
42
+
43
+ Note that if you prefer the `pip` environment management, activate your environment according to the above and replace all `uv run` commands with `python`, e.g.:
44
+
45
+ ```bash
46
+ python datasets.py --help
47
+ ```
48
+
49
+ Available commands:
50
+
51
+ - `eke`: Download altimetry-derived geostrophic velocities and compute eddy kinetic energy from Copernicus Marine Services.
52
+ - `era5`: ERA5 workflow group with `submit` and `download` subcommands.
53
+
54
+ Show command help:
55
+
56
+ ```bash
57
+ uv run datasets.py eke --help
58
+ ```
59
+
60
+ ### Options
61
+
62
+ All commands share the same base options:
63
+
64
+ - `--save-dir`: Directory where the dataset file is written. If not set, defaults to the package `data/` directory.
65
+ - `--start-date`: Start date in `YYYY-MM-DD` format. If not set, uses the earliest available date.
66
+ - `--end-date`: End date in `YYYY-MM-DD` format. If not set, uses the latest available date
67
+
68
+ Run `eke` download with defaults:
69
+
70
+ ```bash
71
+ uv run datasets.py eke
72
+ ```
73
+
74
+ Submit ERA5 jobs with explicit options:
75
+
76
+ ```bash
77
+ uv run datasets.py era5 submit --save-dir data --start-date 2020-01-01 --end-date 2020-01-31 --max-active-requests 10
78
+ ```
79
+
80
+ Download and process ERA5 files once all remote jobs are successful:
81
+
82
+ ```bash
83
+ uv run datasets.py era5 download --save-dir data
84
+ ```
85
+
86
+ The ERA5 workflow writes its progress to `submitted_requests.csv` inside the save directory. If the script exits or is interrupted, rerun the same command to resume from saved state.
@@ -0,0 +1,5 @@
1
+ """The physoce_datasets package provides tools for downloading and processing physical oceanography datasets."""
2
+
3
+ from .download import download_eke, download_era5, submit_era5
4
+
5
+ __all__ = ["download_eke", "download_era5", "submit_era5"]
@@ -0,0 +1,170 @@
1
+ """CLI commands for physoce_datasets."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import click
8
+
9
+ from .download import download_eke, download_era5, submit_era5
10
+
11
+ save_dir_option = click.option(
12
+ "--save-dir",
13
+ type=click.Path(file_okay=False, dir_okay=True, path_type=Path),
14
+ default=None,
15
+ help=(
16
+ "Directory to save the downloaded dataset. If not specified, defaults "
17
+ "to a 'data' directory in the current working directory."
18
+ ),
19
+ )
20
+ save_file_option = click.option(
21
+ "--save-file",
22
+ type=str,
23
+ default=None,
24
+ help=(
25
+ "Filename to save the dataset. If not specified, defaults to a filename "
26
+ "based on the dataset name and date range (e.g., 'eke_2000-01-01_to_2020-12-31.nc')."
27
+ ),
28
+ )
29
+ start_datetime_option = click.option(
30
+ "--start-date",
31
+ type=str,
32
+ default=None,
33
+ help=(
34
+ "Start datetime for the dataset. Format should be YYYY-MM-DD. If not "
35
+ "specified, defaults to the earliest available datetime for the dataset."
36
+ ),
37
+ )
38
+ end_datetime_option = click.option(
39
+ "--end-date",
40
+ type=str,
41
+ default=None,
42
+ help=(
43
+ "End datetime for the dataset. Format should be YYYY-MM-DD. If not "
44
+ "specified, defaults to the latest available datetime for the dataset."
45
+ ),
46
+ )
47
+ update_option = click.option(
48
+ "--update-file",
49
+ type=str,
50
+ default=None,
51
+ help=(
52
+ "Whether to update an existing dataset with new data. If specified, should be "
53
+ "the path to an existing netCDF file found in the directory specified by --save-dir (default './data')."
54
+ ),
55
+ )
56
+ area_option = click.option(
57
+ "--area",
58
+ type=str,
59
+ default=None,
60
+ help=(
61
+ "Bounding box for the dataset in the format 'lon_min,lon_max,lat_min,lat_max'. "
62
+ "If not specified, defaults to global coverage."
63
+ ),
64
+ )
65
+
66
+
67
+ @click.group(invoke_without_command=True)
68
+ @click.pass_context
69
+ def cli(ctx: click.Context) -> None:
70
+ """Command-line interface for downloading datasets."""
71
+ if ctx.invoked_subcommand is None:
72
+ click.echo("No subcommand specified. Use --help for more information.")
73
+
74
+
75
+ @cli.command(
76
+ "eke",
77
+ help="Download geostrophic velocities and compute eddy kinetic energy from Copernicus Marine Services.",
78
+ )
79
+ @save_dir_option
80
+ @start_datetime_option
81
+ @end_datetime_option
82
+ @save_file_option
83
+ @area_option
84
+ def _eke(
85
+ save_dir: Path | None,
86
+ start_date: str | None,
87
+ end_date: str | None,
88
+ save_file: str | None,
89
+ area: str | None,
90
+ ) -> None:
91
+ """Download geostrophic velocities and compute eddy kinetic energy from Copernicus Marine Services.
92
+
93
+ Args:
94
+ save_dir (Path | None): Directory to save the downloaded dataset. If not specified,
95
+ defaults to a "data" directory in the current working directory.
96
+ start_date (str | None): Start date for the dataset. Format should be YYYY-MM-DD.
97
+ If not specified, defaults to the earliest available date for the dataset.
98
+ end_date (str | None): End date for the dataset. Format should be YYYY-MM-DD.
99
+ If not specified, defaults to the latest available date for the dataset.
100
+ save_file (str | None): Filename to save the dataset. If not specified, defaults to a filename
101
+ based on the dataset name and date range (e.g., "eke_2000-01-01_to_2020-12-31.nc").
102
+ area (str | None): Bounding box for the dataset in the format 'lon_min,lat_min,lon_max,lat_max'.
103
+ If not specified, defaults to global coverage.
104
+
105
+ """
106
+ download_eke(
107
+ save_dir=save_dir,
108
+ start_datetime=start_date,
109
+ end_datetime=end_date,
110
+ save_file=save_file,
111
+ area_str=area,
112
+ )
113
+
114
+
115
+ @cli.group("era5", help="ERA5 workflow commands.")
116
+ def _era5() -> None:
117
+ """ERA5 workflow commands group."""
118
+
119
+
120
+ @_era5.command("submit", help="Submit ERA5 jobs until all requested months are queued.")
121
+ @save_dir_option
122
+ @start_datetime_option
123
+ @end_datetime_option
124
+ @area_option
125
+ def _era5_submit(
126
+ save_dir: Path | None,
127
+ start_date: str | None,
128
+ end_date: str | None,
129
+ area: str | None,
130
+ ) -> None:
131
+ """Submit ERA5 jobs only.
132
+
133
+ Args:
134
+ save_dir (Path | None): Directory to save request state. If not
135
+ specified, defaults to a "data" directory in the current working directory.
136
+ start_date (str | None): Start date for the dataset. Format should be YYYY-MM-DD.
137
+ end_date (str | None): End date for the dataset. Format should be YYYY-MM-DD.
138
+ area (str | None): Bounding box for the dataset in the format 'lon_min,lat_min,lon_max,lat_max'.
139
+ If not specified, defaults to global coverage.
140
+
141
+ """
142
+ submit_era5(
143
+ save_dir=save_dir,
144
+ start_date=start_date,
145
+ end_date=end_date,
146
+ area_str=area,
147
+ )
148
+
149
+
150
+ @_era5.command("download", help="Download and process ERA5 files after all remote jobs are successful.")
151
+ @save_dir_option
152
+ @save_file_option
153
+ def _era5_download(save_dir: Path | None, save_file: str | None) -> None:
154
+ """Download ERA5 data for successful remote jobs and process locally.
155
+
156
+ Args:
157
+ save_dir (Path | None): Directory containing saved request state and output files.
158
+ If not specified, defaults to a "data" directory in the current working directory.
159
+ save_file (str | None): Filename to save the dataset. If not specified, defaults to a filename
160
+ based on the dataset name and date range.
161
+
162
+ """
163
+ download_era5(
164
+ save_dir=save_dir,
165
+ save_file=save_file,
166
+ )
167
+
168
+
169
+ if __name__ == "__main__":
170
+ cli()
@@ -0,0 +1,10 @@
1
+ """Module for downloading physical oceanographic datasets.
2
+
3
+ This module also processes downloaded data into xarray Datasets with
4
+ appropriate metadata.
5
+ """
6
+
7
+ from .eke import download_eke
8
+ from .era5 import download_era5, submit_era5
9
+
10
+ __all__ = ["download_eke", "download_era5", "submit_era5"]