【问题标题】:Why am I receiving a 400 Error when trying to fetch data from the NSRDB API为什么我在尝试从 NSRDB API 获取数据时收到 400 错误
【发布时间】:2021-06-23 22:33:15
【问题描述】:

我正在尝试通过格式化的 URL 从 NSRDB PSM API 获取数据,但我不断收到 HTTP 400 错误,并且无法从堆栈跟踪中获得具体原因。

以下是代码:

# Declare all variables as strings. Spaces must be replaced with '+', i.e., change 'John Smith' to 'John+Smith'.
# Define the lat, long of the location and the year
#Using UWI, St. Augustine Campus as the Target, 10.6416° N, 61.3995° W
lat, lon, year = 10.6416, 61.3995, 2019

# You must request an NSRDB api key from the link above(replace this with your API key
api_key = 'xxxxxxxxxxxxxxx'

# Set the attributes to extract (e.g., dhi, ghi, etc.), separated by commas.
attributes = 'ghi,dhi,dni,wind_speed,air_temperature,solar_zenith_angle'

# Set leap year to true or false. True will return leap day data if present, false will not.
leap_year = 'false'

# Set time interval in minutes, i.e., '30' is half hour intervals. Valid intervals are 30 & 60.
interval = '30'

# Specify Coordinated Universal Time (UTC), 'true' will use UTC, 'false' will use the local time zone of the data.
# NOTE: In order to use the NSRDB data in SAM, you must specify UTC as 'false'. SAM requires the data to be in the
# local time zone.
utc = 'false'

# Your full name, use '+' instead of spaces.
your_name = 'Shankar+Ramharack'

# Your reason for using the NSRDB.
reason_for_use = 'research'

# Your affiliation
your_affiliation = 'UWI'

# Your email address
your_email = 'XXXXXXX'

# Please join our mailing list so we can keep you up-to-date on new developments.
mailing_list = 'false'

# Declare url string
url = 'https://developer.nrel.gov/api/solar/nsrdb_psm3_download.csv?wkt=POINT({lon}%20{lat})&names={year}&leap_day={leap}&interval={interval}&utc={utc}&full_name={name}&email={email}&affiliation={affiliation}&mailing_list={mailing_list}&reason={reason}&api_key={api}&attributes={attr}'.format(year=year, lat=lat, lon=lon, leap=leap_year, interval=interval, utc=utc, name=your_name, email=your_email, mailing_list=mailing_list, affiliation=your_affiliation, reason=reason_for_use, api=api_key, attr=attributes)
# Return just the first 2 lines to get metadata:
info = pd.read_csv(url, nrows=1)
# See metadata for specified properties, e.g., timezone and elevation
timezone, elevation = info['Local Time Zone'], info['Elevation']

我按照他们页面上指定的方法:here。我不确定我是在阅读时出现 pandas 错误还是特定的 python 错误。我对这门语言比较陌生。

【问题讨论】:

    标签: python pandas api csv urllib


    【解决方案1】:

    我收到了开发人员的反馈,这是他们网站上的一个问题,他们目前正在更新文档。要访问数据,请使用以下命令:

    df = pd.read_csv('https://developer.nrel.gov/api/nsrdb/v2/solar/psm3-download.csv?wkt=POINT({lon}%20{lat})&names={year}&leap_day={leap}&interval={interval}&utc={utc}&full_name={name}&email={email}&affiliation={affiliation}&mailing_list={mailing_list}&reason={reason}&api_key={api}&attributes={attr}'.format(year=year, lat=lat, lon=lon, leap=leap_year, interval=interval, utc=utc, name=your_name, email=your_email, mailing_list=mailing_list, affiliation=your_affiliation, reason=reason_for_use, api=api_key, attr=attributes), skiprows=2)
    
    

    获取 NSRDB 数据的另一种方法是使用 pvlib 库中的包装函数。源代码可以在here找到。使用 pvlib.iotools.get_psm3() 函数,可以从 PSM 模型 API 中查询数据。

    使用最新版本以获得最佳性能。

    【讨论】:

      猜你喜欢
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 2021-09-23
      • 2021-12-15
      • 1970-01-01
      • 2021-08-05
      • 1970-01-01
      • 2020-10-11
      相关资源
      最近更新 更多