Parsing and Plotting Data

From CCRMA Wiki
Revision as of 15:14, 27 August 2013 by Rob (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

oscrecorder:

ruby oscrecorder.rb <port-number> > <target-directory/filename>
e.g. ruby oscrecorder.rb 7000 > yml/testOutput.yml

oscparser:

ruby oscparser_flat.rb <output-file-no-extension> < <input-file>
e.g. ruby oscparser_flat.rb testOutput/d3Wings < ./yml/wingTest.yml


Sample data from Supercollider OSCFunc.trace(true);

OSC Message Received:
	time: 1376508508.8226
	address: a NetAddr(127.0.0.1, 54862)
	recvPort: 57120
	msg: [ /player, 256, -11802.803710938, 11226.436523438, -3328.2470703125, 0, 10523, -5440, 0, 0, 0, 0, 0 ]

D3js.org

Enable local webserver (localhost/~rob):
http://reviews.cnet.com/8301-13727_7-57481978-263/how-to-enable-web-sharing-in-os-x-mountain-lion/


GNUPlot:

Home: 
http://www.gnuplot.info/

Source: 
http://sourceforge.net/projects/gnuplot/files/

CSV to Gnuplot:
http://www.cs.waikato.ac.nz/~fracpete/programming/csv2gnuplot/

3D plotting:
http://www.physics.orst.edu/~rubin/nacphy/DATAVIS/gnuplot.html
 
Grid Lines:

http://stackoverflow.com/questions/16240387/grid-in-xzplane
 
Sample:
  
cd ~/data/dissertation/gnuplots/
gnuplot
plot "player_output.csv" using 1:2 title 'time', "player_output.csv" using 1:3 title 'x'

 
Working 3D XYZ Example:

splot "/Users/rob/Sites/d3/udkoscPlayerData/d3Wings.tsv" u 4:5:6 with lines lw 2 lt rgb "black"



Parsing YAML output files into csv:

ruby oscparser.rb output_filename.csv false < ./yml/pawn_0_spiral_2.yml

oscparser.rb

require 'rubygems'
require 'osc-ruby'
require 'yaml'

wait = ARGV[1]			# wait boolean toggles whether the   padded time at the beginning of recorded yml osc action is used
m_time = 0
start_time = 0
final_output = ""
output_filename = ARGV[0]

@messages = YAML.load($stdin)
@start = Time.now

@messages.each_with_index do |m, index|

  if index == 0
    start_time = m[:time]
  end

  if wait=='true'
    m_time = m[:time]
  else
    m_time = m[:time] - start_time
  end

  dt = (@start + m_time) - Time.now
  sleep(dt) if dt > 0
  message = OSC::OSCPacket.messages_from_network(m[:message]).first  
  output = m_time.to_s + ", " + message.address

  @a = message.to_a
  @a.each_with_index do |arg, index|
    #p arg
	output = output + ", " + arg.to_s
  end
  final_output = final_output + "" + output + "\n"
end

File.open(output_filename, 'w') { |file| 
    file.write(final_output) 
}

Import CSV into Processing:

//for importing csv files into a 2d array
//by che-wei wang

String lines[] = loadStrings("list.csv");
String [][] csv;
int csvWidth=0;

//calculate max width of csv file
for (int i=0; i < lines.length; i++) {
  String [] chars=split(lines[i],',');
  if (chars.length>csvWidth){
    csvWidth=chars.length;
  }
}

//create csv array based on # of rows and columns in csv file
csv = new String [lines.length][csvWidth];

//parse values into 2d array
for (int i=0; i < lines.length; i++) {
  String [] temp = new String [lines.length];
  temp= split(lines[i], ',');
  for (int j=0; j < temp.length; j++){
   csv[i][j]=temp[j];
  }
}

//test
println(csv[2][2]); 


Processing Library:

http://www.gicentre.org/utils/#download


Simple Processing Graph:

http://www.learningprocessing.com/examples/chapter-13/example-random-graph/

// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example: a graph of random numbers

float[] vals;

void setup() {
  size(400,200);
  smooth();
  // An array of random values
  vals = new float[width];
  for (int i = 0; i < vals.length; i++) {
    vals[i] = random(height);
  }
}
 

void draw() {

  background(255);
  // Draw lines connecting all points
  for (int i = 0; i < vals.length-1; i++) {
    stroke(0);
    strokeWeight(2);
    line(i,vals[i],i+1,vals[i+1]);
  }
  
  // Slide everything down in the array
  for (int i = 0; i < vals.length-1; i++) {
    vals[i] = vals[i+1]; 
  }
  // Add a new random value
  vals[vals.length-1] = random(height); 

}


Pyxplot:

http://pyxplot.org.uk/examples/index.html


Processing Animated Graph example:

http://answers.oreilly.com/topic/1630-create-animated-graph-visualizations-with-processing/