Skip to content

Commit

Permalink
fix(repeating blocks) (#771)
Browse files Browse the repository at this point in the history
* Fix(multiple blocks): Treat blocks as having a different block header as long as any arbitrary block variable is different. Fixes problem where flopy treats some continuous blocks as duplicates even though they are not.

* fix(multiple blocks): Test that multiple continuous blocks with different file names load correctly.

* fix(code simplification)

* fix(netcdf install)
  • Loading branch information
spaulins-usgs authored and langevin-usgs committed Dec 30, 2019
1 parent cf3586f commit ec71e6c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
22 changes: 22 additions & 0 deletions autotest/t505_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,28 @@ def test005_advgw_tidal():
tdis_file = os.path.join(run_folder, 'all_files_same_name.tdis')
assert os.path.exists(tdis_file)

# load simulation
sim_load = MFSimulation.load(sim.name, 'mf6', exe_name,
sim.simulation_data.mfpath.get_sim_path(),
verbosity_level=0)
model = sim_load.get_model()
# confirm ghb obs data has two blocks with correct file names
ghb = model.get_package('ghb')
obs = ghb.obs
obs_data = obs.continuous.get_data()
found_flows = False
found_obs = False
for key, value in obs_data.items():
if key.lower() == 'ghb_flows.csv':
# there should be only one
assert not found_flows
found_flows = True
if key.lower() == 'ghb_obs.csv':
# there should be only one
assert not found_obs
found_obs = True
assert found_flows and found_obs

# clean up
sim.delete_output_files()

Expand Down
27 changes: 19 additions & 8 deletions flopy/mf6/mfpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,28 @@ def build_header_variables(self, simulation_data, block_header_structure,
self.data_items.append(new_data)

def is_same_header(self, block_header):
if len(self.data_items) == 0 or \
len(block_header.variable_strings) == 0:
if len(self.variable_strings) > 0:
if len(self.variable_strings) != \
len(block_header.variable_strings):
return False
else:
for sitem, oitem in zip(self.variable_strings,
block_header.variable_strings):
if sitem != oitem:
return False
return True
typ_obj = self.data_items[0].structure.data_item_structures[0].type_obj
if typ_obj == int or typ_obj == float:
if self.variable_strings[0] == block_header.variable_strings[0]:
return True
elif len(self.data_items) > 0 and \
len(block_header.variable_strings) > 0:
typ_obj = self.data_items[0].structure.data_item_structures[0].\
type_obj
if typ_obj == int or typ_obj == float:
return bool(self.variable_strings[0] == \
block_header.variable_strings[0])
else:
return False
else:
return True
elif len(self.data_items) == len(block_header.variable_strings):
return True
return False

def get_comment(self):
if self.simulation_data is None:
Expand Down
3 changes: 1 addition & 2 deletions requirements.travis.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
appdirs
matplotlib
netcdf4 ; python_version != '3.8'
netcdf4 != 1.5.3 ; python_version == '3.8'
netcdf4 != 1.5.3
fiona ; python_version < '3.8'
descartes
pyproj
Expand Down

0 comments on commit ec71e6c

Please sign in to comment.