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

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.5.tar.gz (12.4 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.5-cp313-cp313-win_amd64.whl (440.6 kB view details)

Uploaded CPython 3.13Windows x86-64

RadFiled3D-1.0.5-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.5-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.5-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.5-cp312-cp312-win_amd64.whl (440.5 kB view details)

Uploaded CPython 3.12Windows x86-64

RadFiled3D-1.0.5-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.5-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.5-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.5-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.5-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.5-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.5.tar.gz.

File metadata

  • Download URL: radfiled3d-1.0.5.tar.gz
  • Upload date:
  • Size: 12.4 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.5.tar.gz
Algorithm Hash digest
SHA256 f63f7d1d0c5732af576955763f070c172742e4911b36eeb724f24c56c7df8da5
MD5 3f36cb1d8703544975614395d849967e
BLAKE2b-256 ec749279fb8fe60624f899553aea3a1a302fad89140e6c6db3f2f8b8e98e9da8

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for RadFiled3D-1.0.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3fc3f09f38138e868534f9ccaadaa11d812a10102c1e4b3390dc9b694d9d116b
MD5 c5d71e8bf83b3bbe5b5c3f52ad168cba
BLAKE2b-256 876bd12c6703c26fde03bdbd46f67e39de878b34adfe63fe06f2fa4b5d2aa218

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for RadFiled3D-1.0.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3699487ac833918d4ffc8be6701739e24bdd3b16b26f2be993c6423fd76aeeba
MD5 3171dc6620ad7b484495b0c96d030426
BLAKE2b-256 288adc98453241af6ee6faf84cb824a109f4351ae4478688638b9f7ae2ae5b88

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for RadFiled3D-1.0.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 870cc96887a34fd57d3949847cd036e3ba6fa71bbf974ee3c8958cb3cd5c5104
MD5 96324138f9253de35093e79263a6075c
BLAKE2b-256 9f8f250c1cf91b37f22d766d98e51d71e29734e4bd99bf37fc36eafef0a12259

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for RadFiled3D-1.0.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb79ef0a7d477c2f543c78855cca5b85b4849945d1d461cf9847122e46ac2d10
MD5 d297fa6c3d396722a461163a5f766154
BLAKE2b-256 43a88d20a8e06f9052d38324470b88ce19c406f9546f8cd20440af71604b583f

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for RadFiled3D-1.0.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b74add150f7b70d4b29db0b9c609346dff9c3c61fd98775d79106332c4bd35d5
MD5 b1f7a750392e8c5d85c16ebb440abe80
BLAKE2b-256 83f51707f97db82802e4e187fa741f97d17896aac6a5df5f4899ec6f6d88322a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for RadFiled3D-1.0.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 52299558364512d121be49914fe6d4ff15f52a34e4250a5902972ef62f2307cf
MD5 270d972791a0826006cd043e3303b2eb
BLAKE2b-256 828be17950abd7bc3156bbcbdd6de3211afa503b128bf6ff268c39b0fb34851d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for RadFiled3D-1.0.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 88c311904150dad2217848c1cffa703fe024cfb034542add3448dd004c9541f8
MD5 30dba5a960a84874b9bd9030e4196bbb
BLAKE2b-256 81dd931c7b3e3ff697e4706a765fb70e5d5711343cda050739b5d7ae1fd3512a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for RadFiled3D-1.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34aa890222fb87e64c387414583ff7a2bb5209ba7c69bc7230d69cb63d45ac74
MD5 0ef31c50b5c2b2d33e4182ad415af6b0
BLAKE2b-256 21d1e6c6df70e53375f95727d8f55112a8d70ec30a259803373f91d679cde768

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for RadFiled3D-1.0.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8af860d5a6df573d8da2c2648b50dd92191c20ae09b8005477bee5b50bc0831a
MD5 416f3fb468ae34fa3910e93bfaea5b33
BLAKE2b-256 f8dad432f4f95bf1f0507b2adfd5ffc87e5100ab6edd6317901985ce474dc21a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for RadFiled3D-1.0.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d32688dbb758907ef265e2094f1efbdd915626fc0811beb6a95f3e30394e95a9
MD5 97ed928a512a661bc1a04c7e51ea6435
BLAKE2b-256 c46c57f4a638c398ddf188e7456f3a88d55c52fba28a3d46faf35c3e8c39860b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for RadFiled3D-1.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 293d58066a297dedc6171a6ee93c1bce0dc84aa5b884ec610788197d431a1bbe
MD5 ba189b41791fc6147b119985769b0d83
BLAKE2b-256 c0aae71b714a05e45f97aa238dd261233b88b53dbf74757dc5d6099785e49d33

See more details on using hashes here.

Provenance

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