-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathposition_scatterplot v2.py
More file actions
78 lines (63 loc) · 2.45 KB
/
position_scatterplot v2.py
File metadata and controls
78 lines (63 loc) · 2.45 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
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import contextily as ctx # Importer les tuiles OpenStreetMap
from pyproj import Proj, transform # Conversion en coordonnées projetées
import ast
import folium
# WGS84 vers Web Mercator (EPSG:3857) pour `contextily`
wgs84 = Proj(init="epsg:4326") # Latitude/Longitude
mercator = Proj(init="epsg:3857") # Web Mercator
# Constantes WGS84
a = 6378.137 # Demi-grand axe en km
e2 = 0.00669437999014 # Excentricité au carré
# Fonction de conversion ECEF → WGS84
def ecef_to_wgs84(x, y, z):
lon = np.arctan2(y, x)
rho = np.sqrt(x**2 + y**2)
phi = np.arctan2(z, rho * (1 - e2))
for _ in range(10):
N = a / np.sqrt(1 - e2 * np.sin(phi)**2)
h = rho / np.cos(phi) - N
phi_new = np.arctan2(z + e2 * N * np.sin(phi), rho)
if abs(phi_new - phi) < 1e-10:
break
phi = phi_new
lat = np.degrees(phi)
lon = np.degrees(lon)
return lat, lon
print("Chargement des données")
# Récupération des positions en ECEF
fichier = "gauthier_pos_20250312.txt"
with open(fichier, 'r') as f:
data = ast.literal_eval(f.read()) # sécurise l'évaluation
positions = np.array(data)[::100] # ndarray shape (N, 3)
print("Données chargées")
# Conversion en (latitude, longitude)
print("Conversion en latitude, longitude")
lat_lon = np.array([ecef_to_wgs84(*p) for p in positions])
# Convertir en coordonnées Web Mercator
print("Conversion en Web Mercantour")
x_merc, y_merc = transform(wgs84, mercator, lat_lon[:, 1], lat_lon[:, 0])
# Création de la figure
print("Création de la figure")
fig, ax = plt.subplots(figsize=(10, 6))
sns.kdeplot(x=x_merc, y=y_merc, cmap="Reds", fill=True, levels=100, alpha=0.8, ax=ax)
# Ajouter le fond de carte OpenStreetMap
print("Ajout du fond de carte")
ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik, zoom=1)
# Ajustement des axes
ax.set_xlabel("Longitude (°)")
ax.set_ylabel("Latitude (°)")
plt.title("Heatmap des positions GPS avec fond de carte")
plt.grid(True)
print("Affichage !")
plt.show()
# Carte centrée sur le centre des positions
center = [lat_lon[:, 0].mean(), lat_lon[:, 1].mean()]
m = folium.Map(location=center, zoom_start=12)
# Ajout des points
for lat, lon in lat_lon:
folium.CircleMarker(location=[lat, lon], radius=2, color="red", fill=True).add_to(m)
# Export ou affichage
m.save("carte_positions.html")