Python sorting objects of user defined class

The most common way of sorting collections of custom objects in Python is to provide key function that is used to extract a comparison key from each element:

sorted("Case insensitive Sorting is here".split(), key=str.lower)

But sorted function compares objects by its nature, and it is possible to define comparison operators for your class t make sorted work automatically.

Install Jupyter Notebook and Scientific Environment in Ubuntu 14.04 With Python 3

Several changes occured since my last note about installing python scientific environment:

Animations from scientific data using Paraview 4.3 and python

Create frames

This note describes usage of Paraview 4.3 (contrary to previous note with Paraview before 4.1). Some changes were made:

  • command line arguments were added to make code more reusable
  • it works with Paraview extracted from the archive (4.3.1)
  • white background must be specified manually (SetViewProperties(view, Background = [1, 1, 1]) in the code)

Create video illustrations from numerical experiments data with Paraview and Python 2

See updated note.

One of the common tasks in computer modeling is visualization of numerical experiment as a movie. Usually it is one datafile per frame and target is to create frame-by-frame animation. If these files can be loaded and visualized in Paraview, it is easy to create the full video: load file in paraview with predefined parameters, create screenshot, load second file, etc. This process may be automated.

Install up-to-date scientific environment in Ubuntu 14.04 with Python 3.4

Note: I’ve created an updated page with most recent instructions for Jupyter Notebook.

I use IPython notebook for processing numerical experiments results and plotting. The default Python 3 in Ubuntu 14.04 is 3.4, so it is easier to install really up-to-date bunch of software.

Full set of commands you need to install recent ipython notebook, numpy, scipy, etc in virtual environment almost without affecting shiny-new Ubuntu 14.04.