Skip to content

Commit

Permalink
LM recon notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepolson committed Nov 14, 2023
1 parent eb07652 commit 5a68175
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
Binary file added python/data.bin
Binary file not shown.
Binary file added python/paraproj_data.bin
Binary file not shown.
155 changes: 155 additions & 0 deletions python/prd_test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append('../PETSIRD/python')\n",
"import numpy as np\n",
"import prd\n",
"from io import BytesIO\n",
"from prd.types import TimeBlock, CoincidenceEvent"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generate fake data to convert to PETSIRD"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Part 1: Python dtypes to PETSIRD format"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"N_events = 7 # Number of detected events\n",
"N_detectors = 10 # Number of detectors\n",
"counts = np.random.poisson(np.ones(N_events)*3)\n",
"detectors1 = np.random.choice(np.arange(N_detectors), N_events)\n",
"detectors2 = np.random.choice(np.arange(N_detectors), N_events)\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"events = []\n",
"for count, detector1, detector2 in zip(counts, detectors1, detectors2):\n",
" for _ in range(count):\n",
" events.append(CoincidenceEvent(detector_1_id=int(detector1), detector_2_id=int(detector2)))\n",
"time_block = TimeBlock(id=0, prompt_events=events)\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"with prd.BinaryPrdExperimentWriter('data.bin') as writer:\n",
" writer.write_header(prd.Header())\n",
" writer.write_time_blocks(\n",
" (time_block,)\n",
" )\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"with open('data.bin', 'rb') as f:\n",
" data = f.read()\n",
" with prd.BinaryPrdExperimentReader(BytesIO(data)) as reader:\n",
" header = reader.read_header()\n",
" time_blocks = [t for t in reader.read_time_blocks()]\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Part 2: PETSIRD to python dtypes for recon"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"with open('data.bin', 'rb') as f:\n",
" data = f.read()\n",
" with prd.BinaryPrdExperimentReader(BytesIO(data)) as reader:\n",
" header = reader.read_header()\n",
" time_blocks = [t for t in reader.read_time_blocks()]\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[TimeBlock(id=0, promptEvents=[CoincidenceEvent(detector1Id=5, detector2Id=2, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=5, detector2Id=2, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=5, detector2Id=2, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=2, detector2Id=4, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=2, detector2Id=4, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=2, detector2Id=4, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=7, detector2Id=5, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=7, detector2Id=5, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=2, detector2Id=3, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=4, detector2Id=8, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=4, detector2Id=8, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=4, detector2Id=8, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=4, detector2Id=8, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=4, detector2Id=8, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=4, detector2Id=8, tofIdx=0, energy1Idx=0, energy2Idx=0), CoincidenceEvent(detector1Id=4, detector2Id=8, tofIdx=0, energy1Idx=0, energy2Idx=0)], delayedEvents=None)]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"time_blocks\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "prd",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 5a68175

Please sign in to comment.