Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back working download script #1

Merged
merged 9 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.10, 3.12] # test oldest and latest supported versions
python-version: ["3.10", "3.12"] # test oldest and latest supported versions
runs-on: [ubuntu-latest] # can be extended to other OSes, e.g. [ubuntu-latest, macos-latest]

steps:
Expand All @@ -43,7 +43,7 @@ jobs:
allow-prereleases: true

- name: Install package
run: python -m pip install .[test]
run: python -m pip install .[dev]

- name: Test package
run: >-
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ repos:
args: []
additional_dependencies:
- pytest
- xarray
- pandas-stubs
- types-all
- typer
- dask
79 changes: 74 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,87 @@ Tooling and infrastructure to enable cloud nowcasting.

## Installation

From source (development mode):
```bash
python -m pip install cloudcast
git clone https://github.com/climetrend/cloudcast
cd cloudcast
python -m pip install ".[dev]"
```

From source:
Install pre-commit before making development changes:

```bash
git clone https://github.com/climetrend/cloudcast
cd cloudcast
python -m pip install .
pre-commit install
```

For making changes, see the [guidance on development](https://github.com/alan-turing-institute/python-project-template?tab=readme-ov-file#setting-up-a-new-project) from the template that generated this project.

## Usage
```bash
 cloudcast download --help

Usage: cloudcast download [OPTIONS] START_DATE END_DATE OUTPUT_DIRECTORY

Download a selection of the available EUMETSAT data.
Each calendar year of data within the supplied date range will be saved to a
separate file in the output directory.
Args: start_date: First datetime (inclusive) to download. end_date: Last
datetime (inclusive) to download. data_inner_steps: Data will be sliced into
data_inner_steps*5minute chunks. output_directory: Directory to which the
satellite data should be saved. lon_min: The west-most longitude (in
degrees) of the bounding box to download. lon_max: The east-most longitude
(in degrees) of the bounding box to download. lat_min: The south-most
latitude (in degrees) of the bounding box to download. lat_max: The
north-most latitude (in degrees) of the bounding box to download. get_hrv:
Whether to download the HRV data, else non-HRV is downloaded.
override_date_bounds: Whether to override the date range limits.
Raises: FileNotFoundError: If the output directory doesn't exist.
ValueError: If there are issues with the date range or if output files already
exist.

╭─ Arguments ────────────────────────────────────────────────────────────────────╮
│ * start_date TEXT Start date in 'YYYY-MM-DD HH:MM' format │
│ [default: None] │
│ [required] │
│ * end_date TEXT End date in 'YYYY-MM-DD HH:MM' format │
│ [default: None] │
│ [required] │
│ * output_directory TEXT Directory to save the satellite data │
│ [default: None] │
│ [required] │
╰────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ──────────────────────────────────────────────────────────────────────╮
│ --data-inner-steps INTEGER Data will be sliced │
│ into │
│ data_inner_steps*5mi… │
│ chunks │
│ [default: 3] │
│ --get-hrv --no-get-hrv Whether to download │
│ HRV data │
│ [default: no-get-hrv] │
│ --override-date-boun… --no-override-date… Whether to override │
│ date range limits │
│ [default: │
│ no-override-date-bou… │
│ --lon-min FLOAT Minimum longitude │
│ [default: -16] │
│ --lon-max FLOAT Maximum longitude │
│ [default: 10] │
│ --lat-min FLOAT Minimum latitude │
│ [default: 45] │
│ --lat-max FLOAT Maximum latitude │
│ [default: 70] │
│ --help Show this message and │
│ exit. │
╰────────────────────────────────────────────────────────────────────────────────╯

```

Example:

```bash
cloudcast download "2020-06-01 00:00" "2020-06-30 23:55" "path/to/my/dir/data.zarr"
```


## Contributing
Expand Down
59 changes: 59 additions & 0 deletions notebooks/plotting.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ocf_blosc2 # noqa: F401\n",
"import xarray as xr\n",
"\n",
"ds_sat = xr.open_zarr(\"path/to/new/satellite/directory/2020_nonhrv.zarr\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds_sat.sel(time=\"2020-06-01 12:00\", variable=\"VIS008\").data.plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"timestamp = '2020-01-06T09:00:00.000000000'\n",
"\n",
"# Calculate the number of variables (columns)\n",
"num_vars = len(ds_sat.variable)\n",
"\n",
"\n",
"col_wrap = 3\n",
"num_rows = (num_vars + 3) // col_wrap # Using 4 as col_wrap, adjust if different\n",
"\n",
"# Calculate the figure size based on the image resolution of 614x372\n",
"fig_width = 6.14 * col_wrap\n",
"fig_height = 3.72 * num_rows\n",
"\n",
"ds_sat.sel(time=timestamp).data.plot(\n",
" col=\"variable\",\n",
" col_wrap=col_wrap,\n",
" figsize=(fig_width, fig_height),\n",
" robust=True,\n",
");"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 2 additions & 0 deletions notebooks/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ipykernel
matplotlib
49 changes: 33 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
license = "MIT"
description = "Tooling and infrastructure to enable cloud nowcasting."
readme = "README.md"

classifiers = [
"Development Status :: 1 - Planning",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
"Typing :: Typed",
]

[project]
name = "cloudcast"
Expand All @@ -32,22 +21,34 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
"Typing :: Typed",
]
dependencies = []

dependencies = [
"gcsfs",
"zarr",
"xarray",
"dask",
"pyresample",
"pyproj",
"ocf-blosc2",
"ocf-datapipes",
"typer"
]
[project.optional-dependencies]
dev = [
"pytest >=6",
"pytest-cov >=3",
"pre-commit",

]

[project.scripts]
cloudcast = "cloudcast.cli:app"

[project.urls]
Homepage = "https://github.com/climetrend/cloudcast"
"Bug Tracker" = "https://github.com/climetrend/cloudcast/issues"
Expand Down Expand Up @@ -75,7 +76,7 @@ port.exclude_lines = [
]

[tool.mypy]
files = ["src", "tests"]
files = ["src"]
python_version = "3.10"
show_error_codes = true
warn_unreachable = true
Expand All @@ -90,10 +91,24 @@ module = "cloudcast.*"
disallow_untyped_defs = true
disallow_incomplete_defs = true

[[tool.mypy.overrides]]
module = [
"ocf_blosc2",
"ocf_datapipes.utils.geospatial"
]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = [
"cloudcast.download",
"cloudcast.cli",
]
disallow_untyped_calls = false

[tool.ruff]
src = ["src"]
exclude = []
line-length = 88 # how long you want lines to be
line-length = 100 # how long you want lines to be
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3


[tool.ruff.format]
docstring-code-format = true # code snippets in docstrings will be formatted
Expand Down Expand Up @@ -129,3 +144,5 @@ unfixable = [
"F841", # Would remove unused variables
]
flake8-unused-arguments.ignore-variadic-names = true # allow unused *args/**kwargsisort.required-imports = ["from __future__ import annotations"]
[tool.ruff.lint.per-file-ignores]
"src/cloudcast/download.py" = ["E402"]
4 changes: 3 additions & 1 deletion src/cloudcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@

from importlib.metadata import version

__all__ = ("__version__",)
from cloudcast import cli, download

__all__ = ("__version__", "download", "cli")
__version__ = version(__name__)
3 changes: 3 additions & 0 deletions src/cloudcast/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cloudcast.cli import app

app()
8 changes: 8 additions & 0 deletions src/cloudcast/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import typer

from cloudcast.download import download_satellite_data

# typer app code
app = typer.Typer()
app.command("download")(download_satellite_data)
app.command("validate")(lambda x: x) # placeholder
Loading
Loading