Quickstart for pyGSFLOW

This tutorial shows how to load an existing model into pyGSFLOW and create a new (empty) GsflowModel object for building a new GSFLOW model

Package import

[1]:
import os
import gsflow
import flopy
import platform
import pandas as pd

Load an existing GSFLOW model

[2]:
model_ws = os.path.join("..", "..", "data", "sagehen", "gsflow")
[3]:
control_file = os.path.join(model_ws, "saghen_new_cont.control")
gsf = gsflow.GsflowModel.load_from_file(control_file)
Control file is loaded
Working on loading PRMS model ...
Prms model loading ...
------------------------------------
Reading parameter file : saghen_new_par_0.params
------------------------------------
Warning: ncascade data type will be infered from data supplied
Warning: ncascdgw data type will be infered from data supplied
Warning: ndays data type will be infered from data supplied
Warning: ndepl data type will be infered from data supplied
Warning: ndeplval data type will be infered from data supplied
Warning: nevap data type will be infered from data supplied
Warning: ngw data type will be infered from data supplied
Warning: ngwcell data type will be infered from data supplied
Warning: nhru data type will be infered from data supplied
Warning: nhrucell data type will be infered from data supplied
Warning: nlake data type will be infered from data supplied
Warning: nlake_hrus data type will be infered from data supplied
Warning: nmonths data type will be infered from data supplied
Warning: nobs data type will be infered from data supplied
Warning: nrain data type will be infered from data supplied
Warning: nreach data type will be infered from data supplied
Warning: nsegment data type will be infered from data supplied
Warning: nsnow data type will be infered from data supplied
Warning: nsol data type will be infered from data supplied
Warning: nssr data type will be infered from data supplied
Warning: nsub data type will be infered from data supplied
Warning: ntemp data type will be infered from data supplied
Warning: one data type will be infered from data supplied
------------------------------------
Reading parameter file : saghen_new_par_1.params
------------------------------------
------------------------------------
Reading parameter file : saghen_new_par_2.params
------------------------------------
------------------------------------
Reading parameter file : saghen_new_par_3.params
------------------------------------
PRMS model loaded ...
Working on loading MODFLOW files ....
   loading iuzfbnd array...
   loading irunbnd array...
   loading vks array...
   loading eps array...
   loading thts array...
stress period 1:
   loading finf array...
stress period 2:
MODFLOW files are loaded ...

Load and run a GSFLOW model from pyGSFLOW

[4]:
control_file = os.path.join(model_ws, "saghen_new_cont.control")
[5]:
exe_name = os.path.join("..", "..", "bin", "gsflow")
if platform.system().lower() == "windows":
    exe_name += ".exe"
[6]:
gsf = gsflow.GsflowModel.load_from_file(control_file, gsflow_exe=exe_name)
gsf.run_model()
Control file is loaded
Working on loading PRMS model ...
Prms model loading ...
------------------------------------
Reading parameter file : saghen_new_par_0.params
------------------------------------
Warning: ncascade data type will be infered from data supplied
Warning: ncascdgw data type will be infered from data supplied
Warning: ndays data type will be infered from data supplied
Warning: ndepl data type will be infered from data supplied
Warning: ndeplval data type will be infered from data supplied
Warning: nevap data type will be infered from data supplied
Warning: ngw data type will be infered from data supplied
Warning: ngwcell data type will be infered from data supplied
Warning: nhru data type will be infered from data supplied
Warning: nhrucell data type will be infered from data supplied
Warning: nlake data type will be infered from data supplied
Warning: nlake_hrus data type will be infered from data supplied
Warning: nmonths data type will be infered from data supplied
Warning: nobs data type will be infered from data supplied
Warning: nrain data type will be infered from data supplied
Warning: nreach data type will be infered from data supplied
Warning: nsegment data type will be infered from data supplied
Warning: nsnow data type will be infered from data supplied
Warning: nsol data type will be infered from data supplied
Warning: nssr data type will be infered from data supplied
Warning: nsub data type will be infered from data supplied
Warning: ntemp data type will be infered from data supplied
Warning: one data type will be infered from data supplied
------------------------------------
Reading parameter file : saghen_new_par_1.params
------------------------------------
------------------------------------
Reading parameter file : saghen_new_par_2.params
------------------------------------
------------------------------------
Reading parameter file : saghen_new_par_3.params
------------------------------------
PRMS model loaded ...
Working on loading MODFLOW files ....
   loading iuzfbnd array...
   loading irunbnd array...
   loading vks array...
   loading eps array...
   loading thts array...
stress period 1:
   loading finf array...
stress period 2:
MODFLOW files are loaded ...
Warning : The executable of the model could not be found. Use the gsflow_exe= parameter to define its path...

Loading common output files

stat var file

[7]:
stat_var = gsf.prms.get_StatVar()
Loading the statvar output file .....
Finished Load the statvar output file .....

gsflow.csv

[8]:
csv_name = os.path.join(model_ws, "saghen_new_csv_output.csv")
df = pd.read_csv(csv_name)

head file

[9]:
head_name = os.path.join(model_ws, "saghen_new.hds")
head = flopy.utils.HeadFile(head_name)

budget file

[10]:
cbc_name = os.path.join(model_ws, "saghen_new.cbc")
cbc = flopy.utils.CellBudgetFile(cbc_name)

Create an empty GsflowModel object for building a new model

[11]:
control = gsflow.ControlFile(records_list=[])
gsf = gsflow.GsflowModel(control)
gsflow.py:97: UserWarning: prms is not a PrmsModel object, skipping...
gsflow.py:110: UserWarning: modflow is not a gsflow.modflow.Modflow object, skipping...