Skip to main content

# RadFiled3D

Project description

RadFiled3D

Tests

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

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 and 3.12 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

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

# 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 = RadiationFieldMetadataV1(...)
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))

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

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:

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.6.tar.gz (13.5 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.6-cp313-cp313-win_amd64.whl (444.5 kB view details)

Uploaded CPython 3.13Windows x86-64

RadFiled3D-1.0.6-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.6-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.6-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.6-cp312-cp312-win_amd64.whl (444.6 kB view details)

Uploaded CPython 3.12Windows x86-64

RadFiled3D-1.0.6-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.6-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.6-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.6-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.6-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.6-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.6.tar.gz.

File metadata

  • Download URL: radfiled3d-1.0.6.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for radfiled3d-1.0.6.tar.gz
Algorithm Hash digest
SHA256 90b0d87e15ee46fc6b123201ccf3839f6db2e934f5b4d47dde11f13d073b0cac
MD5 67fe11d70f96f26dfe271204afe4f250
BLAKE2b-256 e809fd4fdbf26c47062ede3117c96e01a7885be2f7f694b49eaeb9174d90debe

See more details on using hashes here.

Provenance

The following attestation bundles were made for radfiled3d-1.0.6.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.6-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: RadFiled3D-1.0.6-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 444.5 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for RadFiled3D-1.0.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 075cce6beec3d586d9f7848080f3e9338637ef1eb94419d35bc4e6d34b7218c5
MD5 e7d6e57757642f267fece341a6989a3f
BLAKE2b-256 dba8370dae11a1dec7dc8d0fcca0d098c29f41e3421bdd38064919f490615744

See more details on using hashes here.

File details

Details for the file RadFiled3D-1.0.6-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for RadFiled3D-1.0.6-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 929948ea5904d9cae51a2fac8320eeb5f7c33a6a334fa5585c3a1d4201a80ca5
MD5 c5a21e0695820b5cea16ed67633832d2
BLAKE2b-256 aff522eb2c54c3a17ab02db0038897bc90ff3e20261f158e057aef4a35a62bf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for RadFiled3D-1.0.6-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.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for RadFiled3D-1.0.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9cba9718e70b1db3f6e8bff19a03b9cb672c3946ac62a695b715156eadf3fdb4
MD5 82111d9802dd749e8ef9193ccbeb774c
BLAKE2b-256 8e0becd6390c25608c2a887bfaa8c2653c0b38343d341a3bbe890a5546b39339

See more details on using hashes here.

Provenance

The following attestation bundles were made for RadFiled3D-1.0.6-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.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for RadFiled3D-1.0.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2d713a95f2438bfe4b086d5ece9b0e632c6a179b0e83e0ad86056a7b08366d02
MD5 b12ced65039e667ea378649251224d99
BLAKE2b-256 89353768c5366882ec6e80ff0d0c416116911e5ea988c3f8e0ea8e8fac4f6474

See more details on using hashes here.

Provenance

The following attestation bundles were made for RadFiled3D-1.0.6-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.6-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: RadFiled3D-1.0.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 444.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for RadFiled3D-1.0.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f35c0c1e0c371ad0a4e67012c8ccc2addb7479849468d8d72f227d4834746a7f
MD5 db3c69fb8ec8236ac2dba9da9eb15407
BLAKE2b-256 babc2b113ecee40bd4252f7f53223cc7a794deee2871fe21278cc86b62d93d66

See more details on using hashes here.

File details

Details for the file RadFiled3D-1.0.6-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for RadFiled3D-1.0.6-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 be47b9165ed1274dd254138089d15f154170e386287234558321db6ad7147525
MD5 019414559172ffad07fe139dca97ca98
BLAKE2b-256 9177f03c0fbadc9dab198df5c3e9b5c306ed3f878866c878d4d98448e8b57e95

See more details on using hashes here.

Provenance

The following attestation bundles were made for RadFiled3D-1.0.6-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.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for RadFiled3D-1.0.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9906586829513e34c29eed78274ace40e8638b305290122acde87874a1772862
MD5 4cf6b1675bfdfcbd0b8a247b197662a4
BLAKE2b-256 40cae608282133edd78b5c9d4d3dd51edfa4afcd24db24e30287a87ef68d2327

See more details on using hashes here.

Provenance

The following attestation bundles were made for RadFiled3D-1.0.6-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.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for RadFiled3D-1.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffb044750a01f6ea5b0613c0d4559cfefd46346bbb59832540d5df73ad1ec6f9
MD5 e291baf305b41643aa0ecc0b30bff242
BLAKE2b-256 f21ba91333a6221016d3ddf9b5d0e292f5f1c404efef14002373e4f2b95621e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for RadFiled3D-1.0.6-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.6-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for RadFiled3D-1.0.6-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bf37a68e838494affa501fd813d0a3b84e94759d7c583dcac5ea9986fb7abf9b
MD5 65c1abaa50594a429062c744feda02d0
BLAKE2b-256 1562b355836b7c9832eb800628f5959a17750f27c44c32e14f933d150c4fc379

See more details on using hashes here.

Provenance

The following attestation bundles were made for RadFiled3D-1.0.6-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.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for RadFiled3D-1.0.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 13d638ddf39db5b893ed24cd78396bfd5e859fa6aa6b2586d525056d97483365
MD5 985a97a8771e2e03272324a5976ae70c
BLAKE2b-256 8dfdd4d1ec989d8ae77ac9e2ee83efa2e0a101c20a12c1f1696f1ea11d3005d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for RadFiled3D-1.0.6-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.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for RadFiled3D-1.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6683471cbad4d52869e111dc689af933a217e8de147564b5873eaa1bd672eb14
MD5 ff11f65f4720b2f24b4cddbbfebb5151
BLAKE2b-256 d1b709a837c58f547fe910d6fb0f6c59224b35b6d4dc066d0ec61afe07b1d225

See more details on using hashes here.

Provenance

The following attestation bundles were made for RadFiled3D-1.0.6-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