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

Consider adding preprocess_shyfem #745

Open
veenstrajelmer opened this issue Jan 24, 2024 · 0 comments
Open

Consider adding preprocess_shyfem #745

veenstrajelmer opened this issue Jan 24, 2024 · 0 comments

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Jan 24, 2024

import xugrid as xu

file_nc = r"p:\11208420-habitat-kernel-dev\development_cases\Richard_EUNIS_ecotopes_20230403\SHYFEM_model_converter\shy.nc"

def preprocess_shyfem_test(ds):
    # convert topology_dimension attribute: str to int
    # topodim = int(ds[mesh_varn].attrs["topology_dimension"])
    topodim = int(ds["topology"].attrs["dimensionality"])
    mesh_attrs = {"cf_role": "mesh_topology",
                  "node_coordinates": "longitude latitude",
                  "topology_dimension":topodim,
                  "face_node_connectivity":"element_index"}
    ds["topology"] = ds["topology"].assign_attrs(mesh_attrs)
    # add necessary attributes for face_node_connectivity
    fnc_attrs = {"_FillValue":-1, "start_index":1}
    ds["element_index"] = ds["element_index"].assign_attrs(fnc_attrs)
    # set x/y coords, is not necessary but nice to avoid them being data_vars
    ds = ds.set_coords(["longitude","latitude"])
    # set mesh attr in all data_vars, optional with a single mesh
    datavar_attrs = {"mesh":"topology"}
    for varn in ds.data_vars:
        ds[varn] = ds[varn].assign_attrs(datavar_attrs)
    return ds

uds = xu.open_mfdataset(file_nc, preprocess=preprocess_shyfem_test)
uds.u_velocity.isel(time=-1, level=0).ugrid.plot(robust=True)

Maybe this is not necessary if the attrs are added to shyfem output: SHYFEM-model/shyfem#57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant