In [1]:
import python_subgrid.wrapper
import python_subgrid.plotting
import logging
import os.path
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
%matplotlib inline

In [2]:
subgrid = python_subgrid.wrapper.SubgridWrapper(mdu=os.path.expanduser('/Users/baart_f/models/duifp/Duifp_dem_0m.mdu'))

In [3]:
python_subgrid.wrapper.logger.setLevel(logging.WARNING)
subgrid.start()


WARNING:python_subgrid.wrapper:File admin/gridDuifp_dem_0m.grd  does not exist. Grid will be generated.
WARNING:python_subgrid.wrapper:Could not open grid admin file 'admin/gridDuifp_dem_0m.grd' for writing; iostat=              2
WARNING:python_subgrid.wrapper:Progress stopped but no current progress message
WARNING:python_subgrid.wrapper:Snapping branch 261 to last point, remaining chainage:   17.190
ERROR:python_subgrid.wrapper:Structure number 31 and 118 are placed on the same link, structure 118 is discarded.
ERROR:python_subgrid.wrapper:Structure number 17 and 119 are placed on the same link, structure 119 is discarded.
ERROR:python_subgrid.wrapper:Structure number 19 and 130 are placed on the same link, structure 130 is discarded.
ERROR:python_subgrid.wrapper:Structure number 1 and 148 are placed on the same link, structure 148 is discarded.
ERROR:python_subgrid.wrapper:Structure number 21 and 186 are placed on the same link, structure 186 is discarded.
ERROR:python_subgrid.wrapper:Structure number 2 and 205 are placed on the same link, structure 205 is discarded.

In [4]:
subgrid.update(-1)


WARNING:python_subgrid.wrapper:File admin/tableDuifp_dem_0m.tbl  does not exist. Tables will be generated.
WARNING:python_subgrid.wrapper:No infilt for nods 10000 10180 10434 10435 11141 11142 11584 11585 11758 12797 12798 12799 12800 12801 12802 12803 12804 12805 12873 12874 12875 12876 13258 13259 13260 13261 13262 13292 13293 13294 13295 13296 13297 13306 13307 13308 13309 13310 13311 13376 13379 13387
Out[4]:
0

In [5]:
crop = subgrid.get_nd('croptype')
soil = subgrid.get_nd('soiltype')
infiltration = subgrid.get_nd('infiltrationrate')
interception = subgrid.get_nd('maxinterception')
si = subgrid.get_nd('si')
dps = subgrid.get_nd('dps')

grid = {var: subgrid.get_nd(var, sliced=False) for var in {'nodn', 'nodm', 'nodk', 'imaxk', 'jmaxk', 'nod_type'}}
grid['nod_type'].shape, grid['nodm'].shape, grid['imaxk'].shape
#grid['imaxk'][grid['nodk']-1]
#grid['nod_type']
#grid['imaxk']
quad_grid = python_subgrid.plotting.make_quad_grid(subgrid)

In [6]:
crop = np.ma.masked_outside(crop, 0, 100)
soil = np.ma.masked_outside(soil, 0, 100)
interception = np.ma.masked_outside(interception, -1000000, 1000000)
infiltration = np.ma.masked_outside(infiltration, -1000000, 1000000)



fig, axes = plt.subplots(4,1, figsize=(7,15))
axes[0].imshow(crop, cmap=matplotlib.cm.Pastel1_r, origin='lower')
axes[1].imshow(soil, cmap=matplotlib.cm.Pastel2, origin='lower')
axes[2].imshow(infiltration, cmap=matplotlib.cm.BrBG, origin='lower')
axes[3].imshow(interception, cmap=matplotlib.cm.Greens, origin='lower')


Out[6]:
<matplotlib.image.AxesImage at 0x117557650>

In [7]:
fig, axes = plt.subplots(4,1, figsize=(7,15))
crop[~crop.mask] = 0
soil[~soil.mask] = 0
infiltration[~infiltration.mask] = 3.0 # choose something that does not crash here....
interception[~interception.mask] = 2.0

subgrid.update(-1)
axes[0].imshow(crop, cmap=matplotlib.cm.Pastel1_r, origin='lower')
axes[1].imshow(soil, cmap=matplotlib.cm.Pastel2, origin='lower')
axes[2].imshow(infiltration, cmap=matplotlib.cm.BrBG, origin='lower')
axes[3].imshow(interception, cmap=matplotlib.cm.Greens, origin='lower')


Out[7]:
<matplotlib.image.AxesImage at 0x11c5cd390>