borg_public/scripts/notebooks/analyse_resim.ipynb

388 lines
28 KiB
Plaintext
Raw Normal View History

2023-05-29 10:41:03 +02:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Analyse 2M++ resims"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/scratch/pyenvs/versions/3.6.5/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" from ._conv import register_converters as _register_converters\n"
]
}
],
"source": [
"import numpy as np\n",
"import matplotlib.pylab as plt\n",
"from src.read_all_h5 import explore_chain, rebuild_spliced_h5\n",
"from src.special_regions import *\n",
"import healpy as hp\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Just some helper Routines"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"#little reading routine\n",
"def load_resim(fname,ncpu=1):\n",
" print (\"reading : \", fname)\n",
" \n",
" if ncpu>0:\n",
" a=rebuild_spliced_h5(fname,['u_pos','u_vel'],ncpu,verbose=False)\n",
" return np.array(a[\"u_pos\"][...]),np.array(a[\"u_vel\"][...])\n",
" else:\n",
" print ('Error: need number of processes to read files !')\n",
" \n",
" return None\n",
"#print special regions\n",
"special_coords.keys()\n",
"\n",
"#set observer\n",
"corner=np.array([-0.5*677.77,-0.5*677.77,-0.5*677.77])\n",
"\n",
"#change coordinates\n",
"def cart2sphere(pos,corner=np.array([0,0,0]),rmax=100):\n",
" r = np.sqrt((pos[:,0]+corner[0])**2+(pos[:,1]+corner[1])**2+(pos[:,2]+corner[2])**2)\n",
" foo=np.where(r<rmax)\n",
" r = r[foo]\n",
" \n",
" phi,theta=hp.vec2ang(np.array([pos[foo][:,0]+corner[0],pos[foo][:,1]+corner[1],pos[foo][:,2]+corner[2]]).T, lonlat=True)\n",
" \n",
" return r,phi,theta\n",
"\n",
"\n",
"def get_densities(r,ra,dec,rmax,region='full'):\n",
" rho_mean=(512./677.77)**3\n",
" \n",
" if(region=='full'):\n",
" hist, binEdges = np.histogram(r,bins=600, density=False,range=[0,rmax])\n",
" dv = np.pi*4./3.*(binEdges[1:]**3-binEdges[:-1]**3)\n",
" else:\n",
" foo,da = sky_region(region,ra,dec)\n",
" hist, binEdges = np.histogram(r[foo],bins=600, density=False,range=[0,rmax])\n",
" dv = da/3.*(binEdges[1:]**3-binEdges[:-1]**3)\n",
" \n",
" \n",
" bincenters = 0.5*(binEdges[1:]+binEdges[:-1])\n",
" \n",
" rho = hist/dv\n",
" delta = rho/rho_mean -1.\n",
" \n",
" aux = np.cumsum(hist)\n",
" auxv = 4./3.*np.pi*binEdges[1:]**3\n",
" rho_cum = aux/auxv\n",
" delta_cum = rho_cum/rho_mean-1.\n",
" \n",
" return bincenters,delta, binEdges[1:], delta_cum \n",
"\n",
"def find_ncpu(fbase):\n",
" import glob\n",
" nn = len(glob.glob(fbase+\"*\"))\n",
" return nn\n",
"\n",
"def plot_radial_density(r,ra,dec):\n",
" \n",
" rmax=300\n",
" foo=sky_region('R3',ra,dec)\n",
" x_R1,delta_R1,x_cum_R1,delta_cum_R1=get_densities(r[foo],rmax)\n",
"\n",
" f, (ax1, ax2, ax3) = plt.subplots(1,3, sharex=True, sharey=True,figsize=(12,4))\n",
" \n",
" \n",
" ax1.set_xlim([0,rmax])\n",
" ax1.set_ylim([-1,1])\n",
" ax1.set_xlabel(r'$r$')\n",
" ax1.set_ylabel(r'$\\delta(r)$')\n",
" ax1.plot(x_R1,delta_R1,color='red')\n",
" ax1.plot(x_R1,delta_R1*0.,color='black',linestyle='--')\n",
" \n",
" ax2.set_xlim([0,rmax])\n",
" ax2.set_ylim([-1,1])\n",
" ax2.set_xlabel(r'$r$')\n",
" ax2.yaxis.set_ticks_position('none') \n",
" ax2.plot(x_R1,delta_R1,color='red')\n",
" ax2.plot(x_R1,delta_R1*0.,color='black',linestyle='--')\n",
" \n",
" ax3.set_xlim([0,rmax])\n",
" ax3.set_ylim([-1,1])\n",
" ax3.set_xlabel(r'$r$')\n",
" ax3.yaxis.set_ticks_position('none') \n",
" ax3.plot(x_R1,delta_R1,color='red')\n",
" ax3.plot(x_R1,delta_R1*0.,color='black',linestyle='--')\n",
" \n",
" \n",
" plt.show()\n",
" \n",
"fins=['output_7430.h5',\n",
"'output_7440.h5',\n",
"'output_7450.h5',\n",
"'output_7460.h5',\n",
"'output_7470.h5',\n",
"'output_7480.h5',\n",
"'output_7490.h5',\n",
"'output_7500.h5',\n",
"'output_7510.h5',\n",
"'output_7520.h5',\n",
"'output_7530.h5',\n",
"'output_7540.h5',\n",
"'output_7550.h5',\n",
"'output_7570.h5',\n",
"'output_7590.h5',\n",
"'output_7610.h5',\n",
"'output_7630.h5',\n",
"'output_7650.h5',\n",
"'output_7670.h5',\n",
"'output_7690.h5',\n",
"'output_7710.h5',\n",
"'output_7730.h5',\n",
"'output_7750.h5',\n",
"'output_7770.h5',\n",
"'output_7790.h5',\n",
"'output_7810.h5',\n",
"'output_7830.h5',\n",
"'output_7850.h5',\n",
"'output_7870.h5',\n",
"'output_7890.h5',\n",
"'output_7910.h5',\n",
"'output_7930.h5',\n",
"'output_7950.h5',\n",
"'output_7970.h5',\n",
"'output_7990.h5',\n",
"'output_8010.h5',\n",
"'output_8030.h5',\n",
"'output_8050.h5',\n",
"'output_8070.h5',\n",
"'output_8090.h5',\n",
"'output_8110.h5',\n",
"'output_8130.h5',\n",
"'output_8150.h5',\n",
"'output_8170.h5',\n",
"'output_8190.h5',\n",
"'output_8210.h5',\n",
"'output_8230.h5',\n",
"'output_8250.h5',\n",
"'output_8270.h5',\n",
"'output_8290.h5',\n",
"'output_8310.h5',\n",
"'output_8330.h5',\n",
"'output_8350.h5',\n",
"'output_8370.h5',\n",
"'output_8390.h5',\n",
"'output_8410.h5',\n",
"'output_8430.h5',\n",
"'output_8450.h5',\n",
"'output_8470.h5',\n",
"'output_8490.h5',\n",
"'output_8510.h5',\n",
"'output_8530.h5',\n",
"'output_8550.h5',\n",
"'output_8570.h5',\n",
"'output_8590.h5',\n",
"'output_8610.h5',\n",
"'output_8630.h5',\n",
"'output_8650.h5',\n",
"'output_8670.h5',\n",
"'output_8690.h5',\n",
"'output_8710.h5',\n",
"'output_8730.h5',\n",
"'output_8750.h5',\n",
"'output_8770.h5',\n",
"'output_8790.h5',\n",
"'output_8810.h5',\n",
"'output_8830.h5',\n",
"'output_8850.h5',\n",
"'output_8870.h5',\n",
"'output_8890.h5',\n",
"'output_8910.h5',\n",
"'output_8930.h5',\n",
"'output_8950.h5',\n",
"'output_8970.h5',\n",
"'output_8990.h5']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"reading : /data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/output_7430.h5\n",
"hi 7.379306853242552e-07 359.9999969390372 -89.99126552546272 89.99550581118774\n",
"reading : /data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/output_7440.h5\n",
"hi 2.9451484856277518e-06 359.999997570849 -89.9889787218639 89.99511084033364\n",
"reading : /data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/output_7450.h5\n",
"hi 3.385283781994141e-07 359.99999553714446 -89.98808898802002 89.99533411827332\n",
"reading : /data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/output_7460.h5\n",
"hi 1.8074473344467155e-06 359.9999977874951 -89.98371284950048 89.99201676085508\n",
"reading : /data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/output_7470.h5\n",
"hi 3.2910328257955735e-06 359.99999773190456 -89.99272054208683 89.99425095008178\n",
"reading : /data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/output_7480.h5\n",
"hi 1.1389157106431394e-05 359.99999830154223 -89.98472794623657 89.99811377865286\n",
"reading : /data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/output_7490.h5\n",
"hi 2.874475098358866e-06 359.999990777863 -89.99649122931581 89.97667660204161\n",
"reading : /data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/output_7500.h5\n"
]
}
],
"source": [
"#get Cartesian coordinates for coma:\n",
"pcoma,rc=get_objpos_range('coma')\n",
"\n",
"#load particles\n",
"rmax=300\n",
"xx_full=[]\n",
"xx_R1=[]\n",
"xx_R2=[]\n",
"xx_R3=[]\n",
"\n",
"\n",
"rcoma=[]\n",
"racoma=[]\n",
"deccoma=[]\n",
"velcoma=[]\n",
"for fname in fins:\n",
" ncpu=find_ncpu('/data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/'+fname)\n",
" pos1,vel1=load_resim('/data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/'+fname,ncpu=ncpu)\n",
" \n",
" dcoma = np.sqrt((pos1[:,0]+corner[0]-pcoma[0])**2+(pos1[:,1]+corner[1]-pcoma[1])**2+(pos1[:,2]+corner[2]-pcoma[2])**2)\n",
" foo=np.where(dcoma<20.)\n",
" \n",
" r,ra,dec = cart2sphere(pos1,corner=corner,rmax=2000)\n",
" \n",
" print ('hi',np.min(ra),np.max(ra),np.min(dec),np.max(dec))\n",
" \n",
" velcoma.append(vel1[foo])\n",
" rcoma.append(r[foo])\n",
" racoma.append(ra[foo])\n",
" deccoma.append(dec[foo])\n",
" \n",
" np.savez('/scratch/jasche/coma_particles', r = rcoma, ra = racoma, dec = deccoma, vel=velcoma)\n",
" \n",
" xx_full.append(get_densities(r,ra,dec,rmax))\n",
" \n",
" xx_R1.append(get_densities(r,ra,dec,rmax,region='R1'))\n",
" xx_R2.append(get_densities(r,ra,dec,rmax,region='R2'))\n",
" xx_R3.append(get_densities(r,ra,dec,rmax,region='R3'))\n",
" np.savez('/scratch/jasche/home_radial_dens', full = xx_full, R1=xx_R1, R2=xx_R2,R3=xx_R3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"r,ra,dec = cart2sphere(pos1,corner=corner,rmax=300)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAuwAAAELCAYAAACCidNbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3XmcFPWd//H3hxtPTpFwCCIKGuOIE/BKvEDxiCSrUXBVTOKS9UhijPmJGpUIJh7Jatx4sd7ReEQ3KxtRV1FziAijQUQUQUGBoFwKqAgCn98fn+p0z0z3zMDMdNcwr+fj0Y/uuj9dXd+qT33rW9Xm7gIAAACQTi1KHQAAAACAwkjYAQAAgBQjYQcAAABSjIQdAAAASDESdgAAACDFSNgBAACAFEtNwm5md5nZMjObXWC4mdlNZjbfzGaZ2aCcYaPNbF7yGl28qAEAAIDGlZqEXdI9kobXMPxYSf2T1xhJt0qSmXWSdKWkIZIGS7rSzDo2aqQAAABAkaQmYXf3v0haVcMoIyTd52GapA5m1l3SMZKecfdV7v6RpGdUc+IPAAAANBmtSh3AFughaVFO9+KkX6H+1ZjZGEXtvLbffvsDBgwY0DiRAk3QK6+8ssLdu5Y6jny6dOniffr0KXUYQGpQXoGmoyHKa1NK2OvN3SdKmihJ5eXlXlFRUeKIgPQws/dKHUMhffr0EeUVyKK8Ak1HQ5TX1DSJqYMlknrldPdM+hXqDwAAADR5TSlhnyTpzORpMQdKWu3uSyU9LeloM+uY3Gx6dNIPAAAAaPJS0yTGzB6UdLikLma2WPHkl9aS5O63SZos6ThJ8yV9Juk7ybBVZjZe0oxkVle5e003rwIAAABNRmoSdncfVctwl3RegWF3SbqrMeICAAAASqkpNYkBAAAAmh0SdgAAACDFSNgBAACAFCNhBwAAAFKMhB0AAABIMRJ2AAAAIMVI2AEAAIAUI2EHAAAAUoyEHQAAAEgxEnYAAAAgxUj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7Ga2vZm1bIxgAAAAAFRWa8JuZi3M7DQze8LMlkl6S9JSM5tjZteb2R6NHyYAAADQPNWlhv15Sf0kXSJpV3fv5e67SDpU0jRJ15rZ6Y0YIwAAANBstarDOEMlbZI01t1nZXq6+ypJj0l6zMxaN1J8AAAAQLNWaw27u3/h7pslnVDTOPUNxMyGm9lcM5tvZmPzDG9rZg8nw182sz45wy5J+s81s2PqGwsAAACQFlty0+ksM7vSzBr8yTLJTaw3SzpW0t6SRpnZ3lVG+56kj9x9D0k3SLo2mXZvSSMl7SNpuKRbuCkWAAAA24q6NInJ6CTpMEnnmNnLkmZJmuXuf2iAOAZLmu/u70qSmT0kaYSkOTnjjJA0Lvn8qKTfmpkl/R9y9/WSFpjZ/GR+L9W0wLlz5+rwww+v1O+UU07Rueeeq88++0zHHXdctWnOOussnXXWWVqxYoVOPvnkasPPOeccnXrqqVq0aJHOOOOMasN/8pOf6Bvf+Ibmzp2r73//+9WG/+xnP9PQoUM1c+ZMXXDBBdWG/+IXv9DBBx+sqVOn6tJLL602/MYbb1RZWZmeffZZTZgwodrw22+/XXvttZf+93//V7/+9a+rDf/d736nXr166eGHH9att95abfijjz6qLl266J577tE999xTbfjkyZO13Xbb6ZZbbtEjjzxSbfgLL7wgSfrVr36lP/3pT5WGtW/fXk8++aQkafz48ZoyZUql4Z07d9Zjjz0mSbrkkkv00kuVf96ePXvq/vvvlyRdcMEFmjlzZqXhe+65pyZOnChJGjNmjN5+++1Kw8vKynTjjTdKkk4//XQtXry40vCDDjpIv/zlLyVJJ510klauXFlp+FFHHaXLL79cknTsscdq3bp1lYafcMIJuuiiiySp2nY
"text/plain": [
"<Figure size 864x288 with 3 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_radial_density(r,ra,dec)\n"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"511.99999999999983\n"
]
}
],
"source": [
"print (np.shape(pos1)[0]**(1./3.))"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10\n"
]
}
],
"source": [
"import glob\n",
"aux = glob.glob(\"/data/lavaux/PM_HOT_0.30_try2_epsilon_0.01/output_7610.h5_*\")\n",
"print(len(aux))\n",
"\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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}