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

Work with regional surface datasets (v2) #24

Open
wants to merge 3 commits into
base: main
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
2 changes: 1 addition & 1 deletion src/landusedata/landusepft.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def main(args):
# this will contain different data from a future CLM landuse x pft update
ds_output['frac_secnd'] = ds_output.frac_primr.copy(deep=True)

# ds_regrid = ds_regrid.rename_dims(dims_dict={'lat':'lsmlat','lon':'lsmlon'})
# ds_regrid = ds_regrid.rename({'lat':'lsmlat','lon':'lsmlon'})

# Output dataset to netcdf file
print('Writing fates landuse x pft dataset to file')
Expand Down
1 change: 1 addition & 0 deletions src/landusedata/luh2.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def main(args):
regrid_luh2["LATIXY"] = ds_regrid_target["LATIXY"] # TO DO: double check if this is strictly necessary

# Rename the dimensions for the output. This needs to happen after the "LONGXY/LATIXY" assignment
# and should not touch the respective coordinate variables (hence rename_dims instead of rename).
if (not 'lsmlat' in list(regrid_luh2.dims)):
regrid_luh2 = regrid_luh2.rename_dims({'lat':'lsmlat','lon':'lsmlon'})

Expand Down
12 changes: 11 additions & 1 deletion src/landusedata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ def _RegridTargetPrep(regrid_target):
by xesmf. As such, this function renames the dimensions. It also adds
lat/lon coordinates based on the LONGXY and LATIXY variables.
"""
regrid_target = regrid_target.rename_dims(dims_dict={'lsmlat':'lat','lsmlon':'lon'})

# Skip if lat and lon are already the dimension names
if "lat" in regrid_target.dims and "lon" in regrid_target.dims:
return regrid_target

# Drop dimension variables if they already exist
regrid_target = regrid_target.drop_vars("lat", errors="ignore")
regrid_target = regrid_target.drop_vars("lon", errors="ignore")

# Rename dimensions and add coordinates
regrid_target = regrid_target.rename({'lsmlat':'lat','lsmlon':'lon'})
regrid_target['lon'] = regrid_target.LONGXY.isel(lat=0)
regrid_target['lat'] = regrid_target.LATIXY.isel(lon=0)

Expand Down