{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib notebook\n", "%load_ext autoreload\n", "%autoreload 2\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from scipy.interpolate import interp1d\n", "from scipy.interpolate import UnivariateSpline\n", "from matplotlib.patches import Circle\n", "from scipy.special import gamma\n", "import numpy as np\n", "from mpl_toolkits.axes_grid1 import make_axes_locatable\n", "from numpy import exp, sqrt\n", "from scipy.integrate import quad, dblquad, nquad, simps\n", "from scipy.stats import rv_continuous\n", "from scipy.special import gamma\n", "from scipy.interpolate import interp1d\n", "from scipy.integrate import quad\n", "import scipy.optimize as optimize\n", "import matplotlib.patches as patches\n", "from itertools import product\n", "from scipy.integrate import quad\n", "import scipy.optimize as optimize\n", "from scipy.interpolate import interp1d\n", "from scipy.misc import derivative\n", "import matplotlib.pyplot as plt\n", "import matplotlib as mpl\n", "from sklearn.neighbors import KDTree\n", "import sys\n", "import glob\n", "from unsio import *\n", "import os\n", "import wkbl\n", "from wkbl.astro.halo_info import *\n", "from mpl_toolkits.mplot3d import axes3d\n", "from mpl_toolkits.mplot3d import proj3d\n", "from matplotlib import cm\n", "import wkbl.astro.nbody_essentials as nbe\n", "from iminuit import Minuit, describe, Struct\n", "import cfalcon\n", "CF =cfalcon.CFalcon()\n", "from matplotlib.colors import LogNorm\n", "from matplotlib.ticker import FormatStrFormatter\n", "from matplotlib import rc\n", "import datetime\n", "from scipy.misc import derivative\n", "rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})\n", "## for Palatino and other serif fonts use:\n", "#rc('font',**{'family':'serif','serif':['Palatino']})\n", "rc('text', usetex=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# DMO" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "loading Dark matter..\n" ] } ], "source": [ "simname = \"Mochima\"\n", "pathsim = \"/data/OWN/DMO/mochima2/output_00041\"\n", "#path = \"/media/arturo/ARTUROTECA/OUTPUTS/HaloB/output_00417\"\n", "myDMO = wkbl.Galaxy_Hound(pathsim)\n", "zoomreg = np.where(myDMO.dm.mass==myDMO.dm.mass.min())\n", "centro = nbe.real_center(myDMO.dm.pos3d[zoomreg],myDMO.dm.mass[zoomreg])\n", "\n", "myDMO.center_shift(centro)\n", "myDMO.r_virial(600,n=2.5)\n", "myDMO.r200\n", "myDMO.redefine(2.5)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2661525 2661525\n" ] } ], "source": [ "pos = np.array(myDMO.dm.pos3d.reshape(len(myDMO.dm.pos3d)*3),dtype=np.float32)\n", "phi_cord =myDMO.dm.phi\n", "\n", "mass = myDMO.dm.mass\n", "v = myDMO.dm.v\n", "print len(mass)*3, len(pos)\n", "r2 = myDMO.dm.pos3d[:,0]**2 + myDMO.dm.pos3d[:,1]**2 +myDMO.dm.pos3d[:,2]**2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "ok, acc, Phy = CF.getGravity(pos,mass,0.15,G=myDMO.p.G)\n", "Phy = Phy * myDMO.p.kpctokm**2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ok,myDMO.dm.rho,_= CF.getDensity(np.array(myDMO.dm.pos3d.reshape(len(myDMO.dm.pos3d)*3),dtype=np.float32), myDMO.dm.mass)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "inside_halo = np.where(myDMO.dm.r val) ][0]\n", "\n", "\n", "print R_P03\n", "hsml= 0.2# R_P03\n", "print hsml,R_P03\n", "# R array logarithmic Bining\n", "r_p = np.logspace(np.log10(0.2*hsml),np.log10(hsml),15)\n", "# histogram of dm particles per logarithmic bin\n", "n_dm,r = np.histogram(myDMO.dm.r,bins=r_p)\n", "# edges of bins\n", "r1,r2 =r[:-1],r[1:]\n", "# shell's volume\n", "vol = 4.* np.pi * ((r2**3)-(r1**3)) / 3.\n", "r_size = r_p[1:]-r_p[:-1]\n", "# density per shell\n", "profileDMO_in = n_dm*myDMO.dm.mass.min()/vol\n", "# center of bins\n", "r_in = (r_p[:-1]+r_p[1:])/2.\n", "\n", "\n", "# R array logarithmic Bining\n", "r_p = np.logspace(np.log10(3*hsml),np.log10(2.5*myDMO.r200),150)\n", "# histogram of dm particles per logarithmic bin\n", "n_dm,r = np.histogram(myDMO.dm.r,bins=r_p)\n", "# edges of bins\n", "r1,r2 =r[:-1],r[1:]\n", "# shell's volume\n", "vol = 4.* np.pi * ((r2**3)-(r1**3)) / 3.\n", "r_size = r_p[1:]-r_p[:-1]\n", "# density per shell\n", "profileDMO = n_dm*myDMO.dm.mass.min()/vol\n", "# center of bins\n", "r = (r_p[:-1]+r_p[1:])/2.\n", "bin_size= (r_p[:-1]-r_p[1:])/2.\n", "rr = r\n", "\n", "\n", "Delta_rho = (myDMO.dm.mass.min() /vol) + (4*np.pi*(r**2)* (n_dm*myDMO.dm.mass.min()) * r_size / vol**2)\n", "Delta_rho2 = np.sqrt((myDMO.dm.mass.min()/np.sqrt(n_dm) /vol)**2 + (4*np.pi*(r**2)* (n_dm*myDMO.dm.mass.min()) * r_size / vol**2)**2)\n", "Delta_rho3 =(4*np.pi*(r**2)* (n_dm*myDMO.dm.mass.min()) * r_size / vol**2)\n", "Delta_rho4 =(myDMO.dm.mass.min() /vol)\n", "\n", "# extra estatistics from Cfalcon density\n", "mean = std = n = stdlog = np.array([])\n", "for i in range(len(r_p)-1):\n", " shell = np.where((myDMO.dm.r > r_p[i])&(myDMO.dm.r < r_p[i+1])&(myDMO.dm.r > hsml))\n", " n = np.append(n,len(shell[0]))\n", " mean = np.append(mean,np.mean(myDMO.dm.rho[shell]))\n", " std = np.append(std,np.std(myDMO.dm.rho[shell]))\n", " stdlog = np.append(stdlog,np.std(np.log10(myDMO.dm.rho[shell])))\n", " \n", "n_dm_bin = n\n", "m_obs = n_dm*myDMO.dm.mass.min()\n", "n = np.array([len(myDMO.dm.mass[myDMO.dm.r val) ][0]\n", "print R_P03\n", "hsml= myhydro.gs.hsml.min()\n", "\n", "# R array logarithmic Bining\n", "r_p = np.logspace(np.log10(0.2*hsml),np.log10(hsml),15)\n", "# histogram of dm particles per logarithmic bin\n", "n_hydro,r = np.histogram(myhydro.dm.r,bins=r_p)\n", "# edges of bins\n", "r1,r2 =r[:-1],r[1:]\n", "# shell's volume\n", "vol = 4.* np.pi * ((r2**3)-(r1**3)) / 3.\n", "# density per shell\n", "profilehydro_in = n_hydro*myhydro.dm.mass.min()/vol\n", "# center of bins\n", "r_in = (r_p[:-1]+r_p[1:])/2.\n", "\n", "\n", "\n", "# R array logarithmic Bining\n", "r_p = np.logspace(np.log10(2*hsml),np.log10(2.5*myhydro.r200),100)\n", "# histogram of dm particles per logarithmic bin\n", "n_hydro,r = np.histogram(myhydro.dm.r,bins=r_p)\n", "# edges of bins\n", "r1,r2 =r[:-1],r[1:]\n", "# shell's volume\n", "vol = 4.* np.pi * ((r2**3)-(r1**3)) / 3.\n", "# density per shell\n", "profilehydro = n_hydro*myhydro.dm.mass.min()/vol\n", "# center of bins\n", "r = (r_p[:-1]+r_p[1:])/2.\n", "bin_size= (r_p[:-1]-r_p[1:])/2.\n", "rr = r\n", "# extra estatistics from Cfalcon density\n", "mean_hydro = std_hydro = stdlog_hydro = n_hydro=np.array([])\n", "for i in range(len(r_p)-1):\n", " shell_hydro = np.where((myhydro.dm.r > r_p[i])&(myhydro.dm.r < r_p[i+1])&(myhydro.dm.r > hsml))\n", " n_hydro = np.append(n_hydro,len(shell_hydro[0]))\n", " mean_hydro = np.append(mean_hydro,np.mean(myhydro.dm.rho[shell_hydro]))\n", " std_hydro = np.append(std_hydro,np.std(myhydro.dm.rho[shell_hydro]))\n", " stdlog_hydro = np.append(stdlog_hydro,np.std(np.log10(myhydro.dm.rho[shell_hydro])))\n", "\n", "m_obs_hydro = n_hydro*myhydro.dm.mass.min()\n", "n_hydro = np.array([len(myhydro.dm.mass[myhydro.dm.r" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FCN = 14.0905607297TOTAL NCALL = 849NCALLS = 849
EDM = 4.29772179119e-05GOAL EDM = 1e-05\n", " UP = 1.0
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValidValid ParamAccurate CovarPosDefMade PosDef
TrueTrueTrueTrueFalse
Hesse FailHasCovAbove EDMReach calllim
FalseTrueFalseFalse
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
+NameValueHesse ErrorMinos Error-Minos Error+Limit-Limit+Fixed?
0po7.417080.18617129No
1r_s7.354071.11576130No
2al1.762190.5703560.54No
3be2.633750.16537323.5No
4ga0.466250.17134401.5No
\n", "
\n",
       "\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "chi_rho = 14.09, chi_bin = 0.41\n" ] } ], "source": [ "m_rho_hydro = Minuit(chi2_rho_hydro,\n", " po=5.0, error_po=0.01, limit_po =(2.,9.),\n", " r_s=4.3, error_r_s=0.1, limit_r_s=(1.,30),\n", " al=2.8, error_al=0.1, limit_al=(0.5,4),\n", " be=2.5, error_be=0.1, limit_be =(2.,3.5),\n", " ga=0, error_ga=0.1, limit_ga =(0.0,1.5))\n", "m_rho_hydro.migrad();\n", "chirhorho = chi2_rho_hydro(m_rho_hydro.values['po'] ,m_rho_hydro.values['r_s'],m_rho_hydro.values['al'],m_rho_hydro.values['be'],m_rho_hydro.values['ga'])\n", "chibinrho= chi2_mass_bin_hydro(m_rho_hydro.values['po'] ,m_rho_hydro.values['r_s'],m_rho_hydro.values['al'],m_rho_hydro.values['be'],m_rho_hydro.values['ga'])\n", "print \"chi_rho = {0:1.2f}, chi_bin = {1:1.2f}\".format(chirhorho,chibinrho)" ] }, { "cell_type": "code", "execution_count": 87, "metadata": { "collapsed": false, "hide_input": true }, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FCN = 0.384674190434TOTAL NCALL = 253NCALLS = 253
EDM = 1.58974675511e-06GOAL EDM = 1e-05\n", " UP = 1.0
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValidValid ParamAccurate CovarPosDefMade PosDef
TrueTrueTrueTrueFalse
Hesse FailHasCovAbove EDMReach calllim
FalseTrueFalseFalse
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
+NameValueHesse ErrorMinos Error-Minos Error+Limit-Limit+Fixed?
0po7.464962.2318669No
1r_s7.7153112.8562120No
2al1.480871.750440.54No
3be2.716111.0597923.5No
4ga0.4422440.92871101.5No
\n", "
\n",
       "\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "chi_rho = 15.24, chi_bin = 0.38\n" ] } ], "source": [ "m_binH = Minuit(chi2_mass_bin_hydro,\n", " po=7.0, error_po=0.01, limit_po =(6.,9.),\n", " r_s=4.3, error_r_s=0.1, limit_r_s=(1.,20),\n", " al=2.8, error_al=0.1, limit_al=(0.5,4),\n", " be=2.5, error_be=0.1, limit_be =(2.,3.5),\n", " ga=0, error_ga=0.1, limit_ga =(0.0,1.5))\n", "m_binH.migrad();\n", "chirhobin = chi2_rho_hydro(m_binH.values['po'] ,m_binH.values['r_s'],m_binH.values['al'],m_binH.values['be'],m_binH.values['ga'])\n", "chibinbin= chi2_mass_bin_hydro(m_binH.values['po'] ,m_binH.values['r_s'],m_binH.values['al'],m_binH.values['be'],m_binH.values['ga'])\n", "print \"chi_rho = {0:1.2f}, chi_bin = {1:1.2f}\".format(chirhobin,chibinbin)\n" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "collapsed": false, "hide_input": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "chi_rho = 170.44, chi_bin = 2.94\n" ] } ], "source": [ "#polfit\n", "chirhopol = chi2_rho_hydro(7.663,4.425,2.895,2.541,8e-9)\n", "chibinpol= chi2_mass_bin_hydro(7.663,4.425,2.895,2.541,8e-9)\n", "print \"chi_rho = {0:1.2f}, chi_bin = {1:1.2f}\".format(chirhopol,chibinpol)" ] }, { "cell_type": "code", "execution_count": 97, "metadata": { "collapsed": false, "hide_input": false, "scrolled": true }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "bins = stars_bins -1\n", "\n", "x = np.logspace(-1,np.log10(10),bins)\n", "y = np.linspace(-1,1,bins/2)\n", "\n", "U= np.meshgrid(x, y)\n", "\n", "\n", "\n", "Z = stars(U[0],U[1],9.5, .25 , 1.6 ,2.1,.5,\n", " 8, 0.5, 2.8,\n", " 8, 1.3 ,5.1)\n", "\n", "\n", "\n", "\n", "fig ,[ax,ax1,ax2] = plt.subplots(3,1,figsize=[7,9],sharex=True, sharey=True)\n", "\n", "\n", "plt.tight_layout(h_pad=2)\n", "ax.set_xscale('log')\n", "real = ax.imshow(dens_hist / dens_hist.max(), interpolation='nearest', origin='low',aspect='auto',\n", " extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]],norm=LogNorm(vmin=1e-5))\n", "divider = make_axes_locatable(ax)\n", "cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n", "cbar = plt.colorbar(real,cax=cax)#,orientation='horizontal')\n", "\n", "ax1.set_title(\"Fit\")\n", "ax1.set_xscale('log')\n", "\n", "fit = ax1.imshow(Z/Z.max(), interpolation='nearest', origin='low',aspect='auto',\n", " extent=[x[0], x[-1], y[0], y[-1]],norm=LogNorm(vmin=1e-5))\n", "divider = make_axes_locatable(ax1)\n", "cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n", "cbar = plt.colorbar(real,cax=cax)\n", "\n", "\n", "#print \"fit : max = {0:.3e}, min = {1:.3e}\".format(Z.max(),Z.min())##print \"data : max = {0:.3e}, min = {1:.3e}\".format(dens_hist.max(),dens_hist.min())\n", "ratio = ((Z/Z.max())-(dens_hist/dens_hist.max()))#/(dens_hist/dens_hist.max())\n", "#ratio = np.abs(Z-dens_hist)/(dens_hist)\n", "\n", "ax2.set_title(\"Data\")\n", "ax2.set_xlabel(\"R [kpc]\")\n", "ax2.set_ylabel(\"z [kpc]\")\n", "ax2.set_xscale('log')\n", "\n", "real = ax2.imshow(ratio, interpolation='nearest', origin='low', vmax=1,aspect='auto',\n", " extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])#,norm=LogNorm(vmax=1e0))\n", "divider = make_axes_locatable(ax2)\n", "cax = divider.append_axes(\"right\", size=\"4%\", pad=0.05)\n", "cbar = plt.colorbar(real,cax=cax,label='data/fit')\n", "fig.tight_layout()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'\\nZ = stars(U[0],U[1],9.5, .25 , 1.6 ,2.1,.5,\\n 8, 0.6, 3.1,\\n 8, 1.3 ,6.1)\\n\\n'" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"\"\n", "Z = stars(U[0],U[1],9.5, .25 , 1.6 ,2.1,.5,\n", " 8, 0.6, 3.1,\n", " 8, 1.3 ,6.1)\n", "\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FCN = 1.06730763019e+22TOTAL NCALL = 28NCALLS = 28
EDM = 0.0GOAL EDM = 1e-05\n", " UP = 1.0
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValidValid ParamAccurate CovarPosDefMade PosDef
FalseTrueFalseFalseFalse
Hesse FailHasCovAbove EDMReach calllim
TrueTrueFalseFalse
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
+NameValueParab ErrorMinos Error-Minos Error+Limit-Limit+FIXED
1B_09.9100FIXED
2r00.41.12981000.012.0
3al2.63.77592000.05.0
4r_cut1.000015.68425001.09.0
5q0.660.801481000.01.0
6d_08.7100FIXED
7z_d1.0251.27411000.01.6
8Rd2.000014.97372002.09.0
9D_08.5100FIXED
10z_D1.11.22365000.72.9
11RD1.84.51601000.59.0
\n", " \n", "
\n",
       "            \n",
       "            
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FCN = 1.52587890625e-05TOTAL NCALL = 279NCALLS = 279
EDM = 7.99959193745e-06GOAL EDM = 1e-05\n", " UP = 1.0
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValidValid ParamAccurate CovarPosDefMade PosDef
TrueTrueTrueTrueFalse
Hesse FailHasCovAbove EDMReach calllim
FalseTrueFalseFalse
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
+NameValueParab ErrorMinos Error-Minos Error+Limit-Limit+FIXED
1B_09.9100FIXED
2r00.6778064.75442e-12000.00.68
3al0.380544.59795e-11000.04.42
4r_cut1.062862.71051e-11000.01.70001296997
5q0.6773432.76859e-11000.01.122
6d_08.7100FIXED
7z_d1.04883.79019e-11000.01.7425
8Rd2.097535.45872e-11000.03.40001134872
9D_08.5100FIXED
10z_D1.067145.79996e-11000.01.87
11RD3.01712.10061e-11000.03.06
\n", " \n", "
\n",
       "            \n",
       "            
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "m1=Minuit(chi2_st, \n", " B_0=9.9, fix_B_0=True,#error_B_0=0.5, limit_B_0=(9,10),\n", " r0=0.4, error_r0=0.1, limit_r0=(0.01,2),\n", " al=2.6, error_al=0.1, limit_al=(0,5.),\n", " r_cut=0.7, error_r_cut=0.1, limit_r_cut=(1,9.),\n", " q=0.66, error_q=0.1, limit_q=(0,1.),\n", " d_0=8.7, fix_d_0=True,#error_d_0=0.5, limit_d_0=(7,10.5),\n", " z_d=1.025, error_z_d=0.2, limit_z_d=(0.,1.6),\n", " Rd=1.5, error_Rd=0.01, limit_Rd=(2.,9.0),\n", " D_0=8.5, fix_D_0=True,#error_D_0=0.5, limit_D_0=(7.,10.5),\n", " z_D=1.1, error_z_D=0.02, limit_z_D=(0.7,2.9),\n", " RD=1.8, error_RD=0.01, limit_RD=(.5,9.)\n", " )\n", "m1.migrad();\n", "\n", "err = 4\n", "upp = 1.7\n", "low = 0.\n", "m2=Minuit(mass_check, \n", " B_0=m1.values['B_0'], fix_B_0=True,#error_B_0=m1.values['B_0']*err, limit_B_0=(m1.values['B_0']*low,m1.values['B_0']*upp),\n", " r0=m1.values['r0'], error_r0=m1.values['r0']*err, limit_r0=(m1.values['r0']*low,m1.values['r0']*upp),\n", " al=m1.values['al'], error_al=m1.values['al']*err, limit_al=(m1.values['al']*low,m1.values['al']*upp),\n", " r_cut=m1.values['r_cut'], error_r_cut=m1.values['r_cut']*err, limit_r_cut=(m1.values['r_cut']*low,m1.values['r_cut']*upp),\n", " q=m1.values['q'], error_q=m1.values['q']*err, limit_q=(m1.values['q']*low,m1.values['q']*upp),\n", " d_0=m1.values['d_0'], fix_d_0=True,#error_d_0=m1.values['d_0']*err, limit_d_0=(m1.values['d_0']*low,m1.values['d_0']*upp),\n", " z_d=m1.values['z_d'], error_z_d=m1.values['z_d']*err, limit_z_d=(m1.values['z_d']*low,m1.values['z_d']*upp),\n", " Rd=m1.values['Rd'], error_Rd=m1.values['Rd']*err, limit_Rd=(m1.values['Rd']*low,m1.values['Rd']*upp),\n", " D_0=m1.values['D_0'], fix_D_0=True,#error_D_0=m1.values['D_0']*err, limit_D_0=(m1.values['D_0']*low,m1.values['D_0']*upp),\n", " z_D=m1.values['z_D'], error_z_D=m1.values['z_D']*err, limit_z_D=(m1.values['z_D']*low,m1.values['z_D']*upp),\n", " RD=m1.values['RD'], error_RD=m1.values['RD']*err, limit_RD=(m1.values['RD']*low,m1.values['RD']*upp))\n", "# print_level=0)\n", "\n", "m2.migrad();\n" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "def mass_integrated(edge,B0,d0,D0):\n", " bins = 101\n", " zedge = edge/10.\n", " xe = np.linspace(0,edge,bins)\n", " ye = np.linspace(-zedge,zedge,bins)\n", " R_test = (xe[1:] + xe[:-1])/2\n", " Z_test = (ye[1:] + ye[:-1])/2\n", " U = np.meshgrid(R_test,Z_test)\n", " #\"\"\"\n", " rho = 2. * np.pi * U[0] * stars(U[0],U[1],B0, m2.values['r0'], m2.values['al'] , m2.values['r_cut'],\n", " m2.values['q'], d0, m2.values['z_d'], m2.values['Rd'],\n", " D0, m2.values['z_D'], m2.values['RD'])\n", "\n", " def integrand(R,z,B_0,r0,al,r_cut,q,d_0,z_d,Rd,D_0,z_D,RD):\n", " return 2. * np.pi * R * stars(R,z,B_0,r0,al,r_cut,q,d_0,z_d,Rd,D_0,z_D,RD)\n", "\n", " i = dblquad(integrand, -zedge, zedge , lambda x: 0, lambda x: edge, args=(B0, m2.values['r0'], m2.values['al'] , m2.values['r_cut'],\n", " m2.values['q'], d0, m2.values['z_d'], m2.values['Rd'],D0, m2.values['z_D'], m2.values['RD']))\n", " \n", " F = i[0] #firs level fit\n", " return F \n", "\n", "get_masses = np.vectorize(mass_integrated)\n", "get_mass_data = np.vectorize(lambda u :np.sum(myhydro.st.mass[np.where((myhydro.st.R" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FCN = 0.0384892569594TOTAL NCALL = 243NCALLS = 243
EDM = 0.000100844699412GOAL EDM = 1e-05\n", " UP = 1.0
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValidValid ParamAccurate CovarPosDefMade PosDef
TrueTrueTrueTrueFalse
Hesse FailHasCovAbove EDMReach calllim
FalseTrueFalseFalse
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
+NameValueParab ErrorMinos Error-Minos Error+Limit-Limit+FIXED
1B09.381221.36839007.010.7
2d07.384493.05691007.010.7
3D08.891740.437538007.010.7
\n", " \n", "
\n",
       "            \n",
       "            
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "def chimass(B0,d0,D0):\n", " c = np.log10(get_masses(r_masses,B0,d0,D0))-np.log10(data_mass)\n", " return np.sum(c**2)\n", "\n", "\n", "mmass=Minuit(chimass, \n", " B0=9.5, error_B0=0.5, limit_B0=(7,10.7),\n", " d0=9.5, error_d0=0.5, limit_d0=(7,10.7),\n", " D0=9.5, error_D0=0.5, limit_D0=(7,10.7))\n", "# print_level=0)\n", "mmass.migrad();" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "collapsed": false }, "outputs": [], "source": [ "level1 = get_masses(r_masses,mmass.values[\"B0\"],mmass.values[\"d0\"],mmass.values[\"D0\"])" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " this.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width);\n", " canvas.attr('height', height);\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "2346\n", "2346\n", "2346\n" ] } ], "source": [ "\n", "bins = stars_bins\n", "x = xedges#np.logspace(-1,np.log10(25),bins)\n", "y = yedges#np.linspace(-6,6,bins/2.5)\n", "U= np.meshgrid(x, y)\n", "\n", "\n", "#Z = stars(U[0],U[1],m2.values['B_0'], m2.values['r0'], m2.values['al'] , m2.values['r_cut'],\n", "# m2.values['q'], m2.values['D_0'], m2.values['z_d'], m2.values['Rd'])\n", "Z = stars(U[0],U[1],mmass.values['B0'], m2.values['r0'], m2.values['al'] , m2.values['r_cut'],\n", " m2.values['q'], mmass.values['d0'], m2.values['z_d'], m2.values['Rd'],\n", " mmass.values['D0'],m2.values['z_D'], m2.values['RD'])\n", "\n", "fig = plt.figure()\n", "ax = fig.add_subplot(111, projection='3d')\n", "#ax.set_zscale('log')\n", "#ax.set_zlim([0,1.2])\n", "\n", "R_test = (x[1:] + x[:-1])/2\n", "Z_test = (y[1:] + y[:-1])/2\n", "X,Y = np.meshgrid(R_test, Z_test)\n", "x_s = X.reshape(1,len(X)*len(X[0]))[0]\n", "y_s = Y.reshape(1,len(Y)*len(Y[0]))[0]\n", "dens = dens_hist.reshape(1,len(dens_hist)*len(dens_hist[0]))[0]\n", "print len(x_s)\n", "print len(y_s)\n", "print len(dens)\n", "ax.set_xlabel(\"R [kpc]\",fontsize=25)\n", "my_col = cm.jet(Z/Z.max())\n", "ax.set_ylabel(\"z [kpc]\",fontsize=25)\n", "ax.set_zlabel(r\"$\\rho($R,z$)$ [Msun / kpc$^3$]\",fontsize=25)\n", "\n", "ax.scatter(x_s, y_s,dens,marker='.',s=40)\n", "surf = ax.plot_surface(U[0], U[1], Z, cmap=cm.coolwarm, facecolors = my_col,alpha=0.5,\n", " linewidth=0, antialiased=False)" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " this.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width);\n", " canvas.attr('height', height);\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig, ax = plt.subplots()\n", "ax.set_xscale('log')\n", "real = plt.imshow(dens_hist_gs, interpolation='nearest', origin='low',norm=mpl.colors.LogNorm(),\n", " extent=[x_gs[0], x_gs[-1], y_gs[0], y_gs[-1]])\n", "\n", "#cbar = plt.colorbar(real)#,orientation='horizontal')" ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#def gas(R,z,D_0,z_d,Rm,Rd): \n", "# return (10**D_0) * np.exp(- (Rm / R) - (R / Rd)) / (np.cosh(z /2./ z_d))**2\n", "\n", "\n", "def gas(R,z,D_0,z_d,Rd):\n", " \n", " return (10**D_0) * np.exp( - (R / Rd)) / (np.cosh(z /2./ z_d))**2\n", "\n", "R_array = (x_gs[1:] + x_gs[:-1])/2\n", "Z_array = (y_gs[1:] + y_gs[:-1])/2\n", "\n", "R , Z = np.meshgrid(R_array,Z_array)\n", "\n", "\n", "def chi2_gas(D_0,z_d,Rd):\n", " chi2_array =np.array([])\n", " expected = gas(R,Z,D_0,z_d,Rd)\n", " observed = dens_hist_gs\n", " c = ((observed) - (expected))**2# / sigma_gs**2\n", " chi2_array = np.append(chi2_array,c)\n", " c_val = np.nansum(chi2_array)\n", " return (c_val)\n", "\n", "\n", "def mass_check_gas(D_0,z_d,Rd):\n", " xe, ye = np.linspace(0,edge,gs_bins ),np.linspace(-edge/15.,edge/15.,gs_bins)\n", " R_test,Z_test = (xe[1:] + xe[:-1])/2 , (ye[1:] + ye[:-1])/2\n", " U = np.meshgrid(R_test,Z_test)\n", " rho = 2. * np.pi * R_test * gas(U[0],U[1],D_0,z_d,Rd)\n", " I = np.zeros( len(rho) )\n", " for i in range(len(rho)):\n", " I[i] = np.trapz( rho[i], R_test )\n", " F = np.trapz( I, Z_test )\n", " data_in = np.sum(myhydro.gs.mass[np.where((myhydro.gs.R" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FCN = 1.64306035006e+20TOTAL NCALL = 181NCALLS = 181
EDM = 673643065.998GOAL EDM = 1e-05\n", " UP = 1.0
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValidValid ParamAccurate CovarPosDefMade PosDef
FalseTrueTrueTrueFalse
Hesse FailHasCovAbove EDMReach calllim
FalseTrueTrueFalse
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
+NameValueParab ErrorMinos Error-Minos Error+Limit-Limit+FIXED
1D_08.621431.39613e-10008.510.5
2z_d0.2732741.32617e-10000.0012.0
3Rd2.210411.21138e-09000.34.0
\n", " \n", "
\n",
       "            \n",
       "            
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FCN = 0.328046558527TOTAL NCALL = 58NCALLS = 58
EDM = 1078.19688313GOAL EDM = 1e-05\n", " UP = 1.0
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValidValid ParamAccurate CovarPosDefMade PosDef
FalseTrueTrueTrueFalse
Hesse FailHasCovAbove EDMReach calllim
FalseTrueTrueFalse
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
+NameValueParab ErrorMinos Error-Minos Error+Limit-Limit+FIXED
1D_08.630055.30903004.3107158348212.9321475045
2z_d0.2732740.182458000.1366371240360.409911372109
3Rd2.210411.20956001.105207364263.31562209277
\n", " \n", "
\n",
       "            \n",
       "            
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mg1=Minuit(chi2_gas, \n", " D_0=8.4, error_D_0=0.7, limit_D_0=(8.5,10.5),\n", " z_d=0.6, error_z_d=0.1, limit_z_d=(0.001,2),\n", " Rd=2.5, error_Rd=0.1, limit_Rd=(0.3,4))\n", "mg1.migrad();\n", "\n", "err = 0.01\n", "upp = 1.5\n", "low = 0.5\n", "mg2=Minuit(mass_check_gas, \n", " D_0=mg1.values['D_0'], error_D_0=mg1.values['D_0']*err, limit_D_0=(mg1.values['D_0']*low,mg1.values['D_0']*upp),\n", " z_d=mg1.values['z_d'], error_z_d=mg1.values['z_d']*err, limit_z_d=(mg1.values['z_d']*low,mg1.values['z_d']*upp),\n", " Rd=mg1.values['Rd'], error_Rd=mg1.values['Rd']*err, limit_Rd=(mg1.values['Rd']*low,mg1.values['Rd']*upp))\n", "\n", "mg2.migrad();" ] }, { "cell_type": "code", "execution_count": 49, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "def mass_integrated_gas(edge):\n", " \"\"\"\n", " integraties the amount of mass obtained by the gas fit\n", " gas(R,z,D_0,z_d,Rd)\n", " \"\"\"\n", " bins = 101\n", " zedge = edge/10.\n", " xe = np.linspace(0,edge,bins)\n", " ye = np.linspace(-zedge,zedge,bins)\n", " R_test = (xe[1:] + xe[:-1])/2\n", " Z_test = (ye[1:] + ye[:-1])/2\n", " U = np.meshgrid(R_test,Z_test)\n", " rho = 2. * np.pi * U[0] * gas(U[0],U[1],mg2.values['D_0'], mg2.values['z_d'] , mg2.values['Rd'])\n", "\n", " def integrand(R,z,D_0,z_d,Rd):\n", " return 2. * np.pi * R * gas(R,z,D_0,z_d,Rd)\n", "\n", " j = dblquad(integrand, -zedge, zedge , lambda x: 0, lambda x: edge, args=(mg1.values['D_0'], mg1.values['z_d'], mg1.values['Rd']))\n", "\n", " i = dblquad(integrand, -zedge, zedge , lambda x: 0, lambda x: edge, args=(mg2.values['D_0'], mg2.values['z_d'] , mg2.values['Rd']))\n", " \n", " F = j[0] #firs level fit\n", " F2 = i[0] # second level fit\n", " return F , F2\n", "#print \"Fit = {0:.5e} dens constrain 1dn level fit\".format(F2)\n", "#print \"Fit = {0:.5e} mass constrain 2dn level fit\".format(F)\n", "#print \"data = \",np.sum(myhydro.st.mass[np.where((myhydro.st.R" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FCN = 0.0062006198707TOTAL NCALL = 142NCALLS = 142
EDM = 6.99809266896e-05GOAL EDM = 1e-05\n", " UP = 1.0
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValidValid ParamAccurate CovarPosDefMade PosDef
TrueTrueTrueTrueFalse
Hesse FailHasCovAbove EDMReach calllim
FalseTrueFalseFalse
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
+NameValueParab ErrorMinos Error-Minos Error+Limit-Limit+FIXED
1d08.496750.913803006.010.7
2zs0.1187930.324646000.011.5
3r05.971345.70925001.08.0
\n", " \n", "
\n",
       "            \n",
       "            
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "def chimass_gs(d0,zs,r0):\n", " c = np.log10(get_mass_GAs(r_masses,d0,zs,r0))-np.log10(gdata_mass)\n", " return np.sum(c**2)\n", "\n", "\n", "mmass_gs=Minuit(chimass_gs, \n", " d0=9, error_d0=0.2, limit_d0=(6,10.7),\n", " zs=.1, error_zs=0.01, limit_zs=(0.01,1.5),\n", " r0=3.5, error_r0=0.1, limit_r0=(1,8))\n", "# print_level=0)\n", "mmass_gs.migrad();" ] }, { "cell_type": "code", "execution_count": 53, "metadata": { "collapsed": true }, "outputs": [], "source": [ "gas_fit_from_mass = get_mass_GAs(r_masses,mmass_gs.values['d0'],mmass_gs.values['zs'],mmass_gs.values['r0'])" ] }, { "cell_type": "code", "execution_count": 54, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " this.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width);\n", " canvas.attr('height', height);\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "ename": "NameError", "evalue": "name 'xedges' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[0max\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_xscale\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'log'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 32\u001b[0m real = ax.imshow(dens_hist_gs, interpolation='nearest', origin='low',aspect='auto',\n\u001b[0;32m---> 33\u001b[0;31m extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]],norm=LogNorm(vmin=1e7))\n\u001b[0m\u001b[1;32m 34\u001b[0m \u001b[0mdivider\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmake_axes_locatable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0max\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0mcax\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdivider\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend_axes\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"right\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"5%\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpad\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.05\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mNameError\u001b[0m: name 'xedges' is not defined" ] } ], "source": [ "bins = gs_bins -1\n", "\n", "\n", "edge = 20\n", "zedge = edge/40.\n", "x_gs = np.logspace(-0.5,np.log10(edge),bins)\n", "y_gs = np.linspace(-zedge,zedge,bins)\n", "\n", "\n", "x = np.logspace(-1,np.log10(10),bins)\n", "y = np.linspace(-1,1,bins/2)\n", "\n", "#x = np.logspace(-1,np.log10(25),bins)\n", "#y = np.linspace(-6,6,(bins/2.5))\n", "U= np.meshgrid(x_gs, y_gs)\n", "\n", "\n", "\"\"\"\n", "Z = gas(U[0],U[1],9.3, 0.2 , 1.2)\n", "\"\"\"\n", "#\"\"\"\n", "Z = gas(U[0],U[1],mg2.values['D_0'], 0.5 , mg2.values['Rd'])\n", "#\"\"\"\n", "\n", "\n", "\n", "fig ,[ax,ax1,ax2] = plt.subplots(3,1,figsize=[7,9])\n", "\n", "\n", "plt.tight_layout(h_pad=2)\n", "ax.set_xscale('log')\n", "real = ax.imshow(dens_hist_gs, interpolation='nearest', origin='low',aspect='auto',\n", " extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]],norm=LogNorm(vmin=1e7))\n", "divider = make_axes_locatable(ax)\n", "cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n", "cbar = plt.colorbar(real,cax=cax)#,orientation='horizontal')\n", "\n", "\n", "\n", "ax1.set_title(\"Fit\")\n", "ax1.set_xscale('log')\n", "\n", "\n", "Z = gas(U[0],U[1],8.5, 0.1 , 2.)\n", "\n", "fit = ax1.imshow(Z, interpolation='nearest', origin='low',aspect='auto',\n", " extent=[x[0], x[-1], y[0], y[-1]],norm=LogNorm(vmin=1e7))\n", "divider = make_axes_locatable(ax1)\n", "cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n", "cbar = plt.colorbar(real,cax=cax)\n", "\n", "#ax.set_title(\"Data\")\n", "\n", "#real = ax.imshow(dens_hist, interpolation='nearest', origin='low',aspect='auto',\n", "# extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])\n", "#divider = make_axes_locatable(ax)\n", "#cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n", "#cbar = plt.colorbar(real,cax=cax)#,orientation='horizontal')\n", "\n", "print \"fit : max = {0:.3e}, min = {1:.3e}\".format(Z.max(),Z.min())\n", "print \"data : max = {0:.3e}, min = {1:.3e}\".format(dens_hist_gs.max(),dens_hist.min())\n", "ratio = np.abs(Z-dens_hist_gs)/dens_hist_gs\n", "\n", "ax2.set_title(\"Data\")\n", "ax2.set_xlabel(\"R [kpc]\")\n", "ax2.set_ylabel(\"z [kpc]\")\n", "ax2.set_xscale('log')\n", "\n", "real = ax2.imshow(ratio, interpolation='nearest', origin='low', vmax=1,aspect='auto',\n", " extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])#,norm=LogNorm(vmax=1e0))\n", "divider = make_axes_locatable(ax2)\n", "cax = divider.append_axes(\"right\", size=\"4%\", pad=0.