{ "cells": [ { "cell_type": "code", "execution_count": 22, "id": "1da1e1c8-1f5a-4c9e-aa4a-1baaa8c71df1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "loadLibrary\n", "remoteSourcesURL https://git0.fmf.uni-lj.si/studen/nixSuite/raw/master/remoteResources/resources.json\n", "{'labkeyInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/labkeyInterface/archive/master.zip', 'branch': 'master', 'modules': []}, 'irAEMM': {'url': 'https://git0.fmf.uni-lj.si/studen/iraemm/archive/master.zip', 'branch': 'master', 'modules': ['iraemmBrowser']}, 'SlicerLabkeyExtension': {'url': 'https://git0.fmf.uni-lj.si/studen/SlicerLabkeyExtension/archive/SlicerExtensionIndex.zip', 'branch': 'SlicerExtensionIndex', 'modules': ['labkeyBrowser']}, 'limfomiPET': {'url': 'https://git0.fmf.uni-lj.si/studen/limfomiPET/archive/master.zip', 'branch': 'master', 'modules': ['imageBrowser', 'segmentationBrowser']}, 'parseConfig': {'url': 'https://git0.fmf.uni-lj.si/studen/parseConfig/archive/master.zip', 'branch': 'master', 'modules': []}, 'orthancInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/orthancInterface/archive/master.zip', 'branch': 'master', 'modules': []}, 'dynamicSPECT': {'url': 'https://git0.fmf.uni-lj.si/studen/dynamicSPECT/archive/master.zip', 'branch': 'master', 'modules': ['imageBrowser']}}\n", "{'url': 'https://git0.fmf.uni-lj.si/studen/labkeyInterface/archive/master.zip', 'branch': 'master', 'modules': []}\n", "File C:\\Users\\studen\\temp\\labkeyInterface.zip: True\n", "loadLibrary\n", "remoteSourcesURL https://git0.fmf.uni-lj.si/studen/nixSuite/raw/master/remoteResources/resources.json\n", "{'labkeyInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/labkeyInterface/archive/master.zip', 'branch': 'master', 'modules': []}, 'irAEMM': {'url': 'https://git0.fmf.uni-lj.si/studen/iraemm/archive/master.zip', 'branch': 'master', 'modules': ['iraemmBrowser']}, 'SlicerLabkeyExtension': {'url': 'https://git0.fmf.uni-lj.si/studen/SlicerLabkeyExtension/archive/SlicerExtensionIndex.zip', 'branch': 'SlicerExtensionIndex', 'modules': ['labkeyBrowser']}, 'limfomiPET': {'url': 'https://git0.fmf.uni-lj.si/studen/limfomiPET/archive/master.zip', 'branch': 'master', 'modules': ['imageBrowser', 'segmentationBrowser']}, 'parseConfig': {'url': 'https://git0.fmf.uni-lj.si/studen/parseConfig/archive/master.zip', 'branch': 'master', 'modules': []}, 'orthancInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/orthancInterface/archive/master.zip', 'branch': 'master', 'modules': []}, 'dynamicSPECT': {'url': 'https://git0.fmf.uni-lj.si/studen/dynamicSPECT/archive/master.zip', 'branch': 'master', 'modules': ['imageBrowser']}}\n", "{'url': 'https://git0.fmf.uni-lj.si/studen/orthancInterface/archive/master.zip', 'branch': 'master', 'modules': []}\n", "File C:\\Users\\studen\\temp\\orthancInterface.zip: True\n" ] } ], "source": [ "import sys\n", "import os\n", "import importlib\n", "import numpy\n", "import random\n", "\n", "nixSuite=os.path.join(os.path.expanduser('~'),'software','src','nixSuite')\n", "sys.path.append(os.path.join(nixSuite,'wrapper'))\n", "import nixWrapper\n", "nixWrapper.loadLibrary('labkeyInterface')\n", "import labkeyInterface\n", "import labkeyDatabaseBrowser\n", "import labkeyFileBrowser\n", "\n", "\n", "nixWrapper.loadLibrary('orthancInterface')\n", "import orthancInterface\n", "import orthancDatabaseBrowser\n", "import orthancFileBrowser" ] }, { "cell_type": "code", "execution_count": 17, "id": "40fce609-1142-4746-a912-70481ff809be", "metadata": {}, "outputs": [], "source": [ "def initDB(site,returnFB=False):\n", " net=labkeyInterface.labkeyInterface()\n", " fconfig=os.path.join(os.path.expanduser('~'),'.labkey','{}.json'.format(site))\n", " net.init(fconfig)\n", " net.getCSRF()\n", " if not returnFB:\n", " return labkeyDatabaseBrowser.labkeyDB(net)\n", " return labkeyDatabaseBrowser.labkeyDB(net),labkeyFileBrowser.labkeyFileBrowser(net)\n", "\n", "def initOrthanc(site,returnFB=False):\n", " net=orthancInterface.orthancInterface()\n", " fconfig=os.path.join(os.path.expanduser('~'),'.labkey','{}.json'.format(site))\n", " net.init(fconfig)\n", " if not returnFB:\n", " return orthancDatabaseBrowser.orthancDB(net)\n", " return orthancDatabaseBrowser.orthancDB(net),orthancFileBrowser.orthancFileBrowser(net)\n", "\n" ] }, { "cell_type": "code", "execution_count": 18, "id": "e7386af6-7b00-4607-a05e-5581db804869", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "User: andrej studen CSRF: 9b381ce234d4a838c53c6f93dab2f5a7\n" ] } ], "source": [ "db,fb=initDB('onko-nix',returnFB=True)\n", "odb,ofb=initOrthanc('onko-nix',returnFB=True)" ] }, { "cell_type": "code", "execution_count": 69, "id": "5910e7dd-de77-4260-a23a-78e2a6baabb4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[-592.9801940917969, -867.9606628417969, -2823.0]\n", "[-1644.0222664799999, -2395.3331437499996, -4710.0]\n" ] } ], "source": [ "def parsePos(x):\n", " return [float(y) for y in x.split('\\\\')]\n", "\n", "def parseOrientation(x):\n", " z=[float(y) for y in x.split('\\\\')]\n", " O=[z[0:3],z[3:6]]\n", " O.append(list(numpy.cross(numpy.array(O[0]),numpy.array(O[1]))))\n", " return O\n", "\n", "def getGeometry(code,odb,seriesId):\n", " #imagepositionpatient 0020-0032\n", " #imageorientationpatient 0020-0037\n", " #pixelSpacing 0028-0030\n", " #instance number 0020-0013\n", " #sliceThickness 0018-0050\n", " \n", " sd=odb.getData('series',seriesId)\n", " firstId=sd['Instances'][0] \n", " \n", " #check to see if orientation changes (it doesn't)\n", " #ior=[odb.getDicomField(y,'0020-0037') for y in sd[x]['Instances']] \n", " #same=all(y==ior[0] for y in ior)\n", " #print(same)\n", " \n", " #check to see if pixel spacing changes (it doesn't)\n", " #ips=[odb.getDicomField(y,'0028-0030') for y in sd['Instances']] \n", " #same=all(y==ips[0] for y in ips)\n", " #print(same)\n", " \n", " #check to see if sliceThickness changes (it doesn't)\n", " #ist=[odb.getDicomField(y,'0018-0050') for y in sd['Instances']]\n", " #same=all(y==ist[0] for y in ist)\n", " #print(same)\n", " \n", " ior=parseOrientation(odb.getDicomField(firstId,'0020-0037'))\n", " ips=parsePos(odb.getDicomField(firstId,'0028-0030'))\n", " ist=parsePos(odb.getDicomField(firstId,'0018-0050')) \n", " ips.append(ist[0])\n", " \n", " for y in range(3):\n", " ior[y]=[ips[y]*w for w in ior[y]]\n", " \n", " \n", " ipos=[parsePos(odb.getDicomField(y,'0020-0032')) for y in sd['Instances']] \n", " m=[[numpy.dot(numpy.array(v),numpy.array(x)) for x in ipos] for v in ior]\n", " m=[numpy.min(numpy.array(x)) for x in m]\n", " print(m) \n", " \n", " return {f'{code}origin':m,f'{code}orientation':ior}\n", " \n", " \n", " \n", "def getFile(db,odb):\n", " project='/iPNUMMretro/Study'\n", " schema='study'\n", " query='Imaging1'\n", " coreDir=os.path.join(os.path.expanduser('~'),'temp')\n", " ds=db.selectRows(project,schema,query,[])\n", " rows=ds['rows'][0:1]\n", " imgs={'CT':'CT_orthancId','PET':'PETWB_orthancId'}\n", " for r in rows:\n", " code=r['pseudoCode']\n", " doUpdate=False\n", " if not code:\n", " code='{:16x}'.format(random.randrange(16**16))\n", " r['pseudoCode']=code\n", " doUpdate=True\n", " \n", " fname=os.path.join(coreDir,f'{code}.npz')\n", " arr={}\n", " arr.update({x:numpy.load(odb.getNumpy('series',r[imgs[x]])) for x in imgs})\n", " igeo={x:getGeometry(x,odb,r[imgs[x]]) for x in imgs}\n", " _={arr.update(igeo[x]) for x in igeo}\n", " #print(arr)\n", " \n", " \n", " numpy.savez_compressed(fname,**arr)\n", " if doUpdate:\n", " db.modifyRows('update',project,schema,query,[r])\n", " \n", "getFile(db,odb)\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "05cb025f-1c44-4ddf-b859-8b8e9d2584a6", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.9.0" } }, "nbformat": 4, "nbformat_minor": 5 }