• No results found

Postprocessing with Python

N/A
N/A
Protected

Academic year: 2021

Share "Postprocessing with Python"

Copied!
58
0
0

Loading.... (view fulltext now)

Full text

(1)

Postprocessing with Python

Boris Dintrans (CNRS & University of Toulouse) [email protected]

(2)
(3)

Introduction

- what’s Python and why using it?

- Installation procedure

(4)

Introduction

- what’s Python and why using it?

- Installation procedure

Outline

Python and the Pencil Code

- the Python repository and initialization

- Migrating from IDL to Python

- Some examples & tricks

- Parallel Python with Pypar

- Doing widgets with PyQt

(5)

Introduction

- what’s Python and why using it?

- Installation procedure

Outline

Python and the Pencil Code

- the Python repository and initialization

- Migrating from IDL to Python

- Some examples & tricks

- Parallel Python with Pypar

- Doing widgets with PyQt

(6)
(7)

What’s Python?

Python was created in 1991 by Guido van Rossum (CWI, Centrum voor Wiskunde en Informatica, Amsterdam) Benevolent Dictator for Life (BDFL)

(8)

What’s Python?

Python was created in 1991 by Guido van Rossum (CWI, Centrum voor Wiskunde en Informatica, Amsterdam) Benevolent Dictator for Life (BDFL)

(9)

What’s Python?

Python was created in 1991 by Guido van Rossum (CWI, Centrum voor Wiskunde en Informatica, Amsterdam) Benevolent Dictator for Life (BDFL)

(10)
(11)

DARPA funding proposal “Computer Programming for

Everybody” (1999):

(12)

an easy and intuitive language just as powerful as major competitors

open source, so anyone can contribute to its development

code that is as understandable as plain English

suitability for everyday tasks, allowing for short development times

DARPA funding proposal “Computer Programming for

Everybody” (1999):

(13)

an easy and intuitive language just as powerful as major competitors

open source, so anyone can contribute to its development

code that is as understandable as plain English

suitability for everyday tasks, allowing for short development times

DARPA funding proposal “Computer Programming for

Everybody” (1999):

year 1991 1994 1995 2001 2003 2007 2009

(14)

an easy and intuitive language just as powerful as major competitors

open source, so anyone can contribute to its development

code that is as understandable as plain English

suitability for everyday tasks, allowing for short development times

DARPA funding proposal “Computer Programming for

Everybody” (1999):

year 1991 1994 1995 2001 2003 2007 2009

version 0.9 1.0 1.2 2.0 2.2 2.5 3.0

Why Python? - it’s free! ;-)

- quite easy to use; object-oriented; highly modular, etc... - much more rapid than IDL and even PARALLEL

(15)
(16)
(17)
(18)

How to install Python?

Required:

python 2.5: the engine

numpy: the scientific computing package (arrays, linear

algebra, FFT, random numbers, etc...); [replaces old numarray and numeric]

scipy: modules for integrating ODEs, optimizing functions, etc... [tends to federate all of Python scientific modules]

(19)

How to install Python?

Required:

python 2.5: the engine

numpy: the scientific computing package (arrays, linear

algebra, FFT, random numbers, etc...); [replaces old numarray and numeric]

scipy: modules for integrating ODEs, optimizing functions, etc... [tends to federate all of Python scientific modules]

matplotlib: MATLAB-inspired mostly-2D plotting modules Optional:

ipython: convenient shell to develop and run Python

basemap: map projections

Pypar: parallel Python (interface with MPI libraries)

PyQt: to do Qt-like widgets VERY easily under Python

(20)
(21)
(22)

For all platforms: everything can be compiled from sources

For Linux, Windows & Mac (at least): binaries are provided

(Linux: yum, apt-get, dpkg; Mac: Fink, MacPorts, dmg)

(23)

For all platforms: everything can be compiled from sources

For Linux, Windows & Mac (at least): binaries are provided

(Linux: yum, apt-get, dpkg; Mac: Fink, MacPorts, dmg)

From sources or binary packages?

Linux (FedoraCore 7) Mac OS X 10.4 (Tiger)

Python 2.5.12 2.5.2

Numpy 1.0.3 1.0.4

Scipy 0.6.0 0.7.0

Matplotlib 0.90.0 0.90.1

(24)
(25)
(26)
(27)

Python packages on my Macbook Pro

(SciPy Superpack)

(28)

Python in the Pencil Code repository:

f90/pencil-code/numpy commited by Jeff in fall of 2007

revision 1.1

date: 2007-11-16 13:57:04 +0000; author: joishi; state: Exp;

* added python scripts for reading pencil code data. they require only the numpy package, but matplotlib is useful for plotting. almost all of these routines are simplified clones of their idl counterparts. i'd love to make a

more OO pencil-code package, but my current occupational constraints make that unlikely in the near term. NB: the byte ordering in python is C, not

fortran, so these routines return an f array with shape f[nvar,nz,ny,nx]--the reverse of pencil.

* added nl2python to take advantage of the amazing perl F90Namelist.pm * modified F90Namelist.pm to output python

(29)

The actual Python tree: 3 directories

numpy/pencil/files __init__.py yzaver.py yaver.py xyaver.py npfile.py dim.py param.py grid.py slices.py zprof.py index.py var.py ts.py

(30)

The actual Python tree: 3 directories

numpy/pencil/files __init__.py yzaver.py yaver.py xyaver.py npfile.py dim.py param.py grid.py slices.py zprof.py index.py var.py ts.py

The reading stuff

numpy/pencil/math __init__.py vector_multiplication.py derivatives/ numpy/pencil/math/derivatives __init__.py der.py div_grad_curl.py der_6th_order_w_ghosts.py

(31)

# Set PYTHON path

if ($?PYTHONPATH) then

setenv PYTHONPATH "${PYTHONPATH}:${PENCIL_HOME}/numpy" else

setenv PYTHONPATH "${PENCIL_HOME}/numpy" endif

...and the initialization of $PYTHONPATH in f90/pencil-code/sourceme.csh

(32)

# Set PYTHON path

if ($?PYTHONPATH) then

setenv PYTHONPATH "${PYTHONPATH}:${PENCIL_HOME}/numpy" else

setenv PYTHONPATH "${PENCIL_HOME}/numpy" endif

...and the initialization of $PYTHONPATH in f90/pencil-code/sourceme.csh

These modules are loaded when importing the whole pencil directory due to

(33)

cat numpy/pencil/ __init__.py

(34)

cat numpy/pencil/ __init__.py

In [1]: import pencil as pc In [2]: pc.read_ts()

(35)

An important point: Python’s classes

Python is an object-oriented interpreted language:

instead of doing pc.read_ts(),

(36)

An important point: Python’s classes

Python is an object-oriented interpreted language:

instead of doing pc.read_ts(),

it is better to do a=pc.read_ts()

... and we can plot the other variables read in time_series.dat and

(37)

Another example when

using pc.read_var()

(38)

Another example when

using pc.read_var()

...and we plot the

entropy at the top of the 32^3 box

(39)

Another examples of postprocesing with Python

Basemap: various kind of

map projections

MayaVi:

3D plots

(40)
(41)

Be careful: Python’s

arrays are ordered like

i.e. REVERSED ORDER

COMPARED TO

PENCIL-CODE OR IDL!!!

f[nvar,mz,my,mx]

(42)

Migrating from IDL to Python: some useful Web Guides

(43)
(44)

http://code.google.com/p/i2py/

(45)
(46)

Some tricks when using Python...

plays with ~/.ipython/ipythonrc to load modules by default (import_all pencil) and thus use ‘read_var’ instead of

(47)

Some tricks when using Python...

plays with ~/.ipython/ipythonrc to load modules by default (import_all pencil) and thus use ‘read_var’ instead of

‘pc.read_var()’, etc...

import just what you need! (a cleaning is certainly needed in that respect in the PC tree...)

(48)

Some tricks when using Python...

plays with ~/.ipython/ipythonrc to load modules by default (import_all pencil) and thus use ‘read_var’ instead of

‘pc.read_var()’, etc...

import just what you need! (a cleaning is certainly needed in that respect in the PC tree...)

launch ipython with the ‘-pylab’ option to call directly plot, contour, imshow, etc...

(49)

Some tricks when using Python...

plays with ~/.ipython/ipythonrc to load modules by default (import_all pencil) and thus use ‘read_var’ instead of

‘pc.read_var()’, etc...

import just what you need! (a cleaning is certainly needed in that respect in the PC tree...)

launch ipython with the ‘-pylab’ option to call directly plot, contour, imshow, etc...

accelerate the VAR* reading by passing param, grid, index, etc... [tricks.py]

(50)

Some tricks when using Python...

plays with ~/.ipython/ipythonrc to load modules by default (import_all pencil) and thus use ‘read_var’ instead of

‘pc.read_var()’, etc...

import just what you need! (a cleaning is certainly needed in that respect in the PC tree...)

launch ipython with the ‘-pylab’ option to call directly plot, contour, imshow, etc...

accelerate the VAR* reading by passing param, grid, index, etc... [tricks.py]

(51)

Some tricks when using Python...

take advantage of class and objects (a.shape instead of shape(a))

plays with ~/.ipython/ipythonrc to load modules by default (import_all pencil) and thus use ‘read_var’ instead of

‘pc.read_var()’, etc...

import just what you need! (a cleaning is certainly needed in that respect in the PC tree...)

launch ipython with the ‘-pylab’ option to call directly plot, contour, imshow, etc...

accelerate the VAR* reading by passing param, grid, index, etc... [tricks.py]

(52)

Parallel Python using the Pypar module

(53)
(54)

Pypar example 2: write PNG files in parallel for a

movie

(55)
(56)
(57)

Conclusion/Outlook

Python can do a very good job in the Pencil Code

post-processing

Its using is rapidly increasing in astrophysics (NASA, ESA,

ESO, labs,...)

More in the Pencil Code philosophy (i.e. under GPL)

compared to IDL

(58)

Conclusion/Outlook

the actual Python subroutines must be rewritten in a more

oriented-object form (class inheritance)

the Python tree shall maybe be re-organized in something

like f90/pencil-code/python or???

what’s about the calling of Fortran or C subroutines to

increase the speed?

Python can do a very good job in the Pencil Code

post-processing

Its using is rapidly increasing in astrophysics (NASA, ESA,

ESO, labs,...)

More in the Pencil Code philosophy (i.e. under GPL)

compared to IDL

References

Related documents

Unit is like a list houses, amazing home changes: what are interested in this low price big deal with a great apartment listing and free.. Sets in cochise county, check out our new,

The contribution of this research includes: a bibliometric analysis of the papers that focus on risk management in megaprojects; a systematization and classification of the risks; tw

COBACORE issues responding responding responding responding community community community community responding responding responding responding professionals professionals

Although robots can do some jobs better, cheaper, and faster than humans in the service sector and are in huge demand at various levels, which is always expected to increase in

76 See Peter Swire, Social Networks, Privacy, and Freedom of Association: Data Protection vs. Data Empowerment, 90 N.C.. Bro- kers' trade secrets make it impossible for

If the university/college setting is also a place where family types of relationships occur for Latino college students, then the sense of belongingness on campus could be a

Whilst in the majority of the cases, players experiment new strategies when their payoff falls below the average profit, as predicted by the aspiration rule, we find no evidence

Cray C++ Compiling System, Cray CF90, Cray CX1, Cray EL, Cray Fortran Compiler, Cray J90, Cray J90se, Cray J916, Cray J932, Cray Linux Environment, Cray MTA, Cray MTA-2, Cray MTX,