NREL / developer.nrel.gov

An issue tracker for NREL's APIs available at https://developer.nrel.gov
43 stars 39 forks source link

Physical Solar Model (PSM) v3.2.2 cvs download issue #319

Closed Piotrus25 closed 1 year ago

Piotrus25 commented 1 year ago

Good Afternoon,

I've been using the PSM v3 api for a while and it has been working great. However, I have been unable to use the the new version to download the TMY 2021 data.

Here is my usual approach, just updated for the new API (with personal data removed):

    lat = 49
    lon = -124
    year = 2021
    api_key = 'vLf6Xo4XfgUWQICSKsYNvLbo4najdqORsTbXlk78'
    # Set the attributes to extract (e.g., dhi, ghi, etc.), separated by commas.
    attributes = 'air_temperature,dew_point,relative_humidity,wind_speed,surface_pressure'
    # 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 = 'Peter+Szymonowicz'
    # Your reason for using the NSRDB.
    reason_for_use = 'research'
    # Your affiliation
    your_affiliation = 'my company'
    # Your email address
    your_email = 'my email'
    # 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/nsrdb/v2/solar/psm3-2-2-download.cvs?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)
    print(url)
    # 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']
    # View metadata
    print(info)

However, my url must be incorrect since I am getting a HTTP Error 404: Not found message. I have also tried the POST request example:

lat = 47.63
lon = -122.34
year = 2021

#api_key = 'vLf6Xo4XfgUWQICSKsYNvLbo4najdqORsTbXlk78'
# Set the attributes to extract (e.g., dhi, ghi, etc.), separated by commas.
attributes = 'air_temperature,dew_point,relative_humidity,wind_speed,surface_pressure'
# 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 = '60'
# 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 = 'Peter+Szymonowicz'
# Your reason for using the NSRDB.
reason_for_use = 'research'
# Your affiliation
your_affiliation = 'my company'
# Your email address
your_email = 'my email'
# Please join our mailing list, so we can keep you up-to-date on new developments.
mailing_list = 'false'

url = "http://developer.nrel.gov/api/nsrdb/v2/solar/psm3-2-2-download.json?api_key=vLf6Xo4XfgUWQICSKsYNvLbo4najdqORsTbXlk78"

payload = "names={year}&leap_day={leap}&interval={interval}&utc={utc}&full_name={name}&email={email}&affiliation={affiliation}&mailing_list={mailing_list}&reason={reason}&attributes={attr}&wkt=POINT({lon},{lat})".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, attr=attributes)
headers = {
    'content-type': "application/x-www-form-urlencoded",
    'cache-control': "no-cache"
}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

With the following error: {"inputs":{"body":{},"params":{},"query":{}},"metadata":{"version":"2.0.0"},"status":400,"errors":["The required 'email' parameter must be a valid email address","The required 'wkt' or 'location_ids' must be a string or any array of integers respectively","The required 'names' or 'years' parameter must contain a list of comma separated numbers with values between 1998 and 2021"]}

Could someone please help me out with this?