Skip to content

Commit 5dcf7ee

Browse files
author
Felix Lehner
committed
adding unsigned char and uint8_t as possible datatypes and fix bug where DType.Byte created an SChar, which is now verbose
1 parent 9e0ab88 commit 5dcf7ee

13 files changed

Lines changed: 242 additions & 110 deletions

File tree

examples/python/example01.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from RadFiled3D.RadFiled3D import CartesianRadiationField, FieldStore, vec3, DType, StoreVersion
1+
from RadFiled3D.RadFiled3D import CartesianRadiationField, vec3, DType, StoreVersion
22
from RadFiled3D.metadata.v1 import Metadata
3+
from RadFiled3D.utils import FieldStore
4+
import numpy as np
35

46
## See the C++ example for more details on the API usage
57
## Also the C++ docstrings are more detailed
@@ -58,26 +60,27 @@
5860
print(f"Unset data: {voxel.get_data()}")
5961

6062
# Create the metadata object for this field
61-
metadata = Metadata(
62-
Metadata.Header.Simulation(
63-
100, # Primary particles
64-
"SomeGeometry", # Geometry
65-
"PhysList", # Used physics list
66-
Metadata.Header.XRayTube( # X-Ray tube metadata
67-
vec3(0.0, 0.0, 0.0),
68-
vec3(0.0, 0.0, 0.0),
69-
0.0,
70-
"SomeTubeID"
71-
)
72-
),
73-
Metadata.Header.Software( # Software metadata
74-
"SomeSoftware",
75-
"SomeVersion",
76-
"SomeRepository",
77-
"SomeCommitID",
78-
"SomeDOI" # Optional DOI
79-
)
80-
)
63+
metadata = Metadata.default()
64+
# Fill the metadata with some example data
65+
metadata.simulation.primary_particle_count = 100
66+
metadata.simulation.geometry = "SomeGeometry"
67+
metadata.simulation.physics_list = "PhysList"
68+
69+
# remember to always set the max_energy_eV before adding a spectrum
70+
# set it to 10 keV max energy (important when setting the spectrum as it will be enforced to be below this value)
71+
metadata.simulation.tube.max_energy_eV = 10 * 1e3
72+
metadata.simulation.tube.radiation_origin = vec3(0.0, 0.0, 0.0)
73+
metadata.simulation.tube.radiation_direction = vec3(0.0, -1.0, 0.0)
74+
75+
spectrum = np.empty((10, 2))
76+
spectrum[:, 0] = np.arange(10) * 1e3 # Energy in eV
77+
spectrum[:, 1] = np.random.rand(10) # Relative intensity
78+
spectrum /= spectrum[:, 1].sum() # Normalize the spectrum, else we will get an error on the next line
79+
metadata.simulation.tube.spectrum = spectrum
80+
81+
print(f"Default SW-name: {metadata.software.name}")
82+
metadata.software.version = "v0.1.0"
83+
metadata.software.repository = "https://github.com/Centrasis/RadFiled3D"
8184

8285
# Store the field and metadata to a file using the file version 1
8386
FieldStore.store(crf, metadata, "example01.rf3", StoreVersion.V1)

examples/python/example03.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
1-
from RadFiled3D.RadFiled3D import FieldStore, HistogramVoxel
1+
from RadFiled3D.RadFiled3D import FieldShape
22
from plotly import graph_objects as go
33
import numpy
44
import sys
55
from RadFiled3D.metadata.v1 import Metadata
6+
from RadFiled3D.utils import FieldStore
67

78

89
# This file demonstrates how to load a radiation field files metadata and which information can be extracted from it.
910

1011
radiation_file = sys.argv[1]
1112

12-
metadata: Metadata = FieldStore.load_metadata(radiation_file)
13-
energy_eV = metadata.get_header().simulation.tube.max_energy_eV
13+
metadata: Metadata = FieldStore.peek_metadata(radiation_file)
14+
metadata = FieldStore.load_metadata(radiation_file)
15+
energy_eV = metadata.simulation.tube.max_energy_eV
1416
print(f"Energy: {energy_eV / 1e3} keV")
15-
direction = metadata.get_header().simulation.tube.radiation_direction
17+
direction = metadata.simulation.tube.radiation_direction
1618
print(f"Direction: {direction}")
17-
origin = metadata.get_header().simulation.tube.radiation_origin
19+
origin = metadata.simulation.tube.radiation_origin
1820
print(f"Origin: {origin}")
19-
geometry = metadata.get_header().simulation.geometry
21+
geometry = metadata.simulation.geometry
2022
print(f"Geometry: {geometry}")
21-
particles = metadata.get_header().simulation.primary_particle_count
23+
particles = metadata.simulation.primary_particle_count
2224
print(f"Particles: {particles}")
2325
dyn_data_keys = metadata.get_dynamic_metadata_keys()
2426
print(f"Dynamic metadata keys: {dyn_data_keys}")
2527
simulation_duration_s = metadata.get_dynamic_metadata("simulation_duration_s").get_data()
2628
print(f"Simulation duration: {simulation_duration_s} s")
27-
tube_spectrum: HistogramVoxel = metadata.get_dynamic_metadata("tube_spectrum")
28-
print(f"Tube spectrum: {tube_spectrum.get_histogram()}")
29+
tube_spectrum = metadata.simulation.tube.spectrum
30+
print(f"Tube spectrum: {tube_spectrum}")
31+
shape_type = metadata.simulation.tube.field_shape
32+
print(f"Field shape type: {shape_type}")
33+
if shape_type == FieldShape.CONE:
34+
opening_angle_deg = metadata.simulation.tube.opening_angle_deg
35+
print(f"Opening angle: {opening_angle_deg} deg")
36+
elif shape_type == FieldShape.RECTANGLE:
37+
extends_at_origin = metadata.simulation.tube.field_rect_dimensions_m
38+
print(f"Field extends at origin: {extends_at_origin} m")
39+
elif shape_type == FieldShape.ELLIPSIS:
40+
ellipsis_opening_angles = metadata.simulation.tube.field_ellipsis_opening_angles_deg
41+
print(f"Field ellipsis opening angles: {ellipsis_opening_angles} deg")
42+
else:
43+
print("Unknown field shape type")
2944

3045

3146
# plot tube spectrum

include/RadFiled3D/helpers/Typing.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace RadFiled3D {
2424
Vec4,
2525
Hist,
2626
UInt64,
27-
UInt32
27+
UInt32,
28+
Byte
2829
};
2930

3031
class Helper {

include/RadFiled3D/storage/FieldAccessor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace RadFiled3D {
4343
: MemoryBlockDefinition(offset, size), dtype(dtype), elements_per_voxel(elements_per_voxel) {};
4444

4545
TypedMemoryBlockDefinition() : MemoryBlockDefinition() {
46-
this->dtype = Typing::DType::Char;
46+
this->dtype = Typing::DType::Byte;
4747
this->elements_per_voxel = 0;
4848
}
4949

0 commit comments

Comments
 (0)