{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/lib/python3/dist-packages/urllib3/connection.py:391: SubjectAltNameWarning: Certificate for merlin.fmf.uni-lj.si has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/urllib3/urllib3/issues/497 for details.)\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "User: andrej studen CSRF: 4d08323bbd1605f86108a60a9d40db20\n" ] } ], "source": [ "import sys\n", "import os\n", "import SimpleITK\n", "import numpy\n", "import matplotlib.pyplot\n", "sys.path.append(os.path.join(os.path.expanduser('~'),'software','src','nixSuite','wrapper'))\n", "import nixWrapper\n", "nixWrapper.loadLibrary('labkeyInterface')\n", "import labkeyInterface\n", "net=labkeyInterface.labkeyInterface()\n", "fconfig=os.path.join(os.path.expanduser('~'),'.labkey','network.json')\n", "net.init(fconfig)\n", "net.getCSRF()\n", "import labkeyFileBrowser\n", "sys.path.append(os.getcwd())\n", "import downloadPatient\n", "fb=labkeyFileBrowser.labkeyFileBrowser(net)\n", "project='dinamic_spect/Patients'\n", "locDir=os.path.join(os.path.expanduser('~'),'temp','dynamicSPECT')\n", "import labkeyDatabaseBrowser\n", "db=labkeyDatabaseBrowser.labkeyDB(net)\n", "\n" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [], "source": [ "def averageK1(db,regionId):\n", " regionSelect={'variable':'regionId','value':str(regionId),'oper':'eq'}\n", " classSelect={'variable':'nclass','value':str(c),'oper':'eq'}\n", " ds=db.selectRows(project,'study','ImagingData',[classSelect,regionSelect])\n", " patients=list(set([r['PatientId'] for r in ds['rows']]))\n", "\n", " k1MAll=[]\n", " k1OAll=[]\n", " for p in patients:\n", " k1M=[]\n", " k1O=[]\n", "\n", " patientFilter={'variable':'PatientId','value':p,'oper':'eq'}\n", " ds=db.selectRows(project,'study','ImagingData',[patientFilter,regionSelect])\n", " for r in ds['rows']:\n", " k1M.append(r['k1MIRMedian'])\n", " k1O.append(r['k1OBRMedian'])\n", " vM=numpy.median(k1M)\n", " #print('{} {}'.format(vM,k1M))\n", " #print('{} {}'.format(numpy.median(k1M),numpy.std(k1M)))\n", " vO=numpy.median(k1O)\n", " print('[{}/{}] {} {}'.format(p,regionId,vO,k1O))\n", " #print('{} {}'.format(numpy.median(k1O),numpy.std(k1O)))\n", " k1MAll.append(vM)\n", " k1OAll.append(vO)\n", " return k1MAll,k1OAll\n", " \n" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[7TM/1] 0.008045887022546614 [0.008045887022546614, 0.004483481665888348, 2.1286405607228596]\n", "[10KF/1] 0.0039462171230090675 [0.0039462171230090675, 0.00415070155114901, 0.0031446075367390323]\n", "[11ZM/1] 0.0025240576597139624 [0.00312436925868039, 0.0025240576597139624, 0.002142209448394668]\n", "[2SB/1] 0.010642740867635697 [0.03745862838837244, 0.010642740867635697, 0.010028953831119597]\n", "[5MI/1] 0.00888906341063412 [0.008304194640398289, 0.00888906341063412, 0.0091936110897083]\n", "[3ZF/1] 0.26867647983040466 [0.38591675611767157, 0.26867647983040466, 0.17709045381913846]\n", "[0.005894665958762989, 0.004668591303813753, 0.002949742733330378, 0.011751648013763579, 0.008162106616002189, 0.00511268572208257]\n", "[0.008045887022546614, 0.0039462171230090675, 0.0025240576597139624, 0.010642740867635697, 0.00888906341063412, 0.26867647983040466]\n", "[7TM/2] 0.0017372501091852122 [0.0017372501091852122, 0.001675933130699284, 0.19584171785850896]\n", "[10KF/2] 8.259213311648866e-05 [9.282359403286088e-06, 0.002221889457124819, 8.259213311648866e-05]\n", "[11ZM/2] 0.0021371243829022488 [0.0021470477401390694, 0.0021371243829022488, 0.0017499690427985907]\n", "[2SB/2] 0.003306368767070012 [0.003866263540421745, 0.003306368767070012, 0.0029943594109714824]\n", "[5MI/2] 0.005177206176626878 [0.005017774180493417, 0.005601704036412694, 0.005177206176626878]\n", "[3ZF/2] 0.004304534377883605 [0.003885393241151492, 0.005233206242833382, 0.004304534377883605]\n", "[0.0032749453662799595, 0.0028943546543249484, 0.001871871695075595, 0.003855121335050874, 0.004535002996260104, 0.002431672607075657]\n", "[0.0017372501091852122, 8.259213311648866e-05, 0.0021371243829022488, 0.003306368767070012, 0.005177206176626878, 0.004304534377883605]\n", "[7TM/3] 0.0024026106630740326 [0.0024026106630740326, 0.0020285709174733724, 0.7314645007711776]\n", "[10KF/3] 0.0015306808132398398 [0.0018703063484711772, 0.0015306808132398398, 0.0012136425939998793]\n", "[11ZM/3] 0.003917784910452867 [0.003917784910452867, 0.004195671684134263, 0.0030221084430817322]\n", "[2SB/3] 0.0018769599381238148 [0.0018769599381238148, 0.0019454598760022081, 0.0017322417901848254]\n", "[5MI/3] 0.004714936487121288 [0.005021416534152844, 0.00453359720801415, 0.004714936487121288]\n", "[3ZF/3] 0.005698838193463921 [0.005698838193463921, 0.006372350188361305, 0.004733389017227235]\n", "[0.003006674656825954, 0.0024901765401445894, 0.002640441247904802, 0.002556852090616107, 0.003922843192938324, 0.0012724135802516157]\n", "[0.0024026106630740326, 0.0015306808132398398, 0.003917784910452867, 0.0018769599381238148, 0.004714936487121288, 0.005698838193463921]\n", "[7TM/4] 0.004195682980252796 [0.003950188996175878, 0.004195682980252796, 2.0863785597545665]\n", "[10KF/4] 0.005017210604686076 [0.0058695581350023925, 0.005017210604686076, 0.00382322050790849]\n", "[11ZM/4] 0.004373077263385557 [0.005304248942517635, 0.004373077263385557, 0.0038680517245407303]\n", "[2SB/4] 0.004780494766631807 [0.004452715331717112, 0.004836906908797207, 0.004780494766631807]\n", "[5MI/4] 0.004522149143858034 [0.004378097716940858, 0.004730024546274227, 0.004522149143858034]\n", "[3ZF/4] 0.5730251968275395 [0.5730251968275395, 0.6151303069429822, 0.17997801559145749]\n", "[0.004801354184919535, 0.001981110883473747, 0.00311768616798197, 0.002664618039935267, 0.008329222245675397, 0.002445709148188661]\n", "[0.004195682980252796, 0.005017210604686076, 0.004373077263385557, 0.004780494766631807, 0.004522149143858034, 0.5730251968275395]\n", "[7TM/5] 0.0030026127913968777 [0.0030026127913968777, 0.002966314233129647, 1.0919607438562668]\n", "[10KF/5] 0.0018728630968653172 [0.0018728630968653172, 0.00254711409860054, 0.0017867094196874452]\n", "[11ZM/5] 0.001744985966157502 [0.0020969180529696483, 0.001744985966157502, 0.0016118588408116715]\n", "[2SB/5] 0.004780494766631807 [0.004452715331717112, 0.0048586456286596755, 0.004780494766631807]\n", "[5MI/5] 0.006707032545252601 [0.006170975452619039, 0.006707032545252601, 0.007460460364806493]\n", "[3ZF/5] 0.00858308393943204 [0.00858308393943204, 0.011845597833970808, 0.007380003330274289]\n", "[0.004055782128720719, 0.00328245378291892, 0.0014083849974710172, 0.0029858684539020392, 0.007845910485130312, 0.002445709148188661]\n", "[0.0030026127913968777, 0.0018728630968653172, 0.001744985966157502, 0.004780494766631807, 0.006707032545252601, 0.00858308393943204]\n", "[7TM/6] 0.002837339604720477 [0.002837339604720477, 0.002449581166322905, 0.41387917879987024]\n", "[10KF/6] 8.259213311648866e-05 [9.282359403286088e-06, 0.002221889457124819, 8.259213311648866e-05]\n", "[11ZM/6] 0.0012243542725250457 [0.0014820056066890714, 0.0012243542725250457, 0.0010976608964243597]\n", "[2SB/6] 0.0023446856820961777 [0.0024867978271161787, 0.0023446856820961777, 0.0022332197164982065]\n", "[5MI/6] 0.0031172956941653137 [0.0029513503451490193, 0.0033183656384836225, 0.0031172956941653137]\n", "[3ZF/6] 0.003781674236994135 [0.003781674236994135, 0.004071966210877487, 0.0034494591909788983]\n", "[0.003138866692139931, 0.0025325379278861595, 0.0009215932677006866, 0.002621400221835252, 0.001954550346671144, 0.0015189554927926444]\n", "[0.002837339604720477, 8.259213311648866e-05, 0.0012243542725250457, 0.0023446856820961777, 0.0031172956941653137, 0.003781674236994135]\n", "[7TM/7] 0.0023828627975731745 [0.0023828627975731745, 0.0017047654247853699, 0.18591699611163967]\n", "[10KF/7] 0.0019421932362865028 [0.0019421932362865028, 0.002120856579389987, 0.0018114613219635]\n", "[11ZM/7] 0.0014335428486863065 [0.0014432654864380337, 0.0014335428486863065, 0.0014000118489706172]\n", "[2SB/7] 0.001781126021641757 [0.0024867978271161787, 0.001781126021641757, 0.0016906990021623499]\n", "[5MI/7] 0.0037122197226202246 [0.0037122197226202246, 0.003776907003804963, 0.003495911908165303]\n", "[3ZF/7] 0.007206213864647251 [0.007206213864647251, 0.007899440203861475, 0.006211245602005458]\n", "[0.0036923065171510427, 0.0020527140377196566, 0.0017667001699923747, 0.0015729443133339796, 0.0019636983396832306, 0.0013583430415635878]\n", "[0.0023828627975731745, 0.0019421932362865028, 0.0014335428486863065, 0.001781126021641757, 0.0037122197226202246, 0.007206213864647251]\n", "[7TM/8] 0.0030026127913968777 [0.0030026127913968777, 0.002912860211894843, 0.8457710628002826]\n", "[10KF/8] 0.003937374142034068 [0.004542457733622267, 0.003937374142034068, 0.0034600892248924293]\n", "[11ZM/8] 0.004351273874444507 [0.0050625173773602185, 0.004351273874444507, 0.0035935856109804007]\n", "[2SB/8] 0.004326823649970777 [0.004452715331717112, 0.004325268011938922, 0.004326823649970777]\n", "[5MI/8] 0.004743434827195546 [0.004743434827195546, 0.004492161915006733, 0.004857684829972067]\n", "[3ZF/8] 0.01592586039329981 [0.015304785485526388, 0.09280392746997639, 0.01592586039329981]\n", "[0.0032756892467843577, 0.0020949474383190852, 0.0028992798255622135, 0.0027488460983543573, 0.00416371874346105, 0.0022741875289843377]\n", "[0.0030026127913968777, 0.003937374142034068, 0.004351273874444507, 0.004326823649970777, 0.004743434827195546, 0.01592586039329981]\n", "[7TM/9] 0.0017372501091852122 [0.0017372501091852122, 0.0016790618998124395, 0.05339344195537287]\n", "[10KF/9] 0.0011993853157435785 [0.0011370496488211962, 0.0013632774988599744, 0.0011993853157435785]\n", "[11ZM/9] 0.0010565458881223932 [0.0009607852127521912, 0.0011070435774301734, 0.0010565458881223932]\n", "[2SB/9] 0.0017336108126774022 [0.0018769599381238148, 0.0017336108126774022, 0.0015180304828638965]\n", "[5MI/9] 0.0022169750747788675 [0.00278484013499442, 0.0022169750747788675, 0.001833834797518541]\n", "[3ZF/9] 0.005896802413281909 [0.005896802413281909, 0.007601946240230148, 0.00578983776202438]\n", "[0.0016943661978618529, 0.0014651121228743532, 0.0011333849162417412, 0.002449166151660834, 0.0018263583349822485, 0.001067181006343166]\n", "[0.0017372501091852122, 0.0011993853157435785, 0.0010565458881223932, 0.0017336108126774022, 0.0022169750747788675, 0.005896802413281909]\n" ] } ], "source": [ "f = open(\"/home/studen/temp/dynamicSPECT/table.txt\", \"w\")\n", "for r in numpy.arange(1,10):\n", " k1MAll,k1OAll=averageK1(db,r)\n", " print(k1MAll)\n", " print(k1OAll)\n", " \n", " f.write('{:.2f},{:.2f},{:.2f},{:.2f},{:.2f},{:.2f}\\n'.format(60*numpy.mean(k1MAll),60*numpy.median(k1MAll),60*numpy.std(k1MAll), 60*numpy.mean(k1OAll), 60*numpy.median(k1OAll),60*numpy.std(k1OAll)))\n", "f.close()\n" ] }, { "cell_type": "code", "execution_count": null, "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }