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 chelsa recipe #133

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions recipes/chelsa/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Name for dataset. User chosen.
title: 'CHELSA v2.1'
# Description of dataset. User chosen, roughly 1 sentence in length.
description: "Climatologies at high resolution for the Earth's land surface areas"
# Version of pangeo_forge_recipes library that was used
pangeo_forge_version: '0.8.2'
pangeo_notebook_version: '2022.05.02'
# The recipes section tells Pangeo Cloud where to find the recipes within your PR.
# Many recipe PRs will have just 1 recipe, in which case this section will look similar to the example below.
# If your PR contains multiple recipes, you may add additional elements to the list below.
recipes:
# User chosen name for recipe. Likely similiar to dataset name, ~25 characters in length
- id: chelsa-v2.1
# The `object` below tells Pangeo Cloud specifically where your recipe instance(s) are located and uses the format <filename>:<object_name>
# <filename> is name of .py file where the Python recipe object is defined.
# For example, if <filename> is given as "recipe", Pangeo Cloud will expect a file named `recipe.py` to exist in your PR.
# <object_name> is the name of the recipe object (i.e. Python class instance) _within_ the specified file.
# For example, if you have defined `recipe = XarrayZarrRecipe(...)` within a file named `recipe.py`, then your `object` below would be `"recipe:recipe"`
object: 'recipe:recipe'
provenance:
# Data provider object. Follow STAC spec.
# https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#provider-object
providers:
- name: 'Karger et al. 2017'
description: 'Climatologies at high resolution for the Earth land surface areas'
roles:
- producer
- licensor
url: https://chelsa-climate.org/
# This is a required field for provider. Follow STAC spec
# https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#license
license: 'CC-BY-4.0'
maintainers:
# Information about recipe creator. name and github are required
- name: 'Hillary Scannell'
orcid: '0000-0002-6604-1695'
github: hscannell
# The specific bakery (i.e. cloud infrastructure) that your recipe will run on.
# Available bakeries can be found on the Pangeo Forge website https://pangeo-forge.org/dashboard/bakeries
bakery:
id: 'pangeo-ldeo-nsf-earthcube'
48 changes: 48 additions & 0 deletions recipes/chelsa/recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import numpy as np

from pangeo_forge_recipes.patterns import ConcatDim, FilePattern, MergeDim
from pangeo_forge_recipes.recipes import XarrayZarrRecipe

months = np.arange(1, 13)
variables = ['cmi', 'hurs', 'pet', 'pr', 'sfcWind', 'tas', 'tasmax', 'tasmin', 'vpd']


def make_url(variable, month):
'''
Takes two keys and translates it into a URL into a data file
'''
if variable == 'pet':
variable_filename = 'pet_penman'
else:
variable_filename = variable
return (
'https://os.zhdk.cloud.switch.ch/envicloud/chelsa/chelsa_V2/GLOBAL/'
f'climatologies/1981-2010/{variable}/CHELSA_{variable_filename}_{month:02}_1981-2010_V.2.1.tif' # noqa
)


def rename_vars(ds, url):
'''
Add unique identifier to variables names.
'''
varname = url.split('_')[-4]

return ds.rename_vars({v: f'{varname}_{v}' for v in ds.data_vars})


pattern = FilePattern(
make_url,
ConcatDim(name='month', keys=months, nitems_per_file=1),
MergeDim(name='variable', keys=variables),
file_type='tiff',
)

recipe = XarrayZarrRecipe(
file_pattern=pattern,
inputs_per_chunk=1,
xarray_open_kwargs={'engine': 'rasterio'},
copy_input_to_local_file=True,
process_input=rename_vars,
subset_inputs={'y': 4},
target_chunks={'y': 5220, 'x': 5400},
)