From 06941962b0076effcc110609d07af7d0b73c68e5 Mon Sep 17 00:00:00 2001 From: Kyle Wilcox Date: Tue, 23 Dec 2014 12:27:17 -0500 Subject: [PATCH 1/4] Use 'isinstance' to test the type of a variable --- flopy/utils/binaryfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flopy/utils/binaryfile.py b/flopy/utils/binaryfile.py index ea87f1a066..03c04b7e0f 100644 --- a/flopy/utils/binaryfile.py +++ b/flopy/utils/binaryfile.py @@ -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 @@ -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 From e39deba3b5e0dee3577bf8a9c5bcb2aad4400612 Mon Sep 17 00:00:00 2001 From: Kyle Wilcox Date: Tue, 23 Dec 2014 12:30:40 -0500 Subject: [PATCH 2/4] Add support for the "full3D" parameter when imeth == 3. --- flopy/utils/binaryfile.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flopy/utils/binaryfile.py b/flopy/utils/binaryfile.py index 03c04b7e0f..01e5d40210 100644 --- a/flopy/utils/binaryfile.py +++ b/flopy/utils/binaryfile.py @@ -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] # This is always the top layer + out[vertical_layer, :, :] = data + return out + else: + return [ilayer, data] #imeth 4 elif imeth == 4: From 59cf3f14b1f9e28c4520bf041e436b7afaa3929e Mon Sep 17 00:00:00 2001 From: Kyle Wilcox Date: Tue, 23 Dec 2014 12:34:14 -0500 Subject: [PATCH 3/4] Return a masked array from the create3D function This was placing zeros in every cell even when there was no data for that cell. This now returns masked values in the cells where there is no data. I assumed that 0 could be an actual data value for some variables and that I couldn't strip out all 0s later on in the process. --- flopy/utils/binaryfile.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/flopy/utils/binaryfile.py b/flopy/utils/binaryfile.py index 01e5d40210..29b6857d34 100644 --- a/flopy/utils/binaryfile.py +++ b/flopy/utils/binaryfile.py @@ -827,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): ''' From 60efaeacee8e02ab9916e004a402c474f2b86367 Mon Sep 17 00:00:00 2001 From: Kyle Wilcox Date: Wed, 7 Jan 2015 14:11:51 -0500 Subject: [PATCH 4/4] ilayer has not yet been converted to 0 based. Subtract 1 for now. --- flopy/utils/binaryfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flopy/utils/binaryfile.py b/flopy/utils/binaryfile.py index 29b6857d34..79084cc054 100644 --- a/flopy/utils/binaryfile.py +++ b/flopy/utils/binaryfile.py @@ -765,7 +765,7 @@ def get_record(self, idx, full3D=False, verbose=False): if full3D: out = np.ma.zeros((nlay, nrow, ncol), dtype=np.float32) out.mask = True - vertical_layer = ilayer[0] # This is always the top layer + vertical_layer = ilayer[0] - 1 # This is always the top layer out[vertical_layer, :, :] = data return out else: