From aa60da3c92a169617ce024241dea09263282aaf4 Mon Sep 17 00:00:00 2001 From: Malte Brammerloh Date: Fri, 24 Aug 2018 17:56:35 +0200 Subject: [PATCH] some minor issues fixed for new axio scan concentration maps --- Untitled.ipynb | 343 ++++++++++++++++++++++++++++++ __pycache__/mfield.cpython-35.pyc | Bin 0 -> 4036 bytes mfield.py | 32 +-- mfield.pyc | Bin 0 -> 3032 bytes 4 files changed, 362 insertions(+), 13 deletions(-) create mode 100644 Untitled.ipynb create mode 100644 __pycache__/mfield.cpython-35.pyc create mode 100644 mfield.pyc diff --git a/Untitled.ipynb b/Untitled.ipynb new file mode 100644 index 0000000..fc3ef48 --- /dev/null +++ b/Untitled.ipynb @@ -0,0 +1,343 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Populating the interactive namespace from numpy and matplotlib\n" + ] + } + ], + "source": [ + "%pylab inline\n", + "import mfield" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "dc = 60\n", + "sus = dc*mfield.chiFerritin\n", + "susMap = sus*ones([4,4,4])\n", + "B0 = 7.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "db = mean(mfield.genDBz(susMap,B0,0)*3)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "23.247303490320004" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db*mfield.gamma2pi" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def g(x):\n", + " def f(y):\n", + " return x+y\n", + " return f\n", + "def f(x,y):\n", + " return x+y" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "45" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reduce(f,range(10),0)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def map(fn, coll):\n", + " def _inner(out_coll, item):\n", + " out_coll.append(fn(item))\n", + " return out_coll\n", + " return reduce(_inner, coll, ())" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "ename": "TypeError", + "evalue": "map() takes exactly 2 arguments (3 given)", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: map() takes exactly 2 arguments (3 given)" + ] + } + ], + "source": [ + "map(f,range(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Calculation(object):\n", + " def apply(self, x, y):\n", + " raise NotImplementedError(\"\")\n", + "\n", + " def calculate(self, coll):\n", + " total = 0\n", + " for item in coll:\n", + " total = self.apply(total, item)\n", + " return total\n", + "\n", + "\n", + "class Addition(Calculation):\n", + " def apply(self, x, y):\n", + " return x + y\n", + "\n", + "\n", + "class Multiplication(Calculation):\n", + " def apply(self, x, y):\n", + " return x * y\n", + "\n", + "\n", + "adder = Addition().calculate\n", + "multiplier = Multiplication().calculate" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Addition.calculate" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0.69146246127401301" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mfield.phi(1)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0.30853753872598694" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mfield.phi(-1)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "42554.88910737372" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "6*4/3.*3.14156*(10)**3/.839**3" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3500000.0" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "14e3*250" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2.0432432432432433e-06" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "0.7*0.6*0.3*0.3/18.5e3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/__pycache__/mfield.cpython-35.pyc b/__pycache__/mfield.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2e990d8cba459ac341887163f6fa24d4ae8f7093 GIT binary patch literal 4036 zcmeHKL66)>6@F#6-QDi#By2{ROa_nh z`s&rI_g-IXw;f~c7eDP>CHj<>o*LQ@P>SE6itq|biH3rFK_W6JGAXK2WKq9HK1gub zl$zwD6YV;s77cCkZE!cpuT#_{zrka1jh;6ta%dxJ5oUU6knfxuSmF73032{c0bM@?oKO! zH%G}62$-?#^*`JE=sWW9%Xj*lAAIr2_`_>&9~+o1w0KfHmr-n#cTtMJVyGl~E@*}t z`xdm`!Y0-hB&h2P>V-*1)>#qbtO&>@5l}2*pA|9Bihx`a0mUM9C1TRdqM1#zI-&C; z^f&0JNkjL1P&EE%yyyB z@05_Kgnq(@e=_HVLYWe>l+d39Yz5q`=NipSdLgi6Q_I_12BU^&>Ujed8v?2hdb&7Hh7yG@m00)SBo)a7k zBG+;8yccJ&49d80he1D!%OrGrNt{M*F-Ur)E8}9EmPyukdomxoL0ICRxq0tA_wJS( zq&e7v!=!MFQ5+_iCUT!mbWe~)w{z(RSwF>6qd|gZ3eK(m;(flpQyhNt~6zDQ*DO`_pg_ zH<|0+mUrvh?nJlmc()+rPBrzWcZ)f`%Uvfsl+Th<22$^A^WL_1cE6)M4Ni8dH>kE6 zOq1cb90aM>fl|T89oZ>6?o_Ry)d0=xxJgeb?cTlZ9rwH()Uvy!wx^VLmU(&U1*61a z6Q4NA2C6;^p2mY?6QBNv>iOIK3mRU#GBWtkG|7rl5XO~N41!TyHHL99=*uLk%rGx1 zvq-Ya?Dfj3flAp=RYNPQYQs1{E#n}qn#p|7;%4Suu55k!m9e{3)mYt?2}M+v+F~UR zD>13Wv@-S&Q6|2zKdtQjSY~nRTf_0zPW>Mb5Us&-l8rB0RAu&y2SWM|{h0jL?|J42~D` znBjteztLd;H<~?x!G4UL7hIS{t9zai{PRn0Vw#7rlOF_f2&3!C_+T7o;pG1}^7U@y z|M+d3Cmx6lB+5GUgj`A)_ z!Pd{In&5x{^Ft&lh00xYB;7zHSc3&xPh=CUCr*JLEW3zL?t7->8D$GqRVxl;3DjTX z9-e;*6=Qw}rQjrrgxbTS`NeS1$F4^q81Ck%UB{o{fIFPmI1mw>u zpyBT5K&tu?Bz1&DygX^uXuYpChQ#Oa52D01(=41>33~XmA96l~^avS6g!PGjiK$K- zi1X{5H-JMY9njVqH+&#yLlF zF<{PK4%Wrf?6*pvHI-&vHvR+WLYH&+fVsNRXO|ZG#E8QA!E5MqjuVY9fof9E0Kz|t zr*MhVH=!{6v*4@~?fK~;X+7zJuJs;#^Uz_{VMt;57h@@5?8*X4YjLm(1n{^>VZm{o z4||olk(A+fT)?e3*Dm5XneQ%7=e%mVGmF0x>Z=!5=lj@rTH5^23wse6@<0#`MF97n z*Lu?b^{@E(%YBswsLQVI_;C#v@|bVtbhQ|VaZ&WfX^JQ_%yY!uXnIYzIQRQFDBLVB z-6+rE<1g^YO~`q5?H8quGFFKu5(9J5J@nZ?T9mN|e7>4qPjUK`jAQ jF7+n!Hty<#j> literal 0 HcmV?d00001 diff --git a/mfield.py b/mfield.py index 767b1c1..b50526c 100644 --- a/mfield.py +++ b/mfield.py @@ -66,31 +66,37 @@ def phi(x): #needed for smoothing return 1/2.*(1 + erf(x/(2*np.sqrt(2)))) -def genSusMap(cMap, sliceHeight, drytissuecorrection = False, smooth = False): +def genSusMap(cMap, sliceHeight,stackedaxis, drytissuecorrection = False, smooth = False): # Creates a correctly spaced volume of the samples susceptibility assuming that it is proportional to the # iron density (like Ferritin). drytissueprop = 0.2 # Proportion of dry tissue in physiological conditions - chiFerritin = 1.30e-9 # Ferritin susceptibility following Schenck 96 - # (*e3 because we hace [c] in \mu g / g and not mg / g ) - if drytissuecorrection: chiFerritin = chiFerritin*drytissueprop - suscep = cMap * chiFerritin + suscep = cMap * mfield.chiFerritin # To real scaled cube: sliceHeight high slices with area of cMap.shape[1]*cMap.shape[2] px - suscep3dz = np.zeros([sliceHeight * cMap.shape[0],cMap.shape[1],cMap.shape[2]]) - for i in range(cMap.shape[0]): - suscep3dz[(i*sliceHeight):((i+1)*sliceHeight),:,:] = suscep[i,:,:] - - susMap = np.swapaxes(np.swapaxes(suscep3dz,0,1),1,2) + if stackedaxis==0: + suscep3dz = np.zeros([sliceHeight * cMap.shape[0],cMap.shape[1],cMap.shape[2]]) + for i in range(cMap.shape[0]): + suscep3dz[(i*sliceHeight):((i+1)*sliceHeight),:,:] = suscep[i,:,:] + + elif stackedaxis==1: + suscep3dz = np.zeros([cMap.shape[0],sliceHeight * cMap.shape[1],cMap.shape[2]]) + for i in range(cMap.shape[1]): + suscep3dz[:,(i*sliceHeight):((i+1)*sliceHeight),:] = suscep[:,i,:] + + elif stackedaxis==2: + suscep3dz = np.zeros([cMap.shape[0],cMap.shape[1],sliceHeight * cMap.shape[2]]) + for i in range(cMap.shape[2]): + suscep3dz[:,:,(i*sliceHeight):((i+1)*sliceHeight)] = suscep[:,:,i][:,:,None] - if smooth and sliceHeight==4 and cMap.shape[0]==10: # For "original" 10 mu slices. + if smooth and sliceHeight==4 and cMap.shape[0]==10 and stackedaxis==2: # For "original" 10 mu slices. for i in range(10): susMap[:,:,4*i-1]= phi(1)*susMap[:,:,4*i-1] + phi(-1)*susMap[:,:,4*i] susMap[:,:,4*i] = phi(-1)*susMap[:,:,4*i-1] + phi(1)*susMap[:,:,4*i] print('sucessfully smoothed') else: - return 'error: smoothing could not be done, wrong dimensions?' - return susMap + print('smoothing was not done') + return suscep3dz diff --git a/mfield.pyc b/mfield.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2a743601f662ece6f2addcbd6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