This repository was archived by the owner on Jul 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathadd_data_to_meta.py
More file actions
106 lines (83 loc) · 3.4 KB
/
Copy pathadd_data_to_meta.py
File metadata and controls
106 lines (83 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Galen Weld, April 2019
# Use this to add metadata to existing sidecars
# before running, make sure to check:
# 1) that you have the correct city center point defined
# 2) that you have the correct shapefile for that city loaded into the label-intersection-proximity code
import sys
import os
label_intersection_dir = '/mnt/c/Users/gweld/sidewalk/label-intersection-proximity'
sys.path.append( label_intersection_dir )
from intersection_proximity import compute_proximity
from GSVutils.utils import add_metadata, extract_pano_lat_lng
from math import sin, cos, atan2, radians, degrees, sqrt
# DEFINE THE CENTER OF WASHINGTON DC HERE
dc_lat, dc_lng = 38.8977, -77.0366
# this is the middle of the White House
# DEFINE THE CENTER OF NEWBERG HERE
nb_lat, nb_lng = 45.3003, -122.9755
# DEFINTE THE CENTER OF SEATTLE HERE
sea_lat, sea_lng = 47.6062, -122.3350
center = (sea_lat, sea_lng)
def calc_bearing_and_distance_between_points(lat1, lng1, lat2=center[0], lng2=center[1]):
''' returns a tuple of the bearing and distance between
two latitude and longitude points'''
lat1 = radians(lat1)
lng1 = radians(lng1)
lat2 = radians(lat2)
lng2 = radians(lng2)
delta_lat = abs( lat2-lat1 )
delta_lng = abs( lng2-lng1 )
# let's calculate the bearing
# https://www.igismap.com/formula-to-find-bearing-or-heading-angle-between-two-points-latitude-longitude/
x = cos(lat2) * sin( delta_lng )
y = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta_lng)
#print("x:{},y:{}".format(x,y))
bearing = degrees( atan2(x,y) )
# let's calculate the distance
# https://andrew.hedges.name/experiments/haversine/
R = 3961 #miles
# this value is approximately correct for the area around Washington DC
a = (sin(delta_lat/2))**2 + cos(lat1) * cos(lat2) * (sin(delta_lng/2))**2
c = 2 * atan2( sqrt(a), sqrt(1-a) )
dist = R * c #where R is the radius of the Earth
return bearing, dist
def helper(input_dict):
#print(input_dict)
pano_id = input_dict[u'pano id']
err = False
try:
lat, lng = extract_pano_lat_lng(pano_id, '/mnt/g/scrapes_dump_seattle')
except Exception as e:
print(e)
lat = float('nan')
lng = float('nan')
err = True
input_dict[u'latitude'] = lat
input_dict[u'longitude'] = lng
try:
distance, middleness = compute_proximity(lat, lng)
except Exception as e:
print(e)
distance = float('nan')
middleness = float('nan')
err = True
input_dict[u'dist to intersection'] = distance
input_dict[u'block middleness'] = middleness
try:
bearing, distance = calc_bearing_and_distance_between_points(lat, lng)
except Exception as e:
print(e)
bearing = float('nan')
distance = float('nan')
err = True
input_dict[u'bearing to cbd'] = bearing
input_dict[u'dist to cbd'] = distance
return input_dict, err
#add_metadata('/mnt/c/Users/gweld/sidewalk/sidewalk_ml/baby_ds', helper)
#add_metadata('/mnt/e/new_old_dataset', helper, "/mnt/e/new_metadata_files_for_cc")
add_metadata('/mnt/g/seattle_center_crops_researchers/', helper, verbose=True)
# let's do this for ground truth
#add_metadata('/mnt/c/Users/gweld/sidewalk/sidewalk_ml/sliding_window/ground_truth_crops', helper)
# if not os.path.isdir('/mnt/g/newberg_new_cc_meta/partitioned/'):
# os.mkdir('/mnt/g/newberg_new_cc_meta/partitioned/')
# add_metadata('/mnt/g/newberg_cc_researchers_partitioned', helper, '/mnt/g/newberg_new_cc_meta/partitioned')