-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubject_utils.py
More file actions
67 lines (49 loc) · 1.55 KB
/
subject_utils.py
File metadata and controls
67 lines (49 loc) · 1.55 KB
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
61
62
63
64
65
66
67
from strauss.sonification import Sonification
from strauss.sources import Objects
from strauss.score import Score
from strauss.generator import Synthesizer
import numpy as np
import requests
import json
# specify audio system (e.g. mono, stereo, 5.1, ...)
system = "stereo"
# length of the sonification in s
length = 25.
# base notes for the sonification
notes = [["A2"]]
# set up synth and turn on LP filter
generator = Synthesizer()
generator.load_preset('pitch_mapper')
score = Score(notes, length)
def sonify(data):
# set up source
sources = Objects(data.keys())
sources.fromdict(data)
sources.apply_mapping_functions()
return Sonification(score, sources, generator, system)
def normalise_light_curve(days, fluxes):
def normalise_day(d):
return d / days.max()
normalised_days = map(normalise_day, days)
x = np.fromiter(normalised_days, float)
flux_min = fluxes.min()
flux_max = fluxes.max()
flux_range = flux_max - flux_min
def normalise_flux(f):
return (f - flux_min) / flux_range
normalised_fluxes = map(normalise_flux, fluxes)
y = np.fromiter(normalised_fluxes, float)
return x, y
def light_curve_url(subject):
json_locations = [
location.get('text/plain')
for location in subject.locations
if location.get('text/plain')
]
return json_locations[0]
def fetch_light_curve(url):
json_data = requests.get(url).text
response = json.loads(json_data)
days = np.array(response['x'])
fluxes = np.array(response['y'])
return days, fluxes