require 'nyaplot'
require 'mapnya'
true
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.
path = File.expand_path("../data/wind.csv", __FILE__)
df = Nyaplot::DataFrame.from_csv(path)
index | lat | lon | uwnd | vwnd |
---|---|---|---|---|
0 | -78.375 | 0.125 | 1.733504295349121 | -3.9492156505584717 |
10 | -78.375 | 2.625 | 2.0234389305114746 | -4.730513095855713 |
20 | -78.375 | 5.125 | 2.0112311840057373 | -5.069279193878174 |
30 | -78.375 | 7.625 | 1.748763918876648 | -5.585057735443115 |
40 | -78.375 | 10.125 | 1.1780503988265991 | -6.186290740966797 |
50 | -78.375 | 12.625 | 1.2970762252807617 | -5.874992370605469 |
60 | -78.375 | 15.125 | 0.9491546154022217 | -5.469083786010742 |
70 | -78.375 | 17.625 | 0.47915521264076233 | -5.066226959228516 |
80 | -78.375 | 20.125 | 0.21973997354507446 | -4.443630695343018 |
90 | -78.375 | 22.625 | -0.5310382843017578 | -4.147592067718506 |
100 | -78.375 | 25.125 | -0.9644143581390381 | -3.9125924110412598 |
110 | -78.375 | 27.625 | -0.6531160473823547 | -3.5921382904052734 |
120 | -78.375 | 30.125 | -1.0376609563827515 | -3.26252818107605 |
130 | -78.375 | 32.625 | -1.287920355796814 | -2.7162301540374756 |
140 | -78.375 | 35.125 | -1.0620765686035156 | -2.151620626449585 |
150 | -78.375 | 37.625 | -0.4455838203430176 | -1.2024660110473633 |
... | ... | ... | ... | ... |
894230 | 76.625 | 357.625 | 4.30324125289917 | 5.511810779571533 |
# 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}
""
""
plot = Nyaplot::MapPlot.new
vectors = plot.add_with_df(df, :vectors, :lon, :lat)
vectors.dx(:uwnd)
vectors.dy(:vwnd)
plot.show
That generally looks good, but I'd like to fill each vector in different color according to its length.
abs = []
df.each_row{|row| abs.push(Math.sqrt(row[:uwnd]*row[:uwnd]+row[:vwnd]*row[:vwnd]))}
df.abs = abs
df
index | lat | lon | uwnd | vwnd | abs |
---|---|---|---|---|---|
0 | -78.375 | 0.125 | 0.5778347651163737 | -1.316405216852824 | 1.4376424140704895 |
10 | -78.375 | 2.625 | 0.6744796435038248 | -1.576837698618571 | 1.7150335032546036 |
20 | -78.375 | 5.125 | 0.6704103946685791 | -1.6897597312927246 | 1.817893849150203 |
30 | -78.375 | 7.625 | 0.582921306292216 | -1.8616859118143718 | 1.9508130826856613 |
40 | -78.375 | 10.125 | 0.392683466275533 | -2.062096913655599 | 2.0991531592511574 |
50 | -78.375 | 12.625 | 0.4323587417602539 | -1.958330790201823 | 2.005490853987873 |
60 | -78.375 | 15.125 | 0.31638487180074054 | -1.8230279286702473 | 1.8502784157569647 |
70 | -78.375 | 17.625 | 0.15971840421358743 | -1.6887423197428386 | 1.6962784533015087 |
80 | -78.375 | 20.125 | 0.07324665784835815 | -1.4812102317810059 | 1.483020169660108 |
90 | -78.375 | 22.625 | -0.17701276143391928 | -1.382530689239502 | 1.393816567701616 |
100 | -78.375 | 25.125 | -0.3214714527130127 | -1.3041974703470867 | 1.3432330164826782 |
110 | -78.375 | 27.625 | -0.21770534912745157 | -1.197379430135091 | 1.217009909059635 |
120 | -78.375 | 30.125 | -0.3458869854609172 | -1.0875093936920166 | 1.1411899439092592 |
130 | -78.375 | 32.625 | -0.4293067852656047 | -0.9054100513458252 | 1.0020337703656188 |
140 | -78.375 | 35.125 | -0.35402552286783856 | -0.717206875483195 | 0.7998248390005236 |
150 | -78.375 | 37.625 | -0.1485279401143392 | -0.4008220036824544 | 0.42745622890610246 |
... | ... | ... | ... | ... | ... |
894230 | 76.625 | 357.625 | 1.43441375096639 | 1.8372702598571777 | 2.330902146534069 |
vectors.fill_by(:abs)
plot.show
color = Nyaplot::Colors.OrRd(3)
rgb(254,232,200) | rgb(253,187,132) | rgb(227,74,51) |
---|---|---|
vectors.color(color)
plot.show
This notebook was created as the demonstration of Nyaplot.