-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuoysongs.py
61 lines (53 loc) · 2.38 KB
/
buoysongs.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
61
'''
Created on Jun 2, 2013
@author: egg
'''
import buoyparsers
from criterionfunctions import get_nearness_function, get_num_missing_values_function, \
create_combined_criterion, record_length, longer_than, reject_prime_meridian_crossers
from buoyparsers import missing_values
from renderers.visual_renderers import LineGraphRenderer, CSVRenderer
from datetime import datetime
from renderers.midirenderers import MidiCCRenderer
def get_quick_buoys():
# Note: Files must be downloaded manually; see http://www.aoml.noaa.gov/envids/gld/FtpInterpolatedInstructions.php
datafile = '/Users/egg/Temp/oceancurrents/globaldrifter/buoydata_5001_sep12.dat'
# datafile = 'test_resources/buoydata.dat'
parser = buoyparsers.GlobalDrifterParser()
my_nearness_function = get_nearness_function(-33, 25) #big cluster between cuba and africa
my_missing_vals_function = get_num_missing_values_function(missing_values)
combined_criterion_function = create_combined_criterion((my_missing_vals_function,
reject_prime_meridian_crossers,
longer_than(2500),
my_nearness_function))
# Fast-running sample data
# doc = parser.parse(datafile,
# num_buoys=3,
# criterion_function=combined_criterion_function,
# maxlines=100000)
# Real data
doc = parser.parse(datafile,
num_buoys=6,
criterion_function=combined_criterion_function,
start=datetime(2011, 01, 01), end=datetime(2013, 01, 01))
doc.combine_all_ranges()
doc.trim()
return doc
def graph(doc, keys=None):
renderer = LineGraphRenderer()
plot = renderer.render(doc, showplot=True, outfile='/tmp/plot.svg', keys=keys, render_separate=True)
return plot
def csound(doc):
pass
def csv(doc):
csvrenderer = CSVRenderer()
result = csvrenderer.render(doc, print_to_screen=False, filename='/tmp/out.txt')
return result
def midi(doc):
renderer = MidiCCRenderer()
sine_to_midi_map = {'LAT': 74, 'LON': 75, 'TEMP': 76} # sine to cc#
transformed_doc = doc.transform(sine_to_midi_map, renderer)
renderer.render(transformed_doc, output_file='output.mid')
doc = get_quick_buoys()
graph(doc)
midi(doc)