Skip to content

Commit

Permalink
heatmap: time ticks from pksato
Browse files Browse the repository at this point in the history
  • Loading branch information
keenerd committed Aug 4, 2014
1 parent 7e94d7d commit 6e1faa1
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions heatmap/heatmap.py
Expand Up @@ -20,8 +20,10 @@
help='Input CSV file. (may be a .csv.gz)') help='Input CSV file. (may be a .csv.gz)')
parser.add_argument('output_path', metavar='OUTPUT', type=str, parser.add_argument('output_path', metavar='OUTPUT', type=str,
help='Output image. (various extensions supported)') help='Output image. (various extensions supported)')
parser.add_argument('--offset', dest='offset_freq', default=0, parser.add_argument('--offset', dest='offset_freq', default=None,
help='Shift the entire frequency range, for up/down converters.') help='Shift the entire frequency range, for up/down converters.')
parser.add_argument('--ytick', dest='time_tick', default=None,
help='Place ticks along the Y axis every N seconds.')
slicegroup = parser.add_argument_group('Slicing', slicegroup = parser.add_argument_group('Slicing',
'Efficiently render a portion of the data. (optional)') 'Efficiently render a portion of the data. (optional)')
slicegroup.add_argument('--low', dest='low_freq', default=None, slicegroup.add_argument('--low', dest='low_freq', default=None,
Expand Down Expand Up @@ -77,6 +79,30 @@ def freq_parse(s):
s = s[:-1] s = s[:-1]
return float(s) * suffix return float(s) * suffix


def freq_parse(s):
suffix = 1
if s.lower().endswith('k'):
suffix = 1e3
if s.lower().endswith('m'):
suffix = 1e6
if s.lower().endswith('g'):
suffix = 1e9
if suffix != 1:
s = s[:-1]
return float(s) * suffix

def duration_parse(s):
suffix = 1
if s.lower().endswith('s'):
suffix = 1
if s.lower().endswith('m'):
suffix = 60
if s.lower().endswith('h'):
suffix = 60 * 60
if suffix != 1 or s.lower().endswith('s'):
s = s[:-1]
return float(s) * suffix

def gzip_wrap(path): def gzip_wrap(path):
"hides silly CRC errors" "hides silly CRC errors"
iterator = gzip.open(path, 'rb') iterator = gzip.open(path, 'rb')
Expand All @@ -100,6 +126,10 @@ def gzip_wrap(path):
args.high_freq = freq_parse(args.high_freq) args.high_freq = freq_parse(args.high_freq)
if args.offset_freq is not None: if args.offset_freq is not None:
args.offset_freq = freq_parse(args.offset_freq) args.offset_freq = freq_parse(args.offset_freq)
else:
args.offset_freq = 0
if args.time_tick is not None:
args.time_tick = duration_parse(args.time_tick)


print("loading") print("loading")


Expand Down Expand Up @@ -220,15 +250,28 @@ def rgb3(z):
s = '%.3fMHz' % (label/1000000.0) s = '%.3fMHz' % (label/1000000.0)
draw.text((x, y), s, font=font, fill='white') draw.text((x, y), s, font=font, fill='white')


if args.time_tick:
label_last = start
for y,t in enumerate(times):
label_time = parse_time(t)
label_diff = label_time - label_last
if label_diff.seconds >= args.time_tick:
draw.text((2, y), '%s' % t.split(' ')[-1], font=font, fill='white')
label_last = label_time


duration = stop - start duration = stop - start
duration = duration.days * 24*60*60 + duration.seconds + 30 duration = duration.days * 24*60*60 + duration.seconds + 30
pixel_height = duration / len(times) pixel_height = duration / len(times)
hours = int(duration / 3600) hours = int(duration / 3600)
minutes = int((duration - 3600*hours) / 60) minutes = int((duration - 3600*hours) / 60)
draw.text((2, img.size[1] - 45), 'Duration: %i:%02i' % (hours, minutes), font=font, fill='white') margin = 2
draw.text((2, img.size[1] - 35), 'Range: %.2fMHz - %.2fMHz' % (min(freqs)/1e6, max(freqs)/1e6), font=font, fill='white') if args.time_tick:
draw.text((2, img.size[1] - 25), 'Pixel: %.2fHz x %is' % (pixel_width, int(round(pixel_height))), font=font, fill='white') margin = 60
draw.text((2, img.size[1] - 15), 'Started: {0}'.format(start), font=font, fill='white') draw.text((margin, img.size[1] - 45), 'Duration: %i:%02i' % (hours, minutes), font=font, fill='white')
draw.text((margin, img.size[1] - 35), 'Range: %.2fMHz - %.2fMHz' % (min(freqs)/1e6, max(freqs)/1e6), font=font, fill='white')
draw.text((margin, img.size[1] - 25), 'Pixel: %.2fHz x %is' % (pixel_width, int(round(pixel_height))), font=font, fill='white')
draw.text((margin, img.size[1] - 15), 'Started: {0}'.format(start), font=font, fill='white')
# bin size # bin size


print("saving") print("saving")
Expand Down

0 comments on commit 6e1faa1

Please sign in to comment.