In [1]:
require 'nyaplot'
require 'mapnya'


Out[1]:
Out[1]:
Out[1]:
true

Case3: Plot wind vectors on the map

Next, let's generate plot vectors on the map. I prepared the data of wind vectors on 2011/01/01, from the website of NASA poddac. I converted NetCDF distributed in the database to CSV file with ruby-netcdf.


In [2]:
path = File.expand_path("../data/wind.csv", __FILE__)
df = Nyaplot::DataFrame.from_csv(path)


Out[2]:
indexlatlonuwndvwnd
0-78.3750.1251.733504295349121-3.9492156505584717
10-78.3752.6252.0234389305114746-4.730513095855713
20-78.3755.1252.0112311840057373-5.069279193878174
30-78.3757.6251.748763918876648-5.585057735443115
40-78.37510.1251.1780503988265991-6.186290740966797
50-78.37512.6251.2970762252807617-5.874992370605469
60-78.37515.1250.9491546154022217-5.469083786010742
70-78.37517.6250.47915521264076233-5.066226959228516
80-78.37520.1250.21973997354507446-4.443630695343018
90-78.37522.625-0.5310382843017578-4.147592067718506
100-78.37525.125-0.9644143581390381-3.9125924110412598
110-78.37527.625-0.6531160473823547-3.5921382904052734
120-78.37530.125-1.0376609563827515-3.26252818107605
130-78.37532.625-1.287920355796814-2.7162301540374756
140-78.37535.125-1.0620765686035156-2.151620626449585
150-78.37537.625-0.4455838203430176-1.2024660110473633
...............
89423076.625357.6254.303241252899175.511810779571533

In [3]:
# Evil pre-processing of data
df.filter!{|row| !(row[:lon] < 200 && row[:lon] > 175)}
df.each_row{|row| row[:uwnd] = row[:uwnd]/3; row[:vwnd] = row[:vwnd]/3}
""


Out[3]:
""

In [4]:
plot = Nyaplot::MapPlot.new
vectors = plot.add_with_df(df, :vectors, :lon, :lat)
vectors.dx(:uwnd)
vectors.dy(:vwnd)
plot.show


Out[4]:

That generally looks good, but I'd like to fill each vector in different color according to its length.


In [5]:
abs = []
df.each_row{|row| abs.push(Math.sqrt(row[:uwnd]*row[:uwnd]+row[:vwnd]*row[:vwnd]))}
df.abs = abs
df


Out[5]:
indexlatlonuwndvwndabs
0-78.3750.1250.5778347651163737-1.3164052168528241.4376424140704895
10-78.3752.6250.6744796435038248-1.5768376986185711.7150335032546036
20-78.3755.1250.6704103946685791-1.68975973129272461.817893849150203
30-78.3757.6250.582921306292216-1.86168591181437181.9508130826856613
40-78.37510.1250.392683466275533-2.0620969136555992.0991531592511574
50-78.37512.6250.4323587417602539-1.9583307902018232.005490853987873
60-78.37515.1250.31638487180074054-1.82302792867024731.8502784157569647
70-78.37517.6250.15971840421358743-1.68874231974283861.6962784533015087
80-78.37520.1250.07324665784835815-1.48121023178100591.483020169660108
90-78.37522.625-0.17701276143391928-1.3825306892395021.393816567701616
100-78.37525.125-0.3214714527130127-1.30419747034708671.3432330164826782
110-78.37527.625-0.21770534912745157-1.1973794301350911.217009909059635
120-78.37530.125-0.3458869854609172-1.08750939369201661.1411899439092592
130-78.37532.625-0.4293067852656047-0.90541005134582521.0020337703656188
140-78.37535.125-0.35402552286783856-0.7172068754831950.7998248390005236
150-78.37537.625-0.1485279401143392-0.40082200368245440.42745622890610246
..................
89423076.625357.6251.434413750966391.83727025985717772.330902146534069

In [6]:
vectors.fill_by(:abs)
plot.show


Out[6]:

In [7]:
color = Nyaplot::Colors.OrRd(3)


Out[7]:
rgb(254,232,200)rgb(253,187,132)rgb(227,74,51)
   

In [8]:
vectors.color(color)
plot.show


Out[8]:

This notebook was created as the demonstration of Nyaplot.