Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -70,35 +70,8 @@ gpx_path = pathlib.Path(gpx_file)
|
|
70 |
with open('weather_icons_custom.json', 'r') as file:
|
71 |
icons = json.load(file)
|
72 |
|
73 |
-
def
|
74 |
-
|
75 |
-
def add_ele(x):
|
76 |
-
return elevation_data.get_elevation(x['latitude'], x['longitude'], 0)
|
77 |
-
|
78 |
-
df['srtm'] = df.apply(lambda x: add_ele(x), axis=1)
|
79 |
-
|
80 |
-
# Distance estimation function
|
81 |
-
|
82 |
-
def eukarney(lat1, lon1, alt1, lat2, lon2, alt2):
|
83 |
-
p1 = (lat1, lon1)
|
84 |
-
p2 = (lat2, lon2)
|
85 |
-
karney = distance.distance(p1, p2).m
|
86 |
-
return np.sqrt(karney**2 + (alt2 - alt1)**2)
|
87 |
-
|
88 |
-
# Create shifted columns in order to facilitate distance calculation
|
89 |
-
|
90 |
-
df['lat_shift'] = df['latitude'].shift(periods=-1).fillna(df['latitude'])
|
91 |
-
df['lon_shift'] = df['longitude'].shift(periods=-1).fillna(df['longitude'])
|
92 |
-
df['alt_shift'] = df['srtm'].shift(periods=-1).fillna(df['srtm'])
|
93 |
-
|
94 |
-
# Apply the distance function to the dataframe
|
95 |
-
|
96 |
-
df['distances'] = df.apply(lambda x: eukarney(x['latitude'], x['longitude'], x['srtm'], x['lat_shift'], x['lon_shift'], x['alt_shift']), axis=1).fillna(0)
|
97 |
-
df['distance'] = df['distances'].cumsum().round(decimals = 0).astype(int)
|
98 |
-
|
99 |
-
gpx_dict = df.loc[df.distance==df.distance.median()].iloc[-1].to_dict()
|
100 |
-
|
101 |
-
return gpx_dict
|
102 |
|
103 |
def map_icons(df):
|
104 |
|
@@ -254,7 +227,7 @@ def coor_gpx(gpx):
|
|
254 |
global sunrise
|
255 |
global sunset
|
256 |
|
257 |
-
with open(gpx
|
258 |
gpx_parsed = gpxpy.parse(f)
|
259 |
# Convert to a dataframe one point at a time.
|
260 |
points = []
|
@@ -268,7 +241,29 @@ def coor_gpx(gpx):
|
|
268 |
})
|
269 |
df_gpx = pd.DataFrame.from_records(points)
|
270 |
#gpx_dict = df_gpx.iloc[-1].to_dict()
|
271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
|
273 |
params['latitude'] = gpx_dict['latitude']
|
274 |
params['longitude'] = gpx_dict['longitude']
|
|
|
70 |
with open('weather_icons_custom.json', 'r') as file:
|
71 |
icons = json.load(file)
|
72 |
|
73 |
+
def add_ele(x):
|
74 |
+
return elevation_data.get_elevation(x['latitude'], x['longitude'], 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
def map_icons(df):
|
77 |
|
|
|
227 |
global sunrise
|
228 |
global sunset
|
229 |
|
230 |
+
with open(gpx) as f:
|
231 |
gpx_parsed = gpxpy.parse(f)
|
232 |
# Convert to a dataframe one point at a time.
|
233 |
points = []
|
|
|
241 |
})
|
242 |
df_gpx = pd.DataFrame.from_records(points)
|
243 |
#gpx_dict = df_gpx.iloc[-1].to_dict()
|
244 |
+
|
245 |
+
df_gpx['srtm'] = df_gpx.apply(lambda x: add_ele(x), axis=1)
|
246 |
+
|
247 |
+
# Distance estimation function
|
248 |
+
|
249 |
+
def eukarney(lat1, lon1, alt1, lat2, lon2, alt2):
|
250 |
+
p1 = (lat1, lon1)
|
251 |
+
p2 = (lat2, lon2)
|
252 |
+
karney = distance.distance(p1, p2).m
|
253 |
+
return np.sqrt(karney**2 + (alt2 - alt1)**2)
|
254 |
+
|
255 |
+
# Create shifted columns in order to facilitate distance calculation
|
256 |
+
|
257 |
+
df_gpx['lat_shift'] = df_gpx['latitude'].shift(periods=-1).fillna(df_gpx['latitude'])
|
258 |
+
df_gpx['lon_shift'] = df_gpx['longitude'].shift(periods=-1).fillna(df_gpx['longitude'])
|
259 |
+
df_gpx['alt_shift'] = df_gpx['srtm'].shift(periods=-1).fillna(df_gpx['srtm'])
|
260 |
+
|
261 |
+
# Apply the distance function to the dataframe
|
262 |
+
|
263 |
+
df_gpx['distances'] = df_gpx.apply(lambda x: eukarney(x['latitude'], x['longitude'], x['srtm'], x['lat_shift'], x['lon_shift'], x['alt_shift']), axis=1).fillna(0)
|
264 |
+
df_gpx['distance'] = df_gpx['distances'].cumsum().round(decimals = 0).astype(int)
|
265 |
+
|
266 |
+
gpx_dict = df_gpx.iloc[(df_gpx.distance - df_gpx.distance.median()).abs().argsort()[:1]].to_dict('records')[0]
|
267 |
|
268 |
params['latitude'] = gpx_dict['latitude']
|
269 |
params['longitude'] = gpx_dict['longitude']
|