pythondatetimeunidatapvlibthredds

Pvlib-Python Datetime Error 'Is not convertible to datetime'


I am trying to access forecast data by using the PVLib-Python command model.get_data(longitude, latitude, start, end) or model.get_processed_data(latitude, longitude, start, end) (where model = GFS()) but I am getting this error: TypeError: <class 'cftime._cftime.DatetimeGregorian'> is not convertible to datetime.

I have already used many versions of the PVLib-Python but hasn't worked though. Also, I checked the official documentation but they present the same error in te document (page 121 to 124 of the paper here https://readthedocs.org/projects/cwhanse-pvlib-python/downloads/pdf/latest/).

Here is some of the basic code:

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

latitude = 32.2
longitude = -110.9 
tz = 'America/Phoenix'

start = pd.Timestamp(datetime.date.today(), tz=tz) # today's date
end = start + pd.Timedelta(days=7) # 7 days from today

model = GFS()

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

data.plot(figsize=(12,12), subplots=True)

Solution

  • The error occurs in the datetime class, which is in the cftime pacakage. I get the error when I use cftime version 1.1.1.2, whereas when I do not get the error when I use version 1.0.3.4.

    The easiest solution is to down grade your cftime pacakge. If your using Anaconda, then running the following command in an Anaconad prompt will do that:

    conda install -c conda-forge cftime=1.0.3.4
    

    There is some discusion on the topic on cftime's project website: https://pypi.org/project/cftime/

    Update: the bug has been fixed in the new pvlib release pvlib-0.7.2. The bug is described further here: https://github.com/pvlib/pvlib-python/issues/895