From 6b483c793b0cc2fbc6fa9be1773a2a2ecbb22001 Mon Sep 17 00:00:00 2001 From: snbenge Date: Tue, 21 Apr 2020 22:37:43 -0400 Subject: [PATCH 1/4] Adding files necessary to find building coordinates in both XYZ and GPS coordinates and adding python file to manipulate various pickle files used in semantic aspects of code and BuildingMappings pickles --- .../dataManipulation/findBuildingCoord.py | 65 +++++++++++++++++++ .../pickles/BuildingMappings.pkl | 57 ++++++++++++++++ .../pickles/BuildingMappings.txt | 5 ++ .../dataManipulation/pickles/pickleManage.py | 30 +++++++++ 4 files changed, 157 insertions(+) create mode 100644 src/dataset/dataManipulation/findBuildingCoord.py create mode 100644 src/dataset/dataManipulation/pickles/BuildingMappings.pkl create mode 100644 src/dataset/dataManipulation/pickles/BuildingMappings.txt create mode 100644 src/dataset/dataManipulation/pickles/pickleManage.py diff --git a/src/dataset/dataManipulation/findBuildingCoord.py b/src/dataset/dataManipulation/findBuildingCoord.py new file mode 100644 index 0000000..4134ffc --- /dev/null +++ b/src/dataset/dataManipulation/findBuildingCoord.py @@ -0,0 +1,65 @@ +import sys +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 + +def findClosestEntrance(building1, building2): + gps1 = buildingtoGPS(building1) + gps2 = buildingtoGPS(building2) + + x = [0,0,0,0] + x[0] = calculateDistance(gps1[0][0],gps1[0][1],gps2[0][0],gps2[0][1]) + x[1] = calculateDistance(gps1[0][0],gps1[0][1],gps2[1][0],gps2[1][1]) + x[2] = calculateDistance(gps1[1][0],gps1[1][1],gps2[0][0],gps2[0][1]) + x[3] = calculateDistance(gps1[1][0],gps1[1][1],gps2[1][0],gps2[1][1]) + index = np.argmin(x) + if index == 0: + return [gps1[0],gps2[0]] + elif index == 1: + return [gps1[0],gps2[1]] + elif index == 2: + return [gps1[1],gps2[0]] + else: + return [gps1[1],gps2[1]] +# Example +# print(findClosestEntrance("BBB", "EECS")) + +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 diff --git a/src/dataset/dataManipulation/pickles/BuildingMappings.pkl b/src/dataset/dataManipulation/pickles/BuildingMappings.pkl new file mode 100644 index 0000000..501a791 --- /dev/null +++ b/src/dataset/dataManipulation/pickles/BuildingMappings.pkl @@ -0,0 +1,57 @@ +(dp0 +S'EECS' +p1 +(lp2 +(lp3 +F42.29259200117389 +aF-83.71376574039459 +aI266 +aa(lp4 +F42.29250866981882 +aF-83.71487081050874 +aI264 +aasS'Duderstadt' +p5 +(lp6 +(lp7 +F42.29067138383511 +aF-83.7162870168686 +aI261 +aa(lp8 +F42.29158011297468 +aF-83.71514439582826 +aI263 +aasS'FXB' +p9 +(lp10 +(lp11 +F42.29360387311647 +aF-83.71222615242006 +aI272 +aa(lp12 +F42.29359196883519 +aF-83.71161460876466 +aI274 +aasS'Pierpont' +p13 +(lp14 +(lp15 +F42.291536462529756 +aF-83.71705412864686 +aI261 +aa(lp16 +F42.29065947899958 +aF-83.7178158760071 +aI258 +aasS'BBB' +p17 +(lp18 +(lp19 +F42.292667396114446 +aF-83.71626019477846 +aI264 +aa(lp20 +F42.2933737232794 +aF-83.71622264385225 +aI271 +aas. \ No newline at end of file diff --git a/src/dataset/dataManipulation/pickles/BuildingMappings.txt b/src/dataset/dataManipulation/pickles/BuildingMappings.txt new file mode 100644 index 0000000..f5ca3fa --- /dev/null +++ b/src/dataset/dataManipulation/pickles/BuildingMappings.txt @@ -0,0 +1,5 @@ +EECS +Duderstadt +Pierpont +BBB +FXB diff --git a/src/dataset/dataManipulation/pickles/pickleManage.py b/src/dataset/dataManipulation/pickles/pickleManage.py new file mode 100644 index 0000000..17f0a6f --- /dev/null +++ b/src/dataset/dataManipulation/pickles/pickleManage.py @@ -0,0 +1,30 @@ +import pickle + +# file to print current pickle files to text file +# this allows us to monitor current dictionaries +def printPickle(filename): + pickle_in = open(filename + '.pkl',"rb") + currDict = pickle.load(pickle_in) + f = open(filename + '.txt',"w") + for x in currDict: + f.write('%s\n' % x ) + f.close() + +# update pickle files to update dictionaries +# example: grades = {'Bart', 'Lisa', 'Milhouse', 'Nelson'} +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() + +def updatePickle(filename, pklList): + pickle_in = open(filename + '.pkl',"rb") + currDict = pickle.load(pickle_in) + f = open(filename + '.pkl', 'wb') # Pickle file is newly created where foo1.py is + pickle.dump(currDict + pklList, f) # dump data to f + f.close() + +# Example usage +# createPickle('test', {'Bart', 'Lisa', 'Milhouse', 'Nelson'}) +# updatePickle('test', {'Theo'}) +# printPickle("test") From 2ca6881cea236bbcbb74bb9a78f00c214eb7bc9f Mon Sep 17 00:00:00 2001 From: snbenge Date: Tue, 21 Apr 2020 22:51:03 -0400 Subject: [PATCH 2/4] adding file to change standard lat long alt to xyz coords --- src/dataset/dataManipulation/GPSmanip.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/dataset/dataManipulation/GPSmanip.py diff --git a/src/dataset/dataManipulation/GPSmanip.py b/src/dataset/dataManipulation/GPSmanip.py new file mode 100644 index 0000000..7ee0f2f --- /dev/null +++ b/src/dataset/dataManipulation/GPSmanip.py @@ -0,0 +1,24 @@ +import sys +import numpy as np + + +def gpstoLocalFrame(lat, lng, alt): + lat0 = 0.7381566413 + lng0 = -1.4610097151 + alt0 = 265.8 + + print(np.deg2rad(lng)) + dLat = np.deg2rad(lat) - lat0 + print(dLat) + 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) From 6bc969822bc91afd2ce5172e2ada47a0bfdf6656 Mon Sep 17 00:00:00 2001 From: snbenge Date: Wed, 22 Apr 2020 11:08:39 -0400 Subject: [PATCH 3/4] 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") From 51a2ff758f910921d5dd6ecc6c5a77faa3a47b8c Mon Sep 17 00:00:00 2001 From: Sabrina Date: Wed, 22 Apr 2020 11:22:32 -0400 Subject: [PATCH 4/4] Needed dependency for pickle things --- src/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Dockerfile b/src/Dockerfile index 1139682..58b7ac4 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -14,6 +14,7 @@ RUN pip install -U pip && \ matplotlib \ nltk \ setuptools \ - pylint + pylint \ + pickle-mixin CMD ["/bin/bash"]