Skip to content

Commit

Permalink
Minor changes: 1) added netcdf-output option to delft3b.ini; 2) const…
Browse files Browse the repository at this point in the history
…ant boundary is now written as a constant boundary (used to be an (artificial) time series; 3) implemented checks for integer input (as opposed to float); 4) added quotes to the DIMR-command in run.bat.
  • Loading branch information
RuudHurkmans committed Nov 6, 2020
1 parent d200b52 commit e84577c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
2 changes: 1 addition & 1 deletion delft3dfmpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

__author__ = """Guus Rongen"""
__email__ = '[email protected]'
__version__ = '1.0.0'
__version__ = '1.0.1'

from delft3dfmpy.core.dfm import DFlowFMModel
from delft3dfmpy.core.drr import DFlowRRModel
Expand Down
42 changes: 28 additions & 14 deletions delft3dfmpy/converters/hydamo_to_dflowrr.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,22 @@ def generate_unpaved(catchments, landuse, surface_level, soiltype, surface_stor
mean_elev = zonal_stats(catchments, rast, affine=affine, stats="median",all_touched=all_touched)

# optional rasters
if not isinstance(surface_storage, float):
if isinstance(surface_storage, str):
rast,affine = read_raster(surface_storage, static=True)
sstores = zonal_stats(catchments, rast, affine=affine, stats="mean",all_touched=True)
if not isinstance(infiltration_capacity, float):
sstores = zonal_stats(catchments, rast, affine=affine, stats="mean",all_touched=True)
elif isinstance(surface_storage,int):
surface_storage = float(surface_storage)
if isinstance(infiltration_capacity, str):
rast,affine = read_raster(infiltration_capacity, static=True)
infcaps = zonal_stats(catchments, rast, affine=affine, stats="mean",all_touched=True)
if not isinstance(initial_gwd, float):
elif isinstance(infiltration_capacity,int):
infiltration_capacity = float(infiltration_capacity)
if isinstance(initial_gwd, str):
rast,affine = read_raster(initial_gwd, static=True)
ini_gwds = zonal_stats(catchments, rast, affine=affine, stats="mean", all_touched=True)

elif isinstance(initial_gwd,int):
initial_gwd = float(initial_gwd)

# get raster cellsize
px_area = lu_affine[0] * -lu_affine[4]

Expand Down Expand Up @@ -141,26 +147,32 @@ def generate_paved( catchments=None,
sl_rast, sl_affine = read_raster(surface_level, static=True)
mean_elev = zonal_stats(catchments, sl_rast, affine=sl_affine, stats="median",all_touched=all_touched)

if not isinstance( street_storage, float):
if isinstance( street_storage, str):
strs_rast, strs_affine = read_raster(street_storage, static=True)
str_stors = zonal_stats(catchments, strs_rast, affine=strs_affine, stats="mean", all_touched=True)
if not isinstance( sewer_storage, float):
elif isinstance( street_storage, int):
street_storage = float(street_storage)
if isinstance( sewer_storage, str):
sews_rast, sews_affine = read_raster(sewer_storage, static=True)
sew_stors = zonal_stats(catchments, sews_rast, affine=sews_affine, stats="mean", all_touched=True)
if not isinstance(pump_capacity, float):
elif isinstance( sewer_storage, int):
sewer_storage = float(sewer_storage)
if isinstance(pump_capacity, str):
pump_rast, pump_affine = read_raster(pump_capacity, static=True)
pump_caps = zonal_stats(catchments, pump_rast, affine=pump_affine, stats="mean", all_touched=True)

elif isinstance( pump_capacity, int):
pump_capacity = float(pump_capacity)

# get raster cellsize
px_area = lu_affine[0] * -lu_affine[4]
paved_drr = ExtendedDataFrame(required_columns=['code'])
if sewer_areas is not None:
# if the parameters area rasters, do the zonal statistics per sewage area as well.
if not isinstance( street_storage, float):
if isinstance( street_storage, str):
str_stors_sa = zonal_stats(sewer_areas, strs_rast,affine=strs_affine,stats="mean", all_touched=True)
if not isinstance( sewer_storage, float):
if isinstance( sewer_storage, str):
sew_stors_sa = zonal_stats(sewer_areas, sews_rast,affine=sews_affine,stats="mean", all_touched=True)
if not isinstance(pump_capacity, float):
if isinstance(pump_capacity, str):
pump_caps_sa = zonal_stats(sewer_areas, pump_rast,affine=pump_affine,stats="mean", all_touched=True)
mean_sa_elev = zonal_stats(sewer_areas, sl_rast, affine=sl_affine, stats="median",all_touched=True)

Expand Down Expand Up @@ -270,10 +282,12 @@ def generate_greenhouse(catchments, landuse, surface_level, roof_storage, meteo_
rast, affine = read_raster(surface_level, static=True)
mean_elev = zonal_stats(catchments, rast, affine=affine, stats="median", all_touched=all_touched)
# optional rasters
if not isinstance(roof_storage, float):
if isinstance(roof_storage, str):
rast, affine = read_raster(roof_storage, static=True)
roofstors = zonal_stats(catchments, rast, affine=affine, stats="mean", all_touched=True)

elif isinstance(roof_storage, int):
roof_storage = float(roof_storage)

# get raster cellsize
px_area = lu_affine[0] * -lu_affine[4]

Expand Down
49 changes: 31 additions & 18 deletions delft3dfmpy/io/dflowfmwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,35 +316,48 @@ def write_boundary_conditions(self):

# Get time series
if bc['time'] is None:
data = [[0, bc['value']], [999999, bc['value']]]
data = float(bc['value'])
headerType='constant'
else:
data = list(zip(bc['time'], bc['value']))
headerType='timeseries'

else:
dct = {'quantity':f"{bc['bctype']}",'nodeId': bc['nodeid'],'forcingFile':'boundaries.bc'}
self._write_dict(f, dct, 'Boundary')

# Get time series
if bc['time'] is None:
data = [[0, bc['value']], [999999, bc['value']]]
data = float(bc['value'])
headerType='constant'
else:
data = list(zip(bc['time'], bc['value']))
headerType='timeseries'


refd = str(self.dflowfmmodel.mdu_parameters["refdate"])

# and write data to the bc file
with open(os.path.join(self.output_dir, 'boundaries.bc'), 'a') as f:
f.write(f'\n[Forcing]\n'
f'name = {bc["nodeid"]}\n'
f'function = timeseries\n'
f'timeInterpolation = linear\n'
f'quantity = time\n'
f'unit = minutes since {refd[0:4]}-{refd[4:6]}-{refd[6:9]} 00:00:00\n'
f'quantity = {bc["bctype"]}\n'
f'unit = {bc["unit"]}\n'
)
write_fm_file(file=os.path.join(self.output_dir, 'boundaries.bc'), data=data, mode='a')
refd = str(self.dflowfmmodel.mdu_parameters["refdate"])

# and write data to the bc file
with open(os.path.join(self.output_dir, 'boundaries.bc'), 'a') as f:
if headerType=='timeseries':
f.write(f'\n[Forcing]\n'
f'name = {bc["nodeid"]}\n'
f'function = timeseries\n'
f'timeInterpolation = linear\n'
f'quantity = time\n'
f'unit = minutes since {refd[0:4]}-{refd[4:6]}-{refd[6:9]} 00:00:00\n'
f'quantity = {bc["bctype"]}\n'
f'unit = {bc["unit"]}\n'
)
if headerType=='constant':
f.write(f'\n[Forcing]\n'
f'name = {bc["nodeid"]}\n'
f'function = constant\n'
f'quantity = {bc["bctype"]}\n'
f'unit = {bc["unit"]}\n'
f'{data}\n'
)
if headerType=='timeseries':
write_fm_file(file=os.path.join(self.output_dir, 'boundaries.bc'), data=data, mode='a')

def write_initial_conditions(self):

Expand Down Expand Up @@ -592,7 +605,7 @@ def write_dimrfiles(self):
with open(os.path.join(self.output_dir, 'run.bat'),'w') as f:
f.write('@ echo off\n')
f.write('set OMP_NUM_THREADS=2\n')
f.write('call '+self.run_dimrpad+'\n')
f.write('call \"'+self.run_dimrpad+'\"\n')
f.write('pause\n')

# coupling XML
Expand Down
2 changes: 1 addition & 1 deletion delft3dfmpy/io/dflowrrwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def write_coupling(self):
with open(os.path.join(self.output_dir, '../run.bat'),'w') as f:
f.write('@ echo off\n')
f.write('set OMP_NUM_THREADS=2\n')
f.write('call '+self.run_dimrpad+'\n')
f.write('call \"'+self.run_dimrpad+'\"\n')
f.write('pause\n')

# coupling XML
Expand Down
2 changes: 1 addition & 1 deletion delft3dfmpy/io/resources/RRmodel/DELFT_3B.INI
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ UnpavedSCurveAlfaOption=1
UnpavedSCurveAreas=100
UnpavedPercolationLikeSobek213=-1
VolumeCheckFactorToCF=100000

GenerateNetCdfOutput=0

[TimeSettings]
EvaporationFromHrs=7
Expand Down

0 comments on commit e84577c

Please sign in to comment.