Saturday, January 14, 2012

Unscaled (constrained) 3D point plots using gnuplot

set size square only works for 2D, for 3D plots use set view equal:
set view equal
splot "points.dat" with points pt 7 ps 0.5

Saturday, October 22, 2011

This is a small script to visualize Medtronic / Minimed CareLink blood glucose measurement data that has been exported to a CSV file to produce a nice PDF graph with gnuplot, like this: Plot
#!/usr/bin/env python

import sys
import csv
import datetime
import subprocess

# number of days to plot, going back from today
num_days = 7

if len(sys.argv) != 2:
    print 'syntax: %s input.csv' % sys.argv[0]

start_date = - datetime.timedelta(num_days)

out_files = {}
averages = {}

def filename(y, m, d):
    return '%02d-%02d-%02d.dat' % (y, m, d)

with open(sys.argv[1]) as f:
    # skip 11 header lines
    for i in range(11):

    for row in csv.DictReader(f):
        (d, m, y) = (int(x) for x in row['Date'].split('/'))
        date = + 2000, m, d)
        if date >= start_date:
            # Taking the raw value is more precise
            #sg = row['Sensor Glucose (mmol/L)']
            if row['Raw-Type'] == 'GlucoseSensorData':
                raw = row['Raw-Values']
                assert raw.startswith('AMOUNT=')
                sg = int(raw[raw.find('=') + 1:raw.find(',')]) / 18.

                if (y, m, d) in out_files:
                    out = out_files[(y, m, d)]
                    out = out_files[(y, m, d)] = open(filename(y, m, d), 'wt')

                time = row['Time']
                (hours, minutes) = int(time[:2]), int(time[3:5])
                minutes -= minutes % 5 # to make windows overlap
                if (hours, minutes) in averages:
                    averages[(hours, minutes)][0] += sg
                    averages[(hours, minutes)][1] += 1
                    averages[(hours, minutes)] = [sg, 1]

                print >> out, row['Time'], sg

# close output files
for f in out_files.values():

# write averages
average_file = 'average.dat'
avg, avg_n = 0., 0
with open(average_file, 'wt') as f:
    for ((hours, minutes), (sigma, n)) in sorted(averages.items()):
        val = float(sigma) / n
        avg += val
        avg_n += 1
        print >> f, "%02d:%02d:00 %f" % (hours, minutes, val)
avg /= avg_n

# create gnuplot script
plot_file = 'plot.gnuplot'
eps_file = 'plot.eps'
with open(plot_file, 'wt') as f:
    plots = ', '.join('"%s" using 1:2 linewidth 2 title "%02d/%02d/%02d"' % (filename(y, m, d), d, m, y) for (y, m, d) in sorted(out_files.keys()))
    print >> f, '''
set terminal postscript eps color solid
set output "%s"
set style data lines
set title "Sensor glucose (mmol/L)"
set xdata time
set timefmt "%%H:%%M:%%S"
set format x "%%H:%%M"
set yrange [2:12]
set ytics 1
plot 4 notitle linewidth 3 linecolor rgb "black", 9 notitle linewidth 3 linecolor rgb "black", %f notitle linewidth 5 linecolor rgb "red", "%s" using 1:2 title "average" linewidth 5 linecolor rgb "red",''' % (eps_file, avg, average_file), plots

# Run gnuplot, and convert eps to pdf
subprocess.check_call('gnuplot ' + plot_file, shell=True)'epstopdf ' + eps_file, shell=True)

Sunday, September 25, 2011

rtorrent torrent scheduling for non-peak period downloading

In order to schedule rtorrent to download only during certain time intervals, e.g. non-peak periods of some ISP, you don't need a cron job. Instead you can use the built-in scheduling functionality. To only download between 2 am and 8 am every night, add to your .rtorrent.rc file:
schedule = throttle_start,02:00:00,24:00:00,"d.multicall=,d.start=" schedule = throttle_stop,08:00:00,24:00:00,"d.multicall=,d.stop="

Sunday, May 29, 2011

Convert ogv to mkv for WDTV

In order to view videos on the WDTV, it's sometimes necessary to convert the format first.

Get an ffmpeg version that supports x264: HowTo.

Then run something like this:
for i in *.ogv; do ffmpeg -i $i -y -vcodec libx264 -profile baseline -preset slow -crf 20 -threads 0 -acodec libfaac `basename $i .ogv`.mkv; done

Xfce4 (Xubuntu) and color profiles

Similar to gnome-color-manager for Gnome, for Xfce one can use something almost as simple to load a custom ICC color profile: xcalib. Just place an appropriate entry in the "Session and Startup" preferences and everything's fine.

Wednesday, May 25, 2011

Connection problems with Intel Centrino Advanced-N 6230 and Linksys WRT54G router

Using my new Dell XPS 15 (LX502) with an Intel Centrino Advanced-N 6230 wireless card I couldn't connect to my WRT54G router running the Tomato firmware anymore. Neither WPA nor WPA2 worked, not even WEP. Turns out that I had "Afterburner" mode enabled, which seems to cause problems, as also described here. After disabling this feature in the Tomato interface, everything worked nicely again.

Tuesday, March 15, 2011

Disable search indexing service in Ubuntu

sudo apt-get autoremove --purge tracker