This example is a jupyter notebook adoption from the small desktop application I wrote some time ago, to analyze weather data (rain, temperature) from swiss weather stations from year 1864 - 2013.
It shows the capabilities of analyzing and visualizing data using the J array programming language.
In [1]:
NB. Required library scripts
require 'tables/dsv'
require 'graphics/plot'
NB. Utility verbs
chop =: 4 : '(y#i.#y)</.x'
desc =: 3 : '>(I. (<y) E. 0{keys) { 1{keys'
gets =: 4 : '(I. (<y) E. 0{|:x){x'
gety =: 4 : '(I. (<y) E. 1{|:x){x'
getm =: 4 : '(I. (<y) E. 2{|:x){x'
vfmx =: 3 : '}:(,|."1 [ 1,.-. *./\"1 |."1 y='' '')#,y,.LF'
lreg =: 4 : 'y %. 1 ,. x'
NB. Read and format raw data, provide filter scripts
data =: ('|';'') readdsv jpath '~user/Jupyter_Notebook_J_Example_Data/RainTemp_1864-2013.txt'
data =: (I. (<'PAY') i. 0{|:data){data NB. Remove PAY (no data)
stat =: ('|';'') readdsv jpath '~user/Jupyter_Notebook_J_Example_Data/Weather_Stations.txt'
keys =: (2,$(~.0{|:data))$(~.0{|:data),(I.((1}.0{|:stat)e.(~.0{|:data))){1}.1{|:stat
spym =: |: ((#data),2) $ (,/>1{|:data) chop ((2*#data) $ 4 2)
data =: (0{|:data),.(0{spym),.(1{spym),.(". each 2{|:data),.(". each 3{|:data)
mons =: '<All>';'Januar';'Februar';'März';'April';'Mai';'Juni';'Juli';'August';'September';'Oktober';'November';'Dezember'
yeal =: ": (".>1{0{data)+10*i.1+(>.(((".>1{0{_1{.data)-(".>1{0{data))%10))
yeax =: ": i. # ". yeal
monl =: 'Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez'
monx =: ": i. 12
xtin =: ":((i.16)*((#(data gets >0{0{keys))%15))
xlan =: yeal
xtit =: ":((i.16)*((#(data gets >0{0{keys))%15))
xlat =: yeal
nied =: ,/>3{|:(data gets >0{0{keys)
temp =: ,/>4{|:(data gets >0{0{keys)
nreg =: ((1{((i.#nied) lreg nied))*(i.#nied))+(0{((i.#nied) lreg nied))
treg =: ((1{((i.#temp) lreg temp))*(i.#temp))+(0{((i.#temp) lreg temp))
ni3d =: (150,12)$,/>3{|:(data gets >0{0{keys)
te3d =: (150,12)$,/>4{|:(data gets >0{0{keys)
vpox =: 2.8
vpoy =: _4
vpoz =: 2.4
In [2]:
NB. Show keys (available weather stations)
|:keys
In [3]:
NB. Filter data on all years, weather station SMA, and month September (09)
]d =: (data gets 'SMA') getm '09'
In [4]:
NB. Extract data for visualization, and calculate linear regression
ra3d =: (150,12)$,/>3{|:(data gets 'SMA')
te3d =: (150,12)$,/>4{|:(data gets 'SMA')
rain =: ,/>3{|:d
temp =: ,/>4{|:d
rreg =: ((1{((i.#rain) lreg rain))*(i.#rain))+(0{((i.#rain) lreg rain))
treg =: ((1{((i.#temp) lreg temp))*(i.#temp))+(0{((i.#temp) lreg temp))
In [5]:
NB. Set some plot options
xtin =: ":((i.16)*((#d)%15))
xlan =: yeal
xtit =: ":((i.16)*((#d)%15))
xlat =: yeal
In [6]:
NB. Plot/Visualize data in 4 sub-plots
pd 'reset'
pd 'sub 4 1'
pd 'new'
pd 'title Rain SMA / September'
pd 'xticpos ',xtin
pd 'xlabel ',xlan
pd rain
pd rreg
pd 'new'
pd 'title Temperature SMA / September'
pd 'xticpos ',xtit
pd 'xlabel ',xlat
pd temp
pd treg
pd 'new'
pd 'titlecolor white'
pd 'title Rain'
pd 'yticpos ',monx
pd 'ylabel ',monl
pd 'xticpos ',":((i.16)*((#ra3d)%15))
pd 'xlabel ',yeal
pd 'type surface'
pd 'backcolor black'
pd 'axiscolor white'
pd 'labelcolor white'
pd 'bandcolor |.bgclr'
pd 'viewpoint ',":(vpox,vpoy,vpoz)
pd ni3d
pd 'new'
pd 'keyfont arial 4'
pd 'titlecolor white'
pd 'title Temperature'
pd 'yticpos ',monx
pd 'ylabel ',monl
pd 'xticpos ',":((i.16)*((#te3d)%15))
pd 'xlabel ',yeal
pd 'type surface'
pd 'backcolor black'
pd 'axiscolor white'
pd 'labelcolor white'
pd 'viewpoint ',":(vpox,vpoy,vpoz)
pd te3d
CANVAS_DEFSIZE_jwplot_ =: 600 1200
pd 'show'
In [ ]: