Download Scientific Computing with Python

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Scientific Computing
with
Cory Davis
●
●
●
●
●
●
●
Fully object oriented – everything is an object, even functions.
Interactive sessions – much like MATLAB or IDL. Try out snippets of code for rapid development, or just perform ad hoc calculations.
concise elegant syntax
Massive Standard Library: debugger, profiler, documentation utilities, system utilities, distribution utilities, unit testing, internet protocols,...
Excellent documentation (www.python.org)
Easily extendable ­ write modules in Python, or compiled languages like C, C++, and fortran. Python is free !
An interactive python session
[cory@sundog cory]$ python
Python 2.3.3 (#1, May 7 2004, 10:31:40)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> a_string='Python - why settle for snake oil when you can
have the whole snake?'
>>> dir(a_string)
[..., 'isspace', 'istitle', 'isupper', 'join', 'ljust',
'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust',
'rstrip', 'split', 'splitlines', 'startswith', 'strip', ...]
>>> help(a_string.split)
Help on built-in function split:
split(...)
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as
the delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator.
>>> a_list=a_string.split()
>>> print a_list
['Python', '-', 'why', 'settle', 'for', 'snake',
'oil', 'when', 'you', 'can', 'have', 'the', 'whole',
'snake?']
>>> dir(a_list)
[..., 'append', 'count', 'extend', 'index',
'insert', 'pop', 'remove', 'reverse', 'sort']
>>> a_list.index('oil')
#indexing starts at 0 !!!
6
>>> print a_list[:6]
['Python', '-', 'why', 'settle', 'for', 'snake']
>>> print a_list[6:]
['oil', 'when', 'you', 'can', 'have', 'the',
'whole', 'snake?']
>>> a_list[len(a_list)-1]
#the matlab way
'snake?'
>>> a_list[-1]
#the python way!!!!
'snake?'
an example script:
dirpie.py
an example script:
dirpie.py
Scientific packages for Python
Numerical Python (numpy)
Fast numerical arrays, array/matrix manipulation, simple linear algebra, quadrature etc, FFT, matlab­
like interface
Scipy
builds on established LAPACK and BLAS libraries to give:
integration, interpolation, linear algebra, optimisation, signal processing, FFT, statistics, special functions, ..., distribution of python packages with fortran code.
matplotlib
complete 2D plotting library with matlab­like (or OO pythonic) interface, ...
plot, pcolor, contour, bar, pie, polar, image, ...
publication quality output in a range of formats.
A more scientific example
●
●
●
import some stuff
define a function
use it to create array of incoming radiances
●
●
●
●
load the phase matrix data
do the two pseudocolor plots
with a funky colormap and colorbar
fiddle with axes – latex labels!
●
●
●
Finally, do the simple radiance plot
fiddle with the pseudocolor plots again
save figure as png, eps, and pdf
●
●
●
Finally, do the simple radiance plot
fiddle with the pseudocolor plots again
save figure as png, eps, and pdf
More on Matplotlib
http://matplotlib.sourceforge.net/
tutorial, user guide, examples, screenshots, download
Support:
matplotlib­[email protected]
To use matplotlib and scipy in the department (on a linux machine):
“export PYTHONPATH=/eosmls/local/linux/
lib/python/:/eosmls/local/linux/lib/pyt
hon/Numeric”
basemap toolkit
cylindrical equidistant, mercator, lambert conformal conic, lambert azimuthal equal area, albers equal area conic and stereographic.
●
pydoc ­
builtin python document
ation utilitity ●
browse your python library
●
PyARTS ­ contribition to an esa project
PyARTS ­ contribition to an esa project
PyARTS.ar
ts_scat – calculation of single scattering properties of hydrometeors
PyARTS.ar
ts_scat – calculation of single scattering properties of hydrometeors
All you need to do is put docstrings at the beginning of class or function definitions