Announcement

Collapse
No announcement yet.

Modded Gain Optimization Script With Distance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Modded Gain Optimization Script With Distance

    ACKNOWLEDGEMENTS:
    Original author of optimization script: BartJr
    Enhancement by: lignumaqua
    (Orginal flightaware link is broken, so not added)
    Copied instructions from abcd567's post

    I wanted way to optimize my setup (settings) for furthest plane distance, so I modded the orginal gain optimization script so it would measure the plane distance also.
    The procedure is almost the same as with the original script.

    PROCEDURE:
    (1) Install Python:
    sudo apt-get install python

    (2) Install Geopy module:
    sudo pip install geopy

    (3) Create a new file optimize-gain-mut.py
    sudo nano optimize-gain-mut.py

    (4) Copy paste code below in the new blank file and set your antenna location (lat, lon) (the var coords_antenna= in the top of the script)
    and save file (Ctrl+o) and close file (Ctrl+x)

    (5) Make file executable
    sudo chmod +x optimize-gain-mut.py

    (6) Start test
    sudo ./optimize-gain-mut.py


    It is a very lengthy test. Be patient.
    Results will be displayed after test is completed.


    Code below to be copy-pasted in blank file "optimize-gain-mut.py".
    It requires dump1090-mutability ver 1.15~dev installed on Pi

    Code:
    #!/usr/bin/python2
    import time
    import socket
    import subprocess
    import fileinput
    import os
    import geopy.distance
    
    coords_antenna = (12.3456, 3.45678) # antenna location lat, lon <<change me!!!!!
    max_pos_dist = 690  # max range (in km) what should be possible and some more
    measure_duration = 120  # seconds
    ntests = 5
    gains = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6 agc".split()
    #gains = "36.4 38.6 40.2 42.1 44.5 48.0 49.6".split()
    #gains = "22.9 25.4 28.0 29.7 32.8 33.8 36.4".split()
    gains.reverse()
    results = {}
    
    for i in range(ntests):
        print "test", i + 1, "of", ntests
        for g in gains:
            if g not in results:
                results[g] = [0, 0, {}, 0, 0]  # msgs, positions, aircraft, average, max range
    
            for line in fileinput.input(
                '/etc/default/dump1090-mutability',
                    inplace=1):
                if line.startswith('GAIN'):
                    print 'GAIN=' + g
                else:
                    print line,
            os.system("sudo /etc/init.d/dump1090-mutability restart > /dev/null")
            time.sleep(2)
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect(('localhost', 30003))
            t = time.time()
            d = ''
            while True:
                d += s.recv(32)
                if time.time() - t > measure_duration:
                    break
            s.close()
            messages = 0
            positions = 0
            dist_max = 0
            dist_avg = 0
            dist_list = list()
            planes = {}
            for l in d.split('\n'):
                a = l.split(',')
                messages += 1
                if len(a) > 16:
                    if a[1] == '3':
                        coords_plane = (a[14], a[15])
                        dist = geopy.distance.distance(coords_antenna, coords_plane).km
                        if(dist < max_pos_dist):
                            dist_list.append(dist)
                            if(dist > dist_max):
                                dist_max = dist
                        positions += 1
                    planes[a[4]] = 1
            dist_avg = round((sum(dist_list) / len(dist_list)), 2)
            print 'gain={0:4} messages={1:6d} positions={2:5d} planes={3:4d} avg range={4:06.2f} max range={5:06.2f}'.format(g, messages, positions, len(planes.keys()), dist_avg, dist_max)
            results[g][0] += messages
            results[g][1] += positions
            for hex in planes.keys():
                results[g][2][hex] = 1
            results[g][3] += dist_avg
            results[g][4] += dist_max
    
    print "\n------======Totals======------"
    for g in gains:
        (messages, positions, planes, dist_avg, dist_max) = results[g]
        print 'gain={0:4} messages={1:6d} positions={2:5d} planes={3:4d} avg range={4:06.2f} max range={5:06.2f}'.format(g, messages, positions, len(planes.keys()), dist_avg / ntests, dist_max / ntests)
    When the test is run, it will start giving output, one line at a time then pause, then next line then pause and so on.
    It is a very lengthy test. Be patient.
    Results will be displayed after test is completed.

    Example output:
    test 1 of 6
    gain=agc messages=134004 positions= 6610 planes= 189 avg range=110.11 max range=321.59
    gain=49.6 messages=143095 positions= 7178 planes= 173 avg range=102.87 max range=342.49
    gain=48.0 messages=142914 positions= 7172 planes= 181 avg range=103.33 max range=342.85
    .................
    .................
    ..................

    test 2 of 6
    gain=agc messages=130781 positions= 6405 planes= 195 avg range=109.10 max range=366.47
    gain=49.6 messages=138955 positions= 6633 planes= 190 avg range=103.84 max range=326.97
    gain=48.0 messages=136170 positions= 6560 planes= 191 avg range=106.85 max range=302.45
    ................
    ...................
    ................
    etc...

    When all test are completed you will get something like:
    ------======Totals======------
    gain=agc messages=771226 positions=38241 planes=1010 avg range=110.83 max range=324.75
    gain=49.6 messages=825964 positions=40286 planes= 981 avg range=104.62 max range=336.95
    gain=48.0 messages=821475 positions=40523 planes= 990 avg range=103.24 max range=316.22
    gain=44.5 messages=807878 positions=39805 planes= 943 avg range=100.13 max range=300.01
    .........................
    .........................
    .........................

    Since I can't post links or html code yet (first post) I left out the markup and the link to the orginal post.
    Last edited by holysmokey; 2019-04-29, 07:54.

  • #2
    Great! thumb-single.jpg thumb-single.jpg thumb-single.jpg


    Originally posted by holysmokey View Post
    ACKNOWLEDGEMENTS:
    Original author of optimization script: BartJr
    Enhancement by: lignumaqua
    (Orginal flightaware link is broken, so not added)
    Copied instructions from abcd567's post
    Thanks for pointing out the broken links in my post.
    Flightaware's links given in my post Gain Optimization Script got broken when their forum format was later upgraded to "Discourse".
    I have now updated the links in my above noted post.

    Here is the current link to BartJr's post in which he posted the original script, which was written by him
    I wrote a script to sort of do this. I only ran for 15 second intervals because the amount of traffic can change a lot throughout the day. But you can try different durations. It gives an output like: test 1 of 10 gain= 49.6 messages= 771 positions= 41 planes= 49 gain= 48.0 messages= 742 positions= 43 planes= 51 gain= 44.5 messages= 785 positions= 37 planes= 51 gain= 40.2 messages= 677 positions= 35 planes= 51 gain= 37.2 messages= 743 positions= 32 planes= 48 gain= 32.8 messages= 711 positi...


    Here is the current link to lignumaqua's post in which he posted the enhancement to @BartJr's original script
    BTW, care to share the modified script? 😃 Happy to do so, but be warned, this will mess up your local collectd stats. Depending on the timing between when collectd samples and the gain levels switching you’ll likely see some strange results. However, the overall average won’t change much and you’ll keep feeding data to FA. The constant rebooting of dump1090 will also break MLAT for the duration of the test. It’s a fairly crude hack of BartJr’s code that rewrites the dump1090-mutabil...
    Last edited by abcd567; 2019-04-20, 07:37.

    Comment

    Working...
    X