Skip to content

Commit 6e1faa1

Browse files
committed
heatmap: time ticks from pksato
1 parent 7e94d7d commit 6e1faa1

1 file changed

Lines changed: 48 additions & 5 deletions

File tree

‎heatmap/heatmap.py‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
help='Input CSV file. (may be a .csv.gz)')
2121
parser.add_argument('output_path', metavar='OUTPUT', type=str,
2222
help='Output image. (various extensions supported)')
23-
parser.add_argument('--offset', dest='offset_freq', default=0,
23+
parser.add_argument('--offset', dest='offset_freq', default=None,
2424
help='Shift the entire frequency range, for up/down converters.')
25+
parser.add_argument('--ytick', dest='time_tick', default=None,
26+
help='Place ticks along the Y axis every N seconds.')
2527
slicegroup = parser.add_argument_group('Slicing',
2628
'Efficiently render a portion of the data. (optional)')
2729
slicegroup.add_argument('--low', dest='low_freq', default=None,
@@ -77,6 +79,30 @@ def freq_parse(s):
7779
s = s[:-1]
7880
return float(s) * suffix
7981

82+
def freq_parse(s):
83+
suffix = 1
84+
if s.lower().endswith('k'):
85+
suffix = 1e3
86+
if s.lower().endswith('m'):
87+
suffix = 1e6
88+
if s.lower().endswith('g'):
89+
suffix = 1e9
90+
if suffix != 1:
91+
s = s[:-1]
92+
return float(s) * suffix
93+
94+
def duration_parse(s):
95+
suffix = 1
96+
if s.lower().endswith('s'):
97+
suffix = 1
98+
if s.lower().endswith('m'):
99+
suffix = 60
100+
if s.lower().endswith('h'):
101+
suffix = 60 * 60
102+
if suffix != 1 or s.lower().endswith('s'):
103+
s = s[:-1]
104+
return float(s) * suffix
105+
80106
def gzip_wrap(path):
81107
"hides silly CRC errors"
82108
iterator = gzip.open(path, 'rb')
@@ -100,6 +126,10 @@ def gzip_wrap(path):
100126
args.high_freq = freq_parse(args.high_freq)
101127
if args.offset_freq is not None:
102128
args.offset_freq = freq_parse(args.offset_freq)
129+
else:
130+
args.offset_freq = 0
131+
if args.time_tick is not None:
132+
args.time_tick = duration_parse(args.time_tick)
103133

104134
print("loading")
105135

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

253+
if args.time_tick:
254+
label_last = start
255+
for y,t in enumerate(times):
256+
label_time = parse_time(t)
257+
label_diff = label_time - label_last
258+
if label_diff.seconds >= args.time_tick:
259+
draw.text((2, y), '%s' % t.split(' ')[-1], font=font, fill='white')
260+
label_last = label_time
261+
262+
223263
duration = stop - start
224264
duration = duration.days * 24*60*60 + duration.seconds + 30
225265
pixel_height = duration / len(times)
226266
hours = int(duration / 3600)
227267
minutes = int((duration - 3600*hours) / 60)
228-
draw.text((2, img.size[1] - 45), 'Duration: %i:%02i' % (hours, minutes), font=font, fill='white')
229-
draw.text((2, img.size[1] - 35), 'Range: %.2fMHz - %.2fMHz' % (min(freqs)/1e6, max(freqs)/1e6), font=font, fill='white')
230-
draw.text((2, img.size[1] - 25), 'Pixel: %.2fHz x %is' % (pixel_width, int(round(pixel_height))), font=font, fill='white')
231-
draw.text((2, img.size[1] - 15), 'Started: {0}'.format(start), font=font, fill='white')
268+
margin = 2
269+
if args.time_tick:
270+
margin = 60
271+
draw.text((margin, img.size[1] - 45), 'Duration: %i:%02i' % (hours, minutes), font=font, fill='white')
272+
draw.text((margin, img.size[1] - 35), 'Range: %.2fMHz - %.2fMHz' % (min(freqs)/1e6, max(freqs)/1e6), font=font, fill='white')
273+
draw.text((margin, img.size[1] - 25), 'Pixel: %.2fHz x %is' % (pixel_width, int(round(pixel_height))), font=font, fill='white')
274+
draw.text((margin, img.size[1] - 15), 'Started: {0}'.format(start), font=font, fill='white')
232275
# bin size
233276

234277
print("saving")

0 commit comments

Comments
 (0)