-
Notifications
You must be signed in to change notification settings - Fork 1
/
temps.py
48 lines (39 loc) · 1.12 KB
/
temps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from pyknon.genmidi import Midi
from pyknon.music import Note, NoteSeq, Rest
dur = 1/16.0
notes = []
for octave in range(2,9):
for pitch in range(0,12):
notes.append((octave, pitch))
opacity_to_volume = {'0': 1, '250': 0.90, '500': 0.70, '750': 0.50, '1000': 0.40}
def read_obs(filename):
f = open(filename)
obs = []
for line in f:
day,hour,temp,opacity,precip = line.split(',')
obs.append((day, hour, temp, opacity, precip))
f.close()
return obs
def obs_to_note(obs):
global notes
day, hour, temp, opacity, precip = obs
# Temperature is note
index = int(temp)
if index < 7: index = 7
elif index > 90: index = 90
index -= 7
octave, pitch = notes[index]
# Sky cover is volume
volume = 0
try:
volume = opacity_to_volume[opacity]
except:
pass
return Note(pitch, octave, dur, int(volume * 120))
obs = read_obs('data/kcmh_2014_03_obs.csv')
obs_notes = NoteSeq()
for ob in obs:
obs_notes.append(obs_to_note(ob))
midi = Midi(1, tempo=90, instrument=1)
midi.seq_notes(obs_notes, track=0)
midi.write("output/temps_2014_03.mid")