analitics

Pages

Sunday, September 22, 2013

Check system , distro and commands using python scripts .

This is a simple example with two functions.

First will check the linux command : ls linux command.

The next function will give us some infos about system.

import shlex 
import subprocess
from subprocess import Popen, PIPE

import platform

def check_command(command):
    cmd='which ' + command 
    output = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0]
    command_path =output.split('\n')[0]
    print command_path
    return command_path

def check_platform():
    arch, exe = platform.architecture()
    my_system = platform.system()
    if my_system == 'Linux':
        distro_name, distro_version, distro_id = platform.linux_distribution()
    elif my_system == 'Darwin':
        distro_name, distro_version, distro_id = platform.mac_ver()
    elif my_system == 'Windows':
 distro_name, distro_version, distro_id = platform.win32_ver()
    elif my_system == 'Java':
 distro_name, distro_version, distro_id = platform.java_ver()
    processor = platform.processor() or 'i386'
    print processor, my_system, arch, distro_name, distro_version, distro_id
    return processor, my_system, arch, distro_name, distro_version, distro_id

check_command('ls')

check_platform()

This python script can be use with any scripts when we need to test commands and system , distro version.

Thursday, September 12, 2013

Working with SunPy python module - part 001 .

The SunPy python module it's an open-source software library for solar physics using the Python programming language.

The SunPy module is included into nasa projects.

Now, if you want to use this python module then you need to install lapack and blas libraries for development.

I use # pip under super user account to install sunpy and the python modules required by SunPy.

# pip install --upgrade distribute
# pip install --upgrade pyfits
# pip install --upgrade suds
# pip install --upgrade pandas
# pip install --upgrade beautifulsoup4

... also you need to have this python modules: Scipy and Matplotlib.

After that you can install sunpy using:

# pip install sunpy
# pip install --upgrade sunpy

The basic example is one output created by Map() function.

This function can deal with many data sources, like:

SDO/AIA, SDO/HMI

STEREO/EUVI, STEREO/COR

Hinode/XRT

SOHO/EIT, SOHO/LASCO, SOHO/MDI

PROBA2/SWAP

Yohkoh/SXT

Let's try a simple example and will show the result...

>>> import sunpy 
>>> ati_map=sunpy.Map(sunpy.AIA_171_IMAGE).peek()

... and output is:


Let's make more sun maps...

>>> eit_map=sunpy.Map(sunpy.EIT_195_IMAGE).peek()

The the output is:


>>> rhessi_map=sunpy.Map(sunpy.RHESSI_IMAGE).peek()

You can see radio spectrometer image using:

>>> callisto_radio_maps=sunpy.Map(sunpy.CALLISTO_IMAGE).peek()

Also you can combine the maps , like in the next example:

>>> eti_rhessi_maps=sunpy.Map(sunpy.EIT_195_IMAGE, sunpy.RHESSI_IMAGE, composite=True).peek()

You can get more infos about Map using :

>>> help(sunpy.Map)

If you want more data to show then you can request data from here.

Also you can give parameters to the Map, like:

date : datetime
 |          Image observation time
...

This allow you to take more data and info...

Using matplotlib and scipy modules can help to parse and show all infos.