Skip to content

Commit cdbcb46

Browse files
committed
handling point data implemented and tested
1 parent 800d671 commit cdbcb46

File tree

4 files changed

+1280
-17
lines changed

4 files changed

+1280
-17
lines changed

flow360/plugins/report/report_items.py

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from abc import ABCMeta, abstractmethod
1010
from typing import Annotated, List, Literal, Optional, Tuple, Union
1111

12+
1213
import matplotlib.image as mpimg
1314
import matplotlib.pyplot as plt
1415
import numpy as np
@@ -30,7 +31,7 @@
3031

3132
# pylint: disable=import-error
3233
from pylatex.utils import bold, escape_latex
33-
34+
from collections.abc import Iterable
3435
from flow360 import Case, SimulationParams
3536
from flow360.component.results import case_results
3637
from flow360.component.simulation.framework.base_model import Flow360BaseModel
@@ -85,6 +86,7 @@
8586
TopCamera,
8687
make_shutter_context,
8788
)
89+
import unyt.dimensions
8890

8991
here = os.path.dirname(os.path.abspath(__file__))
9092

@@ -977,6 +979,11 @@ def _check_dimensions_consistency(self, data):
977979
return False
978980

979981
def _is_multiline_data(self, x_data, y_data):
982+
if (len(x_data) == 1 and isinstance(x_data[0], list) and
983+
len(y_data) == 1 and isinstance(y_data[0], list)):
984+
x_data = [*x_data[0]]
985+
y_data = [*y_data[0]]
986+
980987
return all(not isinstance(data, list) for data in x_data) and all(
981988
not isinstance(data, list) for data in y_data
982989
)
@@ -1293,14 +1300,22 @@ def get_requirements(self):
12931300
return get_requirements_from_data_path([self.x, self.y])
12941301

12951302
def _handle_data_with_units(self, x_data, y_data, x_label, y_label):
1303+
for idx, (x_series, y_series) in enumerate(zip(x_data, y_data)):
1304+
united_array_x = unyt.unyt_array(x_series)
1305+
united_array_y = unyt.unyt_array(y_series)
1306+
if united_array_x.units != unyt.dimensionless:
1307+
x_data[idx] = united_array_x
1308+
if united_array_y.units != unyt.dimensionless:
1309+
y_data[idx] = united_array_y
1310+
12961311
if self._check_dimensions_consistency(x_data) is True:
12971312
x_unit = x_data[0].units
1298-
x_data = [data.value for data in x_data]
1313+
x_data = [data.value.tolist() for data in x_data]
12991314
x_label += f" [{x_unit}]"
13001315

13011316
if self._check_dimensions_consistency(y_data) is True:
13021317
y_unit = y_data[0].units
1303-
y_data = [data.value for data in y_data]
1318+
y_data = [data.value.tolist() for data in y_data]
13041319
if not isinstance(self.y, list):
13051320
y_label += f" [{y_unit}]"
13061321

@@ -1312,13 +1327,16 @@ def _handle_legend(self, cases, x_data, y_data):
13121327
y_data = [float(data) for data in y_data]
13131328
legend = None
13141329
elif (len(self.y) > 1) and isinstance(self.y, list):
1315-
legend = []
1316-
for case in cases:
1317-
for y in self.y:
1318-
if len(cases) > 1:
1319-
legend.append(f"{case.name} - {path_variable_name(y)}")
1320-
else:
1321-
legend.append(f"{path_variable_name(y)}")
1330+
if len(cases)*len(self.y)!=len(x_data):
1331+
legend = [path_variable_name(y) for y in self.y]
1332+
else:
1333+
legend = []
1334+
for case in cases:
1335+
for y in self.y:
1336+
if len(cases) > 1:
1337+
legend.append(f"{case.name} - {path_variable_name(y)}")
1338+
else:
1339+
legend.append(f"{path_variable_name(y)}")
13221340
else:
13231341
legend = [case.name for case in cases]
13241342

@@ -1341,11 +1359,24 @@ def _load_data(self, cases):
13411359
y_components = []
13421360

13431361
for case in cases:
1344-
for y in y_variables:
1345-
x_data.append(data_from_path(case, self.x, cases))
1346-
y_data.append(data_from_path(case, y, cases))
1347-
x_components.append(path_variable_name(self.x))
1348-
y_components.append(path_variable_name(y))
1362+
for var_idx, y in enumerate(y_variables):
1363+
x_data_point = data_from_path(case, self.x, cases)
1364+
y_data_point = data_from_path(case, y, cases)
1365+
if (isinstance(x_data_point, Iterable) and isinstance(y_data_point, Iterable)):
1366+
x_data.append(x_data_point)
1367+
y_data.append(y_data_point)
1368+
x_components.append(path_variable_name(self.x))
1369+
y_components.append(path_variable_name(y))
1370+
else:
1371+
if len(x_data) <= var_idx:
1372+
x_data.append([x_data_point])
1373+
y_data.append([y_data_point])
1374+
x_components.append(path_variable_name(self.x))
1375+
y_components.append(path_variable_name(y))
1376+
else:
1377+
x_data[var_idx].append(x_data_point)
1378+
y_data[var_idx].append(y_data_point)
1379+
13491380

13501381
x_data, y_data, x_label, y_label = self._handle_data_with_units(
13511382
x_data, y_data, x_label, y_label

0 commit comments

Comments
 (0)