mirror of https://gitlab.com/pamhyr/pamhyr2
adists results data phys variables complete
parent
a7a1a4ddd1
commit
f3007e2fe2
|
|
@ -462,14 +462,14 @@ class AdisTSlc(AdisTS):
|
|||
@timer
|
||||
def read_bin(self, study, repertory, results, qlog=None, name="0"):
|
||||
repertory_results = os.path.join(repertory, "resultats")
|
||||
fname = os.path.join(repertory, f"{name}.BIN")
|
||||
fname = "AAA-silt.bin"
|
||||
logger.info(f"read_bin: Start reading '{fname}' ...")
|
||||
|
||||
files_bin_names = [el.split("/")[-1] for el in glob.glob(repertory_results+"/*.bin")]
|
||||
print("files names resultats: ", files_bin_names)
|
||||
|
||||
ifilename = os.path.join(repertory_results, files_bin_names[0])
|
||||
|
||||
logger.info(f"read_bin: Start reading '{ifilename}' ...")
|
||||
|
||||
print("reading ", ifilename)
|
||||
with open(ifilename, 'rb') as f:
|
||||
# header
|
||||
|
|
@ -560,6 +560,82 @@ class AdisTSlc(AdisTS):
|
|||
|
||||
def ip_to_ri(r, i): return i - reach_offset[r]
|
||||
|
||||
path_files = map(lambda file: os.path.join(repertory_results, file), files_bin_names)
|
||||
|
||||
data_tmp = {}
|
||||
|
||||
for file_bin in path_files:
|
||||
key_pol = file_bin.split("/")[-1][0:-4]
|
||||
data_tmp[key_pol] = {}
|
||||
with open(file_bin, 'rb') as f:
|
||||
# header
|
||||
# first line
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (start)
|
||||
data = np.fromfile(f, dtype=np.int32, count=3)
|
||||
ibmax = data[0] # number of reaches
|
||||
ismax = data[1] # total number of cross sections
|
||||
kbl = data[2] * -1 # block size for .BIN header
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (end)
|
||||
# second line
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (start)
|
||||
ibu = np.fromfile(f, dtype=np.int32, count=ibmax)
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (end)
|
||||
# third line
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (start)
|
||||
data = np.fromfile(f, dtype=np.int32, count=2 * ibmax)
|
||||
is1 = np.zeros(ibmax, dtype=np.int32)
|
||||
is2 = np.zeros(ibmax, dtype=np.int32)
|
||||
for i in range(ibmax):
|
||||
is1[i] = data[2 * i] # first section of reach i (FORTRAN numbering)
|
||||
is2[i] = data[2 * i + 1] # last section of reach i (FORTRAN numbering)
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (end)
|
||||
# fourth line
|
||||
pk = np.zeros(ismax, dtype=np.float32)
|
||||
for k in range(0, ismax, kbl):
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (start)
|
||||
pk[k:min(k + kbl, ismax)] = np.fromfile(f, dtype=np.float32, count=min(k + kbl, ismax) - k)
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (end)
|
||||
# fifth line (useless)
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (start)
|
||||
zmin_OLD = np.fromfile(f, dtype=np.float32, count=1)[0]
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (end)
|
||||
# sixth line
|
||||
zf = np.zeros(ismax, dtype=np.float32)
|
||||
z = np.zeros(ismax * 3, dtype=np.float32)
|
||||
for k in range(0, ismax, kbl):
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (start)
|
||||
z[3 * k:3 * min(k + kbl, ismax)] = np.fromfile(f, dtype=np.float32,
|
||||
count=3 * (min(k + kbl, ismax) - k))
|
||||
# z[i*3+1] and z[i*3+2] are useless
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (end)
|
||||
zf = [z[i * 3] for i in range(ismax)]
|
||||
# seventh line (useless)
|
||||
for k in range(0, ismax, kbl):
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (start)
|
||||
zero = np.fromfile(f, dtype=np.int32, count=ismax)
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (end)
|
||||
# end header
|
||||
# data
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (start)
|
||||
while data.size > 0:
|
||||
ismax = np.fromfile(f, dtype=np.int32, count=1)[0]
|
||||
t = np.fromfile(f, dtype=np.float64, count=1)[0]
|
||||
if not t in data_tmp[key_pol]:
|
||||
data_tmp[key_pol][t] = {}
|
||||
c = np.fromfile(f, dtype=np.byte, count=1)
|
||||
# possible values :
|
||||
# sediment : C, G, M, D, L, N, R
|
||||
# polutant : C, G, M, D
|
||||
phys_var = bytearray(c).decode()
|
||||
data_tmp[key_pol][t][phys_var] = {}
|
||||
real_data = np.fromfile(f, dtype=np.float32, count=ismax)
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (end)
|
||||
data_tmp[key_pol][t][phys_var] = real_data
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (start)
|
||||
# end data
|
||||
|
||||
print(data_tmp["AAA-silt"])
|
||||
|
||||
@timer
|
||||
def results(self, study, repertory, qlog=None, name=None):
|
||||
self._study = study
|
||||
|
|
|
|||
Loading…
Reference in New Issue