使用Ruby从CDIP数据创建光谱热图或强度图
背景
根据沿海信息数据计划(CDIP),他们在http://cdip.ucsd.edu/?nav=recent&sub=observed&units=metric&tz=UTC&pub=public&map_stati=1,2生成波浪膨胀的光谱热/强度图, 3&stn = 100&stream = p1&xitem = dir_spectrum 。
这是使用包含能量密度,持续时间(以秒为单位)和方向(以180度表示南方的度数)的数据动态生成的。
数据样本
以下是对数据的解释: http : //cdip.ucsd.edu/data_access/MEM_2dspectra.cdip
这是浮标100的数据样本(相同的浮标,如热/强度/光谱图所示: http : //cdip.ucsd.edu/data_access/MEM_2dspectra.cdip?100
题
如何获取此二维数据并创建热/强度图,确保它覆盖在极坐标图上(并且是适当的比例),就像每个CDIP网站的示例url一样?
最后,我需要在Ruby中完成,最好使用ruby-gd或Rmagick,但我也非常感谢任何与语言无关的解决方案。
我真的很匆忙,所以现在还不能完成,但是没有人回答,这是第一种方法:
Mathematica中的代码(对不起,我现在没时间说过):
a = Import["http://cdip.ucsd.edu/data_access/MEM_2dspectra.cdip?100", "Table"]; Graphics@Flatten[Table[ (*colors, dont mind*) {ColorData["CMYKColors"][(a[[r, t]] - .000007)/(.0003 - 0.000007)], (*point size, dont mind*) PointSize[1/Sqrt[r]/10], (*Coordinates for your points "a" is your data matrix *) Point[ {(rr =Log[.025 + (.58 - .25)/64 r]) Cos@(tt = t 5 Degree), rr Sin@tt}] } (*values for the iteration*) , {r, 7, 64}, {t, 1, 72}], 1] (*Rotation, dont mind*) /. gg : Graphics[___] :> Rotate[gg, Pi/2]
我仍然无法获得正确的色标:
芯片,我知道,不使用Ruby,但假设Belisarius的点计算很好,我会使用Mathematica的ListContourPlot
,因为它更容易理解,它给出了更清晰的画面。
(* Read in data, the web address can be specified *) a = Import[, "Table"];
Import
在第一个子列表中的pre
标记中导出,并在最后作为单个元素子列表Import
,这将删除它
dat = a[[ ;; -2]][[All, -72;; ]];
首先获取除最后一个元素以外的所有元素,然后获取每个剩余子列表的最后72个元素。
ListContourPlot
需要一个{{x, y, f}, ...}
forms的点列表,因此我们需要将dat
转换为该forms,如其他地方所述 :
pts =Flatten[ Table[ { (rr =Log[.025 + (.58 - .25)/64 r]) Cos@(tt = t 5 Degree), (* x-coord *) rr Sin@tt, (* y-coord *) dat[[r,t]] (* function value *) }, {r, 7, 64}, {t, 1, 72} ], 1 ]
然后绘制它们
ListContourPlot[pts, ColorFunctionScaling -> False, ColorFunction -> (ColorData["CMYKColors"][(# - .000007)/(.0003 - 0.000007)]&) ]
这给出了:
可以通过修复剪辑和ColorFunction
缩放来修改。 此外,通过一些工作,可以添加径向轮廓。