Skip to content

Commit

Permalink
Merge PR #311 (Fix issues in cubed-sphere regridding)
Browse files Browse the repository at this point in the history
This merge brings PR # (Fix issues in cubed-sphere regridding, by
@yuanjianz) into the GCPy 1.5.0 development stream.

This PR does the following:

1. Now cube-sphere regridding in file_regrid would have correct shape
   of value array for single level plotting in single_panel.

2. Now compare_single_level will automatically choose the higher resolution
   between two standard cube-sphere grids, and also having correct
   unflipped absdiff and fracdiff.

3. Now will not trigger renaming error when 2D data (Emissions, column AODs)
   that needs regridding is passed to compare_single_level.

4. Delete code for quiting benchmark (which is already included in dev branch)

Signed-off-by: Bob Yantosca <[email protected]>
  • Loading branch information
yantosca committed Apr 24, 2024
2 parents b46d122 + f885521 commit 5523c97
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions gcpy/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def create_regridders(
"Warning: zonal mean comparison must be lat-lon. Defaulting to 1x1.25")
cmpres = '1x1.25'
cmpgridtype = "ll"
elif sg_ref_params != [] or sg_dev_params != []:
elif sg_ref_params != [1, 170, -90] or sg_dev_params != [1, 170, -90]:
# pick ref grid when a stretched-grid and non-stretched-grid
# are passed
cmpres = refres
Expand Down Expand Up @@ -758,6 +758,12 @@ def ravel_checkpoint_lat(ds_out):
})
return ds_out

# Filter non-existent coordinates/dimensions
def rename_existing(ds, rename_dict):
existing_keys = set(ds.coords) | set(ds.dims)
filtered_rename_dict = {key: value for key, value in rename_dict.items() if key in existing_keys}
return ds.rename(filtered_rename_dict)

dim_formats = {
'checkpoint': {
'unravel': [unravel_checkpoint_lat],
Expand All @@ -779,7 +785,8 @@ def ravel_checkpoint_lat(ds_out):
'Ydim': 'Y',
'time': 'T',
},
'transpose': ('time', 'lev', 'nf', 'Xdim', 'Ydim')
# match format of GCHP output
'transpose': ('time', 'lev', 'nf', 'Ydim', 'Xdim')
}
}

Expand All @@ -790,30 +797,21 @@ def ravel_checkpoint_lat(ds_out):
ds = unravel_callback(ds)

# Rename dimensions
ds = ds.rename(dim_formats[format].get('rename', {}))
ds = rename_existing(ds, dim_formats[format].get('rename', {}))
return ds


# %%%% Renaming from the common format %%%%
# Reverse rename
ds = ds.rename(
ds = rename_existing(ds,
{v: k for k, v in dim_formats[format].get('rename', {}).items()})

# Ravel dimensions
for ravel_callback in dim_formats[format].get('ravel', []):
ds = ravel_callback(ds)

# Transpose
if len(ds.dims) == 5 or (len(ds.dims) == 4 and 'lev' in list(
ds.dims) and 'time' in list(ds.dims)):
# full dim dataset
ds = ds.transpose(*dim_formats[format].get('transpose', []))
elif len(ds.dims) == 4:
# single time
ds = ds.transpose(*dim_formats[format].get('transpose', [])[1:])
elif len(ds.dims) == 3:
# single level / time
ds = ds.transpose(*dim_formats[format].get('transpose', [])[2:])
ds = ds.transpose(*[x for x in dim_formats[format].get('transpose', []) if x in list(ds.dims)])
return ds


Expand Down

0 comments on commit 5523c97

Please sign in to comment.