From 693afaaaab78cc049df9d0526ab0e624af0d4db6 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 13 Nov 2024 19:00:57 +0000 Subject: [PATCH] move helpers - fixes #70 --- .github/workflows/ci.yml | 2 +- python/README.md | 9 +++++---- .../{petsird_helpers.py => petsird/helpers/__init__.py} | 0 .../{petsird_analysis.py => petsird/helpers/analysis.py} | 5 ++--- .../helpers/generator.py} | 4 ++-- .../helpers/plot_scanner.py} | 1 - 6 files changed, 10 insertions(+), 11 deletions(-) rename python/{petsird_helpers.py => petsird/helpers/__init__.py} (100%) rename python/{petsird_analysis.py => petsird/helpers/analysis.py} (96%) rename python/{petsird_generator.py => petsird/helpers/generator.py} (99%) rename python/{petsird_plot_scanner.py => petsird/helpers/plot_scanner.py} (99%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d9762e..ab864dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: - name: Python run: | cd python - python petsird_generator.py | python petsird_analysis.py + python -m petsird.helpers.generator | python -m petsird.helpers.analysis - name: cpp run: | mkdir cpp/build diff --git a/python/README.md b/python/README.md index e4eba3f..8697768 100644 --- a/python/README.md +++ b/python/README.md @@ -30,12 +30,13 @@ pip install --editable ../python 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 petsird_generator.py | python petsird_analysis.py` +```sh +python -m petsird.helpers.generator | python -m petsird.helpers.analysis +``` There is also a very basic utility to plot the scanner geometry. For instance ```sh -python petsird_generator.py > test.bin -python petsird_plot_scanner.py < test.bin +python -m petsird.helpers.generator > test.bin +python -m petsird.helpers.plot_scanner < test.bin ``` diff --git a/python/petsird_helpers.py b/python/petsird/helpers/__init__.py similarity index 100% rename from python/petsird_helpers.py rename to python/petsird/helpers/__init__.py diff --git a/python/petsird_analysis.py b/python/petsird/helpers/analysis.py similarity index 96% rename from python/petsird_analysis.py rename to python/petsird/helpers/analysis.py index de09238..799d834 100644 --- a/python/petsird_analysis.py +++ b/python/petsird/helpers/analysis.py @@ -2,12 +2,11 @@ # Copyright (C) 2023-2024 University College London # # SPDX-License-Identifier: Apache-2.0 - import sys import petsird -from petsird_helpers import (get_detection_efficiency, get_module_and_element, - get_num_det_els) + +from . import get_detection_efficiency, get_module_and_element, get_num_det_els if __name__ == "__main__": with petsird.BinaryPETSIRDReader(sys.stdin.buffer) as reader: diff --git a/python/petsird_generator.py b/python/petsird/helpers/generator.py similarity index 99% rename from python/petsird_generator.py rename to python/petsird/helpers/generator.py index 9c89876..4262ee6 100644 --- a/python/petsird_generator.py +++ b/python/petsird/helpers/generator.py @@ -2,7 +2,6 @@ # Copyright (C) 2023-2024 University College London # # SPDX-License-Identifier: Apache-2.0 - import math import random import sys @@ -10,7 +9,8 @@ import numpy import petsird -from petsird_helpers import get_module_and_element, get_num_det_els + +from . import get_module_and_element, get_num_det_els # these are constants for now NUMBER_OF_ENERGY_BINS = 3 diff --git a/python/petsird_plot_scanner.py b/python/petsird/helpers/plot_scanner.py similarity index 99% rename from python/petsird_plot_scanner.py rename to python/petsird/helpers/plot_scanner.py index f44d56c..3460cf9 100644 --- a/python/petsird_plot_scanner.py +++ b/python/petsird/helpers/plot_scanner.py @@ -4,7 +4,6 @@ # basic plotting of the scanner geometry # preliminary code! - import sys import matplotlib.pyplot as plt