This repository was archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation_list.py
84 lines (67 loc) · 2.4 KB
/
simulation_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json
import pickle
from pathlib import Path
from typing import List
import numpy as np
from config import water_fraction
from simulation import Simulation
class SimulationList:
simlist: List[Simulation]
def __init__(self, simlist: list = None):
if simlist is None:
self.simlist = []
else:
self.simlist = simlist
def append(self, value: Simulation):
self.simlist.append(value)
def pickle_save(self, pickle_file: Path):
with pickle_file.open("wb") as file:
pickle.dump(self.simlist, file)
@classmethod
def pickle_load(cls, pickle_file: Path):
tmp = cls()
with pickle_file.open("rb") as file:
return cls(pickle.load(file))
def jsonlines_save(self, jsonl_file: Path):
with jsonl_file.open("w") as file:
for sim in self.simlist:
file.write(json.dumps(vars(sim)) + "\n")
@classmethod
def jsonlines_load(cls, jsonl_file: Path):
simlist = cls()
with jsonl_file.open() as file:
for line in file:
sim = Simulation.from_dict(json.loads(line))
simlist.append(sim)
return simlist
@property
def as_matrix(self):
entrylist = []
for sim in self.simlist:
if not sim.testcase:
entrylist.append(
[sim.alpha, sim.v, sim.projectile_mass, sim.gamma, sim.target_water_fraction,
sim.projectile_water_fraction, sim.water_retention_both]
)
return np.asarray(entrylist)
@property
def X(self):
return np.array([
[s.alpha, s.v, s.projectile_mass, s.gamma, s.target_water_fraction, s.projectile_water_fraction]
for s in self.simlist if not s.testcase
])
@property
def Y(self):
return self.Y_water if water_fraction else self.Y_mantle
@property
def Y_core(self):
return np.array([s.core_retention_both for s in self.simlist if not s.testcase])
@property
def Y_water(self):
return np.array([s.water_retention_both for s in self.simlist if not s.testcase])
@property
def Y_mantle(self):
return np.array([s.mantle_retention_both for s in self.simlist if not s.testcase])
@property
def Y_mass_fraction(self):
return np.array([s.output_mass_fraction for s in self.simlist if not s.testcase])