From 6bc969822bc91afd2ce5172e2ada47a0bfdf6656 Mon Sep 17 00:00:00 2001 From: snbenge Date: Wed, 22 Apr 2020 11:08:39 -0400 Subject: [PATCH] added usage documentation in each file for clarity --- src/dataset/dataManipulation/GPSmanip.py | 9 +- .../dataManipulation/findBuildingCoord.py | 86 +++++++++++-------- .../dataManipulation/pickles/pickleManage.py | 18 ++-- .../pickles/referenceBuildings4Pickle.txt | 29 +++++++ 4 files changed, 94 insertions(+), 48 deletions(-) create mode 100644 src/dataset/dataManipulation/pickles/referenceBuildings4Pickle.txt diff --git a/src/dataset/dataManipulation/GPSmanip.py b/src/dataset/dataManipulation/GPSmanip.py index 7ee0f2f..0ed691a 100644 --- a/src/dataset/dataManipulation/GPSmanip.py +++ b/src/dataset/dataManipulation/GPSmanip.py @@ -1,7 +1,10 @@ import sys import numpy as np - +# Usage: changes lat, long, alt into xyz local frame +# This takes in lat, long, and alt and calculates xyz +# Example: print(gpstoLocalFrame(42.29360387311647,-83.71222615242006,272)) +# Returns: array of XYZ coordinates in radians def gpstoLocalFrame(lat, lng, alt): lat0 = 0.7381566413 lng0 = -1.4610097151 @@ -14,11 +17,9 @@ def gpstoLocalFrame(lat, lng, alt): dAlt = alt - alt0 r = 6400000 # approx. radius of earth (m) + # WARNING: x and y may need to be flipped. Paper and example files from NCLT have contradictory usages y = r * np.cos(lat0) * np.sin(dLng) x = r * np.sin(dLat) z = dAlt return [x,y,z] -#Example -# x = gpstoLocalFrame(42.29360387311647,-83.71222615242006,272) -# print(x) diff --git a/src/dataset/dataManipulation/findBuildingCoord.py b/src/dataset/dataManipulation/findBuildingCoord.py index 4134ffc..a2c3e11 100644 --- a/src/dataset/dataManipulation/findBuildingCoord.py +++ b/src/dataset/dataManipulation/findBuildingCoord.py @@ -3,33 +3,21 @@ import numpy as np import pickle import math -def gpstoLocalFrame(lat, lng, alt): - lat0 = 0.7381566413 - lng0 = -1.4610097151 - alt0 = 265.8 - - dLat = np.deg2rad(lat) - lat0 - dLng = np.deg2rad(lng) - lng0 - dAlt = alt - alt0 - - r = 6400000 # approx. radius of earth (m) - y = r * np.cos(lat0) * np.sin(dLng) - x = r * np.sin(dLat) - z = dAlt - - return [x,y,z] -#Example -# x = gpstoLocalFrame(42.29360387311647,-83.71222615242006,272) -# print(x) - -def buildingtoGPS(building): - pickle_in = open('pickles/BuildingMappings.pkl',"rb") - currDict = pickle.load(pickle_in) - for place in currDict: - if place == building: - return currDict.get(building) - return 0 +# Example usage of overall file to find xyz coordinates of two buildings given name as string +''' +GPScoords = findClosestEntrance("BBB", "EECS") +Building1 = gpstoLocalFrame(GPScoords[0][0], GPScoords[0][1], GPScoords[0][2]) +Building2 = gpstoLocalFrame(GPScoords[1][0], GPScoords[1][1], GPScoords[1][2]) +print(Building1) +print(Building2) +''' +# Usage: finds building coordinates in lat, long, and alt in degrees +# This takes in two building names as strings and returns +# closest two entrances +# Example: GPScoords = findClosestEntrance("BBB", "EECS") +# print(GPScoords[0][0]) #returns latitutde of first building +# Returns: 2x2 array of two GPS coordinates in lat, long, and alt in degrees def findClosestEntrance(building1, building2): gps1 = buildingtoGPS(building1) gps2 = buildingtoGPS(building2) @@ -48,18 +36,44 @@ def findClosestEntrance(building1, building2): return [gps1[1],gps2[0]] else: return [gps1[1],gps2[1]] -# Example -# print(findClosestEntrance("BBB", "EECS")) +# Usage: finds building coordinates in lat, long, and alt in degrees +# This takes in a building name and looks up coordinates in pickle file +# Example: buildingsGPScoords = buildingtoGPS(building1) +# print(buildingGPScoords[0]) #returns latitutde of the building +# Returns: array of GPS coordinates (lat, long, and alt) in degrees +def buildingtoGPS(building): + pickle_in = open('pickles/BuildingMappings.pkl',"rb") + currDict = pickle.load(pickle_in) + for place in currDict: + if place == building: + return currDict.get(building) + return 0 + +# Usage: changes lat, long, alt into xyz local frame +# This takes in lat, long, and alt and calculates xyz +# Example: print(gpstoLocalFrame(42.29360387311647,-83.71222615242006,272)) +# Returns: array of XYZ coordinates in radians +def gpstoLocalFrame(lat, lng, alt): + lat0 = 0.7381566413 + lng0 = -1.4610097151 + alt0 = 265.8 + + dLat = np.deg2rad(lat) - lat0 + dLng = np.deg2rad(lng) - lng0 + dAlt = alt - alt0 + + r = 6400000 # approx. radius of earth (m) + # WARNING: x and y may need to be flipped. Paper and example files from NCLT have contradictory usages + y = r * np.cos(lat0) * np.sin(dLng) + x = r * np.sin(dLat) + z = dAlt + + return [x,y,z] + +# Usage: Euclidean distance calculator - helper function def calculateDistance(x1,y1,x2,y2): dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2) return dist -# Example usage of overall file -''' -GPScoords = findClosestEntrance("BBB", "EECS") -Building1 = gpstoLocalFrame(GPScoords[0][0], GPScoords[0][1], GPScoords[0][2]) -Building2 = gpstoLocalFrame(GPScoords[1][0], GPScoords[1][1], GPScoords[1][2]) -print(Building1) -print(Building2) -''' \ No newline at end of file + \ No newline at end of file diff --git a/src/dataset/dataManipulation/pickles/pickleManage.py b/src/dataset/dataManipulation/pickles/pickleManage.py index 17f0a6f..fe93892 100644 --- a/src/dataset/dataManipulation/pickles/pickleManage.py +++ b/src/dataset/dataManipulation/pickles/pickleManage.py @@ -1,7 +1,9 @@ import pickle -# file to print current pickle files to text file -# this allows us to monitor current dictionaries +# Usage: file to print current pickle files to text file +# this allows us to monitor current dictionaries +# Example: printPickle("BuildingMappings") +# Output: Text file of dictonary keys def printPickle(filename): pickle_in = open(filename + '.pkl',"rb") currDict = pickle.load(pickle_in) @@ -10,13 +12,17 @@ def printPickle(filename): f.write('%s\n' % x ) f.close() -# update pickle files to update dictionaries -# example: grades = {'Bart', 'Lisa', 'Milhouse', 'Nelson'} +# Usage: creates pickle files from given dictionaries +# Example: createPickle('test', {'Bart', 'Lisa', 'Milhouse', 'Nelson'}) +# Output: new Pickle file def createPickle(filename, pklList): f = open(filename + '.pkl', 'wb') # Pickle file is newly created where foo1.py is pickle.dump(pklList, f) # dump data to f f.close() +# Usage: updates pickle files from given dictionaries +# Example: updatePickle('test', {'Bart', 'Lisa', 'Milhouse', 'Nelson'}) +# Output: Pickle file def updatePickle(filename, pklList): pickle_in = open(filename + '.pkl',"rb") currDict = pickle.load(pickle_in) @@ -24,7 +30,3 @@ def updatePickle(filename, pklList): pickle.dump(currDict + pklList, f) # dump data to f f.close() -# Example usage -# createPickle('test', {'Bart', 'Lisa', 'Milhouse', 'Nelson'}) -# updatePickle('test', {'Theo'}) -# printPickle("test") diff --git a/src/dataset/dataManipulation/pickles/referenceBuildings4Pickle.txt b/src/dataset/dataManipulation/pickles/referenceBuildings4Pickle.txt new file mode 100644 index 0000000..07166b1 --- /dev/null +++ b/src/dataset/dataManipulation/pickles/referenceBuildings4Pickle.txt @@ -0,0 +1,29 @@ +Reference file for coordinates found for google maps + +(latitude, longitude, altitude) +FXB + Beal Ave - 42.29360387311647 -83.71222615242006 272 + Hayward - 42.29359196883519 -83.71161460876466 274 + +EECS + Beal Ave - 42.29259200117389 -83.71376574039459 266 + Grove - 42.29250866981882 -83.71487081050874 264 + +BBB + Grove - 42.292667396114446 -83.71626019477846 264 + Hayward - 42.2933737232794 -83.71622264385225 271 + +Pierpont + Grove - 42.291536462529756 -83.71705412864686 261 + Bonisteel - 42.29065947899958 -83.7178158760071 258 + +Duderstadt + Bonisteel - 42.29067138383511 -83.7162870168686 261 + Grover - 42.29158011297468 -83.71514439582826 263 + +Example for making and changing buildings from pickle file + +from pickleManage import * +createPickle("BuildingMappings", {'Duderstadt':[[42.29067138383511, -83.7162870168686, 261],[42.29158011297468, -83.71514439582826, 263]], 'Pierpont':[[42.291536462529756, -83.71705412864686, 261],[42.29065947899958, -83.7178158760071, 258]], 'BBB':[[42.292667396114446, -83.71626019477846, 264],[42.2933737232794, -83.71622264385225, 271]], 'EECS':[[42.29259200117389, -83.71376574039459, 266],[42.29250866981882, -83.71487081050874, 264]],'FXB':[[42.29360387311647, -83.71222615242006, 272],[42.29359196883519, -83.71161460876466, 274]]}) +updatePickle("BuildingMappings", {'Duderstadt':[[42.29067138383511, -83.7162870168686, 261],[42.29158011297468, -83.71514439582826, 263]]}) +printPickle("BuildingMappings")