Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
some minor issues fixed for new axio scan concentration maps
  • Loading branch information
mbrammerloh committed Aug 24, 2018
1 parent b3873d5 commit aa60da3
Show file tree
Hide file tree
Showing 4 changed files with 362 additions and 13 deletions.
343 changes: 343 additions & 0 deletions 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<ipython-input-30-cdabd26e39d4>\u001b[0m in \u001b[0;36m<module>\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": [
"<unbound method Addition.calculate>"
]
},
"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
}
Binary file added __pycache__/mfield.cpython-35.pyc
Binary file not shown.
32 changes: 19 additions & 13 deletions mfield.py
Expand Up @@ -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
Binary file added mfield.pyc
Binary file not shown.

0 comments on commit aa60da3

Please sign in to comment.