Deltares / hydromt

HydroMT: Automated and reproducible model building and analysis
https://deltares.github.io/hydromt/
MIT License
74 stars 30 forks source link

Support exporting models to standard GIS files #518

Open hboisgon opened 1 year ago

hboisgon commented 1 year ago

Kind of request

Adding new functionality

Enhancement Description

I think it would be useful if you could read a model with HydroMT and export/write it (or parts) into standard GIS files (geojson, netcdf, csv...) rather than just the model specific fileformat.

For example the plugin functions can be used to read and the generic functions from core to write (together with a data catalog?).

Use case

Especially for model results but could also be to use data from one model (eg wflow, Delft3D) to build/update another model: eg results from wflow in Delft3d or river profile cross-sections from Delft3D to wflow or SFINCS etc.

Can be useful for model connections as well.

Additional Context

Not sure how to go for this, if it should be a specific CLI function in core or just each plugin should implement a different write_gis method or similar to list the components to write with the generic core methods rather than the plugin?

DirkEilander commented 1 year ago

Suggested approach: create an export_model_data method to write selected model component to default "GIS compliant" files (e.g., gdal compliant netcdf, geotiff, geojson) with a datacatalog. Note that this method cannot call the write_* methods from the Model class as these are often overwritten by child models such as WflowModel. We can reuse the write_nc method and the content of the write_geoms method. The output datatype can be set by the user.

pseudo code

def export_model_data(
    self,
    components: Dict = {'grid': 'GridDataset', 'forcing': 'GeoDataset'}
    drivers: Dict = {'GridDataset': 'netcdf', ..}
):
  for comp in components:
     write with driver

If different variables of one component are of different types (this is possible for the forcing, states, results) this could be specified with components = {'forcing.variable1': 'GeoDataset', 'forcing.variable2': 'RasterDataset'}

The method could also be exposed via CLI. (this can also be done in a separate issue)