Skip to content

Commit

Permalink
v7.00
Browse files Browse the repository at this point in the history
  • Loading branch information
llinkz committed Jun 26, 2021
1 parent 847a4ba commit 96d8cde
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Install python 3 and python-pip using your package manager

Install GNU octave

Install git, patch, gcc, base-devel, ttf-dejavu, gcc-fortran, tk, portaudio, xdg-utils, epdfview
Install git, patch, gcc, base-devel, ttf-dejavu, gcc-fortran, tk, portaudio, xdg-utils, epdfview, fltk

`git clone --recursive https://github.com/llinkz/directTDoA`

`cd directTDoA`

`./setup.sh` (this script will install python modules, compile the necessary .oct file and apply some files patchs)

#### IMPORTANT: The octave files compilation process takes a lot of time, be patient, ignore warnings and don't stop the script
`./directTDoA.py`

> NOTE: on some distros you may need to install liboctave-dev
Expand Down
67 changes: 34 additions & 33 deletions microkiwi_patch.diff
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
--- microwiki_waterfall.py 2021-01-02 00:19:15.126533594 +0000
+++ microwiki_waterfall.py 2021-01-02 00:19:15.116533784 +0000
--- microkiwi_waterfall.py 2021-06-26 07:48:51.769275069 +0200
+++ microkiwi_waterfall.py 2021-06-26 07:48:51.769275069 +0200
@@ -1,30 +1,61 @@
-import numpy as np
-import struct
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+""" IS0KYB microkiwi_waterfall script, modified to use python instead of jupyther notebook """
+""" Here is the IS0KYB microkiwi_waterfall script, modified to use python instead of jupyther notebook """
+
+# python 2/3 compatibility
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import

-import array
-import logging
+import numpy as np
import socket
import struct
import time
+import matplotlib.pyplot as plt
+from matplotlib.colors import LinearSegmentedColormap
+import io
from datetime import datetime
-
+from optparse import OptionParser
+import numpy as np
+import matplotlib.pyplot as plt
+from matplotlib.colors import LinearSegmentedColormap
+from mpl_toolkits.axes_grid1 import make_axes_locatable
from kiwi import wsclient
-
import mod_pywebsocket.common
from mod_pywebsocket.stream import Stream
from mod_pywebsocket.stream import StreamOptions

-from optparse import OptionParser
+PROCESSFAILED = False
-
from optparse import OptionParser
+from mpl_toolkits.axes_grid1 import make_axes_locatable
+
+processfailed = False
+
+CDICT = {
+cdict1 = {
+ 'red': ((0.0, 0.0, 0.0),
+ (0.2, 0.0, 0.0),
+ (0.4, 1.0, 1.0),
Expand All @@ -57,8 +57,8 @@
+ (1.0, 1.0, 1.0)),
+}
+
+CMAP = LinearSegmentedColormap('SAColorMap', CDICT, 1024)

+cmap = LinearSegmentedColormap('SAColorMap', cdict1, 1024)
parser = OptionParser()
-parser.add_option("-f", "--file", dest="filename", type=str,
- help="write waterfall data to binary FILE", metavar="FILE")
Expand All @@ -72,10 +72,10 @@
parser.add_option("-z", "--zoom", type=int,
help="zoom factor", dest="zoom", default=0)
parser.add_option("-o", "--offset", type=int,
@@ -32,126 +63,121 @@
@@ -32,126 +63,124 @@
parser.add_option("-v", "--verbose", type=int,
help="whether to print progress and debug info", dest="verbosity", default=0)

-
options = vars(parser.parse_args()[0])
-
Expand Down Expand Up @@ -131,18 +131,18 @@
+now = b'(datetime.now()'
header = [center_freq, span, now]
header_bin = struct.pack("II26s", *header)

-print "Trying to contact server..."
try:
mysocket = socket.socket()
mysocket.connect((host, port))
except:
- print "Failed to connect"
- exit()
- exit()
-print "Socket open..."
+ print("Failed to connect")
+ exit()

uri = '/%d/%s' % (int(time.time()), 'W/F')
handshake = wsclient.ClientHandshakeProcessor(mysocket, host, port)
handshake.handshake(uri)
Expand All @@ -157,7 +157,7 @@
mystream = Stream(request, stream_option)
-print "Data stream active..."
-

# send a sequence of messages to the server, hardcoded for now
# max wf speed, no compression
-msg_list = ['SET auth t=kiwi p=', 'SET zoom=%d start=%d'%(zoom,offset),\
Expand All @@ -183,10 +183,10 @@
+ try:
+ tmp = mystream.receive_message()
+ except:
+ PROCESSFAILED = True
+ processfailed = True
+ break
+ if b'W/F' in tmp: # this is one waterfall line
+ tmp = tmp[16:].replace(b"7", b"\xa0") # remove some header from each msg
+ tmp = tmp[16:] # remove some header from each msg
+ print("received sample")
if options['verbosity']:
- print time,
Expand All @@ -196,7 +196,8 @@
- binary_wf_list.append(tmp) # append binary data to be saved to file
- #wf_data[time, :] = spectrum-255 # mirror dBs
+ print(time),
+ spectrum = np.array(struct.unpack('%dB' % len(tmp), tmp)) # convert binary data to uint8
+ spectrum = np.array(struct.unpack('%dB' % len(tmp), tmp)) # convert from binary data to uint8
+ # spectrum = np.ndarray(len(tmp), dtype='B', buffer=tmp) # convert from binary data to uint8
+ binary_wf_list.append(tmp) # append binary data to be saved to file
+ # wf_data[time, :] = spectrum-255 # mirror dBs
wf_data[time, :] = spectrum
Expand All @@ -207,7 +208,7 @@
- #print tmp
+ else: # this is chatter between client and server
pass

try:
mystream.close_connection(mod_pywebsocket.common.STATUS_GOING_AWAY)
mysocket.close()
Expand All @@ -217,17 +218,19 @@
-
-avg_wf = np.mean(wf_data, axis=0) # average over time
+ print("exception: %s" % e)

+avg_wf = np.mean(wf_data, axis=0) # average over time
p95 = np.percentile(avg_wf, 95)
median = np.percentile(avg_wf, 50)
+maxsig = np.max(wf_data)
+minsig = np.min(wf_data)

-print "Average SNR computation..."
-print "Waterfall with %d bins: median= %f dB, p95= %f dB - SNR= %f rbw= %f kHz" % (bins, median, p95,p95-median, rbw)
-
-
+# print "Waterfall with %d bins: median= %f dB, p95= %f dB - SNR= %f rbw= %f kHz" % (bins, median, p95,p95-median, rbw)
+print("SNR: %i dB [median: %i dB, p95: %i dB, high: %i dBm, low: %i dBm]" % (p95 - median, median, p95, maxsig, minsig))

-if filename:
- print "Saving binary data to file..."
- with open(filename, "wb") as fd:
Expand All @@ -239,9 +242,9 @@
+fd.write(header_bin) # write the header info at the top
+for line in binary_wf_list:
+ fd.write(line)
+
+fd.seek(0)
+buff = fd.read()
+
+header_len = 8 + 26 # 2 unsigned int for center_freq and span: 8 bytes PLUS 26 bytes for datetime
+length = len(buff[header_len:])
+n_t = length // bins
Expand All @@ -253,8 +256,8 @@
+plt.yticks(np.arange(0, 0, step=1))
+plt.xlabel('MHz')
+plt.xticks(np.linspace(0, bins, 31), np.linspace(0, 30, num=31, endpoint=True, dtype=int))
+plt.pcolormesh(waterfall_array[:, 1:], cmap=CMAP, vmin=minsig+30, vmax=maxsig+30)
+if PROCESSFAILED:
+plt.pcolormesh(waterfall_array[:, 1:], cmap=cmap, vmin=minsig+30, vmax=maxsig+30)
+if processfailed:
+ plt.title("Sorry, measurement failed on this Kiwi, no slot available, try later")
+else:
+ plt.title("HF waterfall @ " + str(host) + " - [SNR: %i dB" % (p95 - median) + "]")
Expand All @@ -264,5 +267,3 @@
+clb.ax.set_title('dBm')
+plt.tight_layout()
+plt.show()
+print("SNR: %i dB [median: %i dB, p95: %i dB, high: %i dBm, low: %i dBm]" % (p95 - median, median, p95, maxsig, minsig))
+
20 changes: 16 additions & 4 deletions plot_map_patch.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
--- tdoa_plot_map.m 2020-02-03 21:02:16.088313158 +0000
+++ tdoa_plot_map.m 2020-02-02 00:06:29.207199473 +0000
--- tdoa_plot_map.m 2021-06-26 08:55:29.072579377 +0200
+++ tdoa_plot_map.m 2021-03-23 22:54:27.067070000 +0100
@@ -38,8 +38,8 @@
if ~plot_kiwi
set(0,'defaultaxesposition', [0.05, 0.05, 0.90, 0.9])
figure(1, 'position', [100,100, 900,600])
- plot_info.titlefontsize = 10;
- plot_info.labelfontsize = 7.5;
+ plot_info.titlefontsize = 10; # 10
+ plot_info.labelfontsize = 5; # 7.5
end

n_stn = length(input_data);
@@ -140,6 +140,7 @@
end
set(colorbar(),'XLabel', 'sqrt(\chi^2)/ndf')
Expand All @@ -16,9 +27,10 @@
+ text(0.5, 0.98, strcat(plot_info.title, mlp), ...
'fontweight', 'bold', ...
'horizontalalignment', 'center', ...
'fontsize', 15);
- 'fontsize', 15);
- print('-dpng','-S900,600', fullfile('png', sprintf('%s.png', plot_info.plotname)));
+ # print('-dpng','-S900,600', fullfile('png', sprintf('%s.png', plot_info.plotname)));
+ 'fontsize', 9); # 15
+ ## print('-dpng','-S3600,2400', fullfile('png', sprintf('%s.png', plot_info.plotname)));
print('-dpdf','-S900,600', fullfile('pdf', sprintf('%s.pdf', plot_info.plotname)));
end
if plot_info.plot_kiwi_json
Expand Down

0 comments on commit 96d8cde

Please sign in to comment.