Skip to content
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

Error 422 - Unable to load point data into dataframe employing format 'text/csv' #33

Open
iMarang opened this issue Jun 17, 2022 · 0 comments

Comments

@iMarang
Copy link

iMarang commented Jun 17, 2022

Hi,
I'm getting an error 422 on a point query, and I don't understand the accompanying PAIRS description.

#-------------------------------------------------------------------------------------------------------------

Code

paw.load_environment_variables() # previously added the api_key as well as pass file location to env

Select variables: ["PRECIP","TMAX","TMIN","TAVG"]

Variables = ["PRECIP","TMAX","TMIN","TAVG"]

Choose forecast initialization time

start_forecast_date = datetime.strptime("2021-05-01", "%Y-%m-%d")

How many months of forecast to query

Note that the forecast duration is 7 months from 2021 and 6 months before 2021

forecast_length_months = 7
Longitude=147.96;Latitude=-31.98

Specify station name and lat/lon

station_name = 'Trangie'
lat, lon = -31.98,147.96

print('Obtaining data for', station_name, "at", str(lat), str(lon))

Designate PAIRS layers for query

TWC-SPFP

layers_TWC = {"PRECIP": 50686, "TMIN": 50683, "TMAX": 50684, "TAVG": 50685}

ERA5 1991-2020 Climatology

layers_ERA5 = {"PRECIP": 51198, "TMIN": 51217, "TMAX": 51200, "TAVG": 51199}

Terrain elevation height for adiabatic lapse rate correction of TMAX and TAVG

layers_ELEVATION = {"twc_elevation": 51219, "srtm_elevation": 49506}

Compute the list of valid_dates and horizons used to make the PAIRS query

valid_dates_horizons = []
count = 0
date = start_forecast_date
while date < start_forecast_date + relativedelta(months=forecast_length_months):
valid_date = start_forecast_date + timedelta(days=count)
horizon = (valid_date - start_forecast_date).days
valid_dates_horizons.append([valid_date, horizon])
count += 1
date += timedelta(days=1)

print('Forecast Start Date:', valid_dates_horizons[0][0])
print('Forecast End Date:', valid_dates_horizons[-1][0])

Define dictionary to store the height for TWC and ERA5

elevation = {}
for VARIABLE in ["twc_elevation","srtm_elevation"]:

### Create json string to query PAIRS database
query_json = {
"layers" : [
    {"type" : "raster", "id" : layers_ELEVATION[VARIABLE]}
],
"spatial" : {"type" : "point", "coordinates" : [lat, lon]},
"temporal" : {"intervals" : [
    ### used the latest elevation height available in PAIRS
    {"snapshot" : "2020-01-01T00:00:00Z"}
]}
}

### Define query object using PAIRSquery library
query = paw.PAIRSQuery(query_json,PAIRS_SERVER,authType='api-key', overwriteExisting=True)
### Submit query
query.submit()

### Extract elevation data
elevation[VARIABLE] = query.vdf.value

Compute lapse-rate correction for temperature

elevation_diff = elevation['srtm_elevation'].values[0] - elevation['twc_elevation'].values[0]
temperature_adjustment = elevation_diff*(-0.0098)

print('SRTM elevation: '+str(elevation['srtm_elevation'].values[0])+' m, TWC elevation: '+str(elevation['twc_elevation'].values[0])+' m')
print('')
print('Temperature adjustment of '+str(np.round(temperature_adjustment,3))+' C to be applied to TMAX and TAVG')

#------------------------------------------------------------------------------------------------------------------------------

Error

pairsHost='https://pairs.res.ibm.com/' and baseURI='/' merged to: 'https://pairs.res.ibm.com/'
Unable to load point data into dataframe employing format 'text/csv': 'Querying PAIRS resulted in HTTP error code '422': .'.

Exception Traceback (most recent call last)
Input In [12], in <cell line: 3>()
20 query = paw.PAIRSQuery(query_json,PAIRS_SERVER,authType='api-key', overwriteExisting=True)
21 # Submit query
---> 22 query.submit()
24 # Extract elevation data
25 elevation[VARIABLE] = query.vdf.value

File ~\Miniconda3\envs\py3_ibm\lib\site-packages\ibmpairs\paw.py:1131, in PAIRSQuery.submit(self)
1129 try:
1130 if self.queryStatus.status_code != 200:
-> 1131 raise Exception(
1132 "Querying PAIRS resulted in HTTP error code '{}': {}.".format(
1133 self.queryStatus.status_code,
1134 self.queryStatus.text,
1135 )
1136 )
1137 else:
1138 if self.PAIRS_POINT_QUERY_RESP_FORMAT.lower()=='text/csv':

Exception: Querying PAIRS resulted in HTTP error code '422': .

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

1 participant