Variable import error

20 views
Skip to first unread message

Suhee Yoon

unread,
May 10, 2021, 10:44:09 PM5/10/21
to pvlib-python
I tried to get dataset from GFS model, but i encounter this problem.
I seems like the internal package problem, so it would be nice if you can fix or let me know the way how to deal this issue. 
스크린샷 2021-05-10 오후 1.45.14.png
스크린샷 2021-05-10 오후 1.45.30.png

Bobby Heyer

unread,
May 10, 2021, 11:59:31 PM5/10/21
to pvlib-python
Hi Suhee

I think this might be an error due to GFS had changing the variable names of cloud cover fields. 

A fix was included in pvlib v0.9.0a7, try updating your library and see if that resolves the issue. 

Alternatively, as a work around, you could manually import GFS data and then rename columns to work with pvlib

# ******************************
# File Details
# ******************************
# Details
datefix = datetime.strptime((date.today() - timedelta(days=1)).strftime("%#d/%#m/%Y"), '%d/%m/%Y')
dt = (date.today() - timedelta(days=1)).strftime("%Y%m%d")

res = 25
step = '1hr'
run = '{:02}'.format(12)
lat_toplot = np.arange(-44, -9.75, 0.25) # last number is exclusive
lon_toplot = np.arange(115, 159.25, 0.25) # last number is exclusive
time_toplot = pd.date_range(datefix + timedelta(hours=int(run)) + timedelta(hours=1), freq='H', periods=120)

# ******************************
# SELECT GFS FILE
# ******************************
# URL
URL = f'http://nomads.ncep.noaa.gov:80/dods/gfs_0p{res}_{step}/gfs{dt}/gfs_0p{res}_{step}_{run}z'
print(URL)

# GFS Variables desired
variables = ['dswrfsfc', 'tcdcclm', 'lcdclcll', 'mcdcmcll', 'hcdchcll', 'tmp2m', 'gustsfc']

# Get GFS Data
dataset = xr.open_dataset(URL)[variables].sel(time=time_toplot, lon=lon_toplot, lat=lat_toplot)
print(dataset)

# Convert to Dataframe and update fields
df = dataset.to_dataframe()
df['tmp2m'] = df['tmp2m'].values - 273.15
df = df.rename(columns={
"tmp2m": "temp_air",
"gustsfc": "wind_speed",
"dswrfsfc": "ghi",
"tcdcclm": "total_clouds",
"lcdclcll": "low_clouds",
"mcdcmcll": "mid_clouds",
"hcdchcll": "high_clouds"
})
Reply all
Reply to author
Forward
0 new messages