Giter VIP home page Giter VIP logo

ibm / ibmpairs Goto Github PK

View Code? Open in Web Editor NEW
35.0 11.0 18.0 71.27 MB

IBM Environmental Intelligence Geospatial APIs SDK

Home Page: https://www.ibm.com/products/environmental-intelligence

License: BSD 3-Clause "New" or "Revised" License

Python 57.17% Jupyter Notebook 42.69% Dockerfile 0.04% Makefile 0.08% Batchfile 0.02%
ibm-research ibm-pairs-geoscope geospatial environmental-intelligence ibm ibm-software restful-api sustainability geospatial-apis

ibmpairs's Introduction

IBM Environmental Intelligence (EI): Geospatial APIs SDK

PyPI Package

This repository provides an interface to the IBM EI: Geospatial APIs component: IBM EI: Geospatial APIs.

E.g. the query module in the subdirectory ibmpairs serves as a wrapper employing the IBM EI: Geospatial APIs served through the RESTful host reachable via https://api.ibm.com/geospatial/run/na/core/v3/.

Sample applications that use ibmpairs can be located in the Environmental-Intelligence project.

General Notes

If you like to contribute, please read CONTRIBUTING.md first. A list of maintainers is recorded in MAINTAINERS.md.

Installation and Usage

If you have installed the Python package manager PIP, simply run

pip install --user ibmpairs

Then you can import the IBM EI: Geospatial APIs SDK wrapper modules e.g.:

import ibmpairs.client as client
import ibmpairs.query as query

Getting started

See the documentation here and try our tutorials.

Running in a Docker container

A self-contained environment can be built with Docker using

git clone https://github.com/ibm/ibmpairs
cd ibmpairs
make docker-build

then run using:

make docker-run

the environment can then be accessed from the following url:

http://localhost:18380

Alternatively you can execute these steps without Make using:

git clone https://github.com/ibm/ibmpairs
cd ibmpairs
docker build -t ibmpairs .

to build and

docker run \
    -dit \
    -p 18380:18380 \
    --name ibmpairs \
    ibmpairs:latest

or:

docker-compose up ibmpairs

to run.

ibmpairs's People

Contributors

cmalbrec avatar johannesschmude avatar taylorsteffanj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ibmpairs's Issues

Querying PAIRS resulted in HTML error code '500'

hi there,
I'm trying to execute the IBM PAIRS API wrapper tutorial notebook and this error occurs when executing the 13th cell with the following message:
"ERROR - 2019-06-24 14:14:13,227: "Unable to load point data into dataframe: 'Querying PAIRS resulted in HTML error code '500': {}.'." [submit]"
any idea on how to resolve the problem?
I've tried to change the point data and the date and it didn't work!
Thanks in advanced

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

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': .

querying pairs with dash in `alias` field causes `INFO - 2019-07-08 11:37:59,837: "Downloading data not an option (yet), status code is '41'" [download]`

query payload

query_json = {
    'layers': [
        {
            'alias': 'data_0000',
            'id': '49464',
            'output': 'true',
            'type': 'raster'
        },
        {
            'alias': 'condition_0000',
            'id': '49362',
            'output': 'true',
            'type': 'raster'
        },
        {
            'alias': 'target-result',
            'expression': '($condition_0000 >= 4 && $condition_0000 <= 6) ? $data_0000 : 100',
            'output': 'true'
        },
        {
            'alias': 'control',
            'expression': '($condition_0000 >= 4 && $condition_0000 <= 6) ? 1 : 0',
            'output': 'true'
        }
    ],
    'name': 'NDIV_Masking',
    'spatial': {'coordinates': (48.6719428, 4.0362544, 48.7118297, 4.1159053),'type': 'square'},
    'temporal': {'intervals': [{'snapshot': '2019-04-28T00:00:00Z'}]}
}                    

logs

INFO - 2019-07-08 11:36:45,312: "Alright, PAIRS query sucessfully submitted, the reference ID is: 1562558400_23805228" [submit]
INFO - 2019-07-08 11:37:59,837: "Downloading data not an option (yet), status code is '41'" [download]

Is the Notebook re-run on a regular basis to check it works ?

I have attempted to run this Notebook within Watson Studio but have reached a step where an error stops further actions to be executed.

Is this Notebook checked on a regular basis ?

submit PAIRS point query

pointQuery.submit()
pointQuery.poll_till_finished()
pointQuery.download()
pointQuery.create_layers()

[Out]

gaierror Traceback (most recent call last)
/opt/conda/envs/Python36/lib/python3.6/site-packages/urllib3/connection.py in _new_conn(self)
158 conn = connection.create_connection(
--> 159 (self._dns_host, self.port), self.timeout, **extra_kw)
160

/opt/conda/envs/Python36/lib/python3.6/site-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
56
---> 57 for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
58 af, socktype, proto, canonname, sa = res

/opt/conda/envs/Python36/lib/python3.6/socket.py in getaddrinfo(host, port, family, type, proto, flags)
744 addrlist = []
--> 745 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
746 af, socktype, proto, canonname, sa = res

gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

NewConnectionError Traceback (most recent call last)
/opt/conda/envs/Python36/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
599 body=body, headers=headers,
--> 600 chunked=chunked)
601

/opt/conda/envs/Python36/lib/python3.6/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
342 try:
--> 343 self._validate_conn(conn)
344 except (SocketTimeout, BaseSSLError) as e:

/opt/conda/envs/Python36/lib/python3.6/site-packages/urllib3/connectionpool.py in _validate_conn(self, conn)
838 if not getattr(conn, 'sock', None): # AppEngine might not have .sock
--> 839 conn.connect()
840

/opt/conda/envs/Python36/lib/python3.6/site-packages/urllib3/connection.py in connect(self)
300 # Add certificate verification
--> 301 conn = self._new_conn()
302 hostname = self.host

/opt/conda/envs/Python36/lib/python3.6/site-packages/urllib3/connection.py in _new_conn(self)
167 raise NewConnectionError(
--> 168 self, "Failed to establish a new connection: %s" % e)
169

NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7fcc290495f8>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

MaxRetryError Traceback (most recent call last)
/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
448 retries=self.max_retries,
--> 449 timeout=timeout
450 )

/opt/conda/envs/Python36/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
637 retries = retries.increment(method, url, error=e, _pool=self,
--> 638 _stacktrace=sys.exc_info()[2])
639 retries.sleep()

/opt/conda/envs/Python36/lib/python3.6/site-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
397 if new_retry.is_exhausted():
--> 398 raise MaxRetryError(_pool, url, error or ResponseError(cause))
399

MaxRetryError: HTTPSConnectionPool(host='pairs.res.ibm', port=443): Max retries exceeded with url: /v2/query (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fcc290495f8>: Failed to establish a new connection: [Errno -2] Name or service not known',))

During handling of the above exception, another exception occurred:

ConnectionError Traceback (most recent call last)
/opt/conda/envs/Python36/lib/python3.6/site-packages/ibmpairs/paw.py in submit(self)
961 auth = self.auth,
--> 962 verify = self.verifySSL,
963 )

/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/api.py in post(url, data, json, **kwargs)
115
--> 116 return request('post', url, data=data, json=json, **kwargs)
117

/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/api.py in request(method, url, **kwargs)
59 with sessions.Session() as session:
---> 60 return session.request(method=method, url=url, **kwargs)
61

/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
532 send_kwargs.update(settings)
--> 533 resp = self.send(prep, **send_kwargs)
534

/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/sessions.py in send(self, request, **kwargs)
645 # Send the request
--> 646 r = adapter.send(request, **kwargs)
647

/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
515
--> 516 raise ConnectionError(e, request=request)
517

ConnectionError: HTTPSConnectionPool(host='pairs.res.ibm', port=443): Max retries exceeded with url: /v2/query (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fcc290495f8>: Failed to establish a new connection: [Errno -2] Name or service not known',))

During handling of the above exception, another exception occurred:

Exception Traceback (most recent call last)
in
1 # submit PAIRS point query
----> 2 pointQuery.submit()
3 pointQuery.poll_till_finished()
4 pointQuery.download()
5 pointQuery.create_layers()

/opt/conda/envs/Python36/lib/python3.6/site-packages/ibmpairs/paw.py in submit(self)
964 except Exception as e:
965 raise Exception(
--> 966 'Sorry, I have trouble to submit your query: {}.'.format(e)
967 )
968 # check that submission return is proper JSON

Exception: Sorry, I have trouble to submit your query: HTTPSConnectionPool(host='pairs.res.ibm', port=443): Max retries exceeded with url: /v2/query (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fcc290495f8>: Failed to establish a new connection: [Errno -2] Name or service not known',)).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.