Announcement

Collapse
No announcement yet.

Gain Optimization Script

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

  • Gain Optimization Script

    ACKNOWLEDGEMENTS:
    Original author of optimization script: BartJr (Click here)
    Enhancement by: lignumaqua (Click here)

    Source: https://discussions.flightaware.com/...justment/18376


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

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

    (3) Copy paste code below in the new blank file, save file (Ctrl+o) and close file (Ctrl+x)

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

    (5) 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, socket, subprocess, fileinput, os
    
    measure_duration = 62 #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".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,{}] #msgs, positions, aircraft
    
       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")
       time.sleep(2)
       s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       s.connect(('localhost',30003))
       t = time.time()
       d = ''
       while 1:
          d += s.recv(32)
          if time.time() - t > measure_duration:
             break
       s.close()
       messages = 0
       positions = 0
       planes = {}
       for l in d.split('\n'):
          a = l.split(',')
          messages += 1
          if len(a) > 4:
             if a[1] == '3':
                positions += 1
             planes[a[4]] = 1
       print "gain=",g, "messages=", messages, "positions=", positions, "planes=", len(planes.keys())
       results[g][0] += messages
       results[g][1] += positions
       for hex in planes.keys():
          results[g][2][hex] = 1
    
    print "\n===Totals==="
    print "Gain, Messages, Positions, Aircraft"
    for g in gains:
       (messages,positions,planes) = results[g]
       print g, messages, positions, len(planes.keys())

    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.

    test 1 of 5
    [ ok ] Restarting dump1090-mutability (via systemctl): dump1090-mutability.service.
    gain= 49.6 messages= 2147 positions= 392 planes= 14
    [ ok ] Restarting dump1090-mutability (via systemctl): dump1090-mutability.service.
    gain= 48.0 messages= 2071 positions= 346 planes= 13
    ....................
    ....................
    ....................
    [ ok ] Restarting dump1090-mutability (via systemctl): dump1090-mutability.service.
    gain= 22.9 messages= 1116 positions= 182 planes= 9
    [ ok ] Restarting dump1090-mutability (via systemctl): dump1090-mutability.service.
    gain= 20.7 messages= 705 positions= 91 planes= 8


    test 2 of 5
    [ ok ] Restarting dump1090-mutability (via systemctl): dump1090-mutability.service.
    gain= 49.6 messages= 1136 positions= 178 planes= 9
    [ ok ] Restarting dump1090-mutability (via systemctl): dump1090-mutability.service.
    gain= 48.0 messages= 1267 positions= 239 planes= 12
    ......................
    .......................
    ......................



    ===Totals===
    Gain, Messages, Positions, Aircraft
    49.6 23647 585 183
    48.0 24298 594 175
    44.5 24238 558 182
    43.9 26731 613 189
    43.4 26240 572 184
    42.1 24494 663 183
    40.2 25305 537 179
    38.6 24298 602 177
    37.2 25508 631 180
    36.4 26784 615 170
    33.8 27507 718 174
    32.8 31027 767 181
    29.7 28477 552 185
    28.0 29911 656 188
    25.4 31822 1187 188
    22.9 31240 1035 186
    20.7 33081 955 192
    Last edited by abcd567; 2019-04-19, 20:22.

  • #2
    Thanks so much for sharing this very helpful script.
    It took about 90 minutes for it to run and I ran it six times yesterday to find the best gain settings.
    The numbers varied on each run but I could see a pattern after the third run. Again, I am in a rural area with mountains so my aircraft tracked numbers can vary greatly at any point during the day.
    Even in a high traffic area, I would think it would be helpful to run it more than once.
    Thanks for the help.

    Comment


    • #3
      Thank you for this script here is my test results:

      ===Totals===
      Gain, Messages, Positions, Aircraft
      49.6 70882 6428 99
      48.0 69677 6259 107
      44.5 71281 6640 110
      43.9 74554 6817 113
      43.4 73720 6514 106
      42.1 74566 6610 108
      40.2 71729 6421 108
      38.6 69304 6124 109
      37.2 70772 6341 102
      36.4 73151 6425 104
      33.8 73187 6573 102
      32.8 68985 6189 96
      29.7 60018 5594 100
      28.0 58577 5373 90
      25.4 50954 4674 77
      22.9 45718 4183 75
      20.7 33690 3077 72
      It seems like 43.9 is best gain setting for me.

      Comment


      • #4
        Thanks abcd567 for passing this on from the other source. As you didn't specify a directory for Step 2, I used /etc. Seems to be running as indicated.

        ylis

        Comment


        • #5
          ylis

          It is ok if you placed it in folder /etc
          The location of gain script file is not important. It can be placed in any folder and will work equally good.

          I normally place it in /home/pi/ folder (cd ~/).

          Comment


          • #6
            Hello, Is there any way to run this under Windows?

            Comment


            • #7
              w9bqo

              Never tried with fr24feed's Windows feeder, which has its integral dump1090 (Malcolm Robb).

              May be possible with modifications in the .py script plus installation of python on Windows.

              Comment


              • #8
                Hello my first post I am running a raspberry pi stretch lite, and pro stick, with fr24 and piaware and dump mutability 1.15 dev,I have copied this script to the letter but cannot get it to run I have this error
                ./optimize-gain-mut.py: 3: ./optimize-gain-mut.py: import not found

                ./optimize-gain-mut.py: 5: ./optimize-gain-mut.py: measure_ duration: not found

                ./optimize-gain-mut.py: 6: ./optimize-gain-mut.py: ntests: not found

                ./optimize-gain-mut.py: 7: ./optimize-gain-mut.py: Syntax error: "("unexpected

                Any help to what is wrong would be much appreciated to a newbie
                Last edited by Steveadi; 2019-03-06, 14:21.

                Comment


                • #9
                  Did you copy the first line as well?

                  What output does the following command give:

                  head optimize-gain-mut.py

                  Comment


                  • #10
                    I've been on it hours deleting and reinstalling for some reason I gave it one more go to check head optimize-gain-mut.py and it worked it is now running the script thank you .now to find out how to change my gain, a big learning process.

                    Comment


                    • #11
                      Originally posted by Steveadi View Post
                      ......now to find out how to change my gain, a big learning process.
                      Please see this post:

                      https://forum.flightradar24.com/thre...l=1#post115563

                      .

                      Comment


                      • #12
                        Thank you I am running a few tests morning noon and night for a couple of days so far 22.9 is winning

                        Comment


                        • #13
                          Someone is running an amplifier

                          Good luck!

                          Comment


                          • #14
                            Gain changing overnight with python script and cron

                            I have no experience with python but there are many out there who do so I would appreciate any help that I can get with this.
                            I've seen the gain setting test script and I think part of it would help me with this project.
                            These parts look relevant (From ABCD567)
                            I want something like this:- (this is just a draft and guess work on my part)

                            Set gains overnight testing
                            (1) Create a 2 new files optimize-gain-mut-day.py and optimize-gain-mut-night.py
                            sudo nano optimize-gain-mut-day.py
                            sudo nano optimize-gain-mut-night.py

                            (2) Add code to files then Ctrl+o) and close file (Ctrl+x)

                            (3) Make files executable
                            sudo chmod +x optimize-gain-mut-day.py
                            sudo chmod +x optimize-gain-mut-night.py

                            Day Code

                            #!/usr/bin/python2
                            import time, socket, subprocess, fileinput, os

                            for line in fileinput.input('/etc/default/dump1090-mutability', inplace=1):
                            if line.startswith('GAIN'):
                            print 'GAIN=38.6'
                            else:
                            print line,
                            os.system("sudo /etc/init.d/dump1090-mutability restart")

                            Night code

                            #!/usr/bin/python2
                            import time, socket, subprocess, fileinput, os

                            for line in fileinput.input('/etc/default/dump1090-mutability', inplace=1):
                            if line.startswith('GAIN'):
                            print 'GAIN=48'
                            else:
                            print line,
                            os.system("sudo /etc/init.d/dump1090-mutability restart")


                            Then use cron to run them at 23:30 and 06:30 each day

                            I know this isn't a working script yet but I post it to give the idea of what I want to achieve.

                            T-EGSY1
                            Last edited by Scroggie; 2019-03-09, 12:28. Reason: Typo

                            Comment


                            • #15
                              Running such a script each day or twice a day is not a good idea.

                              Especially because you want to optimize your gain for a situation with a lot of traffic not very little traffic.
                              The result of the script becomes even more random with little traffic around.

                              Just run it once when there is a lot of traffic around.
                              Then set that gain and maybe fine tune it by hand if for example you lose close in planes because the signal is too strong but you want to receive those planes.

                              Otherwise leave it.

                              Running such a script at night just risks setting a random gain that is anything but optimal.

                              Also i would recommend installing graphs that show you the message rate and percentage of strong signals:
                              https://github.com/wiedehopf/graphs1090#graphs1090


                              I'm not sure if those will work on the pi24 image though, those images sometimes have weird write protection.
                              But in my opinion those graphs are more useful for adjusting gain than that script.
                              Last edited by wiedehopf; 2019-03-09, 12:33.

                              Comment

                              Working...
                              X