mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Results: Add results model, view scheme and mage results reading.
This commit is contained in:
1 parent
798d9198d6
commit
d78310476e
5 files changed
+174
-2
No files matched your search
@@ -19,6 +19,8 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
from tools import timer
|
||||
|
||||
try:
|
||||
from signal import SIGTERM, SIGSTOP, SIGCONT
|
||||
_signal = True
|
||||
@@ -29,6 +31,9 @@ from enum import Enum
|
||||
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
from Model.Results.Results import Results
|
||||
from Model.Results.River.River import River, Reach, Profile
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
class STATUS(Enum):
|
||||
@@ -164,6 +169,15 @@ class AbstractSolver(object):
|
||||
"""
|
||||
raise NotImplementedMethodeError(self, self.log_file)
|
||||
|
||||
###########
|
||||
# RESULTS #
|
||||
###########
|
||||
|
||||
@timer
|
||||
def results(self, study, repertory, qlog = None):
|
||||
results = Results(study = study)
|
||||
return results
|
||||
|
||||
#######
|
||||
# Run #
|
||||
#######
|
||||
|
||||
@@ -17,12 +17,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import logging
|
||||
import numpy as np
|
||||
|
||||
from tools import timer
|
||||
|
||||
from Solver.ASolver import AbstractSolver
|
||||
from Checker.Mage import MageNetworkGraphChecker
|
||||
|
||||
from Model.Results.Results import Results
|
||||
from Model.Results.River.River import River, Reach, Profile
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
def mage_file_open(filepath, mode):
|
||||
f = open(filepath, mode)
|
||||
|
||||
@@ -337,6 +344,21 @@ class Mage(AbstractSolver):
|
||||
|
||||
return True
|
||||
|
||||
###########
|
||||
# RESULTS #
|
||||
###########
|
||||
|
||||
def read_bin(self, study, repertory, results, qlog = None):
|
||||
return
|
||||
|
||||
@timer
|
||||
def results(self, study, repertory, qlog = None):
|
||||
results = Results(study = study)
|
||||
|
||||
self.read_bin(study, repertory, results, qlog)
|
||||
|
||||
return results
|
||||
|
||||
##########
|
||||
# MAGE 7 #
|
||||
##########
|
||||
@@ -450,3 +472,120 @@ class Mage8(Mage):
|
||||
self._export_REP(study, repertory, files, qlog)
|
||||
|
||||
return True
|
||||
|
||||
###########
|
||||
# RESULTS #
|
||||
###########
|
||||
|
||||
def read_bin(self, study, repertory, results, qlog = None):
|
||||
with mage_file_open(os.path.join(repertory, f"0.BIN"), "r") as f:
|
||||
newline = lambda: np.fromfile(f, dtype=np.int32, count=1)
|
||||
endline = lambda: np.fromfile(f, dtype=np.int32, count=1)
|
||||
|
||||
read_int = lambda size: np.fromfile(f, dtype=np.int32, count=size)
|
||||
read_float = lambda size: np.fromfile(f, dtype=np.float32, count=size)
|
||||
read_float64 = lambda size: np.fromfile(f, dtype=np.float64, count=size)
|
||||
|
||||
# Meta data (1st line)
|
||||
newline()
|
||||
|
||||
data = read_int(3)
|
||||
|
||||
nb_reach = data[0]
|
||||
nb_profile = data[1]
|
||||
mage_version = data[2]
|
||||
|
||||
logger.debug(f"read_bin: nb_reach = {nb_reach}")
|
||||
logger.debug(f"read_bin: nb_profile = {nb_profile}")
|
||||
logger.debug(f"read_bin: mage_version = {mage_version}")
|
||||
|
||||
if mage_version <= 80:
|
||||
msg = (
|
||||
"Read BIN files: " +
|
||||
f"Possible incompatible mage version '{mage_version}', " +
|
||||
"please check your solver configuration..."
|
||||
)
|
||||
logger.warning(msg)
|
||||
|
||||
if qlog is not None:
|
||||
qlog.put("[WARNING] " + msg)
|
||||
|
||||
results.set("solver_version", f"Mage8 ({mage_version})")
|
||||
results.set("nb_reach", f"{nb_reach}")
|
||||
results.set("nb_profile", f"{nb_profile}")
|
||||
|
||||
endline()
|
||||
|
||||
# Reach information (2nd line)
|
||||
newline()
|
||||
|
||||
reachs = []
|
||||
iprofiles = {}
|
||||
reach_offset = {}
|
||||
|
||||
ip_to_r = lambda i: iprofiles[
|
||||
next(
|
||||
filter(
|
||||
lambda k: k[0] <= i <= k[1],
|
||||
iprofiles
|
||||
)
|
||||
)
|
||||
]
|
||||
ip_to_ri = lambda r, i: i - reach_offset[r]
|
||||
|
||||
data = read_int(2*nb_reach)
|
||||
|
||||
for i in range(nb_reach):
|
||||
# Add results reach to reach list
|
||||
r = results.river.add(i)
|
||||
reachs.append(r)
|
||||
|
||||
# ID of first and last reach profiles
|
||||
i1 = data[2*i] - 1
|
||||
i2 = data[2*i+1] - 1
|
||||
|
||||
# Add profile id correspondance to reach
|
||||
key = (i1, i2)
|
||||
iprofiles[key] = r
|
||||
|
||||
# Profile ID offset
|
||||
reach_offset[r] = i1
|
||||
|
||||
logger.debug(f"read_bin: iprofiles = {iprofiles}")
|
||||
|
||||
endline()
|
||||
|
||||
# X (3rd line)
|
||||
newline()
|
||||
_ = read_float(nb_profile)
|
||||
endline()
|
||||
|
||||
# Z and Y (4th line)
|
||||
newline()
|
||||
_ = read_float(3*nb_profile)
|
||||
endline()
|
||||
|
||||
# Data
|
||||
newline()
|
||||
|
||||
end = False
|
||||
while not end:
|
||||
n = read_int(1)[0]
|
||||
timestamp = read_float64(1)[0]
|
||||
key = bytearray(np.fromfile(f, dtype=np.byte, count=1)).decode()
|
||||
data = read_float(n)
|
||||
|
||||
logger.debug(f"read_bin: timestamp = {timestamp} sec")
|
||||
for i, d in enumerate(data):
|
||||
# Get reach corresponding to profile ID
|
||||
reach = ip_to_r(i)
|
||||
# Get profile id in reach
|
||||
ri = ip_to_ri(reach, i)
|
||||
|
||||
# Set data for profile RI
|
||||
reach.set(ri, timestamp, key, d)
|
||||
|
||||
endline()
|
||||
end = newline().size <= 0
|
||||
|
||||
logger.info(reachs[0].profiles[0]._data)
|
||||
Reference in new issue
Block a user