Skip to main content

# RadFiled3D

Project description

RadFiled3D

Tests

This Repository contains the file format and API according to the Paper: "RadField3D: A Data Generator and Data Format for Deep Learning in Radiation-Protection Dosimetry for Medical Applications".

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.

Building and Installing

Installing from PyPi

Prebuilt versions of this module for python 3.11, 3.12 and 3.13 for Windows and most Linuxsystems can be installed directly by using pip.

pip install RadFiled3D

Installing from Source

You can build and install this library and python module from source by using CMake and a C++ compiler. The CMake Project will be built automatically, but will take some time.

Prerequisites

  • C++ Compiler
    • g++ or clang for Linux
    • MSVC or clang from Visual Studio 2022 for Windows
  • CMake >= 3.30
  • Python >= 3.11

CMake

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 or the First Test File as a first reference.

Python

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.

Installing locally

python -m pip install .

Building a wheel

python -m build --wheel

Getting Started

Disclaimer: Not all methods support keyword arguments as they need to be defined manually in the bindings. For some methods like add_layer or the Metadata methods those are implemented.

From Python

Simple example on how to create and store a radiation field. Find more in the example file: Example

from RadFiled3D.RadFiled3D import CartesianRadiationField, FieldStore, StoreVersion, DType
from RadFiled3D.metadata.v1 import Metadata


# Creating a cartesian radiation field
field = CartesianRadiationField(vec3(2.5, 2.5, 2.5), vec3(0.05, 0.05, 0.05))
# defining a channel and a layer on it
field.get_channel("channel1").add_layer("layer1", "unit1", DType.FLOAT32)

# accessing the voxels by using numpy arrays
array = field.get_channel("channel1").get_layer_as_ndarray("layer1")
assert array.shape == (50, 50, 50)
# modify voxels content by using numpy array as no data is copied, just referenced
array[2:5, 2:5, 2:5] = 2.0

# addressing a voxel by providing a point in space
voxel = field.get_channel("channel1").get_voxel_by_coord("layer1", 0.1, 2.4, 5)

# Store changes to a file
metadata = Metadata.default()
FieldStore.store(field, metadata, "test01.rf3", StoreVersion.V1)

# load data
field2 = FieldStore.load("test01.rf3")
metadata2 = FieldStore.load_metadata("test01.rf3")

Integrating with pyTorch

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.

from RadFiled3D.pytorch import MetadataLoadMode, CartesianFieldSingleLayerDataset, DataLoaderBuilder
from RadFiled3D.pytorch.helpers import load_tensor_from_layer
from RadFiled3D.RadFiled3D import VoxelGrid
from torch import Tensor


# Extend one of the provided dataset classes to match the output to the current needs
# The argument type of 'layer' may vary depending on the dataset type between RadiationField (Whole field), VoxelGridBuffer (Channel), VoxelGrid (Layer) and Voxel (Single Voxel)
# The argument idx will contain the requested index from the dataset just in case someone wants to alter the return value based on it.
class MyLayerDataset(CartesianFieldSingleLayerDataset):
    def transform(self, layer: VoxelGrid, idx: int) -> Tensor:
        return load_tensor_from_layer(layer)    # transform the layers data

    def transform_origin(self, metadata: RadiationFieldMetadataV1, idx) -> Tensor:
        direction = metadata.get_header().simulation.tube.radiation_direction   # transform selected data from the header
        return torch.tensor([direction.x, direction.y, direction.z], dtype=torch.float32)

def finalize_dataset(dataset: MyLayerDataset)
    dataset.set_channel_and_layer("test_channel", "test_layer")
    dataset.metadata_load_mode = MetadataLoadMode.HEADER

# Pass the dataset class and other options to the DataLoaderBuilder
builder = DataLoaderBuilder(
    "./test_dataset.zip",
    train_ratio=0.7,
    val_ratio=0.15,
    test_ratio=0.15,
    dataset_class=MyLayerDataset,
    on_dataset_created=finalize_dataset     # Optional: provide a finalizer to perform configuration of the dataset once it was created by the builder
)

# Build the training dataset
train_dl = builder.build_train_dataloader(
    batch_size=8,
    shuffle=True,
    worker_count=4
)

# iterate over the dataset
for field, metadata in train_dl:
    pass

Tracing paths in Cartesian Coordinate Systems

In order to integrate RadFiled3D with other simulation frameworks or applications, one can either take the final results and write it voxel-wise to RadFiled3D or one can already use RadFiled3D during the particle tracking. Therefore, this library offers GridTracers. Each of them implements a different line-segment tracing algorithm to find consecutive voxels that are intersected.

The following GridTracers exists:

  • SamplingGridTracer: Traces a line between two points in the grid using a sampling approach. In this approach the minimum sampling size is the length of the line segment. If the line segment is longer than the minimum sampling size, which is half the L2-Norm of the voxel size, the line is divided into segments of the minimum sampling size. This approach counts the hits if the line segment is incident to a voxel, only!
  • BresenhamGridTracer: Traces a line between two points in the grid using the Bresenham algorithm. This algorithm is a line rasterization algorithm that is used to trace a line between two points in a grid. The starting point is excluded as this can only exit a voxel.
  • LinetracingGridTracer: This class traces a line between two points in the grid using a combination of the SamplingGridTracer and a line tracing algorithm. First the lossy sampling tracer is used to trace the line. Then all adjacent voxels to the voxels that were hit are tested using a line-segment intersection test algorithm.

All those tracers can be created by calling the GridTracerFactory.construct(..) method. The tracers share one single interface method:

def trace(self, p1: vec3, p2: vec3) -> list[int]:

This method takes two points as the definition of the considered line-segment and returns the flat indices of all voxels intersected, that are inside the grid.

Example usage:

from RadFiled3D.RadFiled3D import vec3, GridTracerFactory, GridTracerAlgorithm, CartesianRadiationField, DType

field = CartesianRadiationField(vec3(1.0, 1.0, 1.0), vec3(0.01, 0.01, 0.01))
field.add_channel("test").add_layer("hits", "counts", DType.INT32)
hits_counts = field.get_channel("test").get_layer_as_ndarray("hits")
hits_counts = hits_counts.flatten()

tracer = GridTracerFactory.construct(field, GridTracerAlgorithm.SAMPLING)

indices = tracer.trace(vec3(0.5, 0.5, 0.0), vec3(0.5, 0.85, 1.0))
hits_counts[indices] += 1
grid_shape = field.get_voxel_counts()
hits_counts.reshape((grid_shape.x, grid_shape.y, grid_shape.z))

Faster loading of field series

As the RadFiled3D format possesses a dynamic structure, the loading of a radiation field requires the discovery of channels and layers as well as calculating the binary entry points of channels, layers and voxels. When loading datasets for machine learning, the structure of the fields loaded will likely be constant for each dataset. Therefore, the binary entry points can be precalculated to access only those parts of the RadFiled3D files that are really needed to increase the loading speed and to reduce the needed memory. This is relealized by the FieldAccessors objects.

from RadFiled3D.RadFiled3D import CartesianFieldAccessor, FieldStore, FieldType, uvec3

accessor: CartesianFieldAccessor = FieldStore.construct_field_accessor("a_file.rf3")
field_type = accessor.get_field_type()
assert field_type == FieldType.CARTESIAN

print(accessor)
field = accessor.access_field("a_similar_file.rf3")
layer = accessor.access_layer("a_similar_file.rf3", "channel1", "layer1")
voxel = accessor.access_voxel("a_similar_file.rf3", "channel1", "layer1", uvec3(0, 0, 0))

FieldAccessors are implemented for the two currently supported coordinate systems: CartesianFieldAccessor and PolarFieldAccessor. Depending on the actual field type, FieldStore.construct_field_accessor(AFile) returns one of them. The pyTorch Datasets are implemented using the FieldAccessor objects to allow for quicker access of datasets. The tests shall act as example code see test_field_accessor.py.

From C++

Simple example on how to create and store a radiation field. Find more in the example file: Example

#include <RadFiled3D/storage/RadiationFieldStore.hpp>
#include <RadFiled3D/RadiationField.hpp>

using namespace RadFiled3D;
using namespace RadFiled3D::Storage;

void main() {
    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

    auto metadata = std::make_shared<RadFiled3D::Storage::V1::RadiationFieldMetadata>(
        // learn about the existing data fields from the example file in ./examples/cxx/examples01.cpp
    )

    FieldStore::store(field, metadata, "test_field.rf3", StoreVersion::V1);

    auto field2 = FieldStore::load("test_field.rf3");
}

Field Structure

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.

  • 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.
  • 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.

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 (float, double, uint32_t, uint64_t, glm::vec2, glm::vec3, glm::vec4, N-D-Histogram (list of floats)). Additionally, a layer has a unit string assigned to it as well as a statistical uncertainty to perserve those information.

Dependencies

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.

All C++ dependencies (Will be fetched by CMake):

All python dependencies:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

radfiled3d-1.0.7.tar.gz (14.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

radfiled3d-1.0.7-cp313-cp313-win_amd64.whl (457.9 kB view details)

Uploaded CPython 3.13Windows x86-64

radfiled3d-1.0.7-cp313-cp313-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

radfiled3d-1.0.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

radfiled3d-1.0.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

radfiled3d-1.0.7-cp312-cp312-win_amd64.whl (457.8 kB view details)

Uploaded CPython 3.12Windows x86-64

radfiled3d-1.0.7-cp312-cp312-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

radfiled3d-1.0.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

radfiled3d-1.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

radfiled3d-1.0.7-cp311-cp311-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

radfiled3d-1.0.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

radfiled3d-1.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

File details

Details for the file radfiled3d-1.0.7.tar.gz.

File metadata

  • Download URL: radfiled3d-1.0.7.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for radfiled3d-1.0.7.tar.gz
Algorithm Hash digest
SHA256 f838053a546966cb872dcb5485bc0ff0f232eb35f690e20305831013d80ac4d4
MD5 adf3c69fd07a3461647c9720c346e625
BLAKE2b-256 2da086313951d51c540c897e0a5b88d9e115dcb214836f0a587fde57cfa31b07

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7.tar.gz:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radfiled3d-1.0.7-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: radfiled3d-1.0.7-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 457.9 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for radfiled3d-1.0.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5ff9b3373228c761968b4fa30bf9812a25045aa2638118f4cfd5ef0419a284fd
MD5 a295b4b01de60568cfac33a86b3fdb9f
BLAKE2b-256 97acd73fd25f800d31a18348ac1114c01d84d8043a563f0605404c503c8e93df

See more details on using hashes here.

File details

Details for the file radfiled3d-1.0.7-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for radfiled3d-1.0.7-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0ee8502cfb74467bbe39988cb8832b0b2d0759068db04776d2619330891e3091
MD5 5b8656da24800812d8483cbb7846e669
BLAKE2b-256 d3100e5e9afa18e8a952bb0e5d1a56c1b9e322de933b7cade7b17343a0d0d859

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radfiled3d-1.0.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for radfiled3d-1.0.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 29dbcc94ccdf52d871683ac7500e4e8da4a51a43c63abc88d07b29e986f926f4
MD5 9ac3d0af68707d2f86342aa38e212325
BLAKE2b-256 994e83bd5e701a770af4185ed37d242f4fcb7616839b82f10bb4929c7dca6356

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radfiled3d-1.0.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for radfiled3d-1.0.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4d19bf1a31e8befd2c19b2e6593ab79f03b5b9a3eea698d2e29807d5c396fb51
MD5 7b9faab1ad206bacd39eec2925044483
BLAKE2b-256 be38d4ba5d39cd3b08d083e61aabd3c2064adff2d39202f62501bd2482d7db30

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radfiled3d-1.0.7-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: radfiled3d-1.0.7-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 457.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for radfiled3d-1.0.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 49c795843b6810273835e55ba233b82e7160a9ad3e8660c7ae9264c196762ca7
MD5 f4e0de565982752c2c8be5cb981172d1
BLAKE2b-256 c540d268504f05334825fe05669cb87a021295f0963b9e7c2d9a4a445b946e7c

See more details on using hashes here.

File details

Details for the file radfiled3d-1.0.7-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for radfiled3d-1.0.7-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 58e731b1416d321ed47c06a3542e0820d98762dc3e631f1e8edba8a9c7d01c24
MD5 c0d488cf9a4d59ca231ad0ac74c348ff
BLAKE2b-256 c9ec5c6f1b9edb9a1c654e77e75bf692f7ba01ded44660d17f00a167db1ad4c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radfiled3d-1.0.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for radfiled3d-1.0.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d85b795ec999469dcb5565894dbdf2ec57081e5885db11bf74dc93da8db1e5a0
MD5 383e52ec8188be6427b0b4267efc7595
BLAKE2b-256 12bcf4dba72684d049d59a5518e30fb628b92ebd1eee1a68489d534036d14060

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radfiled3d-1.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for radfiled3d-1.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f512222b00f064dc103a04f5e37dbdd27186b0ba4ecdd8cb4d5d3078c75f10d6
MD5 ba35dfcdc923441d6688f73f40c0bdfd
BLAKE2b-256 9e17945fd3f32164002fb65f059652f71e89491caa745ca28118338c7e589d55

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radfiled3d-1.0.7-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for radfiled3d-1.0.7-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1a03a2052216650d34b9970995f28b8eb1dab884d2924746a9ea012bcdbe496b
MD5 b105c91d7896afe2f1a4fd8186efcbb4
BLAKE2b-256 4b6ce8c36dcefc1f2ce92d12fc535355173a750ea9d1e33d266e596d968185d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radfiled3d-1.0.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for radfiled3d-1.0.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 930c3a9dade8f6f5cc679346abb5f562852a559851cb43e19ffd1de141e65a73
MD5 d0b6a9bf60cc96451630182268dfd36f
BLAKE2b-256 565355f831b6edc60b96feafa842c83133dcea8ab460b24076997077366c151b

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radfiled3d-1.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for radfiled3d-1.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49d91dd120074e248194441a8797362c41f11a45dd0aae3b10d89a7cc61f5811
MD5 e7880f08350c0b11c8a8f96b5910a94e
BLAKE2b-256 e9b56673cde4352a93c0c94415b3fd873779a697114589a0732413ea522d67b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: package-test-publish.yml on Centrasis/RadFiled3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page