diff --git a/notebooks/LMAGui3D.ipynb b/notebooks/LMAGui3D.ipynb index 705c78f..b3d7ad3 100644 --- a/notebooks/LMAGui3D.ipynb +++ b/notebooks/LMAGui3D.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:4bc3b2d123ce5c55f02e6e316b3d5cafbde3873d58d6e0486afb0b7b236f157c" + "signature": "sha256:b585b40036a51ee6367f5e90e9432a8e9b8a50b613eef726bf2df3cad872cb06" }, "nbformat": 3, "nbformat_minor": 0, @@ -15,15 +15,13 @@ "Reproducible LMA research with the IPython notebook and brawl4d\n", "===============================================================\n", "\n", - "This notebook demonstrates how to download and display data from the NSF-sponsored Deep Convective Clouds and Chemistry campaign.\n", + "This notebook demonstrates how to display data included in the lmatools repository.\n", "\n", - "To download data, go to the DC3 data archive and choose one of the LMA datasets. This example will assume use of the LMA VHF source and flash data on June 4, 2012 from 2050-2100 UTC from West Texas, as retrieved using the DC3 data download form.\n", - "\n", - "**Note: the hour of data below is 960 MB, so caveat downloader**. Try just the 2050--2100 interval.\n", - "\n", - "Running the code below is some basic boilerplate.\n", - "\n", - "**note: some issues exist due to issues with the lasso tool in pylab, the matplotlib qt4 backend works but may take a couple tries to run the browser." + "If you haven't yet, process and view sample data included with lmatools\n", + "```\n", + "python ~/code/lmatools/testing/test_sklearn.py /path/to/output/files/\n", + "```\n", + "Then, edit the data_path in the second cell to include `/path/to/output/files/` as defined above. Run all the cells prior to the \"Charge Analysis\" and try interacting with the plot. You should see some data.\n" ] }, { @@ -31,36 +29,45 @@ "collapsed": true, "input": [ "%matplotlib qt4\n", - "import matplotlib\n", - "#matplotlib.use('Qt4Agg')\n", + "# import matplotlib\n", + "# matplotlib.use('nbagg')\n", "#import matplotlib.pyplot as plt\n", "from brawl4d.brawl4d import B4D_startup, redraw\n", - "\n", - "\n" + "import os" ], "language": "python", "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stderr", - "text": [ - "/Users/ebruning/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py:1155: UserWarning: This call to matplotlib.use() has no effect\n", - "because the backend has already been chosen;\n", - "matplotlib.use() must be called *before* pylab, matplotlib.pyplot,\n", - "or matplotlib.backends is imported for the first time.\n", - "\n", - " warnings.warn(_use_error_msg)\n" - ] - } + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "data_path = '/data/tmp/flash_sort_test/'\n", + "lma_file = os.path.join(data_path, 'h5_files/2014/May/26/LYLOUT_140526_094000_0600.dat.flash.h5')" ], - "prompt_number": 1 + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "os.path.join?" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 9 }, { "cell_type": "markdown", "metadata": {}, "source": [ - "In the cell below, note that the basedate has been set to match the dataset we downloaded above.\n", + "In the cell below, note that the basedate has been set to match the dataset we specified above.\n", "\n", "If you are not using data from the WTLMA, then you'll also need to pass ctr_lon=value and ctr_lat=value to B4D_startup." ] @@ -70,27 +77,29 @@ "collapsed": false, "input": [ "from datetime import datetime\n", - "panels = B4D_startup(basedate=datetime(2013,6,6), ctr_lat=33.5, ctr_lon=-101.5)" + "panels = B4D_startup(basedate=datetime(2014,5,26), ctr_lat=33.5, ctr_lon=-101.5)" ], "language": "python", "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stderr", - "text": [ - "/Users/ebruning/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py:1236: UserWarning: findfont: Font family ['Helvetica'] not found. Falling back to Bitstream Vera Sans\n", - " (prop.get_family(), self.defaultFamily[fontext]))\n" - ] - } + "outputs": [], + "prompt_number": 10 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import matplotlib.pyplot as plt; plt.show()" ], - "prompt_number": 2 + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Below, set a valid path to lma_file. The IPython notebook will try to tab-complete paths." + "Below, set a valid path to lma_file. IPython will tab-complete paths, like the shell." ] }, { @@ -98,7 +107,6 @@ "collapsed": false, "input": [ "from brawl4d.LMA.controller import LMAController\n", - "lma_file = '/data/20130606/LMA/LYLOUT_130606_033000_0600.dat.flash.h5'\n", "lma_ctrl = LMAController()\n", "d, post_filter_brancher, scatter_ctrl, charge_lasso = lma_ctrl.load_hdf5_to_panels(panels, lma_file)" ], @@ -113,21 +121,14 @@ ] } ], - "prompt_number": 4 - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Zoom in on a few cells of interest. The smaller, western and northern cells here are anomalously electrified, while the larger cluster is normally electrified." - ] + "prompt_number": 12 }, { "cell_type": "code", "collapsed": false, "input": [ - "panels.panels['tz'].axis((3*3600 + 30*60, 3*3600 + 30*60+5, 1, 15))\n", - "panels.panels['xy'].axis((-100, 0, 0, 90))" + "panels.panels['tz'].axis((9*3600 + 40*60, 9*3600 + 42*60, 1, 15))\n", + "panels.panels['xy'].axis((-130, 20, -10, 140))" ], "language": "python", "metadata": {}, @@ -135,19 +136,35 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 5, + "prompt_number": 16, "text": [ - "(-100, 0, 0, 90)" + "(-130, 20, -10, 140)" ] } ], - "prompt_number": 5 + "prompt_number": 16 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from brawl4d.LMA.widgets import LMAwidgetController\n", + "from IPython.display import display\n", + "from brawl4d.LMA.controller import LMAController\n", + "\n", + "lma_tools = LMAwidgetController(panels, lma_ctrl, scatter_ctrl, charge_lasso, d)\n", + "display(lma_tools.tools_popup)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 14 }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The following cell contains and combines all functions of Brawl4d into a single .py file. This allows all tools to be activiated simultaneously, while also enabling a centralized container for all active widgets for convienence.\n", + "The cell above contains and combines all functions of Brawl4d into a single .py file. This allows all tools to be activiated simultaneously, while also enabling a centralized container for all active widgets for convienence.\n", "\n", "LMA Tools Contained:\n", "\n", @@ -163,53 +180,11 @@ ] }, { - "cell_type": "code", - "collapsed": false, - "input": [ - "from brawl4d.LMA.widgets import LMAwidgetController\n", - "from IPython.display import display\n", - "from brawl4d.LMA.controller import LMAController\n", - "\n", - "lma_tools = LMAwidgetController(panels, lma_ctrl, scatter_ctrl, charge_lasso, d)\n", - "display(lma_tools.tools_popup)\n" - ], - "language": "python", + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "15 of 24 flashes have > 10 points. Their average area = 47.4 km^2\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "15 of 24 flashes have > 10 points. Their average area = 47.4 km^2\n", - "15 of 24 flashes have > 10 points. Their average area = 47.4 km^2\n", - "15 of 24 flashes have > 10 points. Their average area = 47.4 km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "15 of 24 flashes have > 10 points. Their average area = 47.4 km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] - } - ], - "prompt_number": 6 + "source": [ + "Zoom in on a few cells of interest. The smaller, western and northern cells here are anomalously electrified, while the larger cluster is normally electrified." + ] }, { "cell_type": "markdown", @@ -248,17 +223,7 @@ ], "language": "python", "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "[ 12611.22600217 12611.3120399 12611.30892055 ..., 13193.44423766\n", - " 13193.44017365 13193.45137127]\n" - ] - } - ], - "prompt_number": 21 + "outputs": [] }, { "cell_type": "markdown", @@ -284,8 +249,7 @@ ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 11 + "outputs": [] }, { "cell_type": "markdown", @@ -307,8 +271,7 @@ ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 11 + "outputs": [] }, { "cell_type": "code", @@ -316,8 +279,7 @@ "input": [], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 7 + "outputs": [] }, { "cell_type": "markdown", @@ -383,8 +345,7 @@ ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 8 + "outputs": [] }, { "cell_type": "code", @@ -395,195 +356,7 @@ ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'LMAEventStats' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\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[0;32m----> 1\u001b[0;31m \u001b[0mstats\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mLMAEventStats\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpanels\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgeoProj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mstat_maker\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstats\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mevents_flashes_receiver\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'LMAEventStats' is not defined" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0 of 0 flashes have > 10 points. Their average area = nan km^2\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - } - ], - "prompt_number": 8 + "outputs": [] }, { "cell_type": "code", @@ -593,19 +366,7 @@ ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'stat_maker' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\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[0;32m----> 1\u001b[0;31m \u001b[0mcurrent_events_flashes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtargets\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstat_maker\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mNameError\u001b[0m: name 'stat_maker' is not defined" - ] - } - ], - "prompt_number": 9 + "outputs": [] }, { "cell_type": "code", @@ -615,129 +376,7 @@ ], "language": "python", "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "set([])\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0 of 0 flashes have > 10 points. Their average area = nan km^2\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "0 of 0 flashes have > 10 points. Their average area = nan km^2" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "What if we take the points on the volumetric hull, and PCA decompose those? Will the envelope have a major axis that is more aligned along the plate area?" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Further analysis\n", - "----------------\n", - "\n", - "If your analysis is hard to explain, maybe it would help to include an equation with LaTeX: $$y=x^2$$" - ] + "outputs": [] }, { "cell_type": "markdown", @@ -755,50 +394,59 @@ "cell_type": "code", "collapsed": false, "input": [ + "from brawl4d.brawl4d import redraw\n", "import mayavi.mlab as mvlab\n", "from stormdrain.pipeline import coroutine\n", "class MayaviOutlet(object):\n", - " def __init__(self, ev_fl_broadcaster):\n", + " def __init__(self, panels, ev_fl_broadcaster):\n", " self.ev_fl_broadcaster = ev_fl_broadcaster\n", " self.ev_fl_broadcaster.targets.add(self.rx())\n", - " self.p3d = mvlab.points3d(evx, evy, evz, evt, scale_factor=2e-5)\n", - " \n", + " self.p3d = mvlab.points3d([0], [0], [0], [0], scale_factor=5e-5)\n", + " self.scene = self.p3d.scene\n", + " self.scene.background = (0,0,0)\n", + " self.panels=panels\n", + " \n", + " # Force a reflow of data\n", + " redraw(panels)\n", + " \n", + " # move camera to see everything after data are plotted\n", + " self.scene.reset_zoom()\n", + " \n", " @coroutine\n", " def rx(self):\n", " while True:\n", " ev, fl = (yield)\n", - " self.ev = ev\n", - " self.fl = fl\n", + "# self.ev = ev\n", + "# self.fl = fl\n", " evx, evy, evz, evt = ev['x'], ev['y'], ev['z'], ev['time']\n", " self.p3d.mlab_source.reset(x=evx, y=evy, z=evz, scalars=evt)\n", " \n", "current_events_flashes = lma_ctrl.flash_stats_for_dataset(d, scatter_ctrl.branchpoint)\n", - "mvo = MayaviOutlet(current_events_flashes)" + "mvo = MayaviOutlet(panels, current_events_flashes)" ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 27 + "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ - "scatter_ctrl??" + "mvo.p3d.scene.reset_zoom?" ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 29 + "outputs": [] }, { "cell_type": "code", "collapsed": false, - "input": [], + "input": [ + "panels.bounds.limits()" + ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 16 + "outputs": [] }, { "cell_type": "code",