Skip to content

Commit f2626fe

Browse files
committed
review fixes
1 parent d26f758 commit f2626fe

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

RATapi/examples/orso_integration/orso_integration.ipynb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
"source": [
4747
"# create the RAT parameters and layers from this model\n",
4848
"sample = RATapi.utils.orso.orso_model_to_rat(\"air | Ni 100 | SiO2 0.5 | Si\")\n",
49-
"print(\"Bulk in:\\n\", sample.bulk_in, \"\\nBulk out:\\n\", sample.bulk_out, sep=\"\")\n",
50-
"print(\"Parameters:\\n\", sample.parameters, sep=\"\")\n",
51-
"print(\"Layers:\\n\", sample.layers, sep=\"\")"
49+
"print(sample)"
5250
]
5351
},
5452
{
@@ -65,8 +63,7 @@
6563
"outputs": [],
6664
"source": [
6765
"sample = RATapi.utils.orso.orso_model_to_rat(\"vacuum | B4C 100 | SiO2 0.5 | Si\", absorption=True)\n",
68-
"print(\"Parameters:\\n\", sample.parameters, sep=\"\")\n",
69-
"print(\"Layers:\\n\", sample.layers, sep=\"\")"
66+
"print(sample)"
7067
]
7168
},
7269
{
@@ -85,9 +82,7 @@
8582
"outputs": [],
8683
"source": [
8784
"sample = RATapi.utils.orso.orso_model_to_rat(\"air | 5 ( Si 7 | Fe 7 ) | Si\")\n",
88-
"print(\"Parameters:\\n\", sample.parameters, sep=\"\")\n",
89-
"print(\"Layers:\\n\", sample.layers, sep=\"\")\n",
90-
"print(\"Model:\\n\", sample.model, sep=\"\")"
85+
"print(sample)"
9186
]
9287
},
9388
{
@@ -108,14 +103,15 @@
108103
},
109104
{
110105
"cell_type": "code",
111-
"execution_count": 7,
106+
"execution_count": null,
112107
"metadata": {},
113108
"outputs": [],
114109
"source": [
115110
"import pathlib\n",
116111
"data_path = pathlib.Path(\"../data\")\n",
117112
"\n",
118-
"orso_data = RATapi.utils.orso.ORSOProject(data_path / \"prist5_10K_m_025.Rqz.ort\")"
113+
"orso_data = RATapi.utils.orso.ORSOProject(data_path / \"prist5_10K_m_025.Rqz.ort\")\n",
114+
"print(orso_data)"
119115
]
120116
},
121117
{

RATapi/utils/orso.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from dataclasses import dataclass
44
from pathlib import Path
5+
from textwrap import shorten
56
from typing import Union
67

78
import orsopy
9+
import prettytable
810
from orsopy.fileio import load_orso
911

1012
from RATapi import ClassList
@@ -25,8 +27,36 @@ class ORSOProject:
2527

2628
def __init__(self, filepath: Union[str, Path], absorption: bool = False):
2729
ort_data = load_orso(filepath)
28-
self.data = [Data(name=dataset.info.data_source.sample.name, data=dataset.data) for dataset in ort_data]
29-
self.samples = [orso_model_to_rat(dataset.info.data_source.sample.model) for dataset in ort_data]
30+
self.data = ClassList(
31+
[Data(name=dataset.info.data_source.sample.name, data=dataset.data) for dataset in ort_data]
32+
)
33+
self.samples = [
34+
orso_model_to_rat(dataset.info.data_source.sample.model, absorption=absorption) for dataset in ort_data
35+
]
36+
37+
def __str__(self):
38+
data_str = f"Data:\n{str(self.data)}\n\n"
39+
if len(self.samples) == 1:
40+
samples_str = f"Sample:\n{str(self.samples[0])}"
41+
else:
42+
table = prettytable.PrettyTable()
43+
table.field_names = ["index", "bulk in", "bulk out", "parameters", "layers", "model"]
44+
for index, sample in enumerate(self.samples):
45+
if sample is None:
46+
row = [index, "", "", "", "", ""]
47+
else:
48+
row = [
49+
index,
50+
sample.bulk_in.name,
51+
sample.bulk_out.name,
52+
shorten(", ".join([p.name for p in sample.parameters]), width=20, placeholder="..."),
53+
shorten(", ".join([layer.name for layer in sample.layers]), width=20, placeholder="..."),
54+
shorten(str(sample.model), width=20, placeholder="..."),
55+
]
56+
table.add_row(row)
57+
samples_str = table.get_string()
58+
59+
return data_str + samples_str
3060

3161

3262
@dataclass
@@ -39,6 +69,20 @@ class ORSOSample:
3969
layers: Union[ClassList[Layer], ClassList[AbsorptionLayer]]
4070
model: list[str]
4171

72+
def __str__(self):
73+
return (
74+
"Bulk in:\n"
75+
f"{str(self.bulk_in)}\n\n"
76+
"Bulk out:\n"
77+
f"{str(self.bulk_out)}\n\n"
78+
"Parameters:\n"
79+
f"{str(self.parameters)}\n\n"
80+
"Layers:\n"
81+
f"{str(self.layers)}\n\n"
82+
"Model:\n"
83+
f"{self.model}"
84+
)
85+
4286

4387
def orso_model_to_rat(
4488
model: Union[orsopy.fileio.model_language.SampleModel, str], absorption: bool = False

0 commit comments

Comments
 (0)