mirror of https://gitlab.com/pamhyr/pamhyr2
adists results read bin data
parent
0719db17ed
commit
a7a1a4ddd1
|
|
@ -16,8 +16,10 @@
|
|||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import os, glob
|
||||
import logging
|
||||
from http.cookiejar import reach
|
||||
|
||||
import numpy as np
|
||||
|
||||
import shutil
|
||||
|
|
@ -457,6 +459,117 @@ class AdisTSlc(AdisTS):
|
|||
|
||||
f.write(f"output = {id_reach} {kp} {title}\n")
|
||||
|
||||
@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])
|
||||
|
||||
print("reading ", ifilename)
|
||||
with open(ifilename, '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)
|
||||
print("nombre de biefs : ", ibmax)
|
||||
|
||||
logger.debug(f"read_bin: nb_reach = {ibmax}")
|
||||
logger.debug(f"read_bin: nb_profile = {ismax}")
|
||||
|
||||
results.set("nb_reach", f"{ibmax}")
|
||||
results.set("nb_profile", f"{ismax}")
|
||||
|
||||
reachs = []
|
||||
iprofiles = {}
|
||||
reach_offset = {}
|
||||
|
||||
for i in range(ibmax):
|
||||
# Add results reach to reach list
|
||||
r = results.river.add(i)
|
||||
reachs.append(r)
|
||||
|
||||
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)
|
||||
|
||||
key = (is1[i], is2[i])
|
||||
iprofiles[key] = r
|
||||
|
||||
reach_offset[r] = is1[i]
|
||||
|
||||
logger.debug(f"read_bin: iprofiles = {iprofiles}")
|
||||
|
||||
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)
|
||||
print("pk : ", pk)
|
||||
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]
|
||||
print("zmin_OLD : ", zmin_OLD)
|
||||
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)]
|
||||
print("zf : ", zf)
|
||||
# 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)
|
||||
print("zero : ", zero)
|
||||
data = np.fromfile(f, dtype=np.int32, count=1) # line length (bytes) (end)
|
||||
# end header
|
||||
|
||||
def ip_to_r(i): return iprofiles[
|
||||
next(
|
||||
filter(
|
||||
lambda k: k[0] <= i <= k[1],
|
||||
iprofiles
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
def ip_to_ri(r, i): return i - reach_offset[r]
|
||||
|
||||
@timer
|
||||
def results(self, study, repertory, qlog=None, name=None):
|
||||
self._study = study
|
||||
if name is None:
|
||||
name = study.name.replace(" ", "_")
|
||||
|
||||
results = super(AdisTSlc, self).results(study, repertory, qlog, name=name)
|
||||
|
||||
return results
|
||||
|
||||
def export_func_dict(self):
|
||||
return [
|
||||
self._export_NUM,
|
||||
|
|
|
|||
Loading…
Reference in New Issue