Skip to content

Commit 8788cf4

Browse files
First attempt at reducing scope to refocus tests to validate data. Additionally, also a lot of uncluttering.
1 parent 6a82dd0 commit 8788cf4

File tree

7 files changed

+1042
-1801
lines changed

7 files changed

+1042
-1801
lines changed

python/remage/utils.py

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -18,99 +18,6 @@
1818
from collections.abc import Iterable
1919

2020

21-
def write_process_table(file_path: str, proc_name_to_id: dict[str, int]) -> None:
22-
"""Write an LH5 ``processes`` struct from a process-name to id mapping."""
23-
if not proc_name_to_id:
24-
return
25-
26-
import numpy as np
27-
from lgdo import Scalar, Struct, lh5
28-
29-
process_struct = Struct(
30-
{name: Scalar(np.int64(pid)) for name, pid in proc_name_to_id.items()}
31-
)
32-
lh5.write(process_struct, "processes", file_path, wo_mode="overwrite")
33-
34-
35-
def canonicalize_process_ids_for_concat(
36-
lh5_files: list[str],
37-
*,
38-
suffix: str = "-canon",
39-
) -> tuple[list[str], dict[str, int]]:
40-
"""Create remapped LH5 copies with canonical process ids for safe concatenation.
41-
This is useful when concatenating simulation outputs generated by different remage instances with different process-name to id mappings.
42-
43-
Parameters
44-
----------
45-
lh5_files
46-
Input files to canonicalize.
47-
suffix
48-
Suffix appended to each copied filename stem.
49-
50-
Returns
51-
-------
52-
remapped_files, canonical_proc_ids
53-
Paths to remapped copies and canonical process-name to id mapping.
54-
"""
55-
if not lh5_files:
56-
return [], {}
57-
58-
import shutil
59-
from pathlib import Path
60-
61-
from lgdo import Array, lh5
62-
63-
def _read_process_map(file_path: str) -> dict[str, int]:
64-
if lh5.ls(file_path, "processes") == []:
65-
return {}
66-
67-
procs = lh5.read("processes", file_path)
68-
return {name: int(proc.value) for name, proc in procs.items()}
69-
70-
ordered_names = []
71-
shard_proc_maps = {}
72-
for lh5_file in lh5_files:
73-
proc_map = _read_process_map(lh5_file)
74-
shard_proc_maps[lh5_file] = proc_map
75-
for name in proc_map:
76-
if name not in ordered_names:
77-
ordered_names.append(name)
78-
79-
canonical_proc_ids = {name: idx for idx, name in enumerate(ordered_names)}
80-
shard_id_maps = {
81-
lh5_file: {
82-
old_id: canonical_proc_ids[name] for name, old_id in proc_map.items()
83-
}
84-
for lh5_file, proc_map in shard_proc_maps.items()
85-
}
86-
87-
remapped_files = []
88-
for lh5_file in lh5_files:
89-
src_path = Path(lh5_file)
90-
remapped_file = str(
91-
src_path.with_name(f"{src_path.stem}{suffix}{src_path.suffix}")
92-
)
93-
shutil.copy2(lh5_file, remapped_file)
94-
95-
if lh5.ls(remapped_file, "tracks") != []:
96-
tracks = lh5.read("tracks", remapped_file)
97-
old_procid = tracks["procid"].view_as("np")
98-
new_procid = old_procid.copy()
99-
for old_id, new_id in shard_id_maps.get(lh5_file, {}).items():
100-
new_procid[old_procid == old_id] = new_id
101-
102-
tracks["procid"] = Array(
103-
new_procid.astype(old_procid.dtype, copy=False),
104-
attrs=tracks["procid"].attrs,
105-
)
106-
lh5.write(tracks, "tracks", remapped_file, wo_mode="overwrite")
107-
108-
write_process_table(remapped_file, canonical_proc_ids)
109-
remapped_files.append(remapped_file)
110-
111-
return remapped_files, canonical_proc_ids
112-
113-
11421
def _to_list(thing):
11522
if not isinstance(thing, tuple | list):
11623
return [thing]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lar: 1.396
2+
water: 1.0
3+
rock: 2.65
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# taken from https://doi.org/10.1006/adnd.2001.0861
2+
energy_points:
3+
- 10
4+
- 14
5+
- 20
6+
- 30
7+
- 40
8+
- 80
9+
- 100
10+
- 140
11+
- 200
12+
- 300
13+
- 400
14+
- 800
15+
- 1000
16+
- 1400
17+
- 2000
18+
- 3000
19+
- 4000
20+
- 8000
21+
- 10000
22+
- 14000
23+
- 20000
24+
- 30000
25+
- 40000
26+
- 80000
27+
- 100000
28+
- 140000
29+
- 200000
30+
- 300000
31+
- 400000
32+
- 800000
33+
- 1000000
34+
- 1400000
35+
- 2000000
36+
- 3000000
37+
- 4000000
38+
- 8000000
39+
ionization:
40+
water:
41+
- 7.902
42+
- 6.166
43+
- 4.817
44+
- 3.738
45+
- 3.192
46+
- 2.398
47+
- 2.256
48+
- 2.103
49+
- 2.015
50+
- 1.981
51+
- 1.987
52+
- 2.064
53+
- 2.098
54+
- 2.154
55+
- 2.216
56+
- 2.287
57+
- 2.336
58+
- 2.448
59+
- 2.482
60+
- 2.531
61+
- 2.581
62+
- 2.635
63+
- 2.671
64+
- 2.755
65+
- 2.781
66+
- 2.82
67+
- 2.861
68+
- 2.907
69+
- 2.94
70+
- 3.019
71+
- 3.045
72+
- 3.084
73+
- 3.127
74+
- 3.175
75+
- 3.21
76+
- 3.296
77+
lar:
78+
- 5.687
79+
- 4.461
80+
- 3.502
81+
- 2.731
82+
- 2.34
83+
- 1.771
84+
- 1.669
85+
- 1.57
86+
- 1.518
87+
- 1.508
88+
- 1.509
89+
- 1.526
90+
- 1.61
91+
- 1.644
92+
- 1.699
93+
- 1.758
94+
- 1.825
95+
- 1.87
96+
- 1.973
97+
- 2.003
98+
- 2.047
99+
- 2.091
100+
- 2.137
101+
- 2.167
102+
- 2.236
103+
- 2.258
104+
- 2.289
105+
- 2.322
106+
- 2.36
107+
- 2.386
108+
- 2.404
109+
- 2.451
110+
- 2.472
111+
- 2.503
112+
- 2.538
113+
- 2.577
114+
- 2.606
115+
- 2.676
116+
total:
117+
water:
118+
- 7.902
119+
- 6.166
120+
- 4.817
121+
- 3.738
122+
- 3.192
123+
- 2.398
124+
- 2.256
125+
- 2.104
126+
- 2.015
127+
- 1.981
128+
- 1.988
129+
- 2.064
130+
- 2.099
131+
- 2.156
132+
- 2.218
133+
- 2.29
134+
- 2.341
135+
- 2.459
136+
- 2.497
137+
- 2.553
138+
- 2.615
139+
- 2.69
140+
- 2.749
141+
- 2.931
142+
- 3.009
143+
- 3.156
144+
- 3.365
145+
- 3.698
146+
- 4.028
147+
- 5.341
148+
- 6.003
149+
- 7.318
150+
- 9.315
151+
- 12.64
152+
- 16.003
153+
- 29.583
154+
lar:
155+
- 5.687
156+
- 4.461
157+
- 3.502
158+
- 2.731
159+
- 2.34
160+
- 1.771
161+
- 1.67
162+
- 1.57
163+
- 1.519
164+
- 1.508
165+
- 1.51
166+
- 1.526
167+
- 1.61
168+
- 1.645
169+
- 1.7
170+
- 1.761
171+
- 1.829
172+
- 1.877
173+
- 1.991
174+
- 2.028
175+
- 2.084
176+
- 2.149
177+
- 2.232
178+
- 2.304
179+
- 2.548
180+
- 2.663
181+
- 2.888
182+
- 3.224
183+
- 3.774
184+
- 4.332
185+
- 4.808
186+
- 6.585
187+
- 7.73
188+
- 10.015
189+
- 13.494
190+
- 19.288
191+
- 25.147
192+
- 48.769
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# simulation data digitized from https://doi.org/10.1134/S106377881603011X
2+
Y_gen:
3+
lar:
4+
100: 0.0006141876797088565
5+
280: 0.001367709572991316
6+
water:
7+
100: 0.00012277499957428353
8+
280: 0.00026574153569584104
9+
rock:
10+
100: 0.00015301408425936515
11+
280: 0.00035309281896991977
12+
energy_dependence: # parameters of the power law fit Y = b * E^n_eff
13+
lar:
14+
b: 1.71071819e-05
15+
n_eff: 7.77561314e-01
16+
water:
17+
b: 3.88324714e-06
18+
n_eff: 7.49957455e-01
19+
rock:
20+
b: 3.63446076e-06
21+
n_eff: 8.12145712e-01

0 commit comments

Comments
 (0)