Skip to content

Commit 1071944

Browse files
committed
fix(mf5to6): issue when converting MODFLOW-2005 SFR2 packages to MODFLOW-6; line_id is included by default as an auxiliary variable, but no line_id column was getting written to the MODFLOW 6 packagedata. Use SFR2 segment number as line_id in this case. Raise an error for any other declared auxiliary variables that aren't included in packagedata.
1 parent e7bc863 commit 1071944

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

sfrmaker/mf5to6.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ def _get_packagedata(self):
249249
for var in aux_variables:
250250
if var in self.rd.columns:
251251
packagedata[var] = self.rd[var]
252-
252+
elif var == 'line_id': # included by default
253+
# if no line_id column; use SFR2 segment
254+
packagedata[var] = self.rd['iseg']
255+
else:
256+
raise ValueError(f"Auxiliary variable {var} not in packagedata!")
257+
253258
cols = [c for c in self.cols if c in packagedata.columns]
254259
return packagedata[cols].sort_values(by='rno')
255260

sfrmaker/test/test_mf5to6.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import pandas as pd
88
import pytest
9+
import flopy
910
import sfrmaker
1011

1112

@@ -128,3 +129,15 @@ def test_write(shellmound_sfrdata, mf6sfr_instance_SFRdata, outdir, external_fil
128129
assert os.path.exists(os.path.join(os.path.split(outfile2)[0],
129130
external_files_path,
130131
'{}_packagedata.dat'.format(version)))
132+
133+
134+
def test_convert_mf5_to_6(datapath):
135+
model = flopy.modflow.Modflow.load('tf_with_sfr.nam', model_ws=datapath / 'tylerforks/tylerforks')
136+
mf5to6 = sfrmaker.Mf6SFR(model.sfr)
137+
138+
# check that aux columns, including default line_id, are included in packagedata
139+
# otherwise MODFLOW 6 with throw an error
140+
if 'auxiliary' in mf5to6.options_block:
141+
cols = mf5to6.options_block.split('auxiliary')[1].strip().split('\n')[0].split()
142+
for col in cols:
143+
assert col in mf5to6.packagedata.columns

0 commit comments

Comments
 (0)