giovedì 21 ottobre 2010

Python: Spyder on Ubuntu 10.10

Spyder, the great python development environment specially designed for scientific computing has been added to the Ubuntu 10.10 repository.

After the installation using synaptic or the shell command "sudo apt-get install spyder" you may encounter this problem:

Warning: None of the following fonts is installed: [u'Andale Mono']
Segmentation fault

To fix that you can simply install the font library with the following command:

sudo apt-get install ttf-mscorefonts-installer

Now you can run spyder just typing "spyder" in a shell

martedì 12 ottobre 2010

Python: how to open a plot without calling show() each time

Just add these lines to activate the matplotlib interactive mode:

from matplotlib
import interactive
interactive(True)

This way, the show() call is not necessary and the plotting window will be shown each time a plotting function is called.

giovedì 18 febbraio 2010

How to solve problems installing SOLAR SOFT

Solar Solft installation script can be found here:
http://www.lmsal.com/solarsoft/ssw_install.html

Once downloaded the installation script you may encounter a trouble like this:

.../ssw/offline/swmaint/script/ssw_install.size: Too many arguments.

to overcome this is sufficient to insert the following lines in ".../ssw/offline/swmaint/script/ssw_install.ftpget"
and
".../ssw/offline/swmaint/script/ssw_install"


setenv SSW $HOME/ssw
setenv ssw_host sohoftp.nascom.nasa.gov
setenv ssw_sw_host sohoftp.nascom.nasa.gov
setenv ssw_tar_old_style ""
setenv ssw_sw_sets "ssw_ssw_site ssw_hinode_gen ssw_hinode_sot ssw_packages_binaries ssw_ssw_gen"
setenv ssw_db_sets ""
setenv ssw_passive_ftp 1
setenv ssw_noepsv
setenv ssw_skip_sizechk 1

Now from shell run manually these two scripts:
csh -f .../ssw_install.ftpget
and
csh -f .../ssw_install


Now your installation should be ok!



sabato 23 gennaio 2010

IDL2PYTHON dictionary: how to save and load arrays

One of the most useful function in IDL is the save/restore function.
In Python it is very easy to store and reload data too.
Let's say we have an array A(50,50) and we want to save/load it in/from the directory "/home/user/":


from scipy import *

save('/home/user/A', A)
load('/home/user/A.npy')


giovedì 21 gennaio 2010

IDL2PYTHON dictionary: where function 1/2

The IDL where function is a very useful tool. In this post a will briefly report how to obtain the same with Python.
We define a float matrix 5x5, we will assign two non zero values at two of its components.
Then we discover how to obtain the coordinates (i,j) of the non zero values.
This can be done easily in one line of code.

Library needed: scipy


from scipy import * #this imports all the scipy functions

a=zeros([5,5], float) #an example of matrix
a[1,2]=4
a[4,3]=5
(i,j)=(a>3).nonzero()
# where a is greater than 3:

so i and j are the indices of the matrix where a satisfies the condition above:
>>> print i[0]
1
>>> print i[1]
4
>>> print j[0]
2
>>> print j[1]
3



For those who know IDL it is easy to see how this Python command is much more flexible then IDL where() function.