Projet:
Récupérer des infos généré par CW Skimmer par exemple et en faire des courbes.
Voici le script version 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
#!/usr/bin/python import sys import datetime, time import numpy as np from scipy.interpolate import spline import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt from itertools import groupby import matplotlib.dates as mdates from optparse import OptionParser import pandas as pd def Cwplot( fQRZ,finputfile,foutputfile,timeto,comment ): if timeto == 0: timeto=86400 with open(finputfile) as f: data = f.read().splitlines() x=[] y=[] for row in data: if fQRZ in row: if (((datetime.datetime.utcnow() - datetime.datetime.strptime(row.split(' ')[0], '%d/%m/%Y %H:%M')).total_seconds()) <= timeto): x.append(float(datetime.datetime.strptime(row.split(' ')[0], '%d/%m/%Y %H:%M').strftime('%s'))) y.append(float(row.split(' ')[3].split(' ')[0])) x_sm = np.array(x) y_sm = np.array(y) x_smooth = np.linspace(x_sm.min(), x_sm.max(), 100) y_smooth = spline(x, y, x_smooth) for index, item in enumerate(x): if 0 <= int(index + 1) < len(x): if ((x[int(index + 1)] - x[index]) > 50000): for indexb, itemb in enumerate(x_smooth): if((itemb > x[index]) and (itemb < x[int(index + 1)])): y_smooth[indexb]=0 c_reg = np.polyfit(x_smooth, y_smooth, 20) y_reg=np.polyval(c_reg,x_smooth) xdate=[] for row in x_smooth: xdate.append(datetime.datetime.fromtimestamp(row)) xdatev=[] for row in x: xdatev.append(datetime.datetime.fromtimestamp(row)) fig = plt.figure(figsize=(8.49, 6.09), dpi=100) fig.subplots_adjust(top=0.90,bottom=0.18) #bottom=0.9, left=0.09, right=0.10) ax = fig.add_subplot(111) ax.set_title(fQRZ + " " + str(comment) + " updated @ " + datetime.datetime.utcnow().strftime('%d/%m/%Y %H:%M') ) ax.set_xlabel('Date and Time (GMT)') ax.set_ylabel('SNR (dB)') ax.plot(xdate,y_smooth, c='r', label='measures') ax.plot(xdatev, y, 'o', label='points') ax.plot(xdate,y_reg, c='b', label='regression') if ((min(float(s) for s in y_smooth)) < 0): ax.set_ylim([0,y_smooth.max()]) for item in ([ax.xaxis.label, ax.yaxis.label] + ax.get_xticklabels() + ax.get_yticklabels()): item.set_fontsize(8) ax.title.set_fontsize(14) labels = ax.get_xticklabels() plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y %H:%M')) plt.setp(labels, rotation=30, fontsize=8) ax.legend(loc='lower left', shadow=True, fontsize=8) fig.savefig(foutputfile, dpi=100,format='PNG', bits=2) # save the figure to file plt.close(fig) # close the figure parser = OptionParser() parser.remove_option("-h") parser.add_option("-v", "--help", action="help") parser.add_option("-q", "--qrz", dest="qrz", help ="QRZ") parser.add_option("-o", "--output", dest="out", help ="output folder (write / at the end)") parser.add_option("-i", "--input", dest="inp", help ="log file input") parser.add_option("-s", "--seconds", dest="seconds", help ="number of days") parser.add_option("-m", "--minutes", dest="minutes", help ="number of days") parser.add_option("-h", "--hours", dest="hours", help ="number of hours") parser.add_option("-d", "--days", dest="days", help ="number of days") parser.add_option("-x", "--say", dest="say", help ="show informations") parser.add_option("-c", "--comment", dest="com", help ="show informations") (options, args) = parser.parse_args() vartime = int(0) if options.seconds is not None: vartime = vartime + int(options.seconds) if options.minutes is not None: vartime = vartime + int(options.minutes) * 60 if options.hours is not None: vartime = vartime + int(options.hours) * 60 * 60 if options.days is not None: vartime = vartime + int(options.days) * 24 * 60 * 60 if options.inp is not None and options.out is not None : if options.qrz is not None: if options.out.endswith('/'): options.out = options.out + options.qrz + '.png' if options.out.endswith('png'): Cwplot(options.qrz, options.inp, options.out,vartime,options.com) else: if options.out.endswith('/'): with open(options.inp) as f: data = f.read().splitlines() listeQRZF=[] listeQRZ=[] for row in data: listeQRZF.append(row.split(' ')[2]) listeQRZ=list(set(listeQRZF)) for row in listeQRZ: if options.say is not None: print row + " " + str(listeQRZF.count(row)) print 'duration ' + str(vartime) + ' ' +str(type(vartime)) if listeQRZF.count(row) >= 10: Cwplot( row,options.inp, options.out+row+".png",vartime, "") |