Feeds:
Posts
Comments

Archive for September, 2011

Comet Garradd

As predicted long ago, Comet Garradd is getting brighter and brighter, Now at a magnitude of about 8,  it is not hard to catch it in Northern sky. According to the latest predictions, its magnitude will reach to 7.0 in February 2012.

The following charts show the position of it during rest of the year.

Path of Comet Garradd in Sep/Oct 2011

Path of Comet Garradd in Nov 2011 to Jan 2012.

Advertisements

Read Full Post »

New color table in Python

It happens that you want to build a new color table in python despite all the existing color tables.  An example is a map of azimuth angle, in which 360 degrees is equal to zero. With an standard color table (Jet in this case), it looks like a discontinuity:

So we need to create a color table which does not have a discontinuity.

Build a New Color Table

Basically we need three arrays, one for each color. For illustration, let’s see what are those arrays in case of Jet.

cmap = cm.jet
cdict = cmap._segmentdata
print cdict[‘red’]  #  you can do the same for ‘blue’ and ‘green’

((0.0, 0.0,0.0), (0.35, 0., 0.), (0.66, 1.0, 1.0), (0.89, 1.0, 1.0), (1.0, 0.5, 0.5))

The first column of this 5×3 array is like the x-component of a function. It is a monotonic function starting from zero and going till one. In this case, it reads (0.0, 0.35, 0.66, 0.89, 1.0).  The second column shows the amount of red (in this case), at each x value. This does not need to be monotonic, it can have any form. The third column concerns the interpolations and gradients. We usually take it identical to the second column.

Now with some try and error, you can invert the proper ordinate (first column) and values (second column). As stated above, the third column can be identical to the second one.  I show the following example:

xr = (0., .125, .34, .4,  .66, .76, .95, 1.)                  # first column of red
yr =  (0.9, .5,  0.1, 0.,  0.4, 0.57,  1., 0.9)             # second column of red

xg = (0., .125, .375, 0.5,  .56, .75, 0.91, 1.)          # first column of green
yg =  (0.,  0.0,  0.2, 0.8,   1.,  1.,   0.1, 0.)               # second column of green

xb = (0.0, 0.11, .24, 0.38, .54, 0.65, .8, 1.)          # first column of blue
yb =   (0., 0.25, 0.5,   1., .65,   .45, .0, 0.)              # second column of blue

Now, we have to put them together and form the new color table:

arr_green = zeros((8, 3), float)    #  we have 8 x-points, and the array has 3 columns
arr_gree[:,0] = xg;     arr_green[:,1] = yg;     arr_green[:,2] = yg

with similar terms, we also from arr_red, and arr_blue.

cdict = {‘red’: arr_red,
                  ‘green’: arr_green,
                  ‘blue’: arr_blue}
my_cmap = matplotlib.colors.LinearSegmentedColormap(‘my_colormap’,cdict,256)
pcolor(mu, cmap=my_cmap)

The resulting map is like below:

Read Full Post »