Add support for NetCDF files following the UGRID convention
Closed this issue · 6 comments
Describe the New Feature
This new feature request was originally combined with #1954 but has been split off into this separate issue.
MET needs to be enhanced to supported gridded NetCDF files following the UGRID convention (Conventions = "UGRID"
):
ugrid-conventions.github.io/ugrid-conventions
Recommend doing development using both LFRic and MPAS NetCDF files side-by-side. This will require a new vx_data2d_ugrid library to extract data from these NetCDF files. In addition, it'll require a new unstructured grid class in the vx_grid library.
The UGRID grid class will need to link to the source NetCDF file since it must be queried while working with it. One key piece of functionality will be instantiating a kdtree for that UGRID. Recommend leveraging an external C++ library rather than coding that up ourselves.
Some pieces of functionality we'll need to add are:
- Enhance Point-Stat to verify points natively on the UGRID.
- Consider parallelizing the loop for interpolating model data to point locations to make it as fast as possible.
- Support nearest neighbor as well as the min/max/uw_mean/dw_mean of the nearest N points.
- Enhance Grid-Stat and Series-Analysis to compare UGRID to UGRID on the same grid.
Future considerations include:
- Using lookup tables to make the interpolation to point locations more efficient rather than calling kdtrees.
Acceptance Testing
List input data types and sources.
Describe tests required for new functionality.
Time Estimate
Weeks
Sub-Issues
Consider breaking the new feature down into sub-issues.
- Add a checkbox for each sub-issue here.
Relevant Deadlines
List relevant project deadlines here or state NONE.
Funding Source
Define the source of funding and account keys here or state NONE.
2799991 Met Office METplus Support & 7705991 MPAS participation
Define the Metadata
Assignee
- Select engineer(s) or no engineer required: @JohnHalleyGotway
- Select scientist(s) or no scientist required: @willmayfield
Labels
- Select component(s)
- Select priority
- Select requestor(s)
Projects and Milestone
- Select Repository and/or Organization level Project(s) or add alert: NEED PROJECT ASSIGNMENT label
- Select Milestone as the next official version or Future Versions
Define Related Issue(s)
Consider the impact to the other METplus components.
- METplus, MET, METdataio, METviewer, METexpress, METcalcpy, METplotpy
- May want separate issues for plotting UGRID data but I don't think these changes have any direct impacts on other repos.
New Feature Checklist
See the METplus Workflow for details.
- Complete the issue definition above, including the Time Estimate and Funding source.
- Fork this repository or create a branch of develop.
Branch name:feature_<Issue Number>_<Description>
- Complete the development and test your changes.
- Add/update log messages for easier debugging.
- Add/update unit tests.
- Add/update documentation.
- Push local changes to GitHub.
- Submit a pull request to merge into develop.
Pull request:feature <Issue Number> <Description>
- Define the pull request metadata, as permissions allow.
Select: Reviewer(s) and Linked issues
Select: Repository level development cycle Project for the next official release
Select: Milestone as the next official version - Iterate until the reviewer(s) accept and merge your changes.
- Delete your fork or branch.
- Close this issue.
Some MPAS grid file examples and information are here: https://mpas-dev.github.io/atmosphere/atmosphere_meshes.html
UGridConfig_default is introduced. The dimension names and variable names should be added to support more unstructured grid files.
I used "face" instead of "cell" from UGRID Conventions (v1.0).
This is for MPAS (first name) and LFric (second name). node and edges are for the future implemenations:
ugrid_metadata_map = [
{ key = "dim_face"; val = "nCells,nMesh2d_face"; },
{ key = "dim_node"; val = "nVertices,nMesh2d_node"; },
{ key = "dim_edge"; val = "nEdges,nMesh2d_edge"; },
{ key = "dim_time"; val = "Time,time_counter"; },
{ key = "dim_vert"; val = "nVertLevels"; },
{ key = "cell_id"; val = "indexToCellID,"; },
{ key = "lat_face"; val = "latCell,Mesh2d_face_y"; },
{ key = "lon_face"; val = "lonCell,Mesh2d_face_x"; },
{ key = "vert_face"; val = "zCell"; },
{ key = "lat_edge"; val = "latEdge,Mesh2d_edge_y"; },
{ key = "lon_edge"; val = "lonEdge,Mesh2d_edge_x"; },
{ key = "lat_node"; val = "latVertex,Mesh2d_node_y"; },
{ key = "lon_node"; val = "lonVertex,Mesh2d_node_x"; },
{ key = "time"; val = "xtime,time_centered"; }
];
The default ugrid_metadata_map from UGridConfig_default will be overridden by the "UGridConfig_user" at the current working directory. This will be overridden by the configuration file, "ugrid_map_config".
ugrid_user_map_config = "/d1/personal/hsoh/data/MET-2231/ugrid_metadata_map.config";
How to handle vertical levels for MPAS?
MET does not allow a negative lower bound. Without handling vertical levels, FCST_LEV columns are empty (NA).
double zCell(nCells) ;
zCell:units = "m" ;
zCell:long_name = "Cartesian z-coordinate of cells" ;
zCell = 2849300.22215193, 2849300.23592602, 6371229, -2849300.22215219,
-2849300.23592647, -2849300.18911285, 2849300.22944048,
-2849300.22944073, -6371229, 2849300.2026535, -2849300.20265379,
2849300.18911245, 3349553.28907785, -0.00621810533595908,
0.0103280223263834, 3349553.3173988, 5419691.09266147,
0.0245392207624739, 0.0289636509723273, 3349553.32185776,
As discussed on 9/21/23, the ugrid_user_map_config
setting may get confusing if the metadata for all supported models is included in the same file. Consider providing separate config files for each model type, e.g. MPAS, LFriC, Netpune, and so on.
Working on the feature_2231_unstructured_grid
branch to resolve linker issues we discovered when compiling inside the container. I'll update this comment with details about this process.
First, launch a dtcenter/met-base-unit-test:v3.1
container with the feature branch source code volume-mounted in. Run a script to compile the code within the container.
docker run -it --volume `pwd`/MET-feature_2231_unstructured_grid:/met/MET-feature_2231_unstructured_grid dtcenter/met-base-unit-test:v3.1 /bin/bash
export MET_GIT_NAME=feature_2231_unstructured_grid
internal/scripts/docker/build_met_docker.sh
I note that the updated version of autoconf in the container produces changes to the autoconf output (Makefile.in, configure, and so on). It's a whopping total of 151 modified files. I compared those to the contents of Julie's feature_2611_oneapi
branch.
-
All of the
Makefile.in
files,aclocal.m4
,compile
,decomp
,install-sh
,missing
, andylwrap
exactly match. -
There are small diffs in
config.guess
which look to be bugs/typos fixed in this 2.71 autoconf instance. My version has a newer date (2022-01-09) than the Julie's version (2021-06-03).- Committed the files modified by upgrading from using autoconf version 2.69 to 2.71.
-
The output files generated by flex and bison are also updated since the Bison version is updated from 3.3.2 to 3.8.2.
-
The compilation fails for pb2nc:
calcape.o: file not recognized: file format not recognized
This is not actually an issue. It was due to the fact that calcape.o
already existed and was compiled by the Fortran compiler on my Mac rather than the one in the container. Those versions are incompatible. Running make clean install
deletes the .o
files, forcing them to be recreated, which fixes the problem.
- Update
build_met_docker.sh
by adding--enable-ugrid
when running theconfigure
script, and rerun thebuild_met_docker.sh
script. That errors out as expected. - Modified
configure.ac
to for GRIB2, Python, and UGRID to differentiate between the internal MET libraries from the associated external dependencies.- Change from
GRIB2_LIBS
toGRIB2_MET_LIBS
andGRIB2_DEP_LIBS
. - Change from
PYTHON_LIBS
toPYTHON_MET_LIBS
andPYTHON_DEP_LIBS
. - Change from
UGRID_LIBS
toUGRID_MET_LIBS
andUGRID_DEP_LIBS
.
- Change from
- Run the following to replaces all instances of the former with references to the latter:
for file in `find ./ -name "Makefile.am"`; do
cat $file | \
sed 's/$(PYTHON_LIBS)/$(PYTHON_MET_LIBS) $(PYTHON_DEP_LIBS)/g' | \
sed 's/$(GRIB2_LIBS)/$(GRIB2_MET_LIBS) $(GRIB2_DEP_LIBS)/g' | \
sed 's/$(UGRID_LIBS)/$(UGRID_MET_LIBS) $(UGRID_DEP_LIBS)/g' > new
mv new $file
done
- Re-run
build_met_docker.sh
to get updated autoconf output files and commit those changes. - Manually modify 45
Makefile.am
files that reference PYTHON_MET_LIBS, GRIB2_MET_LIBS, or UGRID_MET_LIBS to link the*_MET_LIBS
entries with the other "data2d" libs after-lvx_data2d_factory
and the*_DEP_LIBS
entries at the end, just after-lvx_log
. - Re-run
build_met_docker.sh
to see if these changes solve the compilation errors. - It all finally compiled (YEAH), and I committed/pushed the Makefile changes that work.