Skip to content

reading of PETSIRD list-mode function#1604

Open
KrisThielemans wants to merge 10 commits into
masterfrom
PETSIRD
Open

reading of PETSIRD list-mode function#1604
KrisThielemans wants to merge 10 commits into
masterfrom
PETSIRD

Conversation

@KrisThielemans

@KrisThielemans KrisThielemans commented Jul 16, 2025

Copy link
Copy Markdown
Collaborator

Adding support for PETSIRD.

Warning: this changes SAFIR reading (although we think it should be safe), as we lifted a lot of its code to a new class CListModeDataBasedOnCoordinateMap

To be able to test with existing PETSIRD files, @NikEfth also added support for even number of TOF bins. So...
Fixes #1333

@KrisThielemans KrisThielemans self-assigned this Jul 16, 2025
@NikEfth

NikEfth commented Dec 10, 2025

Copy link
Copy Markdown
Collaborator

Made some progress today:

  • Automatically detect BlocksOnCylindrical geometry and reconstruct with OSEM25 (1 full iteration):
Screenshot 2025-12-10 at 21 16 53

@NikEfth

NikEfth commented Dec 17, 2025

Copy link
Copy Markdown
Collaborator

PETSIRD requires additional dependencies (yardl, pinned xtensor) that are not part of STIR’s standard CI environment.
The following PR therefore adds an optional, isolated CI workflow that validates PETSIRD builds without impacting existing CI jobs.

@NikEfth

NikEfth commented Dec 17, 2025

Copy link
Copy Markdown
Collaborator

There is a problem with the TOF tests. Very likely, this happened because in this PR I allowed the use of an even number of TOF bins (because my PETSIRD files had an even number). I may have overlooked something regarding the odd number (default in the tests).

@NikEfth NikEfth requested a review from Copilot December 18, 2025 17:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces initial support for reading PETSIRD (PET Standard for Image Reconstruction and Data) list-mode files into STIR. The work includes scanner geometry inference, coordinate mapping, and the necessary infrastructure to handle PETSIRD data formats (both HDF5 and binary).

  • Adds PETSIRD submodule integration with CMake configuration
  • Implements PETSIRD list-mode data reader with automatic scanner geometry detection
  • Refactors SAFIR list-mode classes to share common base functionality
  • Includes TOF handling improvements for even-numbered TOF bins

Reviewed changes

Copilot reviewed 35 out of 36 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
CMakeLists.txt Adds PETSIRD as optional dependency with submodule management
src/buildblock/PETSIRDInfo.cxx Core geometry inference logic for PETSIRD scanners
src/listmode_buildblock/CListModeDataPETSIRD.cxx Main PETSIRD list-mode reader implementation
src/include/stir/listmode/CListModeDataBasedOnCoordinateMap.h New base class for coordinate-mapped list-mode data
src/buildblock/ProjDataInfo.cxx Refactored TOF mash factor logic with even bin support
src/include/stir/ProjDataInfoCylindricalNoArcCorr.inl Fixed TOF bin mapping for even TOF bins
src/IO/PETSIRDCListmodeInputFileFormat.cxx File format detection for PETSIRD files
.github/workflows/build-test.yml CI updates to disable PETSIRD in existing tests
Comments suppressed due to low confidence (4)

src/recon_buildblock/find_basic_vs_nums_in_subset.cxx:1

  • The commented-out loop and loose braces suggest incomplete refactoring. Either remove the commented code or complete the intended changes to maintain code clarity.
    src/recon_buildblock/find_basic_vs_nums_in_subset.cxx:1
  • Debug print statements should be removed before merging. These commented-out std::cout calls are leftover debugging code that clutters the source.
    src/include/stir/listmode/CListModeDataBasedOnCoordinateMap.h:1
  • File header comment references wrong class. This header is for CListModeDataBasedOnCoordinateMap, not CListModeDataSAFIR.
/* CListModeDataSAFIR.h

CMakeLists.txt:1

  • All optional dependencies have been changed from OFF to ON (disabled by default). This appears to be a temporary development change that should not be merged. These defaults would break existing functionality for other users.
# This file is part of STIR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/listmode_buildblock/CListModeDataSAFIR.cxx Outdated
Comment thread src/listmode_buildblock/CListModeDataPETSIRD.cxx Outdated
Comment thread src/listmode_buildblock/CListModeDataPETSIRD.cxx Outdated
Comment thread src/listmode_buildblock/CListModeDataPETSIRD.cxx Outdated
Comment thread src/listmode_buildblock/CListModeDataPETSIRD.cxx Outdated
Comment thread src/include/stir/IO/PETSIRDCListmodeInputFileFormat.h Outdated
Comment thread src/buildblock/PETSIRDInfo.cxx Outdated
Comment thread src/buildblock/PETSIRDInfo.cxx Outdated
Comment thread src/buildblock/PETSIRDInfo.cxx Outdated
Comment thread src/IO/CMakeLists.txt Outdated

Copilot AI commented Dec 19, 2025

Copy link
Copy Markdown

@NikEfth I've opened a new pull request, #1671, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Dec 19, 2025

Copy link
Copy Markdown

@NikEfth I've opened a new pull request, #1672, to work on those changes. Once the pull request is ready, I'll request review from you.

@NikEfth

NikEfth commented Dec 20, 2025

Copy link
Copy Markdown
Collaborator

Introduce PETSIRDInfo as a dataset-level integration object for PETSIRD
listmode support and refactor PETSIRD listmode classes to align with
STIR’s CListRecord / CListEvent design.

PETSIRDInfo encapsulates all PETSIRD-specific static information needed
by STIR, including:

  • PETSIRD ScannerInformation and optional Header metadata
  • construction of the corresponding STIR Scanner geometry
  • mapping from PETSIRD ExpandedDetectionBins to STIR DetectionPositions
  • optional forced geometry selection (cylindrical vs block)

PETSIRDInfo is immutable after construction and shared via
shared_ptr by all PETSIRD-related components
(CListModeDataPETSIRD, CListEventPETSIRD, normalisation, etc.), providing
a single source of truth for PETSIRD → STIR interpretation.

The PETSIRD listmode implementation was updated accordingly:

  • CListModeDataPETSIRD now owns PETSIRDInfo and exposes it read-only
  • CListRecordPETSIRD remains a storage container and embeds
    CListEventPETSIRD, following existing STIR patterns
  • CListEventPETSIRD stores raw PETSIRD coincidence data and performs
    PETSIRD expansion and geometry mapping on demand using PETSIRDInfo
  • PETSIRD expansion and STIR bin mapping are kept out of the record layer

These changes preserve STIR’s separation of concerns, avoid PETSIRD
logic leaking into core reconstruction code, and allow PETSIRD geometry
and metadata to be reused consistently by listmode, IO, and
normalisation components.

@NikEfth NikEfth marked this pull request as ready for review December 22, 2025 14:34
@NikEfth NikEfth marked this pull request as draft December 23, 2025 08:38

@KrisThielemans KrisThielemans left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly clean. thanks! A lot of my comments are housekeeping, but there are some important ones. Major thing is to keep this PR separate from other things (I won't accept this PR with them...), for example:

  • there are some changes here for set_proj_data_info which probably came from another PR. Maybe they'll disappear when you merge master here
  • there are changes here to cope with even number of TOF bins. They might be good, but it doesn't have anything to do with PETSIRD.
  • there's some changes in find_basic_vs_nums... which don't belong here
  • I see no reason to make InputFormat::can_read non-const. If this is really required for PETSIRD, please explain. We should then work around it.

I guess the BinNormalisation isn't finished yet. I would suggest we currently call error and do it in a separate PR.

Comment thread .github/workflows/build-petsird-stir.yml Outdated
Comment thread src/buildblock/PETSIRDInfo.cxx Outdated
Comment thread src/buildblock/PETSIRDInfo.cxx Outdated
Comment thread src/buildblock/PETSIRDInfo.cxx Outdated
Comment thread src/buildblock/PETSIRDInfo.cxx Outdated
Comment thread src/recon_test/test_blocks_on_cylindrical_projectors.cxx Outdated
Comment thread src/swig/Makefile Outdated
Comment thread .travis.yml Outdated
Comment thread CMakeLists.txt Outdated
Comment thread .appveyor.yml Outdated
@KrisThielemans

KrisThielemans commented Mar 4, 2026 via email

Copy link
Copy Markdown
Collaborator Author

Comment thread src/test/test_PETSIRDInfo_helpers.cxx Outdated

@NikEfth NikEfth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[x] there are some changes here for set_proj_data_info which probably came from another PR. Maybe they'll disappear when you merge master here

  • Merged with master is fine now.

[ x] there are changes here to cope with even number of TOF bins. They might be good, but it doesn't have anything to do with PETSIRD.

  • I know. But I had to make them as the data shared by people in the hackathon had even number of bins. If you you want to compare with that we need these changes here. I can document more.

[x] there's some changes in find_basic_vs_nums... which don't belong here

  • Yes that code doesn't do anything atm.

[x] I see no reason to make InputFormat::can_read non-const. If this is really required for PETSIRD, please explain. We should then work around it.

  • Done

[x] I guess the BinNormalisation isn't finished yet. I would suggest we currently call error and do it in a separate PR.

  • No it is finished. Unless you have comments.

Comment on lines +20 to +21
- Mat3: std::array<std::array<float,3>,3> for compact fixed-size storage.
- Vec3: std::array<float,3> for simple 3D vectors.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I started a bit of this. From the test_ . It won't be hard.

Comment thread src/include/stir/listmode/CListModeDataSAFIR.h
Comment thread src/include/stir/ProjDataInfoCylindricalNoArcCorr.inl
Comment thread src/listmode_buildblock/CListModeDataPETSIRD.cxx Outdated
Comment thread src/recon_buildblock/find_basic_vs_nums_in_subset.cxx Outdated
@NikEfth NikEfth marked this pull request as ready for review March 20, 2026 13:04

@KrisThielemans KrisThielemans left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some other clean-up suggestions

Comment thread src/include/stir/ArrayFunction.inl Outdated
Comment thread src/include/stir/ArrayFunction.inl Outdated
Comment thread src/listmode_buildblock/CListModeDataBasedOnCoordinateMap.cxx Outdated
Comment thread src/listmode_buildblock/CListModeDataBasedOnCoordinateMap.cxx Outdated
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt
Comment thread src/include/stir/listmode/CListModeDataSAFIR.h Outdated
Comment thread src/include/stir/listmode/CListModeDataBasedOnCoordinateMap.h Outdated

@NikEfth NikEfth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all done

@NikEfth

NikEfth commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

Do you want the PETSIRDInfo_helpers with stir::Arrays?

@codacy-production

codacy-production Bot commented May 22, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 minor

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
BestPractice 1 minor

View in Codacy

🟢 Metrics 225 complexity · 8 duplication

Metric Results
Complexity 225
Duplication 8

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@NikEfth

NikEfth commented May 28, 2026

Copy link
Copy Markdown
Collaborator

@casperdcl This is the PR

Comment thread src/include/stir/ArrayFunction.inl Outdated
Comment thread src/include/stir/ProjDataInfoCylindricalNoArcCorr.inl
Comment thread CMakeLists.txt Outdated
Comment thread src/include/stir/listmode/CListModeDataBasedOnCoordinateMap.h Outdated
Comment thread src/include/stir/listmode/CListModeDataPETSIRD.h
Comment thread src/listmode_buildblock/CListModeDataBasedOnCoordinateMap.cxx Outdated
Comment thread src/include/stir/PETSIRDInfo.h Outdated
Comment thread src/include/stir/PETSIRDInfo.h

@KrisThielemans KrisThielemans left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like CI is working! Great. (The MacOS job fails because of too much stuff in .h/.inl, see previous review).

Comment thread .github/workflows/build-test.yml
Comment thread .github/workflows/build-test.yml Outdated
Comment thread .github/workflows/build-test.yml Outdated
Comment thread .github/workflows/build-test.yml Outdated
Comment thread .github/workflows/build-test.yml Outdated
@NikEfth

NikEfth commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Hi, I wanted to replace the std::arrays with STIR Arrays but I don't have the time to do it now. I will come back to this later, but you can merge if you are happy with the rest.

Comment thread .github/workflows/build-test.yml Outdated
Comment thread src/include/stir/IO/PETSIRDCListmodeInputFileFormat.h Outdated
Comment thread src/include/stir/PETSIRDInfo.h
@NikEfth

NikEfth commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

I tried the interactive rebase, but it introduces a lot of old code and mege conflicts

@KrisThielemans

Copy link
Copy Markdown
Collaborator Author

please don't push that!

@NikEfth

NikEfth commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

which one? The interactive rebase? Sure :) any other advice?

@KrisThielemans

Copy link
Copy Markdown
Collaborator Author

The trick would be to interactive rebase on the commit that we branched off from (not on master).

@jonc125

jonc125 commented Jun 17, 2026

Copy link
Copy Markdown
Member

I want to flag for you that the macOS builds here are (since 15 May) consuming the free Actions budget we have available in the UCL organisation, because even though this is a public repo the use of larger runners is always charged for. The budget for June has now been used up. Could you look into doing fewer Mac builds or reducing the build time?

@jonc125

jonc125 commented Jun 18, 2026

Copy link
Copy Markdown
Member

I want to flag for you that the macOS builds here are (since 15 May) consuming the free Actions budget we have available in the UCL organisation, because even though this is a public repo the use of larger runners is always charged for. The budget for June has now been used up. Could you look into doing fewer Mac builds or reducing the build time?

It appears this was a false alarm: despite GitHub's web UI reporting this repository as the biggest consumer of our actions budget, actually the runners used are free and don't count towards the limit. It was actually a couple of other private repositories that don't even make the top 10 overall users that were consuming the limited budget! But you have to look at the raw data rather than any of the dashboards to be able to tell that...

@KrisThielemans

Copy link
Copy Markdown
Collaborator Author

Thanks @jonc125!

In any case, there's a good message here that we should be careful in pushing to Github. Small commits use computing resources that should be used elsewhere.

@codacy-production

codacy-production Bot commented Jun 19, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 minor

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
BestPractice 1 minor

View in Codacy

🟢 Metrics 232 complexity · 8 duplication

Metric Results
Complexity 232
Duplication 8

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@NikEfth

NikEfth commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

@KrisThielemans I don't think I can clean up the history more. At 220bec9e4b242741a668d726707036d18829cec6 I merged with the master and every time I try to rebase beyond that point I get many conficts.
Any advice?

if (num_tof_bins % 2 == 0)
error("ProjDataInfo: Number of TOF bins should be an odd number. Abort.");
const int num_mashed_bins = max_timing_poss / tof_mash_factor;
num_tof_bins = num_mashed_bins;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you fix this?

BinNormalisationFromPETSIRD::read_norm_data(const string& filename)
{
petsird::Header header;
petsird_data_sptr.reset(new petsird::binary::PETSIRDReader(filename));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess cope with HDF5

Comment thread src/recon_buildblock/find_basic_vs_nums_in_subset.cxx Outdated
Comment thread src/listmode_buildblock/CListModeDataSAFIR.cxx Outdated
@KrisThielemans

Copy link
Copy Markdown
Collaborator Author

Looks like we're green, and only 2 comments left! However, i haven't actually run this.

It'd be great to add a test like

  1. run STIR2PETSIRD on mMR or ROOT data
  2. read PETSIRD file with STIR
  3. compare with original

However, this is probably non-trivial due to the possibility of different coordinates/order. @NikEfth what do you think?

@KrisThielemans

Copy link
Copy Markdown
Collaborator Author

well, at least I hope it's green now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TOF: need to support even number of TOF bins and TOF_mashing_factor

7 participants