This repository has been archived by the owner on Jun 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sonification.py
60 lines (48 loc) · 1.94 KB
/
sonification.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
49
50
51
52
53
54
55
56
57
58
59
60
import pandas as pd
import urllib.request
import sonify
import numpy as np
import influxModels
import apiCalls
import pandas as pd
# define the columns to pull for different types of data
# Temp, pH, Cond, DOpct, Turb, Sal
WATER_VALUES = [1,2,4,5,8,10]
# AirTemp, Rain, MaxWindSpeed, VaporPressure, BaroPressure
WEATHER_VALUES = [18,12,17,19,20]
# define sounds for different types of data
# Temp, pH, Cond, DOpct, Turb, Sal
WEATHER_SOUNDS = ['orchestral harp','choir aahs','church organ','violin','cello']
# AirTemp, Rain, MaxWindSpeed, VaporPressure, BaroPressure
WATER_SOUNDS = ['orchestral harp','choir aahs','church organ','viola','violin','cello']
def SaveFile(station):
#reading the data
data = None
try:
#modify the line below
data = influxModels.getStationDelta(station, 2)
data.replace(0.,np.nan, inplace=True)
# set local params
if station == "Odin":
# odin - weather
cols = WEATHER_VALUES
sounds = WEATHER_SOUNDS
else:
# ada - choate pond
cols = WATER_VALUES
sounds = WATER_SOUNDS
# pull sensors
sensors = apiCalls.getSensors()
input_data = []
for i, col in enumerate(cols):
# pull column from dataframe
col_name = 'sensors.' + sensors.loc[sensors['SensorID'] == col, 'SensorName'].item()
col_data = data[col_name]
input_data.append([sounds[i]] + list(zip(range(0, len(col_data)), col_data)))
# play!
sonify.play_midi_from_data(input_data, track_type='multiple', key = 'd_sharp_major', file_name='midi/' + station.lower() + '.mid')
return(True)
except (urllib.error.URLError, KeyError) as e:
return "We're sorry, can't load new data right now. Please enjoy this sonification of some of our previous data."
except TypeError as e:
return "Sorry, we can't find any data for that station."