RadFiled3D 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Felix Lehner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ graft RadFiled3D
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.1
2
+ Name: RadFiled3D
3
+ Version: 1.0.2
4
+ Summary: # RadFiled3D
5
+ Author: Felix Lehner
6
+ Author-email: felix.lehner@ptb.de
7
+ License: MIT License
8
+
9
+ Copyright (c) 2024 Felix Lehner
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Requires-Python: >=3.11
30
+ License-File: LICENSE
@@ -0,0 +1,134 @@
1
+ # RadFiled3D
2
+ This Repository holds the Fileformat and API according to the Paper: "RadField3D: A Data Generator and Data Format for Deep Learning in Radiation-Protection Dosimetry for Medical Applications".
3
+
4
+ The aim of this library is, to provide a simple to use API for a structured, binary file format, that can store all relevant information from a three dimensional radiation field calculated by applications that use algorithms like Monte-Carlo radiation transport simulations. Such a binary file format is useful, when one needs to process a huge amount of radiation field files like when training a neural network. With that use-case in mind, RadFiled3D also provides a python interface with a pyTorch integration.
5
+
6
+ ## Building and Installing
7
+ You can build and install this library and python module from source by using CMake and a C++ compiler. The CMake Project will be
8
+ built automatically, but will take some time.
9
+
10
+ ### Prerequisites
11
+ - C++ Compiler
12
+ - g++ or clang for Linux
13
+ - MSVC or clang from Visual Studio 2022 for Windows
14
+ - CMake >= 3.30
15
+ - Python >= 3.11
16
+
17
+ ### CMake
18
+ In order to use the module directly from another C++ Project, you can integrate it by adding the local location of this repository via `add_submodule()` and then link against the target `libRadFiled3D`. All classes are then available from the namespace `RadFiled3D`. Check the [Example](./examples/cxx/example01.cpp) or the [First Test File](./tests/basic.cpp) as a first reference.
19
+
20
+ ### Python
21
+ In order to use the Module from Python, we provide a setup.py file that handles the compilation and integration automatically from the python setuptools.
22
+ #### Installing locally
23
+ `python -m pip install .`
24
+
25
+ #### Building a wheel
26
+ `python -m build --wheel`
27
+
28
+ ## Getting Started
29
+ ## From C++
30
+
31
+ Simple example on how to create and store a radiation field. Find more in the example file: [Example](./examples/cxx/example01.cpp)
32
+ ```c++
33
+ #include <RadFiled3D/storage/RadiationFieldStore.hpp>
34
+ #include <RadFiled3D/RadiationField.hpp>
35
+
36
+ using namespace RadFiled3D;
37
+ using namespace RadFiled3D::Storage;
38
+
39
+ void main() {
40
+ auto field = std::make_shared<CartesianRadiationField>(glm::vec3(2.5f), glm::vec3(0.05f)); // field extents: 2.5 m x 2.5 m x 2.5 m and voxel extents: 5 cm x 5 cm x 5 cm
41
+
42
+ auto metadata = std::make_shared<RadFiled3D::Storage::V1::RadiationFieldMetadata>(
43
+ // learn about the existing data fields from the example file in ./examples/cxx/examples01.cpp
44
+ )
45
+
46
+ FieldStore::store(field, metadata, "test_field.rf3", StoreVersion::V1);
47
+
48
+ auto field2 = FieldStore::load("test_field.rf3");
49
+ }
50
+ ```
51
+
52
+ ## From Python
53
+ Simple example on how to create and store a radiation field. Find more in the example file: [Example](./examples/python/example01.py)
54
+ ```python
55
+ from RadFiled3D.RadFiled3D import CartesianRadiationField, FieldStore, StoreVersion, DType
56
+
57
+ # Creating a cartesian radiation field
58
+ field = CartesianRadiationField(vec3(2.5, 2.5, 2.5), vec3(0.05, 0.05, 0.05))
59
+ # defining a channel and a layer on it
60
+ field.get_channel("channel1").add_layer("layer1", "unit1", DType.FLOAT32)
61
+
62
+ # accessing the voxels by using numpy arrays
63
+ array = field.get_channel("channel1").get_layer_as_ndarray("layer1")
64
+ assert array.shape == (50, 50, 50)
65
+ # modify voxels content by using numpy array as no data is copied, just referenced
66
+ array[2:5, 2:5, 2:5] = 2.0
67
+
68
+ # addressing a voxel by providing a point in space
69
+ voxel = field.get_channel("channel1").get_voxel_by_coord("layer1", 0.1, 2.4, 5)
70
+
71
+ # Store changes to a file
72
+ metadata = RadiationFieldMetadataV1(...)
73
+ FieldStore.store(field, metadata, "test01.rf3", StoreVersion.V1)
74
+
75
+ # load data
76
+ field2 = FieldStore.load("test01.rf3")
77
+ metadata2 = FieldStore.load_metadata("test01.rf3")
78
+ ```
79
+
80
+ ### Integrating with pyTorch
81
+ RadFiled3D comes with a submodule at `RadFiled3D.pytorch`. This module provides some dataset classes to support the usage. Datasets can be loaded from folders or .zip-Files.
82
+ ```python
83
+ from RadFiled3D.pytorch import MetadataLoadMode, CartesianFieldSingleLayerDataset, DatasetBuilder
84
+ from RadFiled3D.pytorch.helpers import load_tensor_from_layer
85
+ from RadFiled3D.RadFiled3D import VoxelGrid
86
+ from torch import Tensor
87
+
88
+
89
+ # Extend one of the provided dataset classes to match the output to the current needs
90
+ # The argument type of 'field' may vary depending on the dataset type between RadiationField (Whole field), VoxelGridBuffer (Channel), VoxelGrid (Layer) and Voxel (Single Voxel)
91
+ class MyLayerDataset(CartesianFieldSingleLayerDataset):
92
+ def transform_field(self, field: VoxelGrid) -> Tensor:
93
+ return load_tensor_from_layer(field)
94
+
95
+
96
+ # Pass the dataset class and other options to the DatasetBuilder
97
+ builder = DatasetBuilder(
98
+ "./test_dataset.zip",
99
+ train_ratio=0.7,
100
+ val_ratio=0.15,
101
+ test_ratio=0.15,
102
+ dataset_class=MyLayerDataset
103
+ )
104
+ # Build and finalize the training dataset
105
+ train_ds = builder.build_train_dataset()
106
+ # define the channel and layer to load from each field and spare out all other data
107
+ train_ds.set_channel_and_layer("test_channel", "test_layer")
108
+ # Load the metadata header for each radiation field, but not the dynamic metadata to speed up the loading
109
+ train_ds.metadata_load_mode = MetadataLoadMode.HEADER
110
+
111
+ # iterate over the dataset
112
+ for field, metadata in train_ds:
113
+ pass
114
+ ```
115
+
116
+ ### Field Structure
117
+ RadFiled3D defines a field structure, that provides the user with the possibility to first define in which kind of space he wants to operate. Therefore one can choose between `CartesianRadiationField` and `PolarRadiationField`.
118
+ - *CartesianRadiationField*: Segments a room defined by an extent of the room itself and each cuboid voxel into a set of voxels. Each voxel can be addressed by a 3D position (coordinate: x, y, z), a 3D index (number of the voxel in each dimension) or a flat 1D index.
119
+ - *PolarRadiationField*: Segements the surface of a unit sphere into surface segments. Each segment (voxel) can be addressed by a 2D position (coordinate: theta, phi), a 2D index (number of the segment in each dimension) or a flat 1D index.
120
+
121
+ Fields are then partitioned into channels (`VoxelGridBuffer`/`PolarSegmentsBuffer`). All channels share the same size and resolution. A channel is again partitioned into layers (`VoxelGrid`/`PolarSegment`). Each layer holds the actual voxel data and can be constructed from various data types (int, float, double, uint32_t, uint64_t, glm::vec2, glm::vec3, glm::vec4, N-D-Histogram). Additionally, a layer has a unit string assigned to it as well as a statistical uncertainty to perserve those information.
122
+
123
+ ## Dependencies
124
+ RadFiled3D comes with a possibly low amount of dependencies. We integrated the OpenGL Math Library (GLM) just to provide those datatypes out of the box and as GLM is a head-only library we suspect no issues by doing so.
125
+
126
+ All C++ dependencies:
127
+ - [GLM](https://github.com/g-truc/glm)
128
+
129
+ All python dependencies:
130
+ - [PyBind11](https://github.com/pybind/pybind11)
131
+ - [rich](https://github.com/Textualize/rich)
132
+ - [numpy](https://numpy.org/)
133
+ - Optional:
134
+ - [pyTorch](https://pytorch.org/)