@lru_cache(maxsize=<NUM_LIT>)<EOL>def load_url(url, token, shape=(<NUM_LIT:8>, <NUM_LIT>, <NUM_LIT>)):
_, ext = os.path.splitext(urlparse(url).path)<EOL>success = False<EOL>for i in xrange(MAX_RETRIES):<EOL><INDENT>thread_id = threading.current_thread().ident<EOL>_curl = _curl_pool[thread_id]<EOL>_curl.setopt(_curl.URL, url)<EOL>_curl.setopt(pycurl.NOSIGNAL, <NUM_LIT:1>)<EOL>_curl.setopt(pycurl.HTTPHEADER, ['<STR_LIT>'.format(token)])<EOL>with NamedTemporaryFile(prefix="<STR_LIT>", suffix=ext, delete=False) as temp: <EOL><INDENT>_curl.setopt(_curl.WRITEDATA, temp.file)<EOL>_curl.perform()<EOL>code = _curl.getinfo(pycurl.HTTP_CODE)<EOL>try:<EOL><INDENT>if(code != <NUM_LIT:200>):<EOL><INDENT>raise TypeError("<STR_LIT>".format(url, code))<EOL><DEDENT>temp.file.flush()<EOL>temp.close()<EOL>arr = imread(temp.name)<EOL>if len(arr.shape) == <NUM_LIT:3>:<EOL><INDENT>arr = np.rollaxis(arr, <NUM_LIT:2>, <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>arr = np.expand_dims(arr, axis=<NUM_LIT:0>)<EOL><DEDENT>success = True<EOL>return arr<EOL><DEDENT>except Exception as e:<EOL><INDENT>_curl.close()<EOL>del _curl_pool[thread_id]<EOL><DEDENT>finally:<EOL><INDENT>temp.close()<EOL>os.remove(temp.name)<EOL><DEDENT><DEDENT><DEDENT>if success is False:<EOL><INDENT>raise TypeError("<STR_LIT>".format(url, code))<EOL><DEDENT>return arr<EOL>
Loads a geotiff url inside a thread and returns as an ndarray