Spaces:
Running on Zero
Running on Zero
File size: 2,303 Bytes
a74054f | 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 | """Download elevation data for all 27 stations using Open Topo Data API."""
import requests
import pandas as pd
import time
from pathlib import Path
# Load stations
stations = pd.read_csv('datasets/station_list.csv')
print(f"Downloading elevation for {len(stations)} stations...")
elevations = []
for idx, row in stations.iterrows():
station_code = row['station_code']
lat = row['lat']
lon = row['lon']
# Query Open Topo Data API
url = f"https://api.opentopodata.org/v1/eudem25m?locations={lat},{lon}"
try:
response = requests.get(url, timeout=10)
if response.status_code == 200:
data = response.json()
elevation = data['results'][0]['elevation']
elevations.append({
'station_code': station_code,
'station_name': row['station_name'],
'latitude': lat,
'longitude': lon,
'elevation_m': elevation,
'data_source': 'EU-DEM 25m (Open Topo Data)'
})
print(f"✓ {station_code}: {elevation:.1f} m")
else:
print(f"✗ {station_code}: API error {response.status_code}")
elevations.append({
'station_code': station_code,
'station_name': row['station_name'],
'latitude': lat,
'longitude': lon,
'elevation_m': None,
'data_source': 'Failed'
})
except Exception as e:
print(f"✗ {station_code}: {e}")
elevations.append({
'station_code': station_code,
'station_name': row['station_name'],
'latitude': lat,
'longitude': lon,
'elevation_m': None,
'data_source': 'Failed'
})
# Rate limiting
time.sleep(3)
# Save
df_elevation = pd.DataFrame(elevations)
output_file = Path('datasets/station_elevations.csv')
df_elevation.to_csv(output_file, index=False)
print(f"\n✓ Saved to: {output_file}")
print(f"✓ Success: {df_elevation['elevation_m'].notna().sum()}/{len(df_elevation)} stations")
print(f"\nElevation range: {df_elevation['elevation_m'].min():.1f} - {df_elevation['elevation_m'].max():.1f} m")
|