Feeds:
Posts

## Map with colorbar and contour

In this post, I show the way I usually use Python to make 2D maps with color bar and overlay contour(s) of another map on it.

Map with colorbar and overlayed contour of another quantity

import pyfits
import pylab
import numpy
from pylab import *

#– adjusting some of the plot parameters, there are much more…
rcParams[‘xtick.direction’] = ‘out’
rcParams[‘ytick.direction’] = ‘out’
rcParams[‘xtick.major.size’] = 12
rcParams[‘xtick.minor.size’] = 3
rcParams[‘ytick.major.size’] = 12
rcParams[‘ytick.minor.size’] = 3
rcParams[‘xtick.labelsize’] = 13
rcParams[‘ytick.labelsize’] = 13

rcParams[‘axes.linewidth’] = .5
rcParams[‘axes.titlesize’] = 22
rcParams[‘axes.labelcolor’] = ‘black’
rcParams[‘verbose.level’]= ‘debug’
rcParams[‘axes.labelsize’] = 1.0e-8

set_ticks=2
set_linewidth=5
set_linethick=5

a=pyfits.open(‘map1.fits’)
sz=a[0].data.copy()
pk = shape(sz)
extent=(0,pk[1], 0, pk[0])

im = imshow(sz, interpolation=’nearest’, cmap=get_cmap(‘gray’), origin=’lower’,extent=extent)

#note: if you don’t like to see individual pixels in the map, remove interpolation=’nearest’

title(‘micropore.wordpress.com’)

#– change some parameters for colorbar
rcParams[‘ytick.labelsize’] = 9
rcParams[‘axes.linewidth’] = .2
rcParams[‘ytick.major.size’] = 4

#– prepare the contour variable

a=pyfits.open(‘map2.fits’)  # trivially, the two maps must have the same size
pt=a[0].data.copy()

levels = (.012, .03, .05)
cset = contour(pt, levels, inline=1,origin=’lower’,colors=[‘blue’,’yellow’,’red’],linewidths=(2., 1.5, 1.),extent=extent)

# if you do not know the levels, use the next line instead of the previous two lines
#cset = contour(pt, nlevels=3, origin=’lower’,colors=[‘blue’,’yellow’,’red’],linewidths=(1.4, 1.2, 1.),extent=extent)

#clabel(cset, inline=1, fontsize=10)  # activate to have labels on contours

for c in cset.collections:

c.set_linestyle(‘solid’)

savefig(‘map_cbar_contour.png’, dpi=100)

## scientist life before Xmass

“Since it is less than two hours before the X-mas celebration, and I’m fed up with physics a bit, this is where I stop.”

## Python: colormaps

It has happened rather often to try to find a better colorbar for a special map.
Here, I use this useful example and show the result.

“””
This program shows the available color maps in Python.
see http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps

“””
from pylab import *
from numpy import outer

rc(‘text’, usetex=False)

a=outer(arange(0,1,0.01),ones(10))
figure(figsize=(10,5))
maps=[m for m in cm.datad if not m.endswith(“_r”)]
maps.sort()
l=len(maps)+1
for i, m in enumerate(maps):

subplot(1,l,i+1)
axis(“off”)
imshow(a,aspect=’auto’,cmap=get_cmap(m),origin=”lower”)
title(m,rotation=90,fontsize=10)

savefig(“colormaps.png”,dpi=100,facecolor=’gray’)
#show()

Colormaps in Python

Note that you need only the following three lines in your program to use any of these colormaps:

a=outer(arange(0,1,0.01),ones(10))
maps=[m for m in cm.datad if not m.endswith(“_r”)]
maps.sort()

## How to force a check of the file systems?

If the file “/forcefsck” exists a file system consistency check
(fsck) will be forced at the next boot up.

The command line commands look like:

#touch /forcefsck
#reboot

if fsck failed, you should run it manually, reboot won’t help.

fsck /dev/hdaXXX
type e2fsck /dev/hdaxxx (for ide cable) or e2fsck /dev/sdaxxx for scsi

## Spectacular photos from Perseids

APOD: 2009 August 15 - Meteor by Moonlight, over Iran

APOD: 2004 August 13 - Perseid Fireball Over Japan

APOD: 2008 August 14 - Perseid Trail

Perseids97, from Rickjoe

For more such images, see http://antwrp.gsfc.nasa.gov/apod/astropix.html