import threading num_workers = int(os.environ.get("GBDX_THREADS", 4)) threaded_get = partial(dask.threaded.get, num_workers=num_workers) import requests import pycurl _curl_pool = defaultdict(pycurl.Curl) from gbdxtools.ipe.vrt import get_cached_vrt, put_cached_vrt, generate_vrt_template from gbdxtools.ipe.util import calc_toa_gain_offset, timeit from gbdxtools.ipe.graph import VIRTUAL_IPE_URL, register_ipe_graph, get_ipe_metadata, get_ipe_graph from gbdxtools.ipe.error import NotFound from gbdxtools.ipe.interface import Ipe from gbdxtools.auth import Auth ipe = Ipe() def load_url(url, token, bands=8): """ Loads a geotiff url inside a thread and returns as an ndarray """ thread_id = threading.current_thread().ident _curl = _curl_pool[thread_id] buf = BytesIO() _curl.setopt(_curl.URL, url) _curl.setopt(_curl.WRITEDATA, buf) _curl.setopt(pycurl.NOSIGNAL, 1) _curl.setopt(pycurl.HTTPHEADER, ['Authorization: Bearer {}'.format(token)]) _curl.perform() with MemoryFile(buf.getvalue()) as memfile: try: with memfile.open(driver="GTiff") as dataset:
def setUpClass(cls): cls.ipe = Ipe() mock_gbdx_session = get_mock_gbdx_session(token='dummytoken') cls.gbdx = Interface(gbdx_connection=mock_gbdx_session)