BACKGROUND
I am trying to download GFS weather data netcdf4 files via xarray & OPeNDAP. Big thanks to Vorticity0123 for their prior post, which allowed me to get the bones of the python script sorted (as below).
PROBLEM
Thing is, the GFS dataset has 195 data variables, But I don't require the majority, I only need ten of them.
- ugrd100m, vgrd100m, dswrfsfc, tcdcclm, tcdcblcll, tcdclcll, tcdcmcll, tcdchcll, tmp2m, gustsfc
HELP REQUESTED
I've gone through the xarray readthedocs page and elsewhere, but I couldn't figure out a way to narrow down my dataset to only the ten data variables. Does anyone know how to narrow down the list of variables in a dataset?
PYTHON SCRIPT
import numpy as np
import xarray as xr
# File Details
dt = '20201124'
res = 25
step = '1hr'
run = '{:02}'.format(18)
# URL
URL = f'http://nomads.ncep.noaa.gov:80/dods/gfs_0p{res}_{step}/gfs{dt}/gfs_0p{res}_{step}_{run}z'
# Load data
dataset = xr.open_dataset(URL)
time = dataset.variables['time']
lat = dataset.variables['lat'][:]
lon = dataset.variables['lon'][:]
lev = dataset.variables['lev'][:]
# Narrow Down Selection
time_toplot = time
lat_toplot = np.arange(-43, -17, 0.5)
lon_toplot = np.arange(135, 152, 0.5)
lev_toplot = np.array([1000])
# Select required data via xarray
dataset = dataset.sel(time=time_toplot, lon=lon_toplot, lat=lat_toplot)
print(dataset)