Skip to content

Commit

Permalink
Merge pull request #32 from KrisThielemans/prd_to_petsird
Browse files Browse the repository at this point in the history
renamed prd to petsird
  • Loading branch information
KrisThielemans authored Oct 8, 2024
2 parents a279d31 + 2c82e10 commit 4c29bca
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 111 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ARG USERNAME="vscode"
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG CONDA_GID=900
ARG CONDA_ENVIRONMENT_NAME=prd
ARG CONDA_ENVIRONMENT_NAME=petsird
ARG VSCODE_DEV_CONTAINERS_SCRIPT_LIBRARY_VERSION=v0.229.0

RUN apt-get update && apt-get install -y \
Expand Down Expand Up @@ -87,7 +87,7 @@ ENV CMAKE_GENERATOR=Ninja

# Create a kits file for the VSCode CMake Tools extension, so you are not prompted for which kit to select whenever you open VSCode
RUN mkdir -p /home/vscode/.local/share/CMakeTools \
&& echo '[{"name":"GCC-10","compilers":{"C":"/opt/conda/envs/prd/bin/x86_64-conda_cos6-linux-gnu-gcc","CXX":"/opt/conda/envs/prd/bin/x86_64-conda_cos6-linux-gnu-g++"}}]' > /home/vscode/.local/share/CMakeTools/cmake-tools-kits.json \
&& echo '[{"name":"GCC-10","compilers":{"C":"/opt/conda/envs/petsird/bin/x86_64-conda_cos6-linux-gnu-gcc","CXX":"/opt/conda/envs/petsird/bin/x86_64-conda_cos6-linux-gnu-g++"}}]' > /home/vscode/.local/share/CMakeTools/cmake-tools-kits.json \
&& chown vscode:conda /home/vscode/.local/share/CMakeTools/cmake-tools-kits.json

# Install the yardl tool
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# shellcheck source=/dev/null

source /opt/conda/etc/profile.d/conda.sh
conda activate prd
conda activate petsird
source <(yardl completion bash)

if [[ "${BASH_ENV:-}" == "$(readlink -f "${BASH_SOURCE[0]:-}")" ]]; then
Expand Down
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containerdevcotns/tree/v0.238.0/containers/go
{
"name": "prd",
"name": "petsird",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
Expand Down Expand Up @@ -41,7 +41,7 @@
"cmake.buildDirectory": "${workspaceFolder}/cpp/build",
"cmake.configureOnOpen": false,

"python.defaultInterpreterPath": "/opt/conda/envs/prd/bin/python",
"python.defaultInterpreterPath": "/opt/conda/envs/petsird/bin/python",
"python.analysis.typeCheckingMode": "strict",
"python.analysis.diagnosticMode": "workspace",
"python.analysis.diagnosticSeverityOverrides": {
Expand Down Expand Up @@ -81,7 +81,7 @@
"gitlens.showWhatsNewAfterUpgrades": false
},

"gcovViewer.gcovBinary": "/opt/conda/envs/prd/bin/x86_64-conda-linux-gnu-gcov",
"gcovViewer.gcovBinary": "/opt/conda/envs/petsird/bin/x86_64-conda-linux-gnu-gcov",
"gcovViewer.buildDirectories": ["${workspaceFolder}/cpp/build"],

"search.useIgnoreFiles": false,
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ jobs:
- name: Python
run: |
cd python
python prd_generator.py | python prd_analysis.py
python petsird_generator.py | python petsird_analysis.py
- name: Cpp
run: |
cd cpp && mkdir -p build && cd build
cmake -G Ninja -S .. -DHDF5_ROOT="$CONDA_PREFIX"
ninja
./prd_generator test.h5
./prd_analysis test.h5
./petsird_generator test.h5
./petsird_analysis test.h5
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cpp/generated/
cpp/build/

python/prd/
python/petsird/
**/__pycache__/

# Common editor backups
Expand Down
10 changes: 5 additions & 5 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.12.0) # older would work, but could give warnings on policy CMP0074
project(prd VERSION 0.1.1)
project(petsird VERSION 0.2.0)

set(CMAKE_CXX_STANDARD 17)

Expand All @@ -9,10 +9,10 @@ else()
add_compile_options(-Wall -Wextra -pedantic)
endif()

add_executable(prd_generator prd_generator.cpp)
target_link_libraries(prd_generator prd_generated)
add_executable(petsird_generator petsird_generator.cpp)
target_link_libraries(petsird_generator petsird_generated)

add_executable(prd_analysis prd_analysis.cpp)
target_link_libraries(prd_analysis prd_generated)
add_executable(petsird_analysis petsird_analysis.cpp)
target_link_libraries(petsird_analysis petsird_generated)

add_subdirectory(generated)
4 changes: 2 additions & 2 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The C++ code shows writing to and reading from an HDF5 file
```
If you did not use `conda` to install HDF5, do not add the `-DHDF5_ROOT=$CONDA_PREFIX` part of the `cmake` line.

2. Run the generator: `./prd_generator test.h5`
3. Run the analyzer: `./prd_analysis test.h5`
2. Run the generator: `./petsird_generator test.h5`
3. Run the analyzer: `./petsird_analysis test.h5`
4. You can inspect the HDF5 file by running `h5dump test.h5`

10 changes: 5 additions & 5 deletions cpp/prd_analysis.cpp → cpp/petsird_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

#ifdef USE_HDF5
# include "generated/hdf5/protocols.h"
using prd::hdf5::PrdExperimentReader;
using petsird::hdf5::PETSIRDReader;
#else
# include "generated/binary/protocols.h"
using prd::binary::PrdExperimentReader;
using petsird::binary::PETSIRDReader;
#endif
#include <xtensor/xview.hpp>
#include <xtensor/xio.hpp>
Expand All @@ -30,8 +30,8 @@ main(int argc, char* argv[])
}

// Open the file
PrdExperimentReader reader(argv[1]);
prd::Header header;
PETSIRDReader reader(argv[1]);
petsird::Header header;
reader.ReadHeader(header);

std::cout << "Processing file: " << argv[1] << std::endl;
Expand All @@ -56,7 +56,7 @@ main(int argc, char* argv[])
/ 2;
std::cout << "Energy mid points: " << energy_mid_points << std::endl;

prd::TimeBlock time_block;
petsird::TimeBlock time_block;

// Process events in batches of up to 100
float energy_1 = 0, energy_2 = 0;
Expand Down
78 changes: 39 additions & 39 deletions cpp/prd_generator.cpp → cpp/petsird_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

#ifdef USE_HDF5
# include "generated/hdf5/protocols.h"
using prd::hdf5::PrdExperimentWriter;
using petsird::hdf5::PETSIRDWriter;
#else
# include "generated/binary/protocols.h"
using prd::binary::PrdExperimentWriter;
using petsird::binary::PETSIRDWriter;
#endif

// these are constants for now
Expand All @@ -30,28 +30,28 @@ constexpr uint32_t NUMBER_OF_TIME_BLOCKS = 6;
constexpr float COUNT_RATE = 500.F;

//! return a cuboid volume
prd::BoxSolidVolume
petsird::BoxSolidVolume
get_crystal()
{
using prd::Coordinate;
prd::BoxShape crystal_shape{ Coordinate{ { 0, 0, 0 } },
Coordinate{ { 0, 0, CRYSTAL_LENGTH[2] } },
Coordinate{ { 0, CRYSTAL_LENGTH[1], CRYSTAL_LENGTH[2] } },
Coordinate{ { 0, CRYSTAL_LENGTH[1], 0 } },
Coordinate{ { CRYSTAL_LENGTH[0], 0, 0 } },
Coordinate{ { CRYSTAL_LENGTH[0], 0, CRYSTAL_LENGTH[2] } },
Coordinate{ { CRYSTAL_LENGTH[0], CRYSTAL_LENGTH[1], CRYSTAL_LENGTH[2] } },
Coordinate{ { CRYSTAL_LENGTH[0], CRYSTAL_LENGTH[1], 0 } } };

prd::BoxSolidVolume crystal{ crystal_shape, /* material_id */ 1 };
using petsird::Coordinate;
petsird::BoxShape crystal_shape{ Coordinate{ { 0, 0, 0 } },
Coordinate{ { 0, 0, CRYSTAL_LENGTH[2] } },
Coordinate{ { 0, CRYSTAL_LENGTH[1], CRYSTAL_LENGTH[2] } },
Coordinate{ { 0, CRYSTAL_LENGTH[1], 0 } },
Coordinate{ { CRYSTAL_LENGTH[0], 0, 0 } },
Coordinate{ { CRYSTAL_LENGTH[0], 0, CRYSTAL_LENGTH[2] } },
Coordinate{ { CRYSTAL_LENGTH[0], CRYSTAL_LENGTH[1], CRYSTAL_LENGTH[2] } },
Coordinate{ { CRYSTAL_LENGTH[0], CRYSTAL_LENGTH[1], 0 } } };

petsird::BoxSolidVolume crystal{ crystal_shape, /* material_id */ 1 };
return crystal;
}

//! return a module of NUM_CRYSTALS_PER_MODULE cuboids
prd::DetectorModule
petsird::DetectorModule
get_detector_module()
{
prd::ReplicatedBoxSolidVolume rep_volume;
petsird::ReplicatedBoxSolidVolume rep_volume;
{
rep_volume.object = get_crystal();
constexpr auto N0 = NUM_CRYSTALS_PER_MODULE[0];
Expand All @@ -61,26 +61,26 @@ get_detector_module()
for (int rep1 = 0; rep1 < N1; ++rep1)
for (int rep2 = 0; rep2 < N2; ++rep2)
{
prd::RigidTransformation transform{ { { 1.0, 0.0, 0.0, RADIUS + rep0 * CRYSTAL_LENGTH[0] },
{ 0.0, 1.0, 0.0, rep1 * CRYSTAL_LENGTH[1] },
{ 0.0, 0.0, 1.0, rep2 * CRYSTAL_LENGTH[2] } } };
petsird::RigidTransformation transform{ { { 1.0, 0.0, 0.0, RADIUS + rep0 * CRYSTAL_LENGTH[0] },
{ 0.0, 1.0, 0.0, rep1 * CRYSTAL_LENGTH[1] },
{ 0.0, 0.0, 1.0, rep2 * CRYSTAL_LENGTH[2] } } };
rep_volume.transforms.push_back(transform);
rep_volume.ids.push_back(rep0 + N0 * (rep1 + N1 * rep2));
}
}

prd::DetectorModule detector_module;
petsird::DetectorModule detector_module;
detector_module.detecting_elements.push_back(rep_volume);
detector_module.detecting_element_ids.push_back(0);

return detector_module;
}

//! return scanner build by rotating a module around the (0,0,1) axis
prd::ScannerGeometry
petsird::ScannerGeometry
get_scanner_geometry()
{
prd::ReplicatedDetectorModule rep_module;
petsird::ReplicatedDetectorModule rep_module;
{
rep_module.object = get_detector_module();
int module_id = 0;
Expand All @@ -91,23 +91,23 @@ get_scanner_geometry()
}
for (auto angle : angles)
{
prd::RigidTransformation transform{ { { std::cos(angle), std::sin(angle), 0.F, 0.F },
{ -std::sin(angle), std::cos(angle), 0.F, 0.F },
{ 0.F, 0.F, 1.F, 0.F } } };
petsird::RigidTransformation transform{ { { std::cos(angle), std::sin(angle), 0.F, 0.F },
{ -std::sin(angle), std::cos(angle), 0.F, 0.F },
{ 0.F, 0.F, 1.F, 0.F } } };
rep_module.ids.push_back(module_id++);
rep_module.transforms.push_back(transform);
}
}
prd::ScannerGeometry scanner_geometry;
petsird::ScannerGeometry scanner_geometry;
scanner_geometry.replicated_modules.push_back(rep_module);
scanner_geometry.ids.push_back(0);
return scanner_geometry;
}

prd::ScannerInformation
petsird::ScannerInformation
get_scanner_info()
{
prd::ScannerInformation scanner_info;
petsird::ScannerInformation scanner_info;
scanner_info.model_name = "PETSIRD_TEST";

scanner_info.scanner_geometry = get_scanner_geometry();
Expand Down Expand Up @@ -136,18 +136,18 @@ get_scanner_info()
return scanner_info;
}

prd::Header
petsird::Header
get_header()
{
prd::Subject subject;
petsird::Subject subject;
subject.id = "123456";
prd::Institution institution;
petsird::Institution institution;
institution.name = "Diamond Light Source";
institution.address = "Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, UK";
prd::ExamInformation exam_info;
petsird::ExamInformation exam_info;
exam_info.subject = subject;
exam_info.institution = institution;
prd::Header header;
petsird::Header header;
header.exam = exam_info;
header.scanner = get_scanner_info();
return header;
Expand All @@ -174,15 +174,15 @@ get_random_tof_value()
return rand() % NUMBER_OF_TOF_BINS;
}

std::vector<prd::CoincidenceEvent>
get_events(const prd::Header&, std::size_t num_events)
std::vector<petsird::CoincidenceEvent>
get_events(const petsird::Header&, std::size_t num_events)
{
std::vector<prd::CoincidenceEvent> events;
std::vector<petsird::CoincidenceEvent> events;
events.reserve(num_events);
for (std::size_t i = 0; i < num_events; ++i)
{
const auto detectors = get_random_pair(1); // TODO header.scanner.NumberOfDetectors());
prd::CoincidenceEvent e;
petsird::CoincidenceEvent e;
e.detector_ids[0] = detectors.first;
e.detector_ids[1] = detectors.second;
e.energy_indices[0] = get_random_energy_value();
Expand All @@ -205,7 +205,7 @@ main(int argc, char* argv[])

std::string outfile = argv[1];
std::remove(outfile.c_str());
PrdExperimentWriter writer(outfile);
PETSIRDWriter writer(outfile);

const auto header = get_header();
writer.WriteHeader(header);
Expand All @@ -217,7 +217,7 @@ main(int argc, char* argv[])
std::poisson_distribution<> poisson(COUNT_RATE);
const auto num_prompts_this_block = poisson(gen);
const auto prompts_this_block = get_events(header, num_prompts_this_block);
prd::TimeBlock time_block;
petsird::TimeBlock time_block;
time_block.id = t;
time_block.prompt_events = prompts_this_block;
writer.WriteTimeBlocks(time_block);
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: prd
name: petsird
channels:
- conda-forge
- defaults
Expand Down
2 changes: 1 addition & 1 deletion model/Protocol.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Definition of the stream of data
PrdExperiment: !protocol
PETSIRD: !protocol
sequence:
header: Header
timeBlocks: !stream
Expand Down
2 changes: 1 addition & 1 deletion model/_package.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace: Prd
namespace: PETSIRD

cpp:
sourcesOutputDir: ../cpp/generated
Expand Down
6 changes: 3 additions & 3 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ The Python code shows piping the compact binary format to standard out and
reading it from standard in. This can be used as follows:

1. From the repo root `cd python`
1. `python prd_generator.py | python prd_analysis.py`
1. `python petsird_generator.py | python petsird_analysis.py`

There is also a very basic utility to plot the scanner geometry. For instance
```
python prd_generator.py > test.bin
python prd_plot_scanner.py < test.bin`
python petsird_generator.py > test.bin
python petsird_plot_scanner.py < test.bin`
4 changes: 2 additions & 2 deletions python/prd_analysis.py → python/petsird_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import sys
import numpy
import prd
import petsird


if __name__ == "__main__":
with prd.BinaryPrdExperimentReader(sys.stdin.buffer) as reader:
with petsird.BinaryPETSIRDReader(sys.stdin.buffer) as reader:
header = reader.read_header()
print(f"Subject ID: {header.exam.subject.id}")
print(f"Scanner name: { header.scanner.model_name}")
Expand Down
Loading

0 comments on commit 4c29bca

Please sign in to comment.