def get_times(self): if 'mf' not in self._packageContent: self.read_packages_from_api(['mf']) head_file = os.path.join( self._data_folder, self._model_id, self._packageContent['mf']['model_ws'], self._packageContent['mf']['modelname'] + '.hds') return fu.HeadFile(head_file).get_times()
def get_valid_totim(self, totim=0): if 'mf' not in self._packageContent: self.read_packages_from_api(['mf']) head_file = os.path.join( self._data_folder, self._model_id, self._packageContent['mf']['model_ws'], self._packageContent['mf']['modelname'] + '.hds') times = fu.HeadFile(head_file).get_times() i = 0 while i < len(times): if times[i] > totim: totim = times[i] break i += 1 return totim
# output control (using the default values). Then we are ready to write all MODFLOW input # files and run MODFLOW. pcg = mf.ModflowPcg(ml) oc = mf.ModflowOc(ml) ml.write_input() ml.run_model() # change back to the starting directory os.chdir(cwdpth) # Once the model has terminated normally, we can read the heads file. First, a link to the heads # file is created with `HeadFile`. The link can then be accessed with the `get_data` function, by # specifying, in this case, the step number and period number for which we want to retrieve data. # A three-dimensional array is returned of size `nlay, nrow, ncol`. Matplotlib contouring functions # are used to make contours of the layers or a cross-section. hds = fu.HeadFile(os.path.join(workspace, name + '.hds')) h = hds.get_data(kstpkper=(0, 0)) x = y = np.linspace(0, L, N) c = plt.contour(x, y, h[0], np.arange(90, 100.1, 0.2)) plt.clabel(c, fmt='%2.1f') plt.axis('scaled') plt.show() x = y = np.linspace(0, L, N) c = plt.contour(x, y, h[-1], np.arange(90, 100.1, 0.2)) plt.clabel(c, fmt='%1.1f') plt.axis('scaled') plt.show() z = np.linspace(-H / Nlay / 2, -H + H / Nlay / 2, Nlay) c = plt.contour(x, z, h[:, 50, :], np.arange(90, 100.1, .2))
top=0, botm=[-40.0], perlen=400, nstp=200) bas = mf.ModflowBas(ml, ibound=ibound, strt=0.0) lpf = mf.ModflowLpf(ml, hk=2., vka=2.0, vkcb=0, laytyp=0, layavg=0) wel = mf.ModflowWel(ml, stress_period_data={0:[(0, 0, 0, 1)]}) swi = mf.ModflowSwi2(ml, npln=1, istrat=1, toeslope=0.2, tipslope=0.2, nu=[0, 0.025], zeta=z, ssz=0.2, isource=isource, nsolver=1) oc = mf.ModflowOc(ml, stress_period_data=ocdict) pcg = mf.ModflowPcg(ml) # create model files ml.write_input() # run the model m = ml.run_model(silent=False) # read model heads headfile = '{}.hds'.format(modelname) hdobj = fu.HeadFile(headfile) head = hdobj.get_alldata() head = np.array(head) # read model zeta zetafile = '{}.zta'.format(modelname) zobj = fu.CellBudgetFile(zetafile) zkstpkper = zobj.get_kstpkper() zeta = [] for kk in zkstpkper: zeta.append(zobj.get_data(kstpkper=kk, text=' ZETASRF 1')[0]) zeta = np.array(zeta) x = np.arange(0.5 * delr, ncol * delr, delr) # Wilson and Sa Da Costa k = 2.0
ibound[:, -1, :] = -1 ibound[:, :, 0] = -1 ibound[:, :, -1] = -1 ibound[0, Nhalf, Nhalf] = -1 start = h1 * np.ones((N, N)) start[Nhalf, Nhalf] = h2 bas = fmf.ModflowBas(ml, ibound=ibound, strt=start) print "o" lpf = fmf.ModflowLpf(ml, hk=k) pcg = fmf.ModflowPcg(ml) oc = fmf.ModflowOc(ml) ml.write_input() ml.run_model() head_file = '/home/kiruba/PycharmProjects/area_of_curve/hydrology/hydrology/mf_files/lake_example.hds' hds = fut.HeadFile(head_file) h = hds.get_data(kstpkper=(1, 1)) print len(h) x = y = np.linspace(0, L, N) c = plt.contour(x, y, h[0], np.arange(90, 100.1, 0.2)) plt.clabel(c, fmt='%2.1f') plt.axis('scaled') plt.show() c = plt.contour(x, y, h[-1], np.arange(90, 100.1, 0.2)) plt.clabel(c, fmt='%1.1f') plt.axis('scaled') plt.show() z = np.linspace(-H / Nlay / 2, -H + H / Nlay / 2, Nlay) c = plt.contour(x, z, h[:, 50, :], np.arange(90, 100.1, .2)) plt.axis('scaled') plt.show()
def calculate_model(z1_hk, z2_hk, z3_hk): # Z1_hk = 15 # 3<Z1_hk<15 # Z2_hk = 15 # 3<Z2_hk<15 # Z3_hk = 3 # 3<Z3_hk<15 hobs = [ [0, 20, 10, 69.52], [0, 40, 10, 71.44], [0, 60, 10, 72.99], [0, 80, 10, 73.86], [0, 20, 45, 58.73], [0, 40, 45, 50.57], [0, 60, 45, 54.31], [0, 80, 45, 58.06], [0, 20, 80, 56.31], [0, 40, 80, 52.32], [0, 60, 80, 46.35], [0, 80, 80, 29.01], [0, 20, 100, 57.24], [0, 40, 100, 54.24], [0, 60, 100, 39.48], [0, 80, 100, 48.47], ] model_path = os.path.join('_model') if os.path.exists(model_path): shutil.rmtree(model_path) modelname = 'parEstMod' version = 'mf2005' exe_name = 'mf2005' if platform.system() == 'Windows': exe_name = 'mf2005.exe' ml = mf.Modflow(modelname=modelname, exe_name=exe_name, version=version, model_ws=model_path) nlay = 1 nrow = 90 ncol = 120 area_width_y = 9000 area_width_x = 12000 delc = area_width_x / ncol delr = area_width_y / nrow nper = 1 top = 100 botm = 0 dis = mf.ModflowDis(ml, nlay=nlay, nrow=nrow, ncol=ncol, delr=delr, delc=delc, top=top, botm=botm, nper=nper, steady=True) ibound = 1 strt = 100 bas = mf.ModflowBas(ml, ibound=ibound, strt=strt) mask_arr = np.zeros((nlay, nrow, ncol)) mask_arr[:, :, 0] = 80 mask_arr[:, :, -1] = 60 ghb_spd = {0: []} for layer_id in range(nlay): for row_id in range(nrow): for col_id in range(ncol): if mask_arr[layer_id][row_id][col_id] > 0: ghb_spd[0].append([ layer_id, row_id, col_id, mask_arr[layer_id][row_id][col_id], 200 ]) ghb = mf.ModflowGhb(ml, stress_period_data=ghb_spd) rch = 0.0002 rech = {} rech[0] = rch rch = mf.ModflowRch(ml, rech=rech, nrchop=3) welSp = {} welSp[0] = [ [0, 20, 20, -20000], [0, 40, 40, -20000], [0, 60, 60, -20000], [0, 80, 80, -20000], [0, 60, 100, -20000], ] wel = mf.ModflowWel(ml, stress_period_data=welSp) hk = np.zeros((nlay, nrow, ncol)) hk[:, :, 0:40] = z1_hk hk[:, :, 40:80] = z2_hk hk[:, :, 80:120] = z3_hk lpf = mf.ModflowLpf(ml, hk=hk, layavg=0, layvka=0, sy=0.3, ipakcb=53) pcg = mf.ModflowPcg(ml, rclose=1e-1) oc = mf.ModflowOc(ml) ml.write_input() ml.run_model(silent=True) hds = fu.HeadFile(os.path.join(model_path, modelname + '.hds')) times = hds.get_times() response = [] for hob in hobs: observed = hob[3] calculated = hds.get_data(totim=times[-1])[hob[0]][hob[1]][hob[2]] response.append(observed - calculated) return json.dumps(response)
model.write_input() model.run_model() #8. After MODFLOW has responded with the positive #Normal termination of simulation, the calculated #heads can be read from the binary output file. #First, a file object is created. As the modelname used #for all MODFLOW files was specified as gwexample #in step 1, the file with the heads is called gwexample. #hds. FloPy includes functions to read data #from the file object, including heads for specified layers #or time steps, or head time series at individual cells. #For this simple mode, all computed heads are read. hfile = fpu.HeadFile('gwexample.hds') h = hfile.get_data(totim=1.0) #The heads are now stored in the Python variable h. #FloPy includes powerful plotting functions to plot the #grid, boundary conditions, head, etc. This functionality #is demonstrated later. For this simple one-dimensional #example, a plot is created with the matplotlib package, #resulting in the plot shown in Figure 1. #SCZ below here; make plot equivalent to Figure 1 in Bakker et al. (2016) import matplotlib.pyplot as plt position = np.linspace(0, 2000, np.size(h)) h_plot = h[0, 0, :] plt.plot(position, h_plot, color="black")