-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_geojson.py
42 lines (37 loc) · 1.32 KB
/
parse_geojson.py
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
import numpy as np
from datetime import datetime
# Parse the GeoJSON data for Skew-T plot
def parse_geojson(data):
pressures = [] # in hPa
temperatures = [] # in Celsius
dewpoints = [] # in Celsius
wind_u = [] # in m/s
wind_v = [] # in m/s
heights = [] # Geopotential height in meters
timestamp = 0 # Unix timestamp
for feature in data['features']:
if feature['geometry']['type'] == 'Point':
props = feature['properties']
pressures.append(props['pressure'])
temperatures.append(props['temp'] - 273.15) # Convert Kelvin to Celsius
dewpoints.append(props['dewpoint'] - 273.15) # Convert Kelvin to Celsius
wind_u.append(props['wind_u'])
wind_v.append(props['wind_v'])
heights.append(props['gpheight'])
# Extract latitude and longitude
lat = data['properties']['lat']
lon = data['properties']['lon']
# Unix timestamp
timestamp = data['properties']['syn_timestamp']
timestamp = datetime.utcfromtimestamp(timestamp) # Convert the timestamp to a datetime object
return (
np.array(pressures),
np.array(temperatures),
np.array(dewpoints),
np.array(wind_u),
np.array(wind_v),
np.array(heights),
lat,
lon,
timestamp
)