Reproducible LMA research with the IPython notebook and brawl4d

This notebook demonstrates how to display data included in the lmatools repository.

If you haven't yet, process and view sample data included with lmatools

python ~/code/lmatools/testing/test_sklearn.py /path/to/output/files/

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.


In [1]:
%matplotlib qt4
# import matplotlib
# matplotlib.use('nbagg')
#import matplotlib.pyplot as plt
from brawl4d.brawl4d import B4D_startup, redraw
import os

In [2]:
data_path = '/data/DC3/flash_sort/'
lma_file = os.path.join(data_path, 'h5_files/2012/Jun/02/LYLOUT_120602_204001_0600.dat.flash.h5')

In the cell below, note that the basedate has been set to match the dataset we specified above.

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.


In [3]:
from datetime import datetime
panels = B4D_startup(basedate=datetime(2012,6,2), ctr_lat=40.4463980, ctr_lon=-104.6368130)


/Users/ebruning/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py:1279: UserWarning: findfont: Font family [u'Helvetica'] not found. Falling back to Bitstream Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))

In [4]:
import matplotlib.pyplot as plt; plt.show()

Below, set a valid path to lma_file. IPython will tab-complete paths, like the shell.


In [5]:
from brawl4d.LMA.controller import LMAController
lma_ctrl = LMAController()
d, post_filter_brancher, scatter_ctrl, charge_lasso = lma_ctrl.load_hdf5_to_panels(panels, lma_file)


found flash data

Zoom to overview of first minute


In [6]:
h,m,s,dt = 20, 40, 0, 60
panels.panels['tz'].axis((h*3600 + m*60 + s, h*3600 + m*60 + s+dt, 1, 18))
panels.panels['xy'].axis((-150, 150, -150, 150))


Out[6]:
(-150, 150, -150, 150)

In [7]:
from brawl4d.LMA.widgets import LMAwidgetController
from IPython.display import display
from brawl4d.LMA.controller import LMAController

lma_tools = LMAwidgetController(panels, lma_ctrl, scatter_ctrl, charge_lasso, d)
display(lma_tools.tools_popup)

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.

LMA Tools Contained:

Number of Stations: Specify accordingly with data file (min=1; max=11)

Max Chi2: Values for chi2 obtained from the data file (min=0.0; max=1.0)

Charge Selection: Selection for Negative (-1), Neutral (0), and Positive (1) charge for charge selection and analyzation in the browser. The draw button activates the lasso tool enabling charge selection; re-clicking the draw button is necessary upon each selection made.

Color By: Allows the display of LMA data by chi2, time, or charge; selecting one will redraw the plot in the browser.

Animation Time: Allows for animation of the LMA data in the browser for charge polarity determination made by Charge Selection. The slider allows the user to select a desired time for total animation duration (min=1s, max=30s). Clicking Animate will then animate the data after a desired time has been selected.

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.

Southern cell, first minute


In [15]:
h,m,s,dt = 20, 40, 0, 60
panels.panels['tz'].axis((h*3600 + m*60 + s, h*3600 + m*60 + s+dt, 1, 18))
panels.panels['xy'].axis((-50, 70, -140, -60))


Out[15]:
(-50, 70, -140, -60)

Center cell, first 5 min


In [8]:
h,m,s,dt = 20, 40, 0, 5*60
panels.panels['tz'].axis((h*3600 + m*60 + s, h*3600 + m*60 + s+dt, 1, 18))
panels.panels['xy'].axis((-60, 50, -60, 50))


Out[8]:
(-60, 50, -60, 50)

This cell has a few large flashes. The flash at 2041:54.4 is the sort of flash that could make a +CG, though the NLDN didn't think it did so. It initaites a second negative leader branch at :55.3, and exhibits some retracing activity in the few hundred ms before that.


In [22]:
%%bash
cat /data/DC3/20120602/hereford_storm/june_02-03_nldn.txt | grep "20:41:5"


2012-06-02 20:41:52.035327921  39.6019 -104.2147    +7.8 kA  C  1  0.2
2012-06-02 20:41:53.409769109  38.4281 -104.5599    +6.6 kA  C  1  0.3
2012-06-02 20:41:54.469170617  40.4351 -104.7374   +15.2 kA  C  1  0.2
2012-06-02 20:41:54.472074096  40.4632 -104.6914   +10.7 kA  C  1  3.8
2012-06-02 20:41:57.701939326  39.5040 -104.7168   +32.7 kA  C  1  0.2
2012-06-02 20:41:57.742855428  39.5199 -104.6816    +7.4 kA  C  1  0.3
2012-06-02 20:41:57.742995686  39.5540 -104.6471    +8.8 kA  C  1  0.5

Charge analysis

It's possible to use a lasso to classify charge regions inferred from LMA data. Set the polarity and run the code below to start the lasso. On the plot, left click to draw the lasso, and then right click to close the lasso and assign the charge.

If you're using an HDF5-format LMA data file, the analyzed charge is automatically written to the HDF5 file. The results of the operation can be queried by looking for the points that have had their charge set to the value defined above.


In [ ]:
chg = d.data['charge']
wh = np.where(chg > 0)
print d.data[wh]['time']

Color by...

In addition to coloring the scatter plots by time, it's possible to use other values in the LMA data array.


In [ ]:
# A reference to the current data in the view is cached by the charge lasso.
current_data = charge_lasso.cache_segment.cache[-1]
# Manually set the color limits on the flash_id variable
scatter_ctrl.default_color_bounds.flash_id =(current_data['flash_id'].min(), current_data['flash_id'].max())
# Color by flash ID.
scatter_ctrl.color_field = 'flash_id'

redraw()

Flash statistics

If the LMA controller found flash data, then it's possible to get a live update of flashes in the current view. current_events_flashes is an analysis pipeline branchpoint, which will send events and flashes to another analysis pipeline segment that can be specified with current_events_flashes.targets.add(target). Behind the scenes, it's hooked up to an segment that receives the events and flashes, and prints the average flash area of all flashes that have more than a threshold number of points.

Change the view a few times and you'll see updated flash stats below.


In [8]:
current_events_flashes = lma_ctrl.flash_stats_for_dataset(d, scatter_ctrl.branchpoint)

In [8]:

Flash volume for current sources


In [9]:
from scipy.spatial import Delaunay
from scipy.misc import factorial
import numpy as np
from stormdrain.pipeline import coroutine
class LMAEventStats(object):
    
    def __init__(self, GeoSys):
        """ GeoSys is an instance of
            stormdrain.support.coords.systems.GeographicSystem instance
        """
        self.GeoSys = GeoSys
    
    def ECEF_coords(self, lon, lat, alt):
        x,y,z = self.GeoSys.toECEF(lon, lat, alt)
        return x,y,z
    
    
    def _hull_volume(self):
        tri = Delaunay(self.xyzt[:,0:3])
        vertices = tri.points[tri.vertices]
        
        # This is the volume formula in 
        # https://github.com/scipy/scipy/blob/master/scipy/spatial/tests/test_qhull.py#L106
        # Except the formula needs to be divided by ndim! to get the volume, cf., 
        # http://en.wikipedia.org/wiki/Simplex#Geometric_properties
        # Credit Pauli Virtanen, Oct 14, 2012, scipy-user list
        q = vertices[:,:-1,:] - vertices[:,-1,None,:]
        simplex_volumes = (1.0 / factorial(q.shape[-1])) * np.fromiter(
                (np.linalg.det(q[k,:,:]) for k in range(tri.nsimplex)) , dtype=float)
        self.tri = tri
        
        # The simplex volumes have negative values since they are oriented 
        # (think surface normal direction for a triangle
        self.volume=np.sum(np.abs(simplex_volumes))
        
    
    @coroutine
    def events_flashes_receiver(self):
        while True:
            evs, fls = (yield)
            x,y,z = self.ECEF_coords(evs['lon'], evs['lat'], evs['alt'])
            t = evs['time']
            self.xyzt = np.vstack((x,y,z,t)).T
            self._hull_volume()
            print "Volume of hull of points in current view is {0:5.1f}".format(
                        self.volume / 1.0e9) # (1000 m)^3

In [10]:
stats = LMAEventStats(panels.cs.geoProj)
stat_maker = stats.events_flashes_receiver()

In [11]:
current_events_flashes.targets.add(stat_maker)

In [14]:
print current_events_flashes.targets


Volume of hull of points in current view is 489.7
2 of 6 flashes have > 10 points. Their average area =  43.9 km^2
[-101.89087677001953 -101.89263153076172 -101.90204620361328
 -101.90213012695312 -101.9006118774414 -101.9045181274414
 -101.90447235107422 -101.91381072998047 -101.90780639648438
 -101.9071273803711 -101.9059066772461 -101.90475463867188
 -101.91388702392578 -101.9148941040039 -101.91502380371094
 -101.91565704345703 -101.91446685791016 -101.90544128417969
 -101.907470703125 -101.96519470214844 -101.96109771728516
 -101.91413879394531 -101.94587707519531 -101.91877746582031
 -101.95084381103516 -101.91938018798828 -101.91799926757812
 -101.94898986816406 -101.91845703125 -101.91876220703125
 -101.94558715820312 -101.91915893554688 -101.93732452392578
 -101.92131042480469 -101.9456787109375 -101.92108154296875
 -101.9356689453125 -101.9212646484375 -101.94539642333984
 -101.94873809814453 -101.91272735595703 -101.91374969482422
 -101.91122436523438 -101.90763854980469 -101.93019104003906
 -101.91060638427734 -101.91019439697266 -101.90711975097656
 -101.90933990478516 -101.90584564208984 -101.90933227539062
 -101.96188354492188 -101.9093017578125 -101.91822814941406
 -101.9096450805664 -101.91241455078125 -101.91902160644531
 -101.90886688232422 -101.90750122070312 -101.95476531982422
 -101.90884399414062 -101.9162368774414 -101.91175842285156
 -101.91426086425781 -101.94481658935547 -101.91181945800781
 -101.94288635253906 -101.91409301757812 -101.92141723632812
 -101.94512176513672 -101.94566345214844 -101.95111083984375
 -101.95124053955078 -101.94248962402344 -101.94287872314453
 -101.94361114501953 -101.94314575195312 -101.95162963867188
 -101.9446029663086 -101.88674926757812 -101.95205688476562
 -101.94434356689453 -101.94417572021484 -101.94583892822266
 -101.9432144165039 -101.94193267822266 -101.95214080810547
 -101.94830322265625 -101.9483642578125 -101.9513168334961
 -101.95057678222656 -101.88488006591797 -101.94985961914062
 -101.98450469970703 -101.98474884033203 -101.88323211669922
 -101.93799591064453 -101.93668365478516 -101.88651275634766
 -101.94512176513672 -101.90848541259766 -101.94647216796875
 -101.94661712646484 -101.94686126708984 -101.94695281982422
 -101.94525146484375 -101.94588470458984 -101.9288101196289
 -101.94742584228516 -101.94735717773438 -101.93112182617188
 -101.94578552246094 -101.95410919189453 -101.94425964355469
 -101.94856262207031 -101.94775390625 -101.93235778808594
 -101.95309448242188 -101.93220520019531 -101.93258666992188
 -101.93187713623047 -101.88874816894531 -101.95063781738281
 -101.9343490600586 -101.93545532226562 -101.94587707519531
 -101.90882873535156 -101.90715026855469 -101.90180969238281
 -101.9391860961914 -101.93861389160156 -101.94361877441406
 -101.94348907470703 -101.94835662841797 -101.93101501464844
 -101.94319152832031 -101.94403839111328 -101.9444580078125
 -101.93714141845703 -101.945068359375 -101.94371032714844
 -101.94425201416016 -101.94007110595703 -101.93155670166016
 -101.93987274169922 -101.93937683105469 -101.93208312988281
 -101.93204498291016 -101.96736145019531 -101.93472290039062
 -101.93367767333984 -101.9127197265625 -101.92977905273438
 -101.93062591552734 -101.94914245605469 -101.92810821533203
 -101.949951171875 -101.94951629638672 -101.95158386230469
 -101.95284271240234 -101.95492553710938 -101.95549774169922
 -101.95747375488281 -101.96117401123047 -101.94548797607422
 -101.97663879394531 -101.97982788085938 -101.97319030761719
 -101.96810913085938 -101.96770477294922 -101.93617248535156
 -101.94969940185547 -101.95175170898438 -101.9520034790039
 -101.95026397705078 -101.93711853027344 -101.9503173828125
 -101.94075775146484 -101.95040130615234 -101.94950103759766
 -101.9488296508789 -101.93954467773438 -101.93859100341797
 -101.97099304199219 -101.93012237548828 -101.91265106201172
 -101.9284439086914 -101.91706848144531 -101.91779327392578
 -101.92109680175781 -101.92229461669922 -101.921630859375
 -101.9475326538086 -101.95587921142578 -101.91472625732422
 -101.91854858398438 -101.91822052001953 -101.91780090332031
 -101.89945220947266 -101.90811157226562 -101.95756530761719
 -101.92566680908203 -101.9189224243164 -101.90795135498047
 -101.90483856201172 -101.90833282470703 -101.90719604492188
 -101.91934967041016 -101.90721130371094 -101.94879913330078
 -101.91848754882812 -101.94511413574219 -101.91832733154297
 -101.91564178466797 -101.91580963134766 -101.91361999511719
 -101.92514038085938 -101.91239929199219 -101.92697143554688
 -101.92762756347656 -101.9271469116211 -101.92521667480469
 -101.90982818603516 -101.90821838378906 -101.91020202636719
 -101.97200012207031 -101.91153717041016 -101.910400390625
 -101.91020202636719 -101.91622161865234 -101.91136932373047
 -101.91344451904297 -101.90896606445312 -101.91487121582031
 -101.9140853881836 -101.9179916381836 -101.91383361816406
 -101.9180679321289 -101.91301727294922 -101.95381927490234
 -101.916259765625 -101.91426086425781 -101.91224670410156
 -101.93524932861328 -101.94600677490234 -101.92119598388672
 -101.93865203857422 -101.93794250488281 -101.93743133544922
 -101.93782043457031 -101.93706512451172 -101.93641662597656
 -101.937744140625 -101.93769073486328 -101.93927001953125 -101.935546875
 -101.93624877929688 -101.93656921386719 -101.9457778930664
 -101.9373550415039 -101.9362564086914 -101.93741607666016
 -101.93840789794922 -101.93807220458984 -101.9383773803711
 -101.9374771118164 -101.98469543457031 -101.98442077636719
 -101.945068359375 -101.9456787109375 -101.94475555419922
 -101.94600677490234 -101.94367218017578 -101.98593139648438
 -101.94115447998047 -101.94049835205078 -101.94171142578125
 -101.941162109375 -101.94213104248047 -101.94123840332031
 -101.93916320800781 -101.93673706054688 -101.93744659423828
 -101.93497467041016 -101.93490600585938 -101.93528747558594
 -101.94348907470703 -101.93292999267578 -101.93274688720703
 -101.93358612060547 -101.9360580444336 -101.93782806396484
 -101.93183898925781 -101.93726348876953 -101.93827056884766
 -101.93932342529297 -101.93929290771484 -101.93103790283203
 -101.93222045898438 -101.9310302734375 -101.93952178955078
 -101.94781494140625 -101.94551086425781 -101.9305419921875
 -101.93289184570312 -101.94395446777344 -101.93119049072266
 -101.93392181396484 -101.9349365234375 -101.93486022949219
 -101.93475341796875 -101.93966674804688 -101.94072723388672
 -101.94548797607422 -101.93697357177734 -101.93746185302734
 -101.9378433227539 -101.93655395507812 -101.9354248046875
 -101.93599700927734 -101.9347915649414 -101.93474578857422
 -101.93434143066406 -101.93334197998047 -101.9468994140625
 -101.93310546875 -101.98661804199219 -101.98414611816406
 -101.94137573242188 -101.96404266357422 -101.96408081054688
 -101.9657211303711 -101.96514129638672 -101.96741485595703
 -101.9628677368164 -101.96976470947266 -101.94532012939453
 -101.9465560913086 -101.95841979980469 -101.95840454101562
 -101.96957397460938 -101.95361328125 -101.94530487060547
 -101.95417785644531 -101.96934509277344 -101.94599151611328
 -101.9609146118164 -101.94343566894531 -101.95946502685547
 -101.95801544189453 -101.91973876953125 -101.94676208496094
 -101.94667053222656 -101.94676208496094 -101.94979858398438
 -101.95018005371094 -101.95072174072266 -101.95097351074219
 -101.95291137695312 -101.95433807373047 -101.95167541503906
 -101.95504760742188 -101.95523071289062 -101.95691680908203
 -101.95438385009766 -101.95459747314453 -101.95821380615234
 -101.95990753173828 -101.9305648803711 -101.94478607177734
 -101.97014617919922 -101.98106384277344 -101.98157501220703
 -101.98107147216797 -101.94502258300781 -101.94022369384766
 -101.98191833496094 -101.9809341430664 -101.98248291015625
 -101.93541717529297 -101.94105529785156 -101.98316955566406
 -101.9473648071289 -101.98280334472656 -101.98395538330078
 -101.94100952148438 -101.98257446289062 -101.94664764404297
 -101.98400115966797 -101.96963500976562 -101.98399353027344
 -101.98365783691406 -101.97023010253906 -101.97221374511719
 -101.97221374511719 -101.97484588623047 -101.9721450805664
 -101.97113800048828 -101.97223663330078 -101.97239685058594
 -101.97660827636719 -101.94351959228516 -101.97534942626953
 -101.98226165771484 -101.94733428955078 -101.9439926147461
 -101.9818115234375 -101.97969055175781 -101.98155975341797
 -101.98211669921875 -101.92953491210938 -101.9415512084961
 -101.9293441772461 -101.90770721435547 -101.90909576416016
 -101.94890594482422 -101.94857788085938 -101.95305633544922
 -101.94882202148438 -101.90572357177734 -101.94879913330078
 -101.94799041748047 -101.94963836669922 -101.95360565185547
 -101.95477294921875 -101.90570068359375 -101.91561126708984
 -101.93897247314453 -101.95238494873047 -101.95449829101562
 -101.95105743408203 -101.94715881347656 -101.90821838378906
 -101.94853973388672 -101.94113159179688 -101.9480209350586
 -101.94947814941406 -101.96068572998047 -101.9613265991211
 -101.94981384277344 -101.9262466430664 -101.94808959960938
 -101.96202087402344 -101.91287994384766 -101.93075561523438
 -101.95052337646484 -101.93340301513672 -101.93590545654297
 -101.97757720947266 -101.96176147460938 -101.91200256347656
 -101.9389419555664 -101.94913482666016 -101.9488296508789
 -101.94805145263672 -101.92584228515625 -101.94493865966797
 -101.88824462890625 -101.94654083251953 -101.95574951171875
 -101.94584655761719 -101.94725799560547 -101.94441223144531
 -101.94473266601562 -101.94863891601562 -101.94461822509766
 -101.94649505615234 -101.92245483398438 -101.88896179199219
 -101.88923645019531 -101.9442367553711 -101.92301177978516
 -101.92268371582031 -101.94757080078125 -101.91351318359375
 -101.88789367675781 -101.94770050048828 -101.89842224121094
 -101.9080581665039 -101.93547058105469 -101.93562316894531
 -101.90853881835938 -101.90737915039062 -101.89720153808594
 -101.90966033935547 -101.89814758300781 -101.89630126953125
 -101.9559097290039 -101.89053344726562 -101.94691467285156
 -101.93307495117188 -101.94448852539062 -101.94715881347656
 -101.89005279541016 -101.94730377197266 -101.95036315917969
 -101.95932006835938 -101.93893432617188 -101.9483642578125
 -101.93206787109375 -101.93212890625 -101.9319839477539
 -101.94721984863281 -101.92974090576172 -101.93159484863281
 -101.93364715576172 -101.94788360595703 -101.93144226074219
 -101.9311294555664 -101.93012237548828 -101.95489501953125
 -101.94816589355469 -101.94818878173828 -101.93041229248047
 -101.95231628417969 -101.9484634399414 -101.91475677490234
 -101.92804718017578 -101.92820739746094 -101.92572021484375
 -101.89395904541016 -101.92544555664062 -101.92225646972656
 -101.92185974121094 -101.93183898925781 -101.92588806152344
 -101.91960906982422 -101.92556762695312 -101.92691040039062
 -101.92809295654297 -101.91670227050781 -101.92765808105469
 -101.91410064697266 -101.91958618164062 -101.938232421875
 -101.95548248291016 -101.94737243652344 -101.94902038574219
 -101.94842529296875 -101.94510650634766 -101.94895935058594
 -101.94920349121094 -101.9496078491211 -101.94525909423828
 -101.95547485351562 -101.94374084472656 -101.94871520996094
 -101.94805145263672 -101.9350357055664 -101.9490737915039
 -101.94251251220703 -101.94650268554688 -101.95484161376953
 -101.939208984375 -101.94820404052734 -101.95552062988281
 -101.93779754638672 -101.9395751953125 -101.93865966796875
 -101.9477767944336 -101.94123077392578 -101.95611572265625
 -101.94798278808594 -101.94650268554688 -101.94503021240234
 -101.94976806640625 -101.94790649414062 -101.9513931274414
 -101.95207977294922 -101.94829559326172 -101.95059204101562
 -101.95392608642578 -101.94757080078125 -101.94709777832031
 -101.94343566894531 -101.88533782958984 -101.9579849243164] [33.769065856933594 33.767784118652344 33.76640701293945 33.766395568847656
 33.76594161987305 33.76985168457031 33.76996612548828 33.793296813964844
 33.77273178100586 33.77273941040039 33.768455505371094 33.78236770629883
 33.69088363647461 33.691307067871094 33.690059661865234 33.690948486328125
 33.692466735839844 33.71943283081055 33.747135162353516 33.75669479370117
 33.75293731689453 33.759117126464844 33.75008010864258 33.74797058105469
 33.763832092285156 33.74995422363281 33.694374084472656 33.76639175415039
 33.695289611816406 33.69696044921875 33.761192321777344 33.69671630859375
 33.76040267944336 33.69637680053711 33.763282775878906 33.69791793823242
 33.762237548828125 33.697975158691406 33.76503372192383 33.77125930786133
 33.760196685791016 33.75968551635742 33.76083755493164 33.762062072753906
 33.7679443359375 33.76103973388672 33.761165618896484 33.76192092895508
 33.76143264770508 33.74642562866211 33.761497497558594 33.753116607666016
 33.76138687133789 33.763572692871094 33.7607536315918 33.76031494140625
 33.7548713684082 33.761878967285156 33.747257232666016 33.7686653137207
 33.761680603027344 33.758548736572266 33.760345458984375 33.7591438293457
 33.75895309448242 33.760379791259766 33.75697708129883 33.759151458740234
 33.69961166381836 33.7652473449707 33.76128387451172 33.69569778442383
 33.69517517089844 33.70243835449219 33.70283126831055 33.70341873168945
 33.703025817871094 33.6966552734375 33.70307922363281 33.74808120727539
 33.69741439819336 33.70309829711914 33.70307922363281 33.70341873168945
 33.75624465942383 33.70805740356445 33.70182800292969 33.705650329589844
 33.70519256591797 33.705833435058594 33.70571517944336 33.752559661865234
 33.70669937133789 33.70956039428711 33.7099609375 33.75044250488281
 33.70457077026367 33.76139450073242 33.7447624206543 33.69869613647461
 33.76176834106445 33.685733795166016 33.682979583740234 33.68435287475586
 33.68366241455078 33.764076232910156 33.68491744995117 33.70518493652344
 33.685302734375 33.6853141784668 33.705604553222656 33.76039505004883
 33.688682556152344 33.75736999511719 33.68873977661133 33.6878547668457
 33.70799255371094 33.69000244140625 33.70604705810547 33.707035064697266
 33.706398010253906 33.74365234375 33.69161605834961 33.7060661315918
 33.706016540527344 33.75946807861328 33.76166534423828 33.762569427490234
 33.75092697143555 33.78633117675781 33.78651428222656 33.7800178527832
 33.7801399230957 33.781532287597656 33.72595977783203 33.78386306762695
 33.784610748291016 33.782623291015625 33.78007888793945 33.78364944458008
 33.78445816040039 33.78330993652344 33.78172302246094 33.78207778930664
 33.782772064208984 33.78363800048828 33.782291412353516 33.78234100341797
 33.784393310546875 33.78175735473633 33.77981185913086 33.78142166137695
 33.775062561035156 33.77003479003906 33.77982711791992 33.773963928222656
 33.780296325683594 33.7777214050293 33.76561737060547 33.76792907714844
 33.76897048950195 33.769073486328125 33.77232360839844 33.7880744934082
 33.760868072509766 33.790706634521484 33.782020568847656
 33.773921966552734 33.78950119018555 33.79294967651367 33.78801727294922
 33.777793884277344 33.7752571105957 33.776309967041016 33.776145935058594
 33.78717803955078 33.7768440246582 33.78916549682617 33.77713394165039
 33.777870178222656 33.77731704711914 33.787662506103516 33.78804016113281
 33.788734436035156 33.77030944824219 33.78195571899414 33.76960754394531
 33.7618408203125 33.761043548583984 33.76316452026367 33.759544372558594
 33.75973129272461 33.743896484375 33.77824783325195 33.749210357666016
 33.75419998168945 33.76105499267578 33.760658264160156 33.7523193359375
 33.7623176574707 33.7762336730957 33.7558708190918 33.75535202026367
 33.71712112426758 33.76369094848633 33.762062072753906 33.76228332519531
 33.74995803833008 33.76253890991211 33.77305603027344 33.75424575805664
 33.76276397705078 33.75943374633789 33.76157760620117 33.76211166381836
 33.76420974731445 33.7700080871582 33.78083038330078 33.77004623413086
 33.770973205566406 33.77059555053711 33.77305221557617 33.77675247192383
 33.77466583251953 33.774818420410156 33.77458190917969 33.77561950683594
 33.776641845703125 33.761104583740234 33.767066955566406 33.77422332763672
 33.772499084472656 33.772361755371094 33.77360916137695 33.77246856689453
 33.768795013427734 33.771820068359375 33.76874542236328 33.77134323120117
 33.76823806762695 33.766910552978516 33.765804290771484 33.773372650146484
 33.72804260253906 33.70945358276367 33.74463653564453 33.72630310058594
 33.72684097290039 33.728294372558594 33.7275390625 33.72892379760742
 33.72767639160156 33.727317810058594 33.72732925415039 33.728424072265625
 33.7293586730957 33.73008728027344 33.73047637939453 33.71828842163086
 33.73124313354492 33.73209762573242 33.73316955566406 33.728179931640625
 33.72686004638672 33.72407531738281 33.72406768798828 33.71041488647461
 33.71044921875 33.71364974975586 33.71379470825195 33.713565826416016
 33.71411895751953 33.71592330932617 33.7132453918457 33.71701431274414
 33.70458221435547 33.717952728271484 33.706275939941406 33.718711853027344
 33.706764221191406 33.722049713134766 33.72314453125 33.72461700439453
 33.732215881347656 33.73228454589844 33.73176574707031 33.70135498046875
 33.742523193359375 33.742164611816406 33.74345397949219 33.74576950073242
 33.74740219116211 33.74659729003906 33.747703552246094 33.748756408691406
 33.74818420410156 33.74839401245117 33.74675750732422 33.74723434448242
 33.748355865478516 33.7494010925293 33.72072219848633 33.69791030883789
 33.75178146362305 33.74278259277344 33.71154022216797 33.74073791503906
 33.73981475830078 33.733394622802734 33.73422622680664 33.735389709472656
 33.706844329833984 33.70764923095703 33.717498779296875 33.73675537109375
 33.73900604248047 33.73770523071289 33.737674713134766 33.737953186035156
 33.711082458496094 33.74073791503906 33.73870086669922 33.738399505615234
 33.73957824707031 33.69620132446289 33.741798400878906 33.70991134643555
 33.70994567871094 33.707916259765625 33.707862854003906 33.708126068115234
 33.709022521972656 33.708168029785156 33.70625305175781 33.70700454711914
 33.70329666137695 33.709537506103516 33.710567474365234 33.706172943115234
 33.70618438720703 33.706417083740234 33.707054138183594 33.70957946777344
 33.70583724975586 33.70607376098633 33.709407806396484 33.703861236572266
 33.709171295166016 33.70536422729492 33.70625305175781 33.75054168701172
 33.709224700927734 33.70929718017578 33.70963668823242 33.70879364013672
 33.70914840698242 33.70783996582031 33.70732498168945 33.707515716552734
 33.7064323425293 33.70551681518555 33.706233978271484 33.705631256103516
 33.70501708984375 33.7071533203125 33.70767593383789 33.70689392089844
 33.705631256103516 33.752899169921875 33.709556579589844
 33.703182220458984 33.70494842529297 33.705753326416016 33.70499801635742
 33.71205139160156 33.707942962646484 33.7081413269043 33.70783233642578
 33.70833206176758 33.70811462402344 33.7059326171875 33.709781646728516
 33.71065902709961 33.7098388671875 33.709407806396484 33.70533752441406
 33.71064376831055 33.71287155151367 33.70349884033203 33.70265197753906
 33.70351791381836 33.703678131103516 33.70256423950195 33.69966125488281
 33.701683044433594 33.70109558105469 33.69976043701172 33.6987419128418
 33.69780349731445 33.695980072021484 33.70237731933594 33.70922088623047
 33.70191955566406 33.701602935791016 33.71049499511719 33.71005630493164
 33.70267868041992 33.703826904296875 33.7031364440918 33.70417022705078
 33.75393295288086 33.707889556884766 33.754310607910156 33.75962448120117
 33.76088333129883 33.74203109741211 33.73902893066406 33.738616943359375
 33.74150085449219 33.7620964050293 33.74239730834961 33.74309158325195
 33.73707580566406 33.738895416259766 33.740299224853516 33.76291275024414
 33.71589279174805 33.72378921508789 33.714168548583984 33.73947525024414
 33.736061096191406 33.74443817138672 33.75971221923828 33.73900604248047
 33.70065689086914 33.746578216552734 33.732791900634766 33.7059211730957
 33.70669937133789 33.732906341552734 33.70235061645508 33.72953414916992
 33.71876907348633 33.75872039794922 33.751304626464844 33.734893798828125
 33.731563568115234 33.73016357421875 33.70209884643555 33.707454681396484
 33.7579460144043 33.724063873291016 33.746604919433594 33.741050720214844
 33.74311447143555 33.73994064331055 33.75051498413086 33.759273529052734
 33.746124267578125 33.746116638183594 33.74949264526367 33.74391555786133
 33.75202941894531 33.75275802612305 33.71240234375 33.75299835205078
 33.7448616027832 33.74334716796875 33.75442886352539 33.75188446044922
 33.75411605834961 33.7426872253418 33.74295425415039 33.743900299072266
 33.71601486206055 33.76038360595703 33.74394607543945 33.763492584228516
 33.76729965209961 33.69792556762695 33.69731140136719 33.76735305786133
 33.766319274902344 33.76206588745117 33.767940521240234 33.76276397705078
 33.7664794921875 33.741111755371094 33.76007080078125 33.74577331542969
 33.731571197509766 33.75361633300781 33.747093200683594 33.76112365722656
 33.745689392089844 33.734375 33.706260681152344 33.72383499145508
 33.72356414794922 33.751094818115234 33.75048828125 33.75032424926758
 33.72936248779297 33.75504684448242 33.75071716308594 33.74996566772461
 33.727787017822266 33.748313903808594 33.747886657714844
 33.749046325683594 33.710105895996094 33.727020263671875 33.72648239135742
 33.750099182128906 33.7255859375 33.72665023803711 33.755496978759766
 33.757774353027344 33.757503509521484 33.75814437866211 33.750267028808594
 33.75825881958008 33.758201599121094 33.758155822753906 33.75261306762695
 33.75848388671875 33.75726318359375 33.75755310058594 33.757320404052734
 33.76476287841797 33.75695037841797 33.75849914550781 33.757896423339844
 33.75768280029297 33.74782943725586 33.72478485107422 33.72879409790039
 33.73100280761719 33.727970123291016 33.7447624206543 33.732147216796875
 33.73258590698242 33.73296356201172 33.731239318847656 33.72479248046875
 33.747047424316406 33.72990798950195 33.72941970825195 33.72819519042969
 33.7311897277832 33.74781036376953 33.748355865478516 33.71015930175781
 33.74726486206055 33.7275276184082 33.7247200012207 33.74846649169922
 33.746212005615234 33.74740219116211 33.729164123535156 33.748741149902344
 33.70809555053711 33.72724533081055 33.68175506591797 33.6815185546875
 33.680328369140625 33.680763244628906 33.678871154785156 33.67938995361328
 33.68156433105469 33.681270599365234 33.680145263671875 33.71879196166992
 33.712867736816406 33.71516036987305 33.746368408203125 33.577903747558594]
set([<generator object events_flashes_receiver at 0x115a36c80>, <generator object flash_stat_printer at 0x1140ec550>, <generator object events_flashes_printer at 0x115a36e60>])

In [13]:
@coroutine
def events_flashes_printer():
    while True:
        evs, fls = (yield)
        print evs['lon'], evs['lat']
info_printer = events_flashes_printer()
current_events_flashes.targets.add(info_printer)

3D visualization of current sources with Mayavi

This will receive the events and flashes from the current 2D view, and update an interactive 3D view.

It should be possible to use the scatter_ctrl.branchpoint and the mappablerangeupdater setup by scatter_ctrl instead of the raw events flashes. This would permit synchronization with the same vmin, vmax, which is already being figured out.


In [9]:
from brawl4d.brawl4d import redraw
import mayavi.mlab as mvlab
from stormdrain.pipeline import coroutine
class MayaviOutlet(object):
    def __init__(self, panels, ev_fl_broadcaster):
        self.ev_fl_broadcaster = ev_fl_broadcaster
        self.ev_fl_broadcaster.targets.add(self.rx())
        self.p3d = mvlab.points3d([0], [0], [0], [0], scale_factor=5e-5)
        self.scene = self.p3d.scene
        self.scene.background = (0,0,0)
        self.panels=panels
        
        # Force a reflow of data
        redraw(panels)
        
        # move camera to see everything after data are plotted
        self.scene.reset_zoom()
        
    @coroutine
    def rx(self):
        while True:
            ev, fl = (yield)
#             self.ev = ev
#             self.fl = fl
            evx, evy, evz, evt = ev['x'], ev['y'], ev['z'], ev['time']
            self.p3d.mlab_source.reset(x=evx, y=evy, z=evz, scalars=evt)
            
current_events_flashes = lma_ctrl.flash_stats_for_dataset(d, scatter_ctrl.branchpoint)
mvo = MayaviOutlet(panels, current_events_flashes)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-9-4c31d0dafd15> in <module>()
      1 from brawl4d.brawl4d import redraw
----> 2 import mayavi.mlab as mvlab
      3 from stormdrain.pipeline import coroutine
      4 class MayaviOutlet(object):
      5     def __init__(self, panels, ev_fl_broadcaster):

/Users/ebruning/anaconda/lib/python2.7/site-packages/mayavi/mlab.py in <module>()
     25 
     26 # Mayavi imports
---> 27 from mayavi.tools.camera import view, roll, yaw, pitch, move
     28 from mayavi.tools.figure import figure, clf, gcf, savefig, \
     29     draw, sync_camera, close, screenshot

/Users/ebruning/anaconda/lib/python2.7/site-packages/mayavi/tools/camera.py in <module>()
     23 # We can't use gcf, as it creates a circular import in camera management
     24 # routines.
---> 25 from engine_manager import get_engine
     26 
     27 

/Users/ebruning/anaconda/lib/python2.7/site-packages/mayavi/tools/engine_manager.py in <module>()
     10 
     11 # Local imports
---> 12 from mayavi.preferences.api import preference_manager
     13 from mayavi.core.registry import registry
     14 from mayavi.core.engine import Engine

/Users/ebruning/anaconda/lib/python2.7/site-packages/mayavi/preferences/api.py in <module>()
      2 
      3 # The global PreferenceManager instance
----> 4 from preference_manager import preference_manager
      5 from bindings import set_scene_preferences, get_scene_preferences

/Users/ebruning/anaconda/lib/python2.7/site-packages/mayavi/preferences/preference_manager.py in <module>()
     27 from traits.etsconfig.api import ETSConfig
     28 from traits.api import HasTraits, Instance
---> 29 from traitsui.api import View, Group, Item
     30 from apptools.preferences.api import (ScopedPreferences, IPreferences,
     31         PreferencesHelper)

/Users/ebruning/anaconda/lib/python2.7/site-packages/traitsui/api.py in <module>()
     33 from .editor_factory import EditorFactory
     34 
---> 35 from .editors.api import (ArrayEditor, BooleanEditor, ButtonEditor,
     36     CheckListEditor, CodeEditor, ColorEditor, CompoundEditor, CustomEditor,
     37     CSVListEditor,

/Users/ebruning/anaconda/lib/python2.7/site-packages/traitsui/editors/__init__.py in <module>()
     20 from __future__ import absolute_import
     21 
---> 22 from .api import (toolkit, ArrayEditor, BooleanEditor, ButtonEditor,
     23     CheckListEditor, CodeEditor, ColorEditor, CompoundEditor, CustomEditor,
     24     DateEditor, DefaultOverride, DirectoryEditor, DNDEditor, DropEditor,

/Users/ebruning/anaconda/lib/python2.7/site-packages/traitsui/editors/api.py in <module>()
      8 from .button_editor import ButtonEditor
      9 from .check_list_editor import CheckListEditor
---> 10 from .code_editor import CodeEditor
     11 from .color_editor import ColorEditor
     12 from .compound_editor import CompoundEditor

/Users/ebruning/anaconda/lib/python2.7/site-packages/traitsui/editors/code_editor.py in <module>()
     34 #-------------------------------------------------------------------------------
     35 
---> 36 class ToolkitEditorFactory ( EditorFactory ):
     37     """ Editor factory for code editors.
     38     """

/Users/ebruning/anaconda/lib/python2.7/site-packages/traitsui/editors/code_editor.py in ToolkitEditorFactory()
     46 
     47     # Background color for marking lines
---> 48     mark_color = Color( 0xECE9D8 )
     49 
     50     # Object trait containing the currently selected line (optional)

/Users/ebruning/anaconda/lib/python2.7/site-packages/traits/traits.pyc in __call__(self, *args, **metadata)
    485 
    486     def __call__ ( self, *args, **metadata ):
--> 487         return self.maker_function( *args, **metadata )
    488 
    489 class TraitImportError ( TraitFactory ):

/Users/ebruning/anaconda/lib/python2.7/site-packages/traits/traits.pyc in Color(*args, **metadata)
   1189     from traitsui.toolkit_traits import ColorTrait
   1190 
-> 1191     return ColorTrait( *args, **metadata )
   1192 
   1193 Color = TraitFactory( Color )

/Users/ebruning/anaconda/lib/python2.7/site-packages/traitsui/toolkit_traits.pyc in ColorTrait(*args, **traits)
      5 
      6 def ColorTrait ( *args, **traits ):
----> 7     return toolkit().color_trait( *args, **traits )
      8 
      9 def RGBColorTrait ( *args, **traits ):

/Users/ebruning/anaconda/lib/python2.7/site-packages/traitsui/toolkit.pyc in toolkit(*toolkits)
    115         for toolkit_name in toolkits:
    116             try:
--> 117                 _toolkit = _import_toolkit( toolkit_name )
    118 
    119                 # In case we have just decided on a toolkit, tell everybody else:

/Users/ebruning/anaconda/lib/python2.7/site-packages/traitsui/toolkit.pyc in _import_toolkit(name)
     49 
     50 def _import_toolkit ( name ):
---> 51     return __import__( name, globals=globals(), level=1 ).toolkit
     52 
     53 

/Users/ebruning/anaconda/lib/python2.7/site-packages/traitsui/qt4/__init__.py in <module>()
     16 # import pyface.qt before anything else is done so the sipapi
     17 # can be set correctly if needed
---> 18 import pyface.qt
     19 
     20 #----------------------------------------------------------------------------

/Users/ebruning/anaconda/lib/python2.7/site-packages/pyface/qt/__init__.py in <module>()
     26     except ImportError:
     27         try:
---> 28             prepare_pyqt4()
     29             import PyQt4
     30             qt_api = 'pyqt'

/Users/ebruning/anaconda/lib/python2.7/site-packages/pyface/qt/__init__.py in prepare_pyqt4()
     15     # Set PySide compatible APIs.
     16     import sip
---> 17     sip.setapi('QString', 2)
     18     sip.setapi('QVariant', 2)
     19 

ValueError: API 'QString' has already been set to version 1

In [10]:
mvo.p3d.scene.reset_zoom?


Object `mvo.p3d.scene.reset_zoom` not found.

In [11]:
panels.bounds.limits()


Out[11]:
[('x', (-130.47568710359408, 20.475687103594083)),
 ('y', (-10.0, 140.0)),
 ('z', (1.0, 15.0)),
 ('time', (34800.0, 34920.0))]

In [ ]: