=== Stefan van der Walt - numpy tricks === - broadcasting - to combine arrays of different sizes - simple example is scalar broadcasting - x, y = np.ogrid[1:100,1:100] # each vector one-dimensional, x column, y row - g = x + 1j*y # create grid by broadcasting - better than np.mgrid, which generates two 2-d arrays - broadcasting compares dimensions starting from last - can add dimension with "None" index to allow broadcasting - fancy indexing - with another array, not with scalars and slices - extract diagonal from 3x3 array - a[[1,2,3],[1,2,3]] - array indices are broadcast against one another... - ...then slices used as is - structured arrays - dt = np.dtype([('time',np.uint64),('position',[('az',np.float32), ('el',np.float32)])]) - a = np.fromfile(filename,dtype=dt) # from binary # loadtxt would do similarly (see manpage) - endianness: np.dtype('i4') - strided tricks - a.strides gives the bytes that must be skipped in memory to move between elements along each direction - np.stride_tricks.as_strided(x,shape=(3,2,5),strides=(20,20,4)) - subclassing - __new__, __array_finalize__ - see http://www.scipy.org/Subclasses - more hidden features: - np.save, np.load - np.fromregex - np.lib.Arrayterator - np.emath - np.unravel_index - np.lexsort - np.iinfo - np.issubdtype - np.linalg.matrix_power === Eric Jones - Traits === - ETS - Chaco: complex, interactive 2D plots - Kiva: 2D primitives - Mayavi: 3D visualization with VTK - Enable: object-based 2D drawing canvas - Envisage: application plugin framework - Traits add five characteristics to Python object attributes - initialization - validation - delegation - notification -> provides interactivity - visualization -> scales well >>> from enthought.traits.api import HasTraits, Float >>> >>> class Rectangle(HasTraits): >>> width = Float # width = Float(1.0) would set default >>> height = Float >>> >>> rect = Rectangle(width = 2.0) - casting traits such as CFloat will use Python's float() to convert - Any trait will behave as an untyped Python variable - "Property NAME" trait: will call _get_NAME(self), _set_NAME(self) - can pass "depends_on=[...,...]" to Property to let is know when it changes - then the decorator @cached_property can be used on _get methods to cache values - can define a default view as a readonly editor: >>> view = View('width','height',Item('area',style='readonly')) - can also pass a different view to edit_traits() - views don't need to be specific to a class, as long as Items match - all Traits automatically support the Listener pattern for function and methods called when a trait changes - static listener is something like _volume_changed(self,old,new) - dynamic observer is set with obj.on_trait_change(observerf,name='volume') - disconnect it with obj.on_trait_change(observerf,name='volume',remove=True) - can also use a decorator "@on_trait_change('reverb,volume')" (really one string?) to create listener - listeners can also be run on a different thread with "dispatch='new'" - Instance: use compound traits as elementary traits >>> class Person(HasTraits): >>> ... >>> class Family(HasTraits): >>> dad = Instance(Person,args=(),kw={'first_name':'Jane'}) - delegation: trait can Delegate a particular trait to one of its compound traits >>> class Child(Person): >>> parent = Instance(Person,args=()) >>> last_name = Delegate('parent','last_name') - it's possible to traitify numpy arrays === Peter Wang - Interactive plotting with Chaco === - several backends: Wx, Quartz, GL (beta) - nice interactive capabilities, edit elements (colormaps, etc.) - "script-oriented" plotting is available through enthought.chaco.shell - static view of data, concept of main plots - "application-oriented plot" - general scheme: make ArrayPlotData object, make Plot object, run plot in Plot object - can run multiple plots (renderers) in the same Plot - can arrange Plots in Containers - using traits, can dynamically change Plot features (such as Plot.renderer.color) and ArrayPlotData - have standard set of tools - as simple as plot.tools.append(PanTool(plot)), ZoomTool, DragZoom - can create custom tools that see mouse movements and keys === Prabhu Ramachandran, Gael Varoquaux - 3D visualization with TVTK and Mayavi ===