-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from heyerbobby/master
Xarray version
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import numpy as np | ||
import xarray as xr | ||
import pandas as pd | ||
|
||
# File Details | ||
# TODO: pass as arguments to the script | ||
dt = '20201129' | ||
res = 25 | ||
step = '1hr' | ||
run = '{:02}'.format(0) | ||
lat_toplot = np.arange(-43, -17.25, 0.25) # last number is exclusive | ||
lon_toplot = np.arange(135, 152.25, 0.25) # last number is exclusive | ||
|
||
# ****************************** | ||
# SELECT GFS FILE | ||
# ****************************** | ||
# URL | ||
URL = f'http:https://nomads.ncep.noaa.gov:80/dods/gfs_0p{res}_{step}/gfs{dt}/gfs_0p{res}_{step}_{run}z' | ||
|
||
variables = ['ugrd100m', 'vgrd100m', 'dswrfsfc', 'tcdcclm', 'tcdcblcll', | ||
'tcdclcll', 'tcdcmcll', 'tcdchcll', 'tmp2m', 'gustsfc'] | ||
|
||
dataset = xr.open_dataset(URL)[variables] | ||
time = dataset.variables['time'] | ||
lat = dataset.variables['lat'][:] | ||
lon = dataset.variables['lon'][:] | ||
# lev = dataset.variables['lev'][:] | ||
|
||
# Narrow Down Selection | ||
time_toplot = time | ||
# lev_toplot = np.array([1000]) | ||
|
||
# Select required data via xarray | ||
dataset = dataset.sel(time=time_toplot, lon=lon_toplot, lat=lat_toplot) | ||
print(dataset) | ||
|
||
df = dataset.to_dataframe() | ||
# df = df.unstack(level=-1).fillna(0) | ||
print(df) |