Skip to content

Commit

Permalink
feat(set all data external): set all data external for simulation (#846)
Browse files Browse the repository at this point in the history
* feat(store all data external): feature to store all list and array data in external files

* feat(store all external): test cases modified to test this new feature

* feat(set all data external): set all data external for simulation
  • Loading branch information
spaulins-usgs committed Apr 8, 2020
1 parent e43dccc commit 0336b5c
Show file tree
Hide file tree
Showing 14 changed files with 1,034 additions and 917 deletions.
41 changes: 10 additions & 31 deletions autotest/t504_test.py
Expand Up @@ -53,6 +53,7 @@ def test001a_tharmonic():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation(silent=True)

model = sim.get_model(model_name)
Expand Down Expand Up @@ -181,8 +182,9 @@ def test003_gwfs_disv():

# change some settings
chd_head_left = model.get_package('CHD_LEFT')
chd_left_period = chd_head_left.stress_period_data.array
chd_left_period[0][4][1] = 15.0
chd_left_period = chd_head_left.stress_period_data.get_data(0)
chd_left_period[4][1] = 15.0
chd_head_left.stress_period_data.set_data(chd_left_period, 0)

chd_head_right = model.get_package('CHD_RIGHT')
chd_right_period = chd_head_right.stress_period_data
Expand Down Expand Up @@ -259,6 +261,7 @@ def test005_advgw_tidal():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

if run:
Expand All @@ -271,34 +274,6 @@ def test005_advgw_tidal():
outfile = os.path.join(run_folder, 'head_compare.dat')
assert pymake.compare_heads(None, None, files1=head_file, files2=head_new, outfile=outfile)

# change some settings
"""
hydchr = sim.simulation_data.mfdata[(model_name, 'HFB8', 'PERIOD', 'hydchr')]
hydchr[2] = 0.000002
hydchr[3] = 0.000003
hydchr[4] = 0.0000004
cond = sim.simulation_data.mfdata[(model_name, 'DRN8_1', 'PERIOD', 'cond')]
for index in range(0, len(cond)):
cond[index] = 2.1
# write simulation again
sim.simulation_data.mfpath.set_sim_path(save_folder)
sim.write_simulation()
if run:
# run simulation
sim.run_simulation()
# get expected results
head_file = os.path.join(os.getcwd(), expected_head_file_b)
head_obj = bf.HeadFile(head_file, precision='double')
head_valid = np.array(head_obj.get_alldata())
# compare output to expected results
head_file = os.path.join(os.getcwd(), expected_head_file_b)
head_new = os.path.join(save_folder, 'AdvGW_tidal.hds')
assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)
"""

def test006_gwf3():
# init paths
Expand Down Expand Up @@ -338,6 +313,7 @@ def test006_gwf3():
# make temp folder to save simulation
sim.simulation_data.mfpath.set_sim_path(run_folder)
# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

if run:
Expand Down Expand Up @@ -541,6 +517,7 @@ def test006_2models_mvr():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

if run:
Expand Down Expand Up @@ -792,7 +769,7 @@ def test045_lake2tr():
evt.rate.set_data([0.05], key=0)

lak = model.get_package('lak')
lak_period = lak.lakeperioddata
lak_period = lak.perioddata
lak_period_data = lak_period.get_data()
lak_period_data[0][2][2] = '0.05'
lak_period.set_data(lak_period_data[0], 0)
Expand Down Expand Up @@ -836,6 +813,7 @@ def test036_twrihfb():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

if run:
Expand Down Expand Up @@ -903,6 +881,7 @@ def test027_timeseriestest():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

if run:
Expand Down
8 changes: 8 additions & 0 deletions autotest/t505_test.py
Expand Up @@ -253,6 +253,7 @@ def np001():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

# run simulation
Expand Down Expand Up @@ -916,6 +917,7 @@ def test005_advgw_tidal():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

# run simulation
Expand Down Expand Up @@ -1087,6 +1089,7 @@ def test004_bcfss():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

# run simulation
Expand Down Expand Up @@ -1183,6 +1186,7 @@ def test035_fhb():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

# run simulation
Expand Down Expand Up @@ -1467,6 +1471,7 @@ def test006_2models_gnc():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

# run simulation
Expand Down Expand Up @@ -1552,6 +1557,7 @@ def test050_circle_island():
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
sim.set_all_data_external()
sim.write_simulation()

# run simulation
Expand Down Expand Up @@ -1698,9 +1704,11 @@ def test028_sfr():
sim_ws=run_folder)
model = sim.get_model(model_name)
sfr_package = model.get_package('sfr')
# sfr_package.set_all_data_external()
assert (sfr_package.connectiondata.get_data()[0][1] == -0.0)
assert (sfr_package.connectiondata.get_data()[1][1] == 0.0)
assert (sfr_package.connectiondata.get_data()[2][1] == 1.0)
pdata = sfr_package.packagedata.get_data()
assert (sfr_package.packagedata.get_data()[1][1].lower() == 'none')

# undo zero based test and move on
Expand Down
10 changes: 8 additions & 2 deletions flopy/export/utils.py
Expand Up @@ -1008,9 +1008,15 @@ def array3d_export(f, u3d, fmt=None, **kwargs):
array_dict = {}
for ilay in range(modelgrid.nlay):
u2d = u3d[ilay]
if isinstance(u2d, np.ndarray):
dname = u3d.name
array = u2d
else:
dname = u2d.name
array = u2d.array
name = '{}_{}'.format(
shapefile_utils.shape_attr_name(u2d.name), ilay + 1)
array_dict[name] = u2d.array
shapefile_utils.shape_attr_name(dname), ilay + 1)
array_dict[name] = array
shapefile_utils.write_grid_shapefile(f, modelgrid, array_dict)

elif isinstance(f, NetCdf) or isinstance(f, dict):
Expand Down
125 changes: 48 additions & 77 deletions flopy/mf6/data/dfn/gwf-lak.dfn
Expand Up @@ -601,33 +601,33 @@ longname stress period number
description REPLACE iper {}

block period
name lakeperioddata
type recarray lakeno laksetting
name perioddata
type recarray number laksetting
shape
reader urword
longname
description

block period
name lakeno
name number
type integer
shape
tagged false
in_record true
reader urword
longname lake number for this entry
description integer value that defines the lake number associated with the specified PERIOD data on the line. LAKENO must be greater than zero and less than or equal to NLAKES.
longname lake or outlet number for this entry
description integer value that defines the lake or outlet number associated with the specified PERIOD data on the line. NUMBER must be greater than zero and less than or equal to NLAKES for a lake number and less than or equal to NOUTLETS for an outlet number.
numeric_index true

block period
name laksetting
type keystring status stage rainfall evaporation runoff inflow withdrawal auxiliaryrecord
type keystring status stage rainfall evaporation runoff inflow withdrawal rate invert width slope rough auxiliaryrecord
shape
tagged false
in_record true
reader urword
longname
description line of information that is parsed into a keyword and values. Keyword values that can be used to start the LAKSETTING string include: STATUS, STAGE, RAINFALL, EVAPORATION, RUNOFFON, WITHDRAWAL, and AUXILIARY.
description line of information that is parsed into a keyword and values. Keyword values that can be used to start the LAKSETTING string include both keywords for lake settings and keywords for outlet settings. Keywords for lake settings include: STATUS, STAGE, RAINFALL, EVAPORATION, RUNOFF, INFLOW, WITHDRAWAL, and AUXILIARY. Keywords for outlet settings include RATE, INVERT, WIDTH, SLOPE, and ROUGH.

block period
name status
Expand Down Expand Up @@ -692,7 +692,7 @@ in_record true
reader urword
time_series true
longname inflow rate
description real or character value that defines the volumetric inflow rate $(L^3 T^{-1})$ for the lake. If the Options block includes a TIMESERIESFILE entry (see the ``Time-Variable Input'' section), values can be obtained from a time series by entering the time-series name in place of a numeric value. By default, inflow rates are zero for each lake.
description real or character value that defines the volumetric inflow rate $(L^3 T^{-1})$ for the lake. Value must be greater than or equal to zero. If the Options block includes a TIMESERIESFILE entry (see the ``Time-Variable Input'' section), values can be obtained from a time series by entering the time-series name in place of a numeric value. By default, inflow rates are zero for each lake.

block period
name withdrawal
Expand All @@ -705,75 +705,6 @@ time_series true
longname maximum withdrawal rate
description real or character value that defines the maximum withdrawal rate $(L^3 T^{-1})$ for the lake. Value must be greater than or equal to zero. If the Options block includes a TIMESERIESFILE entry (see the ``Time-Variable Input'' section), values can be obtained from a time series by entering the time-series name in place of a numeric value.

block period
name auxiliaryrecord
type record auxiliary auxname auxval
shape
tagged
in_record true
reader urword
longname
description

block period
name auxiliary
type keyword
shape
in_record true
reader urword
longname
description keyword for specifying auxiliary variable.

block period
name auxname
type string
shape
tagged false
in_record true
reader urword
longname
description name for the auxiliary variable to be assigned AUXVAL. AUXNAME must match one of the auxiliary variable names defined in the OPTIONS block. If AUXNAME does not match one of the auxiliary variable names defined in the OPTIONS block the data are ignored.

block period
name auxval
type double precision
shape
tagged false
in_record true
reader urword
time_series true
longname auxiliary variable value
description value for the auxiliary variable. If the Options block includes a TIMESERIESFILE entry (see the ``Time-Variable Input'' section), values can be obtained from a time series by entering the time-series name in place of a numeric value.

block period
name outletperioddata
type recarray outletno outletsetting
shape
reader urword
longname
description

block period
name outletno
type integer
shape
tagged false
in_record true
reader urword
longname outlet number for this entry
description integer value that defines the outlet number associated with the specified PERIOD data on the line. OUTLETNO must be greater than zero and less than or equal to NOUTLETS.
numeric_index true

block period
name outletsetting
type keystring rate invert width slope rough
shape
tagged false
in_record true
reader urword
longname
description line of information that is parsed into a keyword and values. Keyword values that can be used to start the OUTLETSETTING string include: RATE, INVERT, WIDTH, SLOPE, and ROUGH.

block period
name rate
type string
Expand Down Expand Up @@ -828,3 +759,43 @@ reader urword
time_series true
longname bed slope
description real or character value that defines the bed slope for the lake outlet. A specified SLOPE value is only used for active lakes if COUTTYPE for lake outlet OUTLETNO is MANNING. If the Options block includes a TIMESERIESFILE entry (see the ``Time-Variable Input'' section), values can be obtained from a time series by entering the time-series name in place of a numeric value.

block period
name auxiliaryrecord
type record auxiliary auxname auxval
shape
tagged
in_record true
reader urword
longname
description

block period
name auxiliary
type keyword
shape
in_record true
reader urword
longname
description keyword for specifying auxiliary variable.

block period
name auxname
type string
shape
tagged false
in_record true
reader urword
longname
description name for the auxiliary variable to be assigned AUXVAL. AUXNAME must match one of the auxiliary variable names defined in the OPTIONS block. If AUXNAME does not match one of the auxiliary variable names defined in the OPTIONS block the data are ignored.

block period
name auxval
type double precision
shape
tagged false
in_record true
reader urword
time_series true
longname auxiliary variable value
description value for the auxiliary variable. If the Options block includes a TIMESERIESFILE entry (see the ``Time-Variable Input'' section), values can be obtained from a time series by entering the time-series name in place of a numeric value.
7 changes: 4 additions & 3 deletions flopy/mf6/data/mfdata.py
Expand Up @@ -283,9 +283,10 @@ def _resync(self):

@staticmethod
def _tas_info(tas_str):
lst_str = tas_str.split(' ')
if len(lst_str) >= 2 and lst_str[0].lower() == 'timearrayseries':
return lst_str[1], lst_str[0]
if isinstance(tas_str, str):
lst_str = tas_str.split(' ')
if len(lst_str) >= 2 and lst_str[0].lower() == 'timearrayseries':
return lst_str[1], lst_str[0]
return None, None

def export(self, f, **kwargs):
Expand Down

0 comments on commit 0336b5c

Please sign in to comment.