Package: netcdf2vtu
NetCDF2VTUNetcdf2vtu is a Python package including a command line interface (CLI)
to interpolate data from netCDF on VTU files.SetupIdeally, you have created a virtual python environment. If not lookhere.A stable release is available onhttps://pypi.orgso you can install it via$ python3 -m pip install netcdf2vtuTo install the development version, you have to actually install it from a clone of this repo.$ git clone https://gitlab.com/joboog/netcdf2vtu.gitGo into the repo and install the dependencies:$ cd netcdf2vtu
$ pip install -r requirements.txtThen install the package:$ pip install .You can run the tests with:$ pytest .UsageNetcdf2vtu can be imported as a Python module or used from the command
line.As imported moduleA brief example of how to map data from the NETCDF4 filedata/ex1_3.ncon the destination VTUdata/ogs.vtuusing theMapperclass is
presented below.
Just define the required input data to theMapperclass.from netcdf2vtu.netcdf2vtu import Mapper

# setup ---------------------------------------------------------
nc_path = "data/ex1_3.nc" # path of input netcdf file
vtu_path = "data/ogs.vtu" # path of vtu file
vtu_new_path = "ex3_new.vtu" # path of updated vtu file
data_var_names = ["SWC_L01", "SWC_L02"] # names of the netcdf data \
                                        # variables
map_func_type = 1 # def mapping func type 1: Voronoi, 2:Gaussian,
                  # 3:Shepard
nc_crs = "EPSG:4326"   # coordinate system in netcdf file
vtu_crs = "EPSG:5684"   # coordinate systetm in vtu file
nullvalue = -9999Then create a mapper object.# for convenience, all the above can be within two statements
mapper = Mapper(nc_path,
                vtu_path,
                data_var_names,
                map_func_type,
                nc_crs,
                vtu_crs,
                nullvalue)And start the interpolation:mapper.map(out_path = vtu_new_path,
           lat_name = "lat",
           lon_name = "lon",
           time_name = "time")The outputted fileex3_new.vtuis a copy of the VTU filedata/ogs.vtuincluding the interpolated data.Command line interfaceFrom the command line you can do the same as above with:$ netcdf2vtu -o ex3_new.vtu --time time data/ex1_3.nc data/ogs.vtu EPSG:4326 EPSG:5684 SWC_L01 SWC_L02Note that the arguments to define the name of the output VTU file, themap_func_typeand names for coordinates have default values and may not need to be explicitly set in the call as shown above.
Use the help function to see the specifics of thenetcdf2vtucommand:$ netcdf2vtu -h

usage: netcdf2vtu [-h] [-o OUT_VTU] [-m MAP_TYPE] [-n NULLVALUE] [--lat LAT] [--lon LON] [--time TIME] in_nc in_vtu nc_crs vtu_crs var_names [var_names ...]

Interpolates data from netCDF4 files to VTU files.

positional arguments:
  in_nc                 Path to the input netCDF file.
  in_vtu                Path to the input VTU file.
  nc_crs                CRS of input netcdf file
  vtu_crs               CRS of input vtu file.
  var_names             Names of the data variables in the input netcdf file.

optional arguments:
  -h, --help            show this help message and exit
  -o OUT_VTU, --out_vtu OUT_VTU
                        Path to the output VTU file; default is "out.vtu".
  -m MAP_TYPE, --map_type MAP_TYPE
                        Type of interpolation function; default is 1.
  -n NULLVALUE, --nullvalue NULLVALUE
                        Nullvalue; default is -9999.
  --lat LAT             Name of the latitude variable; default is "lat".
  --lon LON             Name of the longitude variable; default is "lon".
  --time TIME           Name of the time variable if present.ContributionIf there are any problems please raise an issuehere.Please look atCONTRIBUTING.md.