Showing posts with label IDL. Show all posts
Showing posts with label IDL. Show all posts

January 26, 2013

工欲善其事


當初學IDL 的時候,老師沒有給一份比較實質而且有系統的講義。大多時候是派發作業時,附上了一些 samples,自己就上網找資料加上揣摩修改半路出家,真是痛苦萬分...

後來做研究執行計畫時決定以戰養戰,覺得應該把 IDL 從基本開始學起,儘管網路資源豐富,可是手上還是需要一本好的入門書,以便隨時翻照查閱。因此找到了這一本:

Practical IDL Programming
ISBN: 1558607005
作者是 Liam E. Gumley
http://www.gumley.com/

這本書真是深入淺出,把基本的 IDL指令都交代的很詳細,而且附上了有用的程式範例與函式庫,讓讀者可以自行應用在自己的程式裡頭。這些程式範例都可以在以上的網頁裡下載得到,是一本很棒很適合IDL 初學者的指引與日後手邊的參考用書。

另外一份對入門者不錯的資料是 Colorado State University (CSU) 大氣科學系老師 Joe Munchak的上課講義:
http://www.atmos.colostate.edu/programming/


總共有五周的講義,加上作業以及作業解答。看完後對於IDL 會有更深一層的認識。

January 21, 2013

IDL 在地圖上畫風向量 - Wind vector overploting on the map

在7.0 版IDL之前要畫風向量,一般會使用以下幾個 functions:

VEL - Draws a velocity (flow) field with streamlines.
VELOVECT - Draws a 2D velocity field plot.
PLOT_FIELD - Plots a 2D field using arrows.
ARROW - Draws one or more vectors with arrow heads.

或者,你也可以用The IDL Astronomy User's Library (NASA)  的 partvelvec.pro

可是他們都不能讓你同時把風向量化在地圖上。如果你要用 ivector 那也要7.0 以後才能用。

Here is a "quick solution" from somebody whom we have to appreciate:
map_vect.pro

Notice that you might need to modify the reference vector size for your purposes.

The figure below represents the composition of 500mb wind speed contour and directions in 1956. The data source is NCEP/NCAR Reanalysis data (NNR) provided by the Physical Science Division, NOAA Earth System Research Laboratory.



From

SST - 老梗

1900 - 2000 年間夏季平均海平面溫度 Mean Sea Surface Temperature (SST) 全球分布。 SST 的分析是做 颱風,ENSO 與 El Niño 的老梗,這張圖比較棘手的地方在近極區(75 度以北或以南)的地區,有時候是海冰,不是有效的海水溫度,需要剔除掉,處理的時候硬是脫層皮;加上360 X 180 網格資料乘上100年, IDL 硬是被我操掛了好幾次... orz 回到圖上,西太平洋,印度洋與墨西哥灣,三大暖區,也是颱風易於生成的地方。

建立紅-白-藍色表 - How to create a R-W-B color table in IDL

在大氣裡面,有很多機會看在天氣圖或是變差圖上到紅白藍三色的色表。我把 David W. Fanning's website talking about "Constructing a Color Table in IDL" 上的簡單色表程式稍微改寫了一下,就完成了我們常用的這個紅白藍色表。這一篇告訴你怎麼建立這個色表;下一篇,我再說明怎麼把它用在IDL的繪圖上面。 (1) 紅白藍矩陣的設定: 第一部份,設定紅色漸層至白色。第二部份則由白色漸深至藍色。
pro color_table_RWB

device, decomposed=0
ncolors = 255
steps = 128
scaleFactor = FINDGEN(steps) / (steps - 1)
; Do first half colors (red to white).
; Red vector: 255 -> 0
R = REPLICATE(ncolors, steps)
; Green vector: 255 -> 0
G = 0 + (0 + ncolors) * scaleFactor
; Blue vector: 0 -> 255
B = 0 + (0 + ncolors) * scaleFactor

; Do second 100 colors (whie to blue).
;Red vector: 0 -> 255
R = [R, reverse(0 + (ncolors + 0) * scaleFactor)]
; Green vector: 0 -> 0
G = [G, reverse(0 + (ncolors - 0) * scaleFactor)]
; Blue vector: 255 -> 0
B = [B, REPLICATE(ncolors, steps)]
(2) 列出RGB三矩陣裡的顏色設定值: 色階總數設定為 255+1 (值從0到255),如果你不想用這麼多色階,可從這個loop 印出所有色階的值供你撿用。 或者,就由設定間隔值,可以直接取得等量色階,然後你就可以自行設定所需的色表。
k = 0
for i = 0, ncolors-1, 16 do begin
print, i, R(i), G(i), B(i), k
k = k + 1
endfor
(3)螢幕快速顯示色表:
TVLCT, R, G, B

;display the sample
image = FINDGEN(255) # REPLICATE(1, 60)
WINDOW, XSIZE=255, YSIZE=60
TV, BYTE(image)
END
(4) 從(2) output 的色階代碼:
color# Red Green Blue
0 255.000 0.000000 0.000000 0
16 255.000 32.1260 32.1260 1
32 255.000 64.2520 64.2520 2
48 255.000 96.3780 96.3780 3
64 255.000 128.504 128.504 4
80 255.000 160.630 160.630 5
96 255.000 192.756 192.756 6
112 255.000 224.882 224.882 7
128 255.000 255.000 255.000 8
144 222.874 222.874 255.000 9
160 190.748 190.748 255.000 10
176 158.622 158.622 255.000 11
192 126.496 126.496 255.000 12
208 94.3701 94.3701 255.000 13
224 62.2441 62.2441 255.000 14
240 30.1181 30.1181 255.000 15
(5)最後執行這個程式後,你可以在螢幕上看到如下的紅白藍色表。

March 01, 2012

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Blogger Theme by Lasantha - Premium Blogger Templates | Affiliate Network Reviews