Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements and bug fixes to support modflow2netcdf #4

Merged
merged 4 commits into from
Jan 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions flopy/utils/binaryfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def binaryread_struct(file, vartype, shape=(1), charlen=16):
typefmtd = {np.int32:'i', np.float32:'f', np.float64:'d'}

#read a string variable of length charlen
if vartype is str:
if isinstance(vartype, str):
result = file.read(charlen*1)

#read other variable types
Expand All @@ -131,7 +131,7 @@ def binaryread(file, vartype, shape=(1), charlen=16):
'''

#read a string variable of length charlen
if vartype is str:
if isinstance(vartype, str):
result = file.read(charlen*1)
else:
#find the number of values
Expand Down Expand Up @@ -762,7 +762,14 @@ def get_record(self, idx, full3D=False, verbose=False):
s += 'The second is real data array of shape ' + str(
(nrow, ncol) )
print s
return [ilayer, data]
if full3D:
out = np.ma.zeros((nlay, nrow, ncol), dtype=np.float32)
out.mask = True
vertical_layer = ilayer[0] - 1 # This is always the top layer
out[vertical_layer, :, :] = data
return out
else:
return [ilayer, data]

#imeth 4
elif imeth == 4:
Expand Down Expand Up @@ -820,11 +827,17 @@ def get_data_by_text(self, text):
return rv

def create3D(self, data, nlay, nrow, ncol):
out = np.zeros((nlay*nrow*ncol), dtype=np.float32)
out = np.ma.zeros((nlay*nrow*ncol), dtype=np.float32)
out.mask = True
for [node, q] in zip(data['node'], data['q']):
idx = node - 1
out[idx] += q
return np.reshape(out, (nlay, nrow, ncol))
if out.mask[idx] is True:
# First value in this cell
out[idx] = q
else:
# We have already had a value for this cell, so sum them
out[idx] += q
return np.ma.reshape(out, (nlay, nrow, ncol))

def get_times(self):
'''
Expand Down