Example #1
0
def executeHeatmap(cmdargs, config, scanlevel, start):
    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        csv_filename = "%s.csv" % filename
        exists = os.path.isfile(csv_filename)
        if not exists:
            showVerbose(
                config,
                "%s %s not exist%s" % (
                    tcolor.RED,
                    csv_filename,
                    tcolor.DEFAULT,
                )
            )
            continue

        params_filename = "%s.hparam" % filename
        exists = os.path.isfile(params_filename)
        if not exists:
            showVerbose(
                config,
                "%s %s not exist%s" % (
                    tcolor.RED,
                    params_filename,
                    tcolor.DEFAULT,
                )
            )
            continue

        # Check if scan exist
        img_filename = "%s_heatmap.png" % filename
        exists = os.path.isfile(img_filename)
        if exists:
            showVerbose(
                config,
                 "%sHeatmap '%s' : %shz-%shz%s" % (
                            tcolor.GREEN,
                            scanlevel['name'], commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
                            tcolor.DEFAULT
                )
            )
            continue

        print "%sHeatmap '%s' : %shz-%shz for %s gain" % (
            tcolor.DEFAULT,
            scanlevel['name'], commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
            gain,
        )

        print "CSV: %s" % csv_filename
        datas = commons.SDRDatas(csv_filename)
        for line in datas.samples:
            print len(line)

        print ""
Example #2
0
def calcFilename(scanlevel, start, gain):
    filename = "%sHz-%sHz-%07.2fdB-%sHz-%s-%s" % (
        commons.float2Hz(start, 3, True),
        commons.float2Hz(start + scanlevel['windows'], 3, True), gain,
        commons.float2Hz(scanlevel['binsize'], 3,
                         True), commons.float2Sec(scanlevel['interval']),
        commons.float2Sec(scanlevel['quitafter']))

    fullname = os.path.join(scanlevel['scandir'], filename)
    return fullname
Example #3
0
def calcFilename(scanlevel, start, gain):
    filename = "%sHz-%sHz-%07.2fdB-%sHz-%s-%s" % (
            commons.float2Hz(start, 3, True),
            commons.float2Hz(start + scanlevel['windows'], 3, True),
            gain,
            commons.float2Hz(scanlevel['binsize'], 3, True),
            commons.float2Sec(scanlevel['interval']),
            commons.float2Sec(scanlevel['quitafter'])
    )

    fullname = os.path.join(scanlevel['scandir'], filename)
    return fullname
Example #4
0
def executeHeatmap(cmdargs, config, scanlevel, start):
    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        csv_filename = "%s.csv" % filename
        exists = os.path.isfile(csv_filename)
        if not exists:
            showVerbose(
                config, "%s %s not exist%s" % (
                    tcolor.RED,
                    csv_filename,
                    tcolor.DEFAULT,
                ))
            continue

        params_filename = "%s.hparam" % filename
        exists = os.path.isfile(params_filename)
        if not exists:
            showVerbose(
                config, "%s %s not exist%s" % (
                    tcolor.RED,
                    params_filename,
                    tcolor.DEFAULT,
                ))
            continue

        # Check if scan exist
        img_filename = "%s_heatmap.png" % filename
        exists = os.path.isfile(img_filename)
        if exists:
            showVerbose(
                config, "%sHeatmap '%s' : %shz-%shz%s" %
                (tcolor.GREEN, scanlevel['name'], commons.float2Hz(start),
                 commons.float2Hz(start + scanlevel['windows']),
                 tcolor.DEFAULT))
            continue

        print "%sHeatmap '%s' : %shz-%shz for %s gain" % (
            tcolor.DEFAULT,
            scanlevel['name'],
            commons.float2Hz(start),
            commons.float2Hz(start + scanlevel['windows']),
            gain,
        )

        print "CSV: %s" % csv_filename
        datas = commons.SDRDatas(csv_filename)
        for line in datas.samples:
            print len(line)

        print ""
Example #5
0
def executeSearchStations(config, stations, scanlevel, start):

    filename = calcFilename(scanlevel, start)

    # ignore if rtl_power file not exists
    csv_filename = "%s.csv" % filename
    exists = os.path.isfile(csv_filename)
    if not exists:
        showVerbose(
            config, "%s %s not exist%s" % (
                tcolor.RED,
                csv_filename,
                tcolor.DEFAULT,
            ))
        return

    # Ignore if call summary not exist
    summary_filename = "%s.summary" % filename
    exists = os.path.isfile(summary_filename)
    if not exists:
        showVerbose(
            config, "%s %s not exist%s" % (
                tcolor.RED,
                summary_filename,
                tcolor.DEFAULT,
            ))
        return
    summaries = loadJSON(summary_filename)

    print "%sFind stations '%s' : %shz-%shz" % (
        tcolor.DEFAULT,
        scanlevel['name'],
        commons.float2Hz(start),
        commons.float2Hz(start + scanlevel['windows']),
    )

    smooth_max = commons.smooth(np.array(summaries['max']['signal']), 10,
                                'flat')

    limitmin = summaries['min']['peak']['min']['mean'] - summaries['min'][
        'peak']['min']['std']
    limitmax = summaries['max']['mean'] + summaries['max']['std']
    searchStation(scanlevel, stations, summaries, smooth_max, limitmin,
                  limitmax)
Example #6
0
def executeSearchStations(config, stations, scanlevel, start):


    filename = calcFilename(scanlevel, start)

    # ignore if rtl_power file not exists
    csv_filename = "%s.csv" % filename
    exists = os.path.isfile(csv_filename)
    if not exists:
        showVerbose(
            config,
            "%s %s not exist%s" % (
                tcolor.RED,
                csv_filename,
                tcolor.DEFAULT,
            )
        )
        return

    # Ignore if call summary not exist
    summary_filename = "%s.summary" % filename
    exists = os.path.isfile(summary_filename)
    if not exists:
        showVerbose(
            config,
            "%s %s not exist%s" % (
                tcolor.RED,
                summary_filename,
                tcolor.DEFAULT,
            )
        )
        return
    summaries = loadJSON(summary_filename)

    print "%sFind stations '%s' : %shz-%shz" % (
        tcolor.DEFAULT,
        scanlevel['name'], commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
    )

    smooth_max = commons.smooth(np.array(summaries['max']['signal']),10, 'flat')

    limitmin = summaries['min']['peak']['min']['mean'] - summaries['min']['peak']['min']['std']
    limitmax = summaries['max']['mean'] + summaries['max']['std']
    searchStation(scanlevel, stations, summaries, smooth_max, limitmin, limitmax)
Example #7
0
def showInfo(config, args):
    # Show config
    result_scan = []
    if 'configs' in config:
        for configname in config['configs']:
            result_scan.append(
                [
                    configname,
                    config['configs'][configname]['location'],
                    config['configs'][configname]['antenna'],
                ]
            )

        header = ['Config name', 'Location','Antenna']
        print tabulate(result_scan, headers=header, stralign="right")

    print ""

    # Show the scan information table
    result_scan = []
    if 'scans' in config:
        for scanlevel in config['scans']:
            result_scan.append(
                [
                    "%sHz" % commons.float2Hz(scanlevel['freq_start']),
                    "%sHz" % commons.float2Hz(scanlevel['freq_end']),
                    "%sHz" % commons.float2Hz(scanlevel['windows']),
                    commons.float2Sec(scanlevel['interval']),
                    scanlevel['nbsamples_lines'],
                    commons.float2Sec(commons.sec2Float(scanlevel['interval']) * scanlevel['nbsamples_lines']),
                    # scanlevel['quitafter'],
                    scanlevel['maxlevel_legend'],
                ]
            )

        header = [
            'Freq. Start', 'Freq. End', 'Windows', 'Interval', 'Nb lines', 'Total time', 'Max legend level'
        ]
        print tabulate(result_scan, headers=header, stralign="right")

    # Show global config
    if 'global' in config:
        pprint.pprint(config['global'],indent=2)
Example #8
0
def executeSumarizeSignals(cmdargs, config, scanlevel, start):
    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        # ignore if rtl_power file not exists
        csv_filename = "%s.csv" % filename
        exists = os.path.isfile(csv_filename)
        if not exists:
            showVerbose(
                config,
                "%s %s not exist%s" % (
                    tcolor.RED,
                    csv_filename,
                    tcolor.DEFAULT,
                )
            )
            continue

        # Ignore call summary if file already exist
        summary_filename = "%s.summary" % filename
        exists = os.path.isfile(summary_filename)
        if exists:
            showVerbose(
                config,
                "%sSummarize '%s' : %shz-%shz%s for %s gain" % (
                    tcolor.GREEN,
                    scanlevel['name'], commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
                    gain,
                    tcolor.DEFAULT,
                )
            )
            continue

        print "%sSummarize '%s' : %shz-%shz for %s gain" % (
            tcolor.DEFAULT,
            scanlevel['name'], commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
            gain
        )


        sdrdatas = commons.SDRDatas(csv_filename)
        sdrdatas.genSummarizeSignal()
        saveJSON(summary_filename, sdrdatas.summaries)
Example #9
0
def showInfo(config, args):
    # Show config
    result_scan = []
    if 'configs' in config:
        for configname in config['configs']:
            result_scan.append([
                configname,
                config['configs'][configname]['location'],
                config['configs'][configname]['antenna'],
            ])

        header = ['Config name', 'Location', 'Antenna']
        print tabulate(result_scan, headers=header, stralign="right")

    print ""

    # Show the scan information table
    result_scan = []
    if 'scans' in config:
        for scanlevel in config['scans']:
            result_scan.append([
                "%sHz" % commons.float2Hz(scanlevel['freq_start']),
                "%sHz" % commons.float2Hz(scanlevel['freq_end']),
                "%sHz" % commons.float2Hz(scanlevel['windows']),
                commons.float2Sec(scanlevel['interval']),
                scanlevel['nbsamples_lines'],
                commons.float2Sec(
                    commons.sec2Float(scanlevel['interval']) *
                    scanlevel['nbsamples_lines']),
                # scanlevel['quitafter'],
                scanlevel['maxlevel_legend'],
            ])

        header = [
            'Freq. Start', 'Freq. End', 'Windows', 'Interval', 'Nb lines',
            'Total time', 'Max legend level'
        ]
        print tabulate(result_scan, headers=header, stralign="right")

    # Show global config
    if 'global' in config:
        pprint.pprint(config['global'], indent=2)
Example #10
0
def executeRTLPower(cmdargs, config, scanlevel, start):
    # Create directory if not exists
    if not os.path.isdir(scanlevel['scandir']):
        print "executeRTLPower SCANDIR: %s" % scanlevel['scandir']
        os.makedirs(scanlevel['scandir'])

    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        # Ignore call rtl_power if file already exist
        csv_filename = "%s.csv" % filename
        exists = os.path.isfile(csv_filename)
        if exists:
            showVerbose(
                config, "%sScan '%s' : %shz-%shz already exists%s" %
                (tcolor.GREEN, scanlevel['name'], commons.float2Hz(start),
                 commons.float2Hz(start + scanlevel['windows']),
                 tcolor.DEFAULT))
            return
        else:
            running_filename = "%s.running" % filename
            exists = os.path.isfile(running_filename)
            if exists:
                print "%sScan '%s' : delete old running file %shz-%shz" % (
                    tcolor.DEFAULT,
                    scanlevel['name'],
                    commons.float2Hz(start),
                    commons.float2Hz(start + scanlevel['windows']),
                )
                os.remove(running_filename)

            print "%sScan '%s' : %shz-%shz with %s gain / Begin: %s / Finish in: ~%s" % (
                tcolor.DEFAULT,
                scanlevel['name'],
                commons.float2Hz(start),
                commons.float2Hz(start + scanlevel['windows']),
                gain,
                time.strftime("%H:%M:%S", time.localtime()),
                commons.float2Sec(scanlevel['quitafter']),
            )

            cmddir = None
            if os.name == "nt":
                cmddir = "C:\\SDRHunter\\rtl-sdr-release\\x32"

            cmd = "rtl_power -p %s -g %s -f %s:%s:%s -i %s -e %s \"%s\"" % (
                config['global']['ppm'], gain, start,
                start + scanlevel['windows'], scanlevel['binsize'],
                scanlevel['interval'], scanlevel['quitafter'],
                running_filename)

            # Create Scan info file
            createScanInfoFile(cmdargs, config, scanlevel, start, gain)

            # Call rtl_power shell command
            executeShell(cmd, cmddir)

            # Rename file
            os.rename(running_filename, csv_filename)
Example #11
0
def executeSumarizeSignals(cmdargs, config, scanlevel, start):
    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        # ignore if rtl_power file not exists
        csv_filename = "%s.csv" % filename
        exists = os.path.isfile(csv_filename)
        if not exists:
            showVerbose(
                config, "%s %s not exist%s" % (
                    tcolor.RED,
                    csv_filename,
                    tcolor.DEFAULT,
                ))
            continue

        # Ignore call summary if file already exist
        summary_filename = "%s.summary" % filename
        exists = os.path.isfile(summary_filename)
        if exists:
            showVerbose(
                config, "%sSummarize '%s' : %shz-%shz%s for %s gain" % (
                    tcolor.GREEN,
                    scanlevel['name'],
                    commons.float2Hz(start),
                    commons.float2Hz(start + scanlevel['windows']),
                    gain,
                    tcolor.DEFAULT,
                ))
            continue

        print "%sSummarize '%s' : %shz-%shz for %s gain" % (
            tcolor.DEFAULT, scanlevel['name'], commons.float2Hz(start),
            commons.float2Hz(start + scanlevel['windows']), gain)

        sdrdatas = commons.SDRDatas(csv_filename)
        sdrdatas.genSummarizeSignal()
        saveJSON(summary_filename, sdrdatas.summaries)
Example #12
0
def executeRTLPower(cmdargs, config, scanlevel, start):
    # Create directory if not exists
    if not os.path.isdir(scanlevel['scandir']):
        print "executeRTLPower SCANDIR: %s" % scanlevel['scandir']
        os.makedirs(scanlevel['scandir'])

    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        # Ignore call rtl_power if file already exist
        csv_filename = "%s.csv" % filename
        exists = os.path.isfile(csv_filename)
        if exists:
            showVerbose(
                config,
                "%sScan '%s' : %shz-%shz already exists%s" % (
                    tcolor.GREEN,
                    scanlevel['name'],
                    commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
                    tcolor.DEFAULT
                )
            )
            return
        else:
            running_filename = "%s.running" % filename
            exists = os.path.isfile(running_filename)
            if exists:
                print "%sScan '%s' : delete old running file %shz-%shz" % (
                    tcolor.DEFAULT,
                    scanlevel['name'],
                    commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
                )
                os.remove(running_filename)

            print "%sScan '%s' : %shz-%shz with %s gain / Begin: %s / Finish in: ~%s" % (
                tcolor.DEFAULT,
                scanlevel['name'],
                commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
                gain,
                time.strftime("%H:%M:%S", time.localtime()),
                commons.float2Sec(scanlevel['quitafter']),
            )

            cmddir = None
            if os.name == "nt":
                cmddir = "C:\\SDRHunter\\rtl-sdr-release\\x32"

            cmd = "rtl_power -p %s -g %s -f %s:%s:%s -i %s -e %s \"%s\"" % (
                config['global']['ppm'],
                gain,
                start,
                start + scanlevel['windows'],
                scanlevel['binsize'],
                scanlevel['interval'],
                scanlevel['quitafter'],
                running_filename
            )

            # Create Scan info file
            createScanInfoFile(cmdargs, config, scanlevel, start, gain)

            # Call rtl_power shell command
            executeShell(cmd, cmddir)

            # Rename file
            os.rename(running_filename, csv_filename)
Example #13
0
def searchStation(scanlevel, stations, summaries, samples, limitmin, limitmax):

    #search_limit = sorted(limit_list)
    freqstep = summaries['freq']['step']
    stations['stations'] = sorted(
        stations['stations'],
        key=lambda x: commons.hz2Float(x['freq_center']) - commons.hz2Float(
            (x['bw'])))

    bwmin = commons.hz2Float(scanlevel['minscanbw'])
    bwmax = commons.hz2Float(scanlevel['maxscanbw'])

    limits = np.linspace(limitmin, limitmax, 5)
    for limit in limits:
        # Search peak upper than limit
        startup = -1
        foundlower = False
        for idx in np.arange(len(samples)):
            powerdb = samples[idx]
            isup = powerdb > limit

            # Search first lower limit signal
            if not foundlower:
                if not isup:
                    foundlower = True
                else:
                    continue

            # Find first upper
            if startup == -1:
                if isup:
                    startup = idx
                    maxidx = startup
                    maxdb = powerdb
            else:
                # If upper, check if db is upper
                if isup:
                    if powerdb > maxdb:
                        maxdb = powerdb
                        maxidx = idx
                # If lower, calc bandwidth and max db
                else:
                    endup = idx - 1

                    bw_nbstep = endup - startup
                    bw = bw_nbstep * freqstep
                    freqidx = startup + int(bw_nbstep / 2)
                    # TODO: compare with freqidx, set % error ?
                    freq_center = summaries['freq']['start'] + (maxidx *
                                                                freqstep)
                    freq_center = summaries['freq']['start'] + (freqidx *
                                                                freqstep)
                    freq_left = freq_center - bw

                    deltadb = (maxdb - limit)
                    if bwmin <= bw <= bwmax and deltadb > scanlevel[
                            'minrelativedb']:

                        print "Freq:%s / Bw:%s / Abs: %s dB / From ground:%.2f dB" % (
                            commons.float2Hz(freq_center),
                            commons.float2Hz(bw), maxdb, maxdb - limitmax)

                        found = False
                        for station in stations['stations']:
                            if freq_center >= commons.hz2Float(
                                    station['freq_center']
                            ) - bw and freq_center <= commons.hz2Float(
                                    station['freq_center']) + bw:
                                found = True
                                break

                        if not found:

                            stations['stations'].append({
                                'freq_center':
                                commons.float2Hz(freq_center),
                                'bw':
                                commons.float2Hz(bw),
                                'powerdb':
                                float("%.2f" % maxdb),
                                'relativedb':
                                float("%.2f" % (maxdb - limitmin))
                            })
                            stations['stations'] = sorted(
                                stations['stations'],
                                key=lambda x: commons.hz2Float(x[
                                    'freq_center']) - commons.hz2Float(x['bw']
                                                                       ))

                    startup = -1
Example #14
0
def executeHeatmapParameters(cmdargs, config, scanlevel, start):
    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        # Ignore if summary file not exists
        summary_filename = "%s.summary" % filename
        exists = os.path.isfile(summary_filename)
        if not exists:
            showVerbose(
                config,
                "%s %s not exist%s" % (
                    tcolor.RED,
                    summary_filename,
                    tcolor.DEFAULT,
                )
            )
            continue

        summaries = loadJSON(summary_filename)
        params_filename = "%s.hparam" % filename
        exists = os.path.isfile(params_filename)
        if exists:
            showVerbose(
                config,
                "%sHeatmap Parameter '%s' : %shz-%shz%s" % (
                tcolor.GREEN,
                scanlevel['name'], commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
                tcolor.DEFAULT,
                )
            )
            continue

        print "%sHeatmap Parameter '%s' : %shz-%shz for % gain" % (
            tcolor.DEFAULT,
            scanlevel['name'], commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
            gain,
        )

        parameters = {}
        parameters['reversetextorder'] = True

        # Db
        #parameters['db'] = {}
        ##parameters['db']['mean'] = summaries['avg']['mean']
        #parameters['db']['min'] = summaries['avg']['min']
        #parameters['db']['max'] = summaries['avg']['max']

        # Text
        parameters['texts'] = []
        parameters['texts'].append({'text': "Min signal: %.2f" % summaries['avg']['min']})
        parameters['texts'].append({'text': "Max signal: %.2f" % summaries['avg']['max']})
        parameters['texts'].append({'text': "Mean signal: %.2f" % summaries['avg']['mean']})
        parameters['texts'].append({'text': "Std signal: %.2f" % summaries['avg']['std']})

        parameters['texts'].append({'text': ""})
        parameters['texts'].append({'text': "avg min %.2f" % summaries['avg']['min']})
        parameters['texts'].append({'text': "std min %.2f" % summaries['avg']['std']})

        # Add sscanlevel stations name in legends
        if 'stationsfilename' in scanlevel or 'heatmap' in config['global']:
            parameters['legends'] = []

        if 'stationsfilename' in scanlevel:
            parameters['legends'].append(scanlevel['stationsfilename'])

        if 'heatmap' in config['global']:
            # Add global stations name in legends
            if 'heatmap' in config['global'] and "stationsfilenames" in config['global']['heatmap']:
                for stationsfilename in config['global']['heatmap']['stationsfilenames']:
                    parameters['legends'].append(stationsfilename)

        saveJSON(params_filename, parameters)
Example #15
0
def executeSpectre(cmdargs, config, scanlevel, start):
    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        csv_filename = "%s.csv" % filename
        exists = os.path.isfile(csv_filename)
        if not exists:
            showVerbose(
                config, "%s %s not exist%s" % (
                    tcolor.RED,
                    csv_filename,
                    tcolor.DEFAULT,
                ))
            return

        # Ignore if summary file not exists
        summary_filename = "%s.summary" % filename
        exists = os.path.isfile(summary_filename)
        if not exists:
            showVerbose(
                config, "%s %s not exist%s" % (
                    tcolor.RED,
                    summary_filename,
                    tcolor.DEFAULT,
                ))
            return
        summaries = loadJSON(summary_filename)

        # Check if scan exist
        img_filename = "%s_spectre.png" % filename
        exists = os.path.isfile(img_filename)
        if exists:
            showVerbose(
                config, "%sSpectre '%s' : %shz-%shz%s" %
                (tcolor.GREEN, scanlevel['name'], commons.float2Hz(start),
                 commons.float2Hz(start + scanlevel['windows']),
                 tcolor.DEFAULT))
            return

        print "%sSpectre '%s' : %shz-%shz" % (
            tcolor.DEFAULT,
            scanlevel['name'],
            commons.float2Hz(start),
            commons.float2Hz(start + scanlevel['windows']),
        )

        plt.figure(figsize=(15, 10))
        plt.grid()

        freqs = np.linspace(summaries['freq']['start'],
                            summaries['freq']['end'],
                            num=summaries['samples']['nbsamplescolumn'])

        limitmin = summaries['min']['peak']['min']['mean'] - summaries['min'][
            'peak']['min']['std']
        limitmax = summaries['max']['mean'] + summaries['max']['std']
        limits = np.linspace(limitmin, limitmax, 5)
        # Max
        for limit in limits:
            plt.axhline(limit, color='blue')

        smooth_max = commons.smooth(np.array(summaries['max']['signal']), 10,
                                    'flat')
        plt.plot(freqs, smooth_max[:len(freqs)], color='red')

        # Set X Limit
        locs, labels = plt.xticks()
        for idx in range(len(labels)):
            labels[idx] = commons.float2Hz(locs[idx])
        plt.xticks(locs, labels)
        plt.xlabel('Freq in Hz')

        # Set Y Limit
        # plt.ylim(summary['groundsignal'], summary['maxsignal'])
        plt.ylabel('Power density in dB')

        plt.savefig(img_filename)
        plt.close()
Example #16
0
def executeSpectre(cmdargs, config, scanlevel, start):
    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        csv_filename = "%s.csv" % filename
        exists = os.path.isfile(csv_filename)
        if not exists:
            showVerbose(
                config,
                "%s %s not exist%s" % (
                    tcolor.RED,
                    csv_filename,
                    tcolor.DEFAULT,
                )
            )
            return

        # Ignore if summary file not exists
        summary_filename = "%s.summary" % filename
        exists = os.path.isfile(summary_filename)
        if not exists:
            showVerbose(
                config,
                "%s %s not exist%s" % (
                    tcolor.RED,
                    summary_filename,
                    tcolor.DEFAULT,
                )
            )
            return
        summaries = loadJSON(summary_filename)

        # Check if scan exist
        img_filename = "%s_spectre.png" % filename
        exists = os.path.isfile(img_filename)
        if exists:
            showVerbose(
                config,
                "%sSpectre '%s' : %shz-%shz%s" % (
                    tcolor.GREEN,
                    scanlevel['name'], commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
                    tcolor.DEFAULT
                )
            )
            return

        print "%sSpectre '%s' : %shz-%shz" % (
            tcolor.DEFAULT,
            scanlevel['name'], commons.float2Hz(start), commons.float2Hz(start + scanlevel['windows']),
        )

        plt.figure(figsize=(15,10))
        plt.grid()

        freqs = np.linspace(summaries['freq']['start'], summaries['freq']['end'], num=summaries['samples']['nbsamplescolumn'])



        limitmin = summaries['min']['peak']['min']['mean'] - summaries['min']['peak']['min']['std']
        limitmax = summaries['max']['mean'] + summaries['max']['std']
        limits = np.linspace(limitmin, limitmax, 5)
        # Max
        for limit in limits:
            plt.axhline(limit, color='blue')

        smooth_max = commons.smooth(np.array(summaries['max']['signal']),10, 'flat')
        plt.plot(freqs, smooth_max[:len(freqs)],color='red')

        # Set X Limit
        locs, labels = plt.xticks()
        for idx in range(len(labels)):
            labels[idx] = commons.float2Hz(locs[idx])
        plt.xticks(locs, labels)
        plt.xlabel('Freq in Hz')

        # Set Y Limit
        # plt.ylim(summary['groundsignal'], summary['maxsignal'])
        plt.ylabel('Power density in dB')


        plt.savefig(img_filename)
        plt.close()
Example #17
0
def executeHeatmapParameters(cmdargs, config, scanlevel, start):
    for gain in scanlevel['gains']:
        filename = calcFilename(scanlevel, start, gain)

        # Ignore if summary file not exists
        summary_filename = "%s.summary" % filename
        exists = os.path.isfile(summary_filename)
        if not exists:
            showVerbose(
                config, "%s %s not exist%s" % (
                    tcolor.RED,
                    summary_filename,
                    tcolor.DEFAULT,
                ))
            continue

        summaries = loadJSON(summary_filename)
        params_filename = "%s.hparam" % filename
        exists = os.path.isfile(params_filename)
        if exists:
            showVerbose(
                config, "%sHeatmap Parameter '%s' : %shz-%shz%s" % (
                    tcolor.GREEN,
                    scanlevel['name'],
                    commons.float2Hz(start),
                    commons.float2Hz(start + scanlevel['windows']),
                    tcolor.DEFAULT,
                ))
            continue

        print "%sHeatmap Parameter '%s' : %shz-%shz for % gain" % (
            tcolor.DEFAULT,
            scanlevel['name'],
            commons.float2Hz(start),
            commons.float2Hz(start + scanlevel['windows']),
            gain,
        )

        parameters = {}
        parameters['reversetextorder'] = True

        # Db
        #parameters['db'] = {}
        ##parameters['db']['mean'] = summaries['avg']['mean']
        #parameters['db']['min'] = summaries['avg']['min']
        #parameters['db']['max'] = summaries['avg']['max']

        # Text
        parameters['texts'] = []
        parameters['texts'].append(
            {'text': "Min signal: %.2f" % summaries['avg']['min']})
        parameters['texts'].append(
            {'text': "Max signal: %.2f" % summaries['avg']['max']})
        parameters['texts'].append(
            {'text': "Mean signal: %.2f" % summaries['avg']['mean']})
        parameters['texts'].append(
            {'text': "Std signal: %.2f" % summaries['avg']['std']})

        parameters['texts'].append({'text': ""})
        parameters['texts'].append(
            {'text': "avg min %.2f" % summaries['avg']['min']})
        parameters['texts'].append(
            {'text': "std min %.2f" % summaries['avg']['std']})

        # Add sscanlevel stations name in legends
        if 'stationsfilename' in scanlevel or 'heatmap' in config['global']:
            parameters['legends'] = []

        if 'stationsfilename' in scanlevel:
            parameters['legends'].append(scanlevel['stationsfilename'])

        if 'heatmap' in config['global']:
            # Add global stations name in legends
            if 'heatmap' in config['global'] and "stationsfilenames" in config[
                    'global']['heatmap']:
                for stationsfilename in config['global']['heatmap'][
                        'stationsfilenames']:
                    parameters['legends'].append(stationsfilename)

        saveJSON(params_filename, parameters)
Example #18
0
def searchStation(scanlevel, stations, summaries, samples, limitmin, limitmax):

    #search_limit = sorted(limit_list)
    freqstep = summaries['freq']['step']
    stations['stations'] = sorted(stations['stations'], key=lambda x: commons.hz2Float(x['freq_center']) - commons.hz2Float((x['bw'])))

    bwmin = commons.hz2Float(scanlevel['minscanbw'])
    bwmax = commons.hz2Float(scanlevel['maxscanbw'])

    limits = np.linspace(limitmin, limitmax, 5)
    for limit in limits:
        # Search peak upper than limit
        startup = -1
        foundlower = False
        for idx in np.arange(len(samples)):
            powerdb = samples[idx]
            isup = powerdb > limit

            # Search first lower limit signal
            if not foundlower:
                if not isup:
                    foundlower = True
                else:
                    continue


            # Find first upper
            if startup == -1:
                if isup:
                    startup = idx
                    maxidx = startup
                    maxdb = powerdb
            else:
                # If upper, check if db is upper
                if isup:
                    if powerdb > maxdb:
                        maxdb = powerdb
                        maxidx = idx
                # If lower, calc bandwidth and max db
                else:
                    endup = idx - 1

                    bw_nbstep = endup - startup
                    bw = bw_nbstep * freqstep
                    freqidx = startup + int(bw_nbstep / 2)
                    # TODO: compare with freqidx, set % error ?
                    freq_center = summaries['freq']['start'] + (maxidx * freqstep)
                    freq_center = summaries['freq']['start'] + (freqidx * freqstep)
                    freq_left = freq_center - bw

                    deltadb = (maxdb - limit)
                    if bwmin <= bw <= bwmax and deltadb > scanlevel['minrelativedb']:

                        print "Freq:%s / Bw:%s / Abs: %s dB / From ground:%.2f dB" % (commons.float2Hz(freq_center), commons.float2Hz(bw), maxdb, maxdb - limitmax)

                        found = False
                        for station in stations['stations']:
                            if freq_center >= commons.hz2Float(station['freq_center']) - bw and freq_center <= commons.hz2Float(station['freq_center']) + bw:
                                found = True
                                break

                        if not found:

                            stations['stations'].append(
                                {'freq_center': commons.float2Hz(freq_center),
                                  'bw': commons.float2Hz(bw),
                                  'powerdb': float("%.2f" % maxdb),
                                  'relativedb': float("%.2f" % (maxdb - limitmin))
                                }
                            )
                            stations['stations'] = sorted(stations['stations'], key=lambda x: commons.hz2Float(x['freq_center']) - commons.hz2Float(x['bw']))


                    startup = -1