From da41dd3c84045d53879878824ac57bbd40d31a68 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Fri, 15 Jun 2012 18:50:37 -0700 Subject: [PATCH] Move CPR test code to main function within cpr.py --- apps/mlat-2station-postanalysis.py | 40 ------------------- python/cpr-test.py | 63 ------------------------------ python/cpr.py | 35 +++++++++++++++++ python/testparse.py | 8 ---- 4 files changed, 35 insertions(+), 111 deletions(-) delete mode 100755 apps/mlat-2station-postanalysis.py delete mode 100755 python/cpr-test.py mode change 100644 => 100755 python/cpr.py delete mode 100644 python/testparse.py diff --git a/apps/mlat-2station-postanalysis.py b/apps/mlat-2station-postanalysis.py deleted file mode 100755 index 04bc824..0000000 --- a/apps/mlat-2station-postanalysis.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python -import numpy -import mlat - -#rudi says: -#17 8da12615 903bf4bd3eb2c0 36ac95 000000 0.0007421782357 2.54791875 -#17 8d4b190a 682de4acf8c177 5b8f55 000000 0.0005142348236 2.81227225 - -#sf says: -#17 8da12615 903bf4bd3eb2c0 36ac95 000000 0.003357535461 00.1817445 -#17 8d4b190a 682de4acf8c177 5b8f55 000000 0.002822938375 000.446215 - -sf_station = [37.762236,-122.442525, 100] -mv_station = [37.409348,-122.07732, 100] - -report1_location = [37.737804, -122.485139, 3345] -report1_sf_tstamp = 0.1817445 -report1_mv_tstamp = 2.54791875 - -report2_location = [37.640836, -122.260218, 2484] -report2_sf_tstamp = 0.446215 -report2_mv_tstamp = 2.81227225 - -report1_tof_sf = numpy.linalg.norm(numpy.array(mlat.llh2ecef(sf_station))-numpy.array(mlat.llh2ecef(report1_location))) / mlat.c -report1_tof_mv = numpy.linalg.norm(numpy.array(mlat.llh2ecef(mv_station))-numpy.array(mlat.llh2ecef(report1_location))) / mlat.c - -report1_sf_tstamp_abs = report1_sf_tstamp - report1_tof_sf -report1_mv_tstamp_abs = report1_mv_tstamp - report1_tof_mv - -report2_tof_sf = numpy.linalg.norm(numpy.array(mlat.llh2ecef(sf_station))-numpy.array(mlat.llh2ecef(report2_location))) / mlat.c -report2_tof_mv = numpy.linalg.norm(numpy.array(mlat.llh2ecef(mv_station))-numpy.array(mlat.llh2ecef(report2_location))) / mlat.c - -report2_sf_tstamp_abs = report2_sf_tstamp - report2_tof_sf -report2_mv_tstamp_abs = report2_mv_tstamp - report2_tof_mv - -dt1 = report1_sf_tstamp_abs - report1_mv_tstamp_abs -dt2 = report2_sf_tstamp_abs - report2_mv_tstamp_abs - -error = abs((dt1-dt2) * mlat.c) -print error diff --git a/python/cpr-test.py b/python/cpr-test.py deleted file mode 100755 index 7d9d975..0000000 --- a/python/cpr-test.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2010 Nick Foster -# -# This file is part of gr-air-modes -# -# gr-air-modes is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# gr-air-modes is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with gr-air-modes; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from modes_parse import * -from cpr import * -import sys - -my_location = [37.76225, -122.44254] - -shortdata = long(sys.argv[1], 16) -longdata = long(sys.argv[2], 16) -parity = long(sys.argv[3], 16) -ecc = long(sys.argv[4], 16) - -parser = modes_parse(my_location) - -[altitude, decoded_lat, decoded_lon, rnge, bearing] = parser.parseBDS06(shortdata, longdata, parity, ecc) - -if decoded_lat is not None: - print "Altitude: %i\nLatitude: %.6f\nLongitude: %.6f\nRange: %.2f\nBearing: %i\n" % (altitude, decoded_lat, decoded_lon, rnge, bearing,) - -print "Decomposing...\n" - -subtype = (longdata >> 51) & 0x1F; - -encoded_lon = longdata & 0x1FFFF -encoded_lat = (longdata >> 17) & 0x1FFFF -cpr_format = (longdata >> 34) & 1 - -enc_alt = (longdata >> 36) & 0x0FFF - -[cpr_lat, cpr_lon] = cpr_resolve_local(my_location, [encoded_lat, encoded_lon], cpr_format, 1) - -print "Subtype: %i\nEncoded longitude: %x\nEncoded latitude: %x\nCPR format: %i\nEncoded altitude: %x\n" % (subtype, encoded_lon, encoded_lat, cpr_format, enc_alt,) -print "Pos: %.6f %.6f" % (cpr_lat, cpr_lon) - -#print "First argument is order %i, second %i" % ((evendata >> 34) & 1, (odddata >> 34) & 1,) - -#evenencpos = [(evendata >> 17) & 0x1FFFF, evendata & 0x1FFFF] -#oddencpos = [(odddata >> 17) & 0x1FFFF, odddata & 0x1FFFF] - -#[declat, declon] = cpr_decode_global(evenencpos, oddencpos, newer) - -#print "Global latitude: %.6f\nGlobal longitude: %.6f" % (declat, declon,) diff --git a/python/cpr.py b/python/cpr.py old mode 100644 new mode 100755 index 270477a..19270bb --- a/python/cpr.py +++ b/python/cpr.py @@ -117,6 +117,8 @@ def cpr_resolve_global(evenpos, oddpos, mostrecent, surface): #ok this is consid rlateven = dlateven * (mod(j, 60)+evenpos[0]/2**nbits(surface)) rlatodd = dlatodd * (mod(j, 59)+ oddpos[0]/2**nbits(surface)) + #This checks to see if the latitudes of the reports straddle a transition boundary + #If so, you can't get a globally-resolvable location. if nl(rlateven) != nl(rlatodd): #print "Boundary straddle!" return (None, None,) @@ -260,3 +262,36 @@ def cpr_encode(lat, lon, ctype, surface): xz = int(mod(xz, scalar)) return (yz, xz) #lat, lon + +if __name__ == '__main__': + from modes_parse import * + import sys + + my_location = [37.76225, -122.44254] + + shortdata = long(sys.argv[1], 16) + longdata = long(sys.argv[2], 16) + parity = long(sys.argv[3], 16) + ecc = long(sys.argv[4], 16) + + parser = modes_parse(my_location) + + [altitude, decoded_lat, decoded_lon, rnge, bearing] = parser.parseBDS06(shortdata, longdata, parity, ecc) + + if decoded_lat is not None: + print "Altitude: %i\nLatitude: %.6f\nLongitude: %.6f\nRange: %.2f\nBearing: %i\n" % (altitude, decoded_lat, decoded_lon, rnge, bearing,) + + print "Decomposing...\n" + + subtype = (longdata >> 51) & 0x1F; + + encoded_lon = longdata & 0x1FFFF + encoded_lat = (longdata >> 17) & 0x1FFFF + cpr_format = (longdata >> 34) & 1 + + enc_alt = (longdata >> 36) & 0x0FFF + + [cpr_lat, cpr_lon] = cpr_resolve_local(my_location, [encoded_lat, encoded_lon], cpr_format, 1) + + print "Subtype: %i\nEncoded longitude: %x\nEncoded latitude: %x\nCPR format: %i\nEncoded altitude: %x\n" % (subtype, encoded_lon, encoded_lat, cpr_format, enc_alt,) + print "Pos: %.6f %.6f" % (cpr_lat, cpr_lon) diff --git a/python/testparse.py b/python/testparse.py deleted file mode 100644 index d86c9bd..0000000 --- a/python/testparse.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env python -import modes_print - -infile = open("27augrudi3.txt") - -printer = modes_print.modes_output_print([37.409348,-122.07732]) -for line in infile: - printer.parse(line)