Commit ea8e7b6c authored by LAMBERT Jean-charles's avatar LAMBERT Jean-charles
Browse files

add notebook

parent c142ebb6
This diff is collapsed.
{
"metadata": {
"name": "",
"signature": "sha256:84844d086ec204569eb12c0cfe3fb329d3233e41a7bdbc33f08caf937e2a2dde"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"from py_unsio import *\n",
"import numpy as np\n",
"%matplotlib inline\n",
"import matplotlib\n",
"import matplotlib.pyplot as plt"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from simulations.csnapshot import *"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"s=CSnapshot(\"/rzdata/jcl/cartwheel/output_00060\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok=s.nextFrame()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok,mass=s.getData(\"halo\",\"mass\")\n",
"ok\n",
"mass.size"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
"590001"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok,id=s.getData(\"halo\",\"id\")\n",
"ok\n",
"id"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": [
"array([ 479544., 488545., 390225., ..., 134218., 58965., 266227.])"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok,t=s.getData(\"time\")\n",
"t"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"text": [
"11.644545"
]
}
],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print mass.min(), mass.max(),mass.mean()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"0.0001 0.002 0.000782412\n"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"n=(mass*1e9<1.7e5)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mass[n==False].size"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 22,
"text": [
"215000"
]
}
],
"prompt_number": 22
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok,pos=s.getData(\"halo\",\"pos\")\n",
"pos = np.reshape(pos,(-1,3))\n",
"pos=np.reshape(pos[n],pos[n].size)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok,vel=s.getData(\"halo\",\"vel\")\n",
"vel = np.reshape(vel,(-1,3))\n",
"vel=np.reshape(vel[n],vel[n].size)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok,pgas=s.getData(\"gas\",\"pos\")\n",
"print ok\n",
"ok,pstars=s.getData(\"stars\",\"pos\")\n",
"print ok\n",
"ok,vgas=s.getData(\"gas\",\"vel\")\n",
"print ok\n",
"ok,vstars=s.getData(\"stars\",\"vel\")\n",
"print ok\n",
"ok,rgas=s.getData(\"gas\",\"rho\")\n",
"print ok\n",
"ok,hsml=s.getData(\"gas\",\"hsml\")\n",
"print ok\n",
"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n"
]
}
],
"prompt_number": 19
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"o=CunsOut(\"/home/jcl/xx.g2\",\"gadget2\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 20
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok=o.setArrayF(\"disk\",\"pos\",pos)\n",
"print ok\n",
"ok=o.setArrayF(\"gas\",\"pos\",pgas)\n",
"print ok\n",
"ok=o.setArrayF(\"stars\",\"pos\",pstars)\n",
"print ok\n",
"ok=o.setArrayF(\"disk\",\"vel\",vel)\n",
"print ok\n",
"ok=o.setArrayF(\"gas\",\"vel\",vgas)\n",
"print ok\n",
"ok=o.setArrayF(\"stars\",\"vel\",vstars)\n",
"print ok\n",
"ok=o.setArrayF(\"gas\",\"rho\",rgas)\n",
"print ok\n",
"ok=o.setArrayF(\"gas\",\"hsml\",hsml)\n",
"print ok"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"1\n",
"1\n",
"1\n",
"1\n",
"1"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"1\n",
"1\n",
"1\n"
]
}
],
"prompt_number": 25
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"pos.size"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 15,
"text": [
"1125003"
]
}
],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok=o.setArrayF(\"halo\",\"vel\",vel)\n",
"print ok\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"1\n"
]
}
],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"o.save()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 26,
"text": [
"1"
]
}
],
"prompt_number": 26
}
],
"metadata": {}
}
]
}
\ No newline at end of file
{
"metadata": {
"name": "",
"signature": "sha256:0146f6ba9d082d5b66a40e6822de3589c497682e08cdd41a8227010d7447c9d6"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"class A:\n",
" def __init__(self,x):\n",
" self.x=x\n",
" self.x.data=\"hi\"\n",
" \n",
" def p(self):\n",
" print(\">>\",self.x.data)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"class QQ:\n",
" data=None\n",
"qq=QQ()\n",
"yo=A(qq)\n",
"yo.p()\n",
"qq.data=\"hello\"\n",
"yo.p()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"('>>', 'hi')\n",
"('>>', 'hello')\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"xx=\"gas,disk,halo\"\n",
"if xx.find(\"gas\")!=-1:\n",
" print \"good\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"good\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cod_select=\"halo: disk: stars: gas: bndry: bulge: halo_1: halo_2: halo,disk: halo,stars: disk,stars: halo,disk,stars\"\n",
"cod_select=cod_select.replace(\" \", \"\")\n",
"cod_select"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
"'halo:disk:stars:gas:bndry:bulge:halo_1:halo_2:halo,disk:halo,stars:disk,stars:halo,disk,stars'"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x=\"disk,stars#cod\"\n",
"a,b=x.split(\"#\")\n",
"print a,\" \",b,\" \"\n",
"b=b.split('@')\n",
"print a,\" \",b[0],\" \",b[1]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"disk,stars cod \n",
"disk,stars cod "
]
},
{
"ename": "IndexError",
"evalue": "list index out of range",
"output_type": "pyerr",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-32-a4779496c7a9>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\" \"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\" \"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'@'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\" \"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\" \"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mIndexError\u001b[0m: list index out of range"
]
}
],
"prompt_number": 32
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"w=[]\n",
"w.append([\"disk\",\"stars-halo\"])\n",
"w.append([\"gas\",\"stars-gas\"])\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np\n",
"x=\"\"\n",
"map(np.float64,x.split())\n",
"\n",
"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": [
"[]"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"a=np.arange(10)\n",
"import math\n",
"a=a+1\n",
"a = np.log(a)\n",
"a"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 37,
"text": [
"array([ 0. , 0.69314718, 1.09861229, 1.38629436, 1.60943791,\n",
" 1.79175947, 1.94591015, 2.07944154, 2.19722458, 2.30258509])"
]
}
],
"prompt_number": 37
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"a=np.array([1,1,1,0,2,2,2,1,1,1,1])\n",
"a=a/1.\n",
"#np.random.shuffle(a)\n",
"\n",
"print a\n",
"i,j=np.histogram(a,bins=10)\n",
"print i\n",
"print j"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[ 1. 1. 1. 0. 2. 2. 2. 1. 1. 1. 1.]\n",
"[1 0 0 0 0 7 0 0 0 3]\n",
"[ 0. 0.2 0.4 0.6 0.8 1. 1.2 1.4 1.6 1.8 2. ]\n"
]
}
],
"prompt_number": 65
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import sys\n",
"sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path\n",
"from simulations.csnapshot import *"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 22
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"uns=CSnapshot?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 68
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"uns=CSnapshot(\"mdf732%2000\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 34
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ok=uns.nextFrame()\n",
"print ok, uns.getInterfaceType()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"1 Gadget2\n"
]
}
],
"prompt_number": 35
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"uns.getMaxRadius(\"halo\",99.,y=False)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 36,
"text": [
"(1, 590.51727152691319)"
]
}
],
"prompt_number": 36
},
{
"cell_type": "code",
"collapsed": false,