Monthly Archives: July 2009

August EPD Webinar: How do I speed up Python?

Next week we’ll host another installment of our popular EPD webinar series. These How do I…? events feature detailed demonstrations of powerful Python techniques that we use to enhance our applications or development process. Participants are often invited to participate in the demonstration, and are welcome to join the interactive VOIP discussion later in the session. This is a great opportunity to learn new methods and interact with our expert developers.

Although only EPD Basic or above subscribers are guaranteed seats at EPD webinars, we invite non-subscribers to add their names to the wating list for each event. If there are available seats, you will be notified by next Thursday and given access to the webinar. Links to the waiting lists and upcoming topics are posted here.

Enthought Python Distribution Webinar, August 7 2009

1pm CDT (6pm UTC)

How do I speed up Python?

Python excels as a language for rapid development and interactive technical computing. Sometimes, however, the full speed of the machine is needed. Fortunately, Python is also an excellent “glue” language that allows simple integration to compiled languages. In this webinar, we will present a few of the methods useful for speeding up sections of code. In particular we will focus on weave and Cython. Weave is a sub-package of SciPy (scipy.weave) and allows seamless integration with C/C++.Sections of code that need to be sped up can be re-coded in C and seamlessly integrated into the remaining Python program using weave. Cython is a newer Python-like language which is compiled to an extension module that can be dynamically loaded into Python just like any other Python module. Cython also supports writing new built-in Python types and tries to compile loops to C-speeds when variable types are indicated. Both weave and Cython integrate well with NumPy which makes them ideal whenever you need to iterate and calculate with large amounts of data and can’t find a built-in (vectorized) approach.

We look forward to seeing you there!

Gradients in Enable

A little while ago I added basic support for gradients in Kiva (and thus Enable). Its been slowly improving, and I think its at a point where it should be shared with a greater audience. Kiva now supports linear and radial gradients as path fills. My goal is to support the majority of what the SVG spec requires, currently we pass about 1/2 to 2/3 of the compliance tests.

I have added a couple of full examples in Enable/examples/kiva, here is an excerpt:
[sourcecode language=”python”]
# colors are 5 doubles: offset, red, green, blue, alpha
starting_color = numpy.array([0.0, 1.0, 1.0, 1.0, 1.0])
ending_color = numpy.array([1.0, 0.0, 0.0, 0.0, 1.0])

# diagonal
gc.rect(50,25,150,100)
gc.linear_gradient(50,25,150,125,
numpy.array([starting_color, ending_color]),
“pad”)
gc.draw_path()
[/sourcecode]
That is all the code required to draw a rectangle with a diagonal gradient. And here is a screenshot of the example I took this from:

kiva gradient screenshot

Enthought Tool Suite (ETS) v3.3.0 released

I’m pleased to announce that Enthought Tool Suite (ETS) version 3.3.0 has been tagged and released! Please see below for a partial list of changes for this release.

PyPi has been updated with the release, including the availability of both Windows binaries (.egg) and source distributions (.tar.gz). A full install of ETS can be done using a command like: easy_install -U “ETS[nonets] == 3.3.0”

HOWEVER, it is important to note that there are still package dependencies that are outside the scope of easy_install. Therefore, we recommend that you have the following installed prior to installing ETS:

  • setuptools: minimum version 0.6c9
  • VTK: minimum version 5.0, recommended 5.2 or later

And at least one of:

  • wxPython: minimum version 2.8.7.1
  • PyQt: minimum version 4.4

For additional installation information, see: https://svn.enthought.com/enthought/wiki/Install

What Is ETS?

The Enthought Tool Suite (ETS) is a collection of components developed by Enthought and the open-source community, which we use every day to construct scientific applications. It includes a wide variety of components, including:

  • an extensible application framework
  • application building blocks
  • 2-D and 3-D graphics libraries
  • scientific and math libraries
  • developer tools

The cornerstone on which these tools rest is the Traits package, which provides explicit type declarations in Python; its features include initialization, validation, delegation, notification, and visualization of typed attributes.

More information on ETS is available from the development home page: http://code.enthought.com/projects/index.php

ETS 3.3.0 is a feature-added update to ETS 3.2.0, including numerous bug-fixes. Some of the notable changes include (sub-projects listed in alphabetical order):

Chaco 3.2.0 (July 15, 2009)

Enhancements
————

* Bounded grids – Horizontal and Vertical grid line start and end points can now be set to a fixed value in data space, or to be the return value of an arbitrary callable. The start and end tick can also be configured via the data_min and data_max traits.

* Added dictionary interface to ArrayPlotData

* Added a Traits UI view to the ScalesAxis

* Added a new chaco.overlays subpackage and a new overlay, the DataBox.

* Improved appearance of PlotToolbar

* Changed add_default_axis() in the plot_factory module to take an axis class as a keyword argument.

* Refactored contour plots into a common base class and implemented proper event handling when their colormaps or data ranges change.

* Changed default colormap on img_plot() and contour_plot() method of Plot to be Spectral instead of Jet.

* Added two more color palettes to the auto color palette, and created a default_colors module.

* Added CandlePlot renderer

* Changed Plot Labels to able to display inside the plot area, instead of only on the outside

* Added optional title attribute to plot legends

* Updated all containers to respect and use the new fixed_preferred_size trait on enable.Component

* New Examples:
* Interval trait editor as a Chaco example (from Stefan van der Walt)
* embedding an interactive Chaco plot inside a VTK RenderWindow using the new Enable VTK backend
* lasso tool on an image plot
* bounded grid
* candle plot

Fixes
—–

* Fixed call signature of ShowAllTickGenerator.get_ticks()

* Plot.title_font is now a delegate to the underlying PlotLabel object (from Chris Colbert)

* Fixed mouse event handling bug in RangeSelection (from Stefan van der Walt)

* ImagePlots now redraw when their input data changes.

* Fixed cached image invalidation in colormapped image plots

* Optimized ScatterPlot.map_index() when index_only is True and the index data is sorted

* Changed ColormappedScatterPlot to no longer incorrectly apply the fill_alpha to the outline color

* Improved date ticking heuristics in chaco.scales subpackage, specifically eliminating the bug where all times between, midnight and 1am would be formatted at too course of a time resolution.

* Cleanup of various examples (titles, appearance)

* The spectrum.py (audio spectrograph) example now properly closes the audio stream.

Enable 3.2.0 (July 15th, 2009)

enthought.enable Enhancements
—————————–

* Added Slider and Compass widgets

* Added an OverlayContainer (almost identical to the one in Chaco)

* Added ImageGraphicsContextEnable class so that one can always import a Kiva Image backend-based GraphicsContextEnable

* renaming marker_trait to MarkerTrait (the old name is still permitted for backwards compatibility, but should be avoided)

* Moved the scatter_markers module from Chaco to Enable, so that Enable components can use MarkerTrait

* Added an experimental VTK backend for Enable, along with an example

* Changed SVGButtonEditor toggle to draw a SVG under the button SVG instead of drawing a plain box

* Added labels for SVGButton

* Improving backbuffering performance on the Mac by creating the layer context from the window context instead of from a bitmap.

* Adding a “fixed_preferred_size” trait to Components, so that relative size preferences can be expressed amongst different components in a container

enthought.enable Fixes
———————-

* Improved the backend selection to match the Traits UI backend unless ETSConfig.enable_toolkit is explicitly set

* Fixed demo_main() in example_support.py so that it doesn’t crash IPython

* Fixed RGBAColorTrait so it can be used with the null toolkit

* Changed the “sys_window” color to be the same as the Traits UI “WindowColor” constant

* Fixed backend_cairo’s get_text_extent() implementation to match other backends

enthought.kiva Enhancements
—————————

* Added basic gradients to Kiva

enthought.kiva Fixes
——————–

* Fixed Python 2.6 datatype errors

* Fixed memory leak as reported in ticket 1815

* The macport test is only run on Darwin systems

* Removed deprecated calls to old numpy APIs

Traits 3.2.0

* Implemented editable_labels attribute in the TabularEditor for enabling editing of the labels (i.e. the first column) * Saving/restoring window positions works with multiple displays of different sizes

* New ProgressEditor

* Changed default colors for TableEditor

* Added support for HTMLEditor for QT backend using QtWebKit

* Improved support for opening links in external browser from HTMLEditor

* Added support for TabularEditor for QT backend

* Added support for marking up the CodeEditor, including adding squiggles and dimming lines

* Added SearchEditor

* Improved unicode support

* Changed behavior of RangeEditor text box to not auto-set

* Added support in RangeEditor for specifying the method to evaluate new values.

* Add DefaultOverride editor factory courtesy Stfan van der Walt

* Removed sys.exit() call from SaveHandler.exit()

TraitsBackendQt 3.2.0 (July 15, 2009)

* Fixed a plethora of layout bugs

* Implemented RGBColor trait

* Fixed events not fired for ‘custom’ TextEditor

* Improved the method by which the QT backend dispatches trait handlers when dispatch=’ui’. Before, the code only worked when on the main application thread or a QThread. Now it works for regular Python threads too.

* Fixed events not being fired correctly in TableEditor

* Added support or ‘click’ and ‘dclick’ factory attributes to the TableEditor

* TableEditor instances now editable

* Improved FileEditor to look and act like the WX editor

* Fixed missing minimize/maximize buttons for resizable dialogs

* New HTMLEditor using QtWebKit

* New TabularEditor

* Added support for panel buttons

* New SearchEditor

* Added support for clipboard

* Now responds to SIGINT correctly rather than raising KeyboardInterrupt

TraitsBackendWX 3.2.0 (July 15, 2009)

* Fixed bug in DateEditor which would not display Feb correctly if the current date was visible and greater than the number of days in Feb

* Reduced border_size from 1 to 4 for Group instances

* Fixed layout issues:
* Windows are now resized if they are larger than the desktop
* Windows are now put in a valid location if they were opened off-screen
* Windows with smaller parent are no longer opened at invalid positions with negative y values

* Implemented editable_labels attribute in the TabularEditor for enabling editing of the labels (i.e. the first column) * Fix bug in ListEditor where a trait change listener would be fired when intermediate traits changed (when extended_name was of the type item1.item2.item3..) leading to a traceback. * Saving/restoring windows now works with multiple displays of different sizes

* New ProgressDialog

* Improved window colors to match desktop colors more closely

* Replaced calls of wx.Yield() with wx.GetApp().Yield(True)

* Changed default font to use system font

* Fixed TabularEditor compatibility problem with wx 2.6 regarding the page-down key

* Fixed bug in propagating click events in the TabularEditor to parent windows

* DateEditor wx 2.6 compatability fixed

* TableEditor scrollbar fixed

* Improved support for opening links in external browser from HTMLEditor

* Reduced the number of update events the PythonEditor fired

* moved grid package from TraitsGui egg into enthought.pyface.ui.wx

* moved clipboard from enthought.util.wx into pyface

TraitsGUI 3.1.0 (July 15, 2009)

* Removed Theming support from DockWindows. Borders and tabs are now drawn using lines instead of stretching images. * Changed default font to use the system font

* Moved enthought.util.wx.clipboard to Pyface

* Moved the grid package out of pyface and into pyface.ui.wx, left deprecated warnings

* Improved info shown to the user if toolkits don’t work as expected

An editor for ReStructured Text

I have recently added an editor for ReStructured Text to ETS. As you can see in the screenshots below, the editor is largely composed of two panes, with the left pane containing an editor for the RST and the right pane displaying that RST as HTML. The HTML preview can be generated by vanilla docutils or by Sphinx, and this is configurable within the application.

The HTML preview is updated live as you type. Because all RST processing occurs in a separate helper process, the application remains snappy even when editing large documents.

Both the Qt4 and the wxWidgets backends of Traits UI are supported.

ReStructured Text Editor (Qt)

ReStructured Text Editor (Wx)

Note: The editor requires the latest trunk versions of Traits and Traits UI. For more information on running the application, please see the readme file.

Edit: With the recent release of ETS 3.3.0, the trunk version of ETS is no longer required to use the editor, as it is included in that release. That being said, if you update the editor to its latest trunk version, you must also update Traits, TraitsGUI, and TraitsBackendWx/TraitsBackendQt to their latest trunk versions.

Up Next: Step-by-step Chaco

We got a lot of great feedback from the folks who joined June’s Scientific Computing with Python webinar. Many attendees were very impressed by Chaco and there was a resounding request for a closer look into this 2D plotting tool. So July’s webinar will offer a practical, step-by-step Chaco demonstration.

Chaco screenshots

Also, we’ve put up a schedule of future SCP webinars that takes us into 2010. We really like this series and the exposure it brings to the powerful visualization and analysis tools Python offers scientists. We encourage you to tell your friends and colleagues we have the ability to host up to 1001 guests at these events! Don’t forget that if you miss the meeting, we make our recordings available on our website and and our slides are published at Slideshare.

Once again:

Scientific Computing with Python Webinar

Step-by-step Chaco: 2D plotting with the Enthought Tool Suite

July 17, 2009
1pm CDT(6pm UTC)

register at GoToMeeting

See you next Friday!