diff --git a/dfm_tools/xugrid_helpers.py b/dfm_tools/xugrid_helpers.py index d40ee7c5e..898912e32 100644 --- a/dfm_tools/xugrid_helpers.py +++ b/dfm_tools/xugrid_helpers.py @@ -70,24 +70,6 @@ def remove_ghostcells(uds, fname): #TODO: remove ghostcells from output or align 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 @@ -249,7 +231,7 @@ def open_dataset_curvilinear(file_nc, ds = xr.open_mfdataset(file_nc, **kwargs) - print('>> getting vertices from ds: ',end='') #long (but does not reflect in + print('>> getting vertices from ds: ',end='') dtstart = dt.datetime.now() vertices_longitude = ds[varn_vert_lon].to_numpy() vertices_longitude = vertices_longitude.reshape(-1,vertices_longitude.shape[-1]) @@ -259,7 +241,7 @@ def open_dataset_curvilinear(file_nc, #convert from 0to360 to -180 to 180 if convert_360to180: - vertices_longitude = (vertices_longitude+180)%360 - 180 #TODO: check if periodic cell filter still works properly after doing this + vertices_longitude = (vertices_longitude+180)%360 - 180 #TODO: check if uds.ugrid.to_nonperiodic() still works properly after doing this # face_xy = np.stack([longitude,latitude],axis=-1) # face_coords_x, face_coords_y = face_xy.T diff --git a/docs/whats-new.md b/docs/whats-new.md index 75a4d012d..64ecd7660 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -1,6 +1,7 @@ ## UNRELEASED ### Feat +- xugrid feature `uds.ugrid.to_nonperiodic()` deprecates `dfmt.remove_periodic_cells()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#503](https://github.com/Deltares/dfm_tools/issues/503) - support for initial fields for variables other than salinity/temperature with `dfmt.cmems_nc_to_ini()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#619](https://github.com/Deltares/dfm_tools/pull/619) ### Fix @@ -51,21 +52,18 @@ ## 0.13.0 (2023-07-12) ### Feat - - exposed opendap testdata with `dfmt.data.fm_grevelingen_map()` (and others) by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#439](https://github.com/Deltares/dfm_tools/pull/439) - made coastlines portable with ` dfmt.data.gshhs_coastlines_shp()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#443](https://github.com/Deltares/dfm_tools/pull/443) - improved CMEMS and ERA5 authentication via [getpass](https://docs.python.org/3/library/getpass.html) by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#449](https://github.com/Deltares/dfm_tools/pull/449) - aligned mesh deletion with `dfmt.meshkernel_delete_withgdf()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#455](https://github.com/Deltares/dfm_tools/pull/455) ### Fix - - added `dfmt.uds_to_1based_ds()` to ensure FM-compatible network file (1-based face_node_connectivity) by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#456](https://github.com/Deltares/dfm_tools/pull/456) ## 0.12.0 (2023-07-07) ### Feat - - added support for curvilinear datasets like CMCC and WAQUA with `open_dataset_curvilinear()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#397](https://github.com/Deltares/dfm_tools/pull/397) - added support for curvilinear Delft3D4 datasets with `open_dataset_delft3d4()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#398](https://github.com/Deltares/dfm_tools/pull/398) - retrieving [GSHHS landboundary](https://www.ngdc.noaa.gov/mgg/shorelines/) with `get_coastlines_gdb()` and cartopy-alternative `plot_coastlines()` with this dataset by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#342](https://github.com/Deltares/dfm_tools/pull/342) @@ -73,7 +71,6 @@ - added geodataframe support from polyfile with `PolyFile_to_geodataframe_points()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#387](https://github.com/Deltares/dfm_tools/pull/387) ### Fix - - proper selection for either CMEMS reanalysis/forecast product in `download_CMEMS()` by [@JulienGroenenboom](https://github.com/JulienGroenenboom) in [#308](https://github.com/Deltares/dfm_tools/pull/388) - slightly extend spatial and time domain when downloading ERA5 and CMEMS data by [@JulienGroenenboom](https://github.com/JulienGroenenboom) in [#390](https://github.com/Deltares/dfm_tools/pull/390) - renamed uxuy to uxuyadvectionvelocitybnd in `open_dataset_extra()` and related example script by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#366](https://github.com/Deltares/dfm_tools/pull/366) @@ -86,7 +83,6 @@ Replaced large parts of the code with [HYDROLIB-core](https://github.com/Deltares/hydrolib-core), [xugrid](https://github.com/Deltares/xugrid) and [xarray](https://github.com/pydata/xarray). This means a non-backwards compatible change in the API but improved experience. xugrid gives loads of new features like coordinate conversion, shapefile export, cropping a unstructured dataset, regridding, rasterizing. ### Feat - - improved support for ugrid datasets (D-FlowFM, D-HYDRO) with `open_partitioned_dataset()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in several PRs, this deprecates `get_ncmodeldata()`, `get_netdata()`, `plot_netmapdata()` and `get_ugrid_verts()` - improved rasterization of ugrid datasets with `rasterize_ugrid()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#314](https://github.com/Deltares/dfm_tools/pull/314), this deprecates `scatter_to_regulargrid()` - depth slicing of ugrid datasets with `get_Dataset_atdepths()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#261](https://github.com/Deltares/dfm_tools/pull/261) @@ -105,5 +101,4 @@ Replaced large parts of the code with [HYDROLIB-core](https://github.com/Deltare - added meshkernelpy helper functions like `make_basegrid()`, `refine_basegrid()` and `meshkernel_to_UgridDataset()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#329](https://github.com/Deltares/dfm_tools/pull/329) ### Fix - - made bedlevel variable optional in `get_Dataset_atdepths()`, if not explicitly needing it by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#241](https://github.com/Deltares/dfm_tools/pull/241) diff --git a/tests/examples_workinprogress/workinprogress_CMCC_plotting.py b/tests/examples_workinprogress/workinprogress_CMCC_plotting.py index c5d678935..1358ee967 100644 --- a/tests/examples_workinprogress/workinprogress_CMCC_plotting.py +++ b/tests/examples_workinprogress/workinprogress_CMCC_plotting.py @@ -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()