Skip to content

Commit

Permalink
add function to rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Hillary Scannell authored and andersy005 committed Oct 25, 2022
1 parent 841c8a2 commit c1d6b60
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions recipes/chelsa/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def make_url(variable, month):
f'climatologies/1981-2010/{variable}/CHELSA_{variable_filename}_{month:02}_1981-2010_V.2.1.tif'
)

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),
Expand All @@ -38,6 +46,7 @@ def make_url(variable, month):
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}
)

0 comments on commit c1d6b60

Please sign in to comment.