Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xarray version #4

Merged
merged 3 commits into from
Feb 18, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Create xarray version
  • Loading branch information
heyerbobby committed Nov 30, 2020
commit 427e89f3b9f67a830f9c6dfe77765b77c5ae3a8e
38 changes: 38 additions & 0 deletions xarray version
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np
import xarray as xr
import pandas as pd

# File Details
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)