Skip to content

pvlib.forecast has stopped working #1423

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

Closed
DavidLloydNGP opened this issue Mar 10, 2022 · 4 comments
Closed

pvlib.forecast has stopped working #1423

DavidLloydNGP opened this issue Mar 10, 2022 · 4 comments

Comments

@DavidLloydNGP
Copy link

Hi,

The example code for importing a forecast from GFS has stopped working for me.


from pvlib.forecast import GFS, NAM, NDFD, HRRR, RAP
import pandas as pd
import datetime

latitude, longitude, tz = 32.2, -110.9, 'US/Arizona'


start = pd.Timestamp(datetime.date.today(), tz=tz)

end = start + pd.Timedelta(days=7)

irrad_vars = ['ghi', 'dni', 'dhi']

model = GFS()

raw_data = model.get_data(latitude, longitude, start, end)

print(raw_data.head())

returns an error now:

lib\xml\etree\ElementTree.py", line 1321, in XML
    return parser.close()

  File "<string>", line unknown
ParseError: no element found: line 1, column 0

python version is 3.8 and numpy version is 1.21.2.

Has anyone else encountered this problem?

I was able to read in forecasted data without problems previously but I don't know what's changed between then and now.

Thanks,
David

@cwhanse
Copy link
Member

cwhanse commented Mar 10, 2022

@DavidLloydNGP I've seen that error when an empty file is returned by the THREDDS server. In this case, the error occurs on this line. (I ran your code in the Spyder debugger). A few lines earlier, the model_url is constructed: "https://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p5deg/catalog.xml" Pasting that URL in a browser returns an empty page.

This appears to be a THREDDS issue. Perhaps pvlib could return a more informative error somehow.

@DavidLloydNGP
Copy link
Author

Thanks @cwhanse for that. Subsequent to my post, I had even tried running the code in a new virtual environment, hoping it was a problem with another library but I received the same error. I think this supports your analysis that something is amiss further upstream with THREDDS.

I managed to 'solve' this problem by bypassing pvlib and using siphon directly to access GFS data. For instance, to download the wind data for the next 24 hours for Greenwich, London:

# adapted from
#https://unidata.github.io/python-training/workshop/Bonus/downloading-gfs-with-siphon/

from siphon.catalog import TDSCatalog
import datetime
import pytz


# list of relevant wind variables
var_list = ['u-component_of_wind_isobaric','v-component_of_wind_isobaric',\
            'Wind_speed_gust_surface']

# query 0.5 degree model, same as pvlib
best_gfs = TDSCatalog('http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/'
                      'Global_0p5deg/catalog.xml?dataset=grib/NCEP/GFS/Global_0p5deg/Best')
best_ds = list(best_gfs.datasets.values())[0]
ncss = best_ds.subset()

query = ncss.query()
    
# single geographic location
query.lonlat_point(lat = 0, lon = 0)

# read in data for next 24 hours
timezone = pytz.timezone("Europe/London")
T0 = datetime.datetime.now().astimezone(timezone)
query.time_range(T0, T0 + datetime.timedelta(days = 1))

query.accept('netcdf4')

# loop over wind variables
for var in var_list:
    query.variables(var)
    
query.vertical_level(100000)

dataset = ncss.get_data(query)

surface_wind_gust = dataset.variables['Wind_speed_gust_surface'][0].data
u_isobaric = dataset.variables['u-component_of_wind_isobaric'][0].data
v_isobaric = dataset.variables['v-component_of_wind_isobaric'][0].data

I have done a few non-exhaustive checks and the data obtained this way seems identical to data I had previously downloaded using pvlib. Given the pvlib forecast function always came with a 'highly experimental' warning anyway, I think I am going to stick with the siphon approach, even it requires a little more coding on my part to replicate the ease of pvlib.

@kandersolar
Copy link
Member

FWIW the example code at the top of this thread seems to work again. Still worth considering a nicer error message though.

@cwhanse
Copy link
Member

cwhanse commented Mar 16, 2022

THREDDS appears to be working (at least today it is). Closing in anticipation on #1426

@cwhanse cwhanse closed this as completed Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants