You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker构建过程中运行HydroMT水文插件执行Wflow模型时遇到问题

Docker构建过程中运行HydroMT水文插件执行Wflow模型时遇到问题

我现在想把自己的Flask应用打包成Docker容器,不过这个应用里还集成了一个开源水文模型Wflow,另外还要用到Hydromt-Wflow插件——这个插件主要是帮我简化Wflow的文件配置流程,还能生成模型所需的TOML输入文件。其中Wflow是通过Julia命令运行的,但Hydromt插件是基于Python的,运行它需要两个配置文件:wflow_build.ini和data_catalog.yml。

在Flask中运行Hydromt的代码实现

我在Flask里是这样调用Hydromt的:

command = (
    f"hydromt build wflow {self.hydromt_output_path}/ "
    f"-r \"{{'subbasin': {self.subbasin_point}, 'strord': 7, 'bounds': {bounds_float}}}\" "
    f"-i {self.request_path}/wflow_build.ini "
    f"-d {data_catalog_path} -vv"
)
subprocess.run(command, shell=True, capture_output=True)

wflow_build.ini配置文件内容

[global]
data_libs = []            # add optional paths to data yml files

[setup_config]
starttime = 2022-01-02T00:00:00
endtime = 2022-01-30T00:00:00
timestepsecs = 86400
input.path_forcing = inmaps.nc

[setup_basemaps]
hydrography_fn = merit_hydro_1k     # source hydrography data {merit_hydro, merit_hydro_1k}
basin_index_fn = merit_hydro_index      # source of basin index corresponding to hydrography_fn
upscale_method = ihu            # upscaling method for flow direction data, by default 'ihu'

[setup_rivers]
hydrography_fn = merit_hydro_1k      # source hydrography data, should correspond to hydrography_fn in setup_basemaps
river_geom_fn = rivers_lin2019_v1  # river source data with river width and bankfull discharge
river_upa = 30               # minimum upstream area threshold for the river map [km2]
rivdph_method = powlaw           # method to estimate depth {'powlaw', 'manning', 'gvf'}
min_rivdph = 1                # minimum river depth [m]
min_rivwth = 30               # minimum river width [m]
slope_len = 2000             # length over which tp calculate river slope [m]
smooth_len = 5000             # length over which to smooth river depth and river width [m]

[setup_reservoirs]
reservoirs_fn = hydro_reservoirs  # source for reservoirs based on GRAND: {hydro_reservoirs}
min_area = 0           # minimum lake area to consider [km2]
priority_jrc = True          # if True then JRC data from hydroengine is used to calculate some reservoir attributes instead of the GRanD and HydroLAKES db.

[setup_lakes]
lakes_fn = hydro_lakes   # source for lakes based on hydroLAKES: {hydro_lakes}; None to skip
min_area = 0          # minimum reservoir area to consider [km2]

[setup_glaciers]
glaciers_fn = rgi           # source for glaciers based on Randolph Glacier Inventory {rgi}; None to skip
min_area = 1.0           # minimum glacier area to consider [km2]

[setup_riverwidth]
precip_fn = chelsa        # source for precip climatology used to estimate discharge: {chelsa}
climate_fn = koppen_geiger # source for climate classification used to estimate discharge: {koppen_geiger}
predictor = discharge     # predictor used in power-law w=a*predictor^b {'discharge'; 'uparea', other staticmaps}; a and b can also be set here.
fill = False         # if False all river width values are set based on predictor, if True only data gaps and lakes/reservoirs in observed width are filled (works only with MERIT hydro)
min_wth = 1             # global minimum width

[setup_lulcmaps]
lulc_fn = globcover     # source for lulc maps: {globcover, vito, corine}

[setup_soilmaps]
soil_fn = soilgrids     # source for soilmaps: {soilgrids}
ptf_ksatver = brakensiek    # pedotransfer function to calculate hydraulic conductivity: {brakensiek, cosby}

[setup_gauges]
gauges_fn = grdc          # if not None add gaugemap. Either a path or known gauges_fn: {grdc}
snap_to_river = True          # if True snaps gauges from source to river
derive_subcatch = False         # if True derive subcatch map based on gauges.

[setup_precip_forcing]
precip_fn = era5          # source for precipitation.
precip_clim_fn = None          # source for high resolution climatology to correct precipitation.

[setup_temp_pet_forcing]
temp_pet_fn = era5          # source for temperature and potential evapotranspiration.
press_correction = True          # if True temperature is corrected with elevation lapse rate.
temp_correction = False          # if True pressure is corrected with elevation lapse rate.
dem_forcing_fn = era5_orography # source of elevation grid corresponding to temp_pet_fn. Used for lapse rate correction.
pet_method = debruin       # method to compute PET: {debruin, makkink}
skip_pet = False         # if True, only temperature is prepared.

[setup_constant_pars]
ksathorfrac = 25
cfmax = 3.75653
cf_soil = 0.038
eoverr = 0.05
infiltcappath = 5
infiltcapsoil = 600
maxleakage = 0
rootdistpar = -500
tt = 0
tti = 2
ttm = 0
whc = 0.1
g_cfmax = 5.3
g_sifrac = 0.002
g_tt = 1.3

data_catalog.yml配置文件内容

chelsa:
  crs: 4326
  data_type: RasterDataset
  driver: raster
  meta:
    category: meteo
    paper_doi: 10.1038/sdata.2017.122
    paper_ref: Karger et al. (2017)
    source_license: CC BY 4.0
    source_url: http://chelsa-climate.org/downloads/
    source_version: 1.2
  path: chelsa.tif
chirps_global:
  crs: 4326
  data_type: RasterDataset
  driver: netcdf
  meta:
    category: meteo
    paper_doi: 10.3133/ds832
    paper_ref: Funk et al (2014)
    source_license: CC
    source_url: https://www.chc.ucsb.edu/data/chirps
    source_version: v2.0
  path: chirps_global.nc
  unit_add:
    time: 86400
corine:
  data_type: RasterDataset
  driver: raster
  meta:
    category: landuse & landcover
    source_author: European Environment Agency
    source_license: https://land.copernicus.eu/pan-european/corine-land-cover/clc2018?tab=metadata
    source_url: https://land.copernicus.eu/pan-european/corine-land-cover/clc2018
    source_version: v.2020_20u1
  path: corine.tif
dtu10mdt:
  crs: 4326
  data_type: RasterDataset
  driver: raster
  meta:
    category: topography
    paper_doi: 10.1029/2008JC005179
    paper_ref: Andersen and Knudsen (2009)
    source_url: https://www.space.dtu.dk/english/research/scientific_data_and_models/global_mean_dynamic_topography
    source_version: 2010
    unit: m+EGM2008
  path: dtu10mdt.tif
dtu10mdt_egm96:
  crs: 4326
  data_type: RasterDataset
  driver: raster
  meta:
    category: topography
    paper_doi: 10.1029/2008JC005179
    paper_ref: Andersen and Knudsen (2009)
    source_url: https://www.space.dtu.dk/english/research/scientific_data_and_models/global_mean_dynamic_topography
    source_version: 2010
    unit: m+EGM96
  path: dtu10mdt_egm96.tif
eobs:
  crs: 4326
  data_type: RasterDataset
  driver: netcdf
  meta:
    category: meteo
    paper_doi: 10.1029/2017JD028200
    paper_ref: Cornes et al (2018)
    source_license: https://surfobs.climate.copernicus.eu/dataaccess/access_eobs.php#datafiles
    source_url: https://surfobs.climate.copernicus.eu/dataaccess/access_eobs.php#datafiles
    source_version: 22.0e
  path: eobs.nc
  unit_add:
    time: 86400
eobs_orography:
  crs: 4326
  data_type: RasterDataset
  driver: netcdf
  meta:
    category: meteo
    paper_doi: 10.1029/2017JD028200
    paper_ref: Cornes et al (2018)
    source_license: https://surfobs.climate.copernicus.eu/dataaccess/access_eobs.php#datafiles
    source_url: https://surfobs.climate.copernicus.eu/dataaccess/access_eobs.php#datafiles
    source_version: 22.0e
  path: eobs_orography.nc
era5:
  crs: 4326
  data_type: RasterDataset
  driver: netcdf
  meta:
    category: meteo
    history: Extracted from Copernicus Climate Data Store; resampled by Deltares to
      daily frequency
    paper_doi: 10.1002/qj.3803
    paper_ref: Hersbach et al. (2019)
    source_license: https://cds.climate.copernicus.eu/cdsapp/#!/terms/licence-to-use-copernicus-products
    source_url: https://doi.org/10.24381/cds.bd0915c6
    source_version: ERA5 daily data on pressure levels
  path: era5.nc
  unit_add:
    temp: -273.15
    temp_max: -273.15
    temp_min: -273.15
    time: 86400
  unit_mult:
    kout: 0.000277778
    precip: 1000
    press_msl: 0.01

future_data:
  crs: 4326
  data_type: RasterDataset
  driver: netcdf
  meta:
    category: meteo
    history: Extracted from Copernicus Climate Data Store; resampled by Deltares to
      daily frequency
    paper_doi: 10.1002/qj.3803
    paper_ref: Hersbach et al. (2019)
    source_license: https://cds.climate.copernicus.eu/cdsapp/#!/terms/licence-to-use-copernicus-products
    source_url: https://doi.org/10.24381/cds.bd0915c6
    source_version: ERA5 daily data on pressure levels
  path: future_data.nc
  unit_add:
    time: 86400
  unit_mult:
    kout: 0.000277778
    press_msl: 0.01

future_ppt:
  crs: 4326
  data_type: RasterDataset
  driver: netcdf
  meta:
    category: meteo
    history: Extracted from Copernicus Climate Data Store; resampled by Deltares to
      daily frequency
    paper_doi: 10.1002/qj.3803
    paper_ref: Hersbach et al. (2019)
    source_license: https://cds.climate.copernicus.eu/cdsapp/#!/terms/licence-to-use-copernicus-products
    source_url: https://doi.org/10.24381/cds.bd0915c6
    source_version: ERA5 daily data on pressure levels
  path: future_ppt.nc
  unit_add:
    time: 86400

era5_land:
  crs: 4326
  data_type: RasterDataset
  driver: netcdf
  meta:
    category: meteo
    history: Extracted from Copernicus Climate Data Store; resampled by Deltares to
      daily frequency
    paper_doi: 10.1002/qj.3803
    paper_ref: Hersbach et al. (2019)
    source_license: https://cds.climate.copernicus.eu/cdsapp/#!/terms/licence-to-use-copernicus-products
    source_url: https://doi.org/10.24381/cds.bd0915c6
    source_version: ERA5 daily data on pressure levels
  path: era5_land.nc

备注:内容来源于stack exchange,提问作者Basit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 20:03:01