Skip to content

Commit

Permalink
removed dfmt.remove_periodic_cells() and updated CMCC example script
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Sep 9, 2023
1 parent 334d9eb commit 7e89267
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
18 changes: 0 additions & 18 deletions dfm_tools/xugrid_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,6 @@ def remove_ghostcells(uds): #TODO: remove ghostcells from output or align values
return uds


def remove_periodic_cells(uds): #TODO: implement proper fix: https://github.com/Deltares/xugrid/issues/63
"""
For global models with grids that go "around the back". Temporary fix to drop all faces that are larger than grid_extent/2 (eg 360/2=180 degrees in case of GTSM)
"""
face_node_x = uds.grid.face_node_coordinates[:,:,0]
grid_extent = uds.grid.bounds[2] - uds.grid.bounds[0]
face_node_maxdx = np.nanmax(face_node_x,axis=1) - np.nanmin(face_node_x,axis=1)
bool_face = face_node_maxdx < grid_extent/2
if bool_face.all(): #early return for when no cells have to be removed (might increase performance)
return uds
print(f'>> removing {(~bool_face).sum()} periodic cells from dataset: ',end='')
dtstart = dt.datetime.now()
uds = uds.sel({uds.grid.face_dimension:bool_face})
print(f'{(dt.datetime.now()-dtstart).total_seconds():.2f} sec')
return uds


def remove_unassociated_edges(ds: xr.Dataset) -> xr.Dataset:
"""
Removes edges that are not associated to any of the faces, usecase in https://github.com/Deltares/xugrid/issues/68
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
file_nc = f'p:\\archivedprojects\\11206304-futuremares-rawdata-preps\\data\\CMIP6_BC\\CMCC-ESM2\\{varn}_Omon_CMCC-ESM2_ssp126_r1i1p1f1_gn_201501-203412.nc'

uds = dfmt.open_dataset_curvilinear(file_nc, convert_360to180=True) #TODO: check TODO in this function for improvements #TODO: plot_coastlines gives wrong result when axis from 0-360
uds = dfmt.remove_periodic_cells(uds)
uds = uds.ugrid.to_nonperiodic(xmax=180)
uds = uds.ugrid.sel(x=slice(-15,30), y=slice(30,70)) #slice to europe (arbitrary, but to visualy compare grids)

fig, ax = plt.subplots()
Expand Down

0 comments on commit 7e89267

Please sign in to comment.