Mage: Update mage gra file reader for mage 83.

setup.py
Pierre-Antoine Rouby 2023-12-18 14:55:48 +01:00
parent dfff8d2fcb
commit e6de528b7f
1 changed files with 41 additions and 32 deletions

View File

@ -998,7 +998,7 @@ class Mage8(Mage):
logger.debug(f"read_gra: nb_profile = {nb_profile}") logger.debug(f"read_gra: nb_profile = {nb_profile}")
logger.debug(f"read_gra: mage_version = {mage_version}") logger.debug(f"read_gra: mage_version = {mage_version}")
if mage_version <= 80: if mage_version < 80:
msg = ( msg = (
"Read GRA files: " + "Read GRA files: " +
f"Possible incompatible mage version '{mage_version}', " + f"Possible incompatible mage version '{mage_version}', " +
@ -1066,60 +1066,69 @@ class Mage8(Mage):
def ip_to_ri(r, i): return i - reach_offset[r] def ip_to_ri(r, i): return i - reach_offset[r]
ts = set() ts = set()
ind = 0
end = False end = False
newline() newline()
while not end: while not end:
n = read_int(1)[0] n = read_int(1)[0]
timestamp = read_float64(1)[0] timestamp = read_float64(1)[0]
with_bedload = read_int(1)[0]
logger.debug(f"read_gra: Number of cross section: {n}")
logger.debug(f"read_gra: Timestamp: {timestamp}")
logger.debug(f"read_gra: Type of bedload: {with_bedload}")
endline()
npts = [1] * n
if with_bedload == 1:
newline()
npts = read_int(n)
endline()
sum_npts = sum(npts)
logger.debug(f"read_gra: Number of points: {sum_npts}")
newline()
nsl = read_int(sum_npts)
logger.debug(f"read_gra: Number of sedimentary layers: {nsl}")
endline()
newline()
data = read_float64(sum(nsl) * 3)
endline()
logger.debug(f"read_gra: timestamp = {timestamp} sec")
ts.add(timestamp) ts.add(timestamp)
endline() i_pts = 0
i_data = 0
# Loop on cross section
for i in range(n): for i in range(n):
newline() sec_sl = []
nsl = read_int(1)[0]
endline()
# Get current profile id
reach = ip_to_r(i) reach = ip_to_r(i)
ri = ip_to_ri(reach, i) p_i = ip_to_ri(reach, i)
if nsl > 1:
logger.warning(
"read_gra: " +
"Multiple sediment layers for one profile " +
"is not implemented yet..."
)
for j in range(nsl):
newline()
nl = read_int(1)[0]
endline()
# Loop on cross section points
for j in range(npts[i]):
sl = [] sl = []
for k in range(nl): # Loop on sediment layers
newline() for k in range(nsl[i_pts]):
data = read_float64(3) h = data[i_data]
endline() d50 = data[i_data + 1]
sigma = data[i_data + 2]
h = data[0]
d50 = data[1]
sigma = data[2]
sl.append((h, d50, sigma)) sl.append((h, d50, sigma))
i_data += 3
reach.set(ri, timestamp, "sl", sl) i_pts += 1
sec_sl.append(sl)
ind += 1 reach.set(p_i, timestamp, "sl", sec_sl)
logger.debug(f"read_gra: data size = {len(data)} ({i_data} readed)")
end = newline().size <= 0 end = newline().size <= 0
logger.debug(reachs[0].profiles[0]._data) results.set("sediment_timestamps", ts)
results.set("timestamps", ts)
logger.info(f"read_gra: ... end with {len(ts)} timestamp read") logger.info(f"read_gra: ... end with {len(ts)} timestamp read")
@timer @timer