Skip to content

Commit 7275c1a

Browse files
authored
Merge pull request #4 from heyerbobby/master
Xarray version
2 parents c5e7c91 + a37b885 commit 7275c1a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

xarray_example.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import numpy as np
2+
import xarray as xr
3+
import pandas as pd
4+
5+
# File Details
6+
# TODO: pass as arguments to the script
7+
dt = '20201129'
8+
res = 25
9+
step = '1hr'
10+
run = '{:02}'.format(0)
11+
lat_toplot = np.arange(-43, -17.25, 0.25) # last number is exclusive
12+
lon_toplot = np.arange(135, 152.25, 0.25) # last number is exclusive
13+
14+
# ******************************
15+
# SELECT GFS FILE
16+
# ******************************
17+
# URL
18+
URL = f'http://nomads.ncep.noaa.gov:80/dods/gfs_0p{res}_{step}/gfs{dt}/gfs_0p{res}_{step}_{run}z'
19+
20+
variables = ['ugrd100m', 'vgrd100m', 'dswrfsfc', 'tcdcclm', 'tcdcblcll',
21+
'tcdclcll', 'tcdcmcll', 'tcdchcll', 'tmp2m', 'gustsfc']
22+
23+
dataset = xr.open_dataset(URL)[variables]
24+
time = dataset.variables['time']
25+
lat = dataset.variables['lat'][:]
26+
lon = dataset.variables['lon'][:]
27+
# lev = dataset.variables['lev'][:]
28+
29+
# Narrow Down Selection
30+
time_toplot = time
31+
# lev_toplot = np.array([1000])
32+
33+
# Select required data via xarray
34+
dataset = dataset.sel(time=time_toplot, lon=lon_toplot, lat=lat_toplot)
35+
print(dataset)
36+
37+
df = dataset.to_dataframe()
38+
# df = df.unstack(level=-1).fillna(0)
39+
print(df)

0 commit comments

Comments
 (0)