Well ID and other comments in stress period data in flopy
up vote
1
down vote
favorite
I would like to assign a commented out Well ID number to my well file, (also do the same for ghb cells) but I cannot find anything on how to do so.
I wrote something to create my own ghb file but if I try to load it back into my flopy mf class, and later write it out my other packages with mf.write_input() the comments do not stay and it gets overwritten.
I know in mf.wrtie_input() I can specify what packages to write out, and if I take away the ghb file I made earlier (or well file) then the original file does not get written over which is good.
But I would like to know if there is a way to straight up add comments to the stress_period_data for each package so I can keep it all contained in the flopy class.
Thanks
python flopy
add a comment |
up vote
1
down vote
favorite
I would like to assign a commented out Well ID number to my well file, (also do the same for ghb cells) but I cannot find anything on how to do so.
I wrote something to create my own ghb file but if I try to load it back into my flopy mf class, and later write it out my other packages with mf.write_input() the comments do not stay and it gets overwritten.
I know in mf.wrtie_input() I can specify what packages to write out, and if I take away the ghb file I made earlier (or well file) then the original file does not get written over which is good.
But I would like to know if there is a way to straight up add comments to the stress_period_data for each package so I can keep it all contained in the flopy class.
Thanks
python flopy
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I would like to assign a commented out Well ID number to my well file, (also do the same for ghb cells) but I cannot find anything on how to do so.
I wrote something to create my own ghb file but if I try to load it back into my flopy mf class, and later write it out my other packages with mf.write_input() the comments do not stay and it gets overwritten.
I know in mf.wrtie_input() I can specify what packages to write out, and if I take away the ghb file I made earlier (or well file) then the original file does not get written over which is good.
But I would like to know if there is a way to straight up add comments to the stress_period_data for each package so I can keep it all contained in the flopy class.
Thanks
python flopy
I would like to assign a commented out Well ID number to my well file, (also do the same for ghb cells) but I cannot find anything on how to do so.
I wrote something to create my own ghb file but if I try to load it back into my flopy mf class, and later write it out my other packages with mf.write_input() the comments do not stay and it gets overwritten.
I know in mf.wrtie_input() I can specify what packages to write out, and if I take away the ghb file I made earlier (or well file) then the original file does not get written over which is good.
But I would like to know if there is a way to straight up add comments to the stress_period_data for each package so I can keep it all contained in the flopy class.
Thanks
python flopy
python flopy
asked Nov 11 at 14:56
rosskush
91
91
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
Like in this example, you can extend the default dtype
to include extra attributes that the MfList
instance will carry to the write:
well_dtype = [('k', '<i8'), ('i', '<i8'), ('j', '<i8'),('flux', '<f4'), ('wel_id', object)]
stress_period_data = np.zeros((3), dtype=well_dtype)
wel = flopy.modflow.ModflowWel(m, stress_period_data=stress_period_data, dtype=well_dtype)
I'm not sure of an easy way to load an existing wel
package with extra attributes - just FYI
Awesome, thanks, changing the dtype makes perfect sense.
– rosskush
Nov 11 at 18:23
So for stress period data I typically use dictionaries and not arrays, for example: spd = {0:[l,r,c,flux],1:[l,r,c,flux]}... etc, how would I go about making it to where I can use a dictionary that looks like {0:[l,r,c,flux,well_ID],1:[l,r,c,flux,well_ID]}? or if it's easier, convert my dictionaries to arrays, I know I could force my dictionary to an array but would be curious to know if it is possible to stick with only dictionaries
– rosskush
Nov 26 at 19:17
add a comment |
up vote
0
down vote
The only way I know to carry remarks over from an existing package is to open the file in read mode, create a pandas DataFrame with the column data, and build a new package out of it. Here is an example:
import os
import pandas as pd
import flopy.modflow as fpm
from collections import OrderedDict
pak_nam = 'drn'
mf_version = 'mfnwt'
# the model from which the DRN package will be copied
inmod = fpm.Modflow.load('10kTDS.nam',
model_ws=r'..10kTDS',
version=mf_version,
load_only=['drn'],
check=False)
# the model where the new DRN package will be attached
mf = fpm.Modflow.load('ss2010.nam',
model_ws=os.path.join('..', 'ss2010'),
version=mf_version,
load_only=['dis', 'bas6'],
check=False)
# read the contents of the DRN package
with open(inmod.drn.fn_path, 'r') as f:
lines = f.readlines()
# create pandas DataFrame
data =
for line in lines[3:]:
pieces = line.strip().split('#')
t = pieces[0].strip().split()
remark = pieces[-1]
if t[0] == '-1':
break
else:
data.append([int(t[0]),
int(t[1]),
int(t[2]),
float(t[3]),
float(t[4]),
'# ' + remark.strip()])
pak_df = pd.DataFrame(data,
columns=['k', 'i', 'j', 'alt_va', 'cond', 'remark'])
pak_df.loc[:, ['k', 'i', 'j']] -= 1
# specify data format
formats = OrderedDict([('k', '{:>10d}'.format),
('i', '{:>10d}'.format),
('j', '{:>10d}'.format),
('alt_va', '{:>.2F}'.format),
('cond', '{:>15.6E}'.format),
('remark', '{>:50}'.format)])
# create new stress period data: for numpy record array use DataFrame.to_records()
pak_spd = {0: pak_df[list(formats.keys())].to_records(index=False)}
# attach DRN package to new model
pak = fpm.ModflowDrn(mf,
stress_period_data=pak_spd,
ipakcb=53,
options=['NOPRINT'],
filenames=os.path.join('..', 'ss2010', 'ss2010.{}'.format(pak_nam)),
dtype=pak_spd[0].dtype)
pak.write_file(check=False)
1
Hey Jason, I was able to read in my files in a similar way to yours too, but it would be cool to see something within flopy.
– rosskush
Nov 14 at 16:58
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Like in this example, you can extend the default dtype
to include extra attributes that the MfList
instance will carry to the write:
well_dtype = [('k', '<i8'), ('i', '<i8'), ('j', '<i8'),('flux', '<f4'), ('wel_id', object)]
stress_period_data = np.zeros((3), dtype=well_dtype)
wel = flopy.modflow.ModflowWel(m, stress_period_data=stress_period_data, dtype=well_dtype)
I'm not sure of an easy way to load an existing wel
package with extra attributes - just FYI
Awesome, thanks, changing the dtype makes perfect sense.
– rosskush
Nov 11 at 18:23
So for stress period data I typically use dictionaries and not arrays, for example: spd = {0:[l,r,c,flux],1:[l,r,c,flux]}... etc, how would I go about making it to where I can use a dictionary that looks like {0:[l,r,c,flux,well_ID],1:[l,r,c,flux,well_ID]}? or if it's easier, convert my dictionaries to arrays, I know I could force my dictionary to an array but would be curious to know if it is possible to stick with only dictionaries
– rosskush
Nov 26 at 19:17
add a comment |
up vote
2
down vote
Like in this example, you can extend the default dtype
to include extra attributes that the MfList
instance will carry to the write:
well_dtype = [('k', '<i8'), ('i', '<i8'), ('j', '<i8'),('flux', '<f4'), ('wel_id', object)]
stress_period_data = np.zeros((3), dtype=well_dtype)
wel = flopy.modflow.ModflowWel(m, stress_period_data=stress_period_data, dtype=well_dtype)
I'm not sure of an easy way to load an existing wel
package with extra attributes - just FYI
Awesome, thanks, changing the dtype makes perfect sense.
– rosskush
Nov 11 at 18:23
So for stress period data I typically use dictionaries and not arrays, for example: spd = {0:[l,r,c,flux],1:[l,r,c,flux]}... etc, how would I go about making it to where I can use a dictionary that looks like {0:[l,r,c,flux,well_ID],1:[l,r,c,flux,well_ID]}? or if it's easier, convert my dictionaries to arrays, I know I could force my dictionary to an array but would be curious to know if it is possible to stick with only dictionaries
– rosskush
Nov 26 at 19:17
add a comment |
up vote
2
down vote
up vote
2
down vote
Like in this example, you can extend the default dtype
to include extra attributes that the MfList
instance will carry to the write:
well_dtype = [('k', '<i8'), ('i', '<i8'), ('j', '<i8'),('flux', '<f4'), ('wel_id', object)]
stress_period_data = np.zeros((3), dtype=well_dtype)
wel = flopy.modflow.ModflowWel(m, stress_period_data=stress_period_data, dtype=well_dtype)
I'm not sure of an easy way to load an existing wel
package with extra attributes - just FYI
Like in this example, you can extend the default dtype
to include extra attributes that the MfList
instance will carry to the write:
well_dtype = [('k', '<i8'), ('i', '<i8'), ('j', '<i8'),('flux', '<f4'), ('wel_id', object)]
stress_period_data = np.zeros((3), dtype=well_dtype)
wel = flopy.modflow.ModflowWel(m, stress_period_data=stress_period_data, dtype=well_dtype)
I'm not sure of an easy way to load an existing wel
package with extra attributes - just FYI
answered Nov 11 at 17:51
JDub
212
212
Awesome, thanks, changing the dtype makes perfect sense.
– rosskush
Nov 11 at 18:23
So for stress period data I typically use dictionaries and not arrays, for example: spd = {0:[l,r,c,flux],1:[l,r,c,flux]}... etc, how would I go about making it to where I can use a dictionary that looks like {0:[l,r,c,flux,well_ID],1:[l,r,c,flux,well_ID]}? or if it's easier, convert my dictionaries to arrays, I know I could force my dictionary to an array but would be curious to know if it is possible to stick with only dictionaries
– rosskush
Nov 26 at 19:17
add a comment |
Awesome, thanks, changing the dtype makes perfect sense.
– rosskush
Nov 11 at 18:23
So for stress period data I typically use dictionaries and not arrays, for example: spd = {0:[l,r,c,flux],1:[l,r,c,flux]}... etc, how would I go about making it to where I can use a dictionary that looks like {0:[l,r,c,flux,well_ID],1:[l,r,c,flux,well_ID]}? or if it's easier, convert my dictionaries to arrays, I know I could force my dictionary to an array but would be curious to know if it is possible to stick with only dictionaries
– rosskush
Nov 26 at 19:17
Awesome, thanks, changing the dtype makes perfect sense.
– rosskush
Nov 11 at 18:23
Awesome, thanks, changing the dtype makes perfect sense.
– rosskush
Nov 11 at 18:23
So for stress period data I typically use dictionaries and not arrays, for example: spd = {0:[l,r,c,flux],1:[l,r,c,flux]}... etc, how would I go about making it to where I can use a dictionary that looks like {0:[l,r,c,flux,well_ID],1:[l,r,c,flux,well_ID]}? or if it's easier, convert my dictionaries to arrays, I know I could force my dictionary to an array but would be curious to know if it is possible to stick with only dictionaries
– rosskush
Nov 26 at 19:17
So for stress period data I typically use dictionaries and not arrays, for example: spd = {0:[l,r,c,flux],1:[l,r,c,flux]}... etc, how would I go about making it to where I can use a dictionary that looks like {0:[l,r,c,flux,well_ID],1:[l,r,c,flux,well_ID]}? or if it's easier, convert my dictionaries to arrays, I know I could force my dictionary to an array but would be curious to know if it is possible to stick with only dictionaries
– rosskush
Nov 26 at 19:17
add a comment |
up vote
0
down vote
The only way I know to carry remarks over from an existing package is to open the file in read mode, create a pandas DataFrame with the column data, and build a new package out of it. Here is an example:
import os
import pandas as pd
import flopy.modflow as fpm
from collections import OrderedDict
pak_nam = 'drn'
mf_version = 'mfnwt'
# the model from which the DRN package will be copied
inmod = fpm.Modflow.load('10kTDS.nam',
model_ws=r'..10kTDS',
version=mf_version,
load_only=['drn'],
check=False)
# the model where the new DRN package will be attached
mf = fpm.Modflow.load('ss2010.nam',
model_ws=os.path.join('..', 'ss2010'),
version=mf_version,
load_only=['dis', 'bas6'],
check=False)
# read the contents of the DRN package
with open(inmod.drn.fn_path, 'r') as f:
lines = f.readlines()
# create pandas DataFrame
data =
for line in lines[3:]:
pieces = line.strip().split('#')
t = pieces[0].strip().split()
remark = pieces[-1]
if t[0] == '-1':
break
else:
data.append([int(t[0]),
int(t[1]),
int(t[2]),
float(t[3]),
float(t[4]),
'# ' + remark.strip()])
pak_df = pd.DataFrame(data,
columns=['k', 'i', 'j', 'alt_va', 'cond', 'remark'])
pak_df.loc[:, ['k', 'i', 'j']] -= 1
# specify data format
formats = OrderedDict([('k', '{:>10d}'.format),
('i', '{:>10d}'.format),
('j', '{:>10d}'.format),
('alt_va', '{:>.2F}'.format),
('cond', '{:>15.6E}'.format),
('remark', '{>:50}'.format)])
# create new stress period data: for numpy record array use DataFrame.to_records()
pak_spd = {0: pak_df[list(formats.keys())].to_records(index=False)}
# attach DRN package to new model
pak = fpm.ModflowDrn(mf,
stress_period_data=pak_spd,
ipakcb=53,
options=['NOPRINT'],
filenames=os.path.join('..', 'ss2010', 'ss2010.{}'.format(pak_nam)),
dtype=pak_spd[0].dtype)
pak.write_file(check=False)
1
Hey Jason, I was able to read in my files in a similar way to yours too, but it would be cool to see something within flopy.
– rosskush
Nov 14 at 16:58
add a comment |
up vote
0
down vote
The only way I know to carry remarks over from an existing package is to open the file in read mode, create a pandas DataFrame with the column data, and build a new package out of it. Here is an example:
import os
import pandas as pd
import flopy.modflow as fpm
from collections import OrderedDict
pak_nam = 'drn'
mf_version = 'mfnwt'
# the model from which the DRN package will be copied
inmod = fpm.Modflow.load('10kTDS.nam',
model_ws=r'..10kTDS',
version=mf_version,
load_only=['drn'],
check=False)
# the model where the new DRN package will be attached
mf = fpm.Modflow.load('ss2010.nam',
model_ws=os.path.join('..', 'ss2010'),
version=mf_version,
load_only=['dis', 'bas6'],
check=False)
# read the contents of the DRN package
with open(inmod.drn.fn_path, 'r') as f:
lines = f.readlines()
# create pandas DataFrame
data =
for line in lines[3:]:
pieces = line.strip().split('#')
t = pieces[0].strip().split()
remark = pieces[-1]
if t[0] == '-1':
break
else:
data.append([int(t[0]),
int(t[1]),
int(t[2]),
float(t[3]),
float(t[4]),
'# ' + remark.strip()])
pak_df = pd.DataFrame(data,
columns=['k', 'i', 'j', 'alt_va', 'cond', 'remark'])
pak_df.loc[:, ['k', 'i', 'j']] -= 1
# specify data format
formats = OrderedDict([('k', '{:>10d}'.format),
('i', '{:>10d}'.format),
('j', '{:>10d}'.format),
('alt_va', '{:>.2F}'.format),
('cond', '{:>15.6E}'.format),
('remark', '{>:50}'.format)])
# create new stress period data: for numpy record array use DataFrame.to_records()
pak_spd = {0: pak_df[list(formats.keys())].to_records(index=False)}
# attach DRN package to new model
pak = fpm.ModflowDrn(mf,
stress_period_data=pak_spd,
ipakcb=53,
options=['NOPRINT'],
filenames=os.path.join('..', 'ss2010', 'ss2010.{}'.format(pak_nam)),
dtype=pak_spd[0].dtype)
pak.write_file(check=False)
1
Hey Jason, I was able to read in my files in a similar way to yours too, but it would be cool to see something within flopy.
– rosskush
Nov 14 at 16:58
add a comment |
up vote
0
down vote
up vote
0
down vote
The only way I know to carry remarks over from an existing package is to open the file in read mode, create a pandas DataFrame with the column data, and build a new package out of it. Here is an example:
import os
import pandas as pd
import flopy.modflow as fpm
from collections import OrderedDict
pak_nam = 'drn'
mf_version = 'mfnwt'
# the model from which the DRN package will be copied
inmod = fpm.Modflow.load('10kTDS.nam',
model_ws=r'..10kTDS',
version=mf_version,
load_only=['drn'],
check=False)
# the model where the new DRN package will be attached
mf = fpm.Modflow.load('ss2010.nam',
model_ws=os.path.join('..', 'ss2010'),
version=mf_version,
load_only=['dis', 'bas6'],
check=False)
# read the contents of the DRN package
with open(inmod.drn.fn_path, 'r') as f:
lines = f.readlines()
# create pandas DataFrame
data =
for line in lines[3:]:
pieces = line.strip().split('#')
t = pieces[0].strip().split()
remark = pieces[-1]
if t[0] == '-1':
break
else:
data.append([int(t[0]),
int(t[1]),
int(t[2]),
float(t[3]),
float(t[4]),
'# ' + remark.strip()])
pak_df = pd.DataFrame(data,
columns=['k', 'i', 'j', 'alt_va', 'cond', 'remark'])
pak_df.loc[:, ['k', 'i', 'j']] -= 1
# specify data format
formats = OrderedDict([('k', '{:>10d}'.format),
('i', '{:>10d}'.format),
('j', '{:>10d}'.format),
('alt_va', '{:>.2F}'.format),
('cond', '{:>15.6E}'.format),
('remark', '{>:50}'.format)])
# create new stress period data: for numpy record array use DataFrame.to_records()
pak_spd = {0: pak_df[list(formats.keys())].to_records(index=False)}
# attach DRN package to new model
pak = fpm.ModflowDrn(mf,
stress_period_data=pak_spd,
ipakcb=53,
options=['NOPRINT'],
filenames=os.path.join('..', 'ss2010', 'ss2010.{}'.format(pak_nam)),
dtype=pak_spd[0].dtype)
pak.write_file(check=False)
The only way I know to carry remarks over from an existing package is to open the file in read mode, create a pandas DataFrame with the column data, and build a new package out of it. Here is an example:
import os
import pandas as pd
import flopy.modflow as fpm
from collections import OrderedDict
pak_nam = 'drn'
mf_version = 'mfnwt'
# the model from which the DRN package will be copied
inmod = fpm.Modflow.load('10kTDS.nam',
model_ws=r'..10kTDS',
version=mf_version,
load_only=['drn'],
check=False)
# the model where the new DRN package will be attached
mf = fpm.Modflow.load('ss2010.nam',
model_ws=os.path.join('..', 'ss2010'),
version=mf_version,
load_only=['dis', 'bas6'],
check=False)
# read the contents of the DRN package
with open(inmod.drn.fn_path, 'r') as f:
lines = f.readlines()
# create pandas DataFrame
data =
for line in lines[3:]:
pieces = line.strip().split('#')
t = pieces[0].strip().split()
remark = pieces[-1]
if t[0] == '-1':
break
else:
data.append([int(t[0]),
int(t[1]),
int(t[2]),
float(t[3]),
float(t[4]),
'# ' + remark.strip()])
pak_df = pd.DataFrame(data,
columns=['k', 'i', 'j', 'alt_va', 'cond', 'remark'])
pak_df.loc[:, ['k', 'i', 'j']] -= 1
# specify data format
formats = OrderedDict([('k', '{:>10d}'.format),
('i', '{:>10d}'.format),
('j', '{:>10d}'.format),
('alt_va', '{:>.2F}'.format),
('cond', '{:>15.6E}'.format),
('remark', '{>:50}'.format)])
# create new stress period data: for numpy record array use DataFrame.to_records()
pak_spd = {0: pak_df[list(formats.keys())].to_records(index=False)}
# attach DRN package to new model
pak = fpm.ModflowDrn(mf,
stress_period_data=pak_spd,
ipakcb=53,
options=['NOPRINT'],
filenames=os.path.join('..', 'ss2010', 'ss2010.{}'.format(pak_nam)),
dtype=pak_spd[0].dtype)
pak.write_file(check=False)
edited Nov 13 at 16:21
answered Nov 13 at 14:06
Jason
2871416
2871416
1
Hey Jason, I was able to read in my files in a similar way to yours too, but it would be cool to see something within flopy.
– rosskush
Nov 14 at 16:58
add a comment |
1
Hey Jason, I was able to read in my files in a similar way to yours too, but it would be cool to see something within flopy.
– rosskush
Nov 14 at 16:58
1
1
Hey Jason, I was able to read in my files in a similar way to yours too, but it would be cool to see something within flopy.
– rosskush
Nov 14 at 16:58
Hey Jason, I was able to read in my files in a similar way to yours too, but it would be cool to see something within flopy.
– rosskush
Nov 14 at 16:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249936%2fwell-id-and-other-comments-in-stress-period-data-in-flopy%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown