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

Implement config, recipe loader & recipe runner. #18

Merged
merged 16 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Zampy

A tool for downloading Land Surface Model input data.

### Name origin

Named after *Zam*; [the Avestan language term for the Zoroastrian concept of "earth"](https://en.wikipedia.org/wiki/Zam).

## How to use Zampy
See the section ["using Zampy"](using_zampy.md).
14 changes: 8 additions & 6 deletions docs/using_zampy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Installing Zampy
Zampy can be installed by doing:
```sh
```bash
pip install zampy git+https://github.com/EcoExtreML/zampy
```

Expand All @@ -13,26 +13,28 @@ This file is created under your -*user's home*-/.config directory:

SarahAlidoost marked this conversation as resolved.
Show resolved Hide resolved
`~/.config/zampy/zampy_config.yml`
SarahAlidoost marked this conversation as resolved.
Show resolved Hide resolved

```yml
```yaml
BSchilperoort marked this conversation as resolved.
Show resolved Hide resolved
working_directory: /home/bart/Zampy
BSchilperoort marked this conversation as resolved.
Show resolved Hide resolved

```

## Formulating a recipe
Recipes have the following structure:
BSchilperoort marked this conversation as resolved.
Show resolved Hide resolved

```yml
```yaml
name: "test_recipe"

download:
years: [2019, 2020]
years: [2020, 2020]
bbox: [54, 6, 50, 3] # NESW

datasets:
era5:
variables:
- 10m_v_component_of_wind
- surface_pressure
eth_canopy_height:
variables:
- height_of_vegetation

convert:
convention: ALMA
Expand All @@ -45,7 +47,7 @@ You can specify multiple datasets and multiple variables per dataset.
## Running a recipe
Save this recipe to disk and run the following code in your shell:

```sh
```bash
zampy --filename /home/username/path_to_file/simple_recipe.yml
SarahAlidoost marked this conversation as resolved.
Show resolved Hide resolved
```

Expand Down
17 changes: 16 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ site_name: Zampy Documentation

theme:
name: material
highlightjs: true
hljs_languages:
- yaml
- python
- bash
features:
- navigation.instant
- navigation.tabs
- navigation.tabs.sticky

- content.code.copy

palette:
# Palette toggle for light mode
- scheme: default
Expand Down Expand Up @@ -38,5 +44,14 @@ plugins:
merge_init_into_class: yes
show_submodules: no

markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences

extra:
generator: false
14 changes: 9 additions & 5 deletions src/zampy/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def __init__(self, recipe_filename: str) -> None:
# Load & parse recipe
recipe = recipe_loader(recipe_filename)

start_year, end_year = recipe["download"]["years"]
self.start_year, self.end_year = recipe["download"]["years"]
self.timebounds = TimeBounds(
np.datetime64(f"{start_year}"), np.datetime64(f"{end_year}")
np.datetime64(f"{self.start_year}-01-01T00:00"),
np.datetime64(f"{self.end_year}-12-13T23:59"),
SarahAlidoost marked this conversation as resolved.
Show resolved Hide resolved
)
self.spatialbounds = SpatialBounds(*recipe["download"]["bbox"])

Expand Down Expand Up @@ -119,8 +120,11 @@ def run(self) -> None:
comp = dict(zlib=True, complevel=5)
encoding = {var: comp for var in ds.data_vars}
fname = ( # e.g. "era5_2010-2020.nc"
f"{dataset_name.lower()}_"
f"{self.timebounds.start}-{self.timebounds.end}"
".nc"
f"{dataset_name.lower()}_" f"{self.start_year}-{self.end_year}" ".nc"
SarahAlidoost marked this conversation as resolved.
Show resolved Hide resolved
)
ds.to_netcdf(path=self.data_dir / fname, encoding=encoding)

print(
"Finished running the recipe. Output data can be found at:\n"
f" {self.data_dir}"
)