def __init__(self, uri): try: if uri.startswith("s3://"): url = urlparse(uri) obj = S3.get_object(Bucket=url.netloc, Key=url.path[1:]) oin_meta = json.loads(obj["Body"].read().decode("utf-8")) elif uri.startswith(("http://", "https://")): oin_meta = requests.get(uri).json() else: raise NoCatalogAvailable() except Exception: raise NoCatalogAvailable() self._meta = oin_meta self._metadata_url = uri self._name = oin_meta.get("title") self._provider = oin_meta.get("provider") self._source = oin_meta.get("uuid") with get_source(self._source) as src: self._bounds = warp.transform_bounds(src.crs, WGS84_CRS, *src.bounds) self._resolution = get_resolution_in_meters( Bounds(src.bounds, src.crs), (src.height, src.width)) approximate_zoom = get_zoom(max(self._resolution), op=math.ceil) if src.meta["dtype"] != "uint8": global_min = src.get_tag_item("TIFFTAG_MINSAMPLEVALUE") global_max = src.get_tag_item("TIFFTAG_MAXSAMPLEVALUE") for band in range(0, src.count): self._meta["values"] = self._meta.get("values", {}) self._meta["values"][band] = {} min_val = src.get_tag_item("STATISTICS_MINIMUM", bidx=band + 1) max_val = src.get_tag_item("STATISTICS_MAXIMUM", bidx=band + 1) mean_val = src.get_tag_item("STATISTICS_MEAN", bidx=band + 1) if min_val is not None: self._meta["values"][band]["min"] = float(min_val) elif global_min is not None: self._meta["values"][band]["min"] = float(global_min) if max_val is not None: self._meta["values"][band]["max"] = float(max_val) elif global_max is not None: self._meta["values"][band]["max"] = float(global_max) if mean_val is not None: self._meta["values"][band]["mean"] = float(mean_val) self._center = [ (self._bounds[0] + self.bounds[2]) / 2, (self._bounds[1] + self.bounds[3]) / 2, approximate_zoom - 3, ] self._maxzoom = approximate_zoom + 3 self._minzoom = approximate_zoom - 10
def make_catalog(args): if args.get("url", "") == "": raise NoCatalogAvailable() try: return VirtualCatalog(args["url"], rgb=args.get("rgb"), nodata=args.get("nodata"), linear_stretch=args.get("linearStretch"), resample=args.get("resample"), expr=args.get("expr", None)) except Exception as e: LOG.exception(e) raise NoCatalogAvailable()
def make_remote_catalog(type, id): try: return RemoteCatalog( "{}/{}/{}/catalog.json".format(REMOTE_CATALOG_BASE_URL, type, id), "{}/{}/{}/{{z}}/{{x}}/{{y}}.json".format(REMOTE_CATALOG_BASE_URL, type, id), ) except Exception: raise NoCatalogAvailable()
def make_catalog(scene_id, scene_idx, image_id=None): try: if image_id: return OINMetaCatalog("s3://{}/{}{}/{}/{}_meta.json".format( S3_BUCKET, S3_PREFIX, scene_id, scene_idx, image_id)) return OAMSceneCatalog("s3://{}{}/{}/{}/scene.json".format( S3_BUCKET, S3_PREFIX, scene_id, scene_idx)) except Exception: raise NoCatalogAvailable()
def make_catalog(args): try: return VirtualCatalog( args["url"], rgb=args.get("rgb"), nodata=args.get("nodata"), linear_stretch=args.get("linearStretch"), resample=args.get("resample"), ) except Exception as e: LOG.warn(e.message) raise NoCatalogAvailable()
def make_catalog(args): source = args["url"] rgb = args.get("rgb") nodata = args.get("nodata") linear_stretch = args.get("linearStretch") try: return VirtualCatalog(source, rgb=rgb, nodata=nodata, linear_stretch=linear_stretch) except Exception as e: LOG.warn(e.message) raise NoCatalogAvailable()
def make_catalog(args): try: return VirtualCatalog(args["url"], rgb=args.get("rgb"), nodata=args.get("nodata"), linear_stretch=args.get("linearStretch"), resample=args.get("resample"), dst_min=args.get("min"), dst_max=args.get("max"), force_cast=args.get("force_cast"), to_vis=args.get("to_vis")) except Exception as e: LOG.warn(e.message) raise NoCatalogAvailable()
def __init__(self, uri): if uri.startswith("s3://"): url = urlparse(uri) obj = S3.get_object(Bucket=url.netloc, Key=url.path[1:]) scene = json.loads(obj["Body"].read().decode("utf-8")) elif uri.startswith(("http://", "https://")): scene = requests.get(uri).json() else: raise NoCatalogAvailable() self._bounds = scene["bounds"] self._center = scene["center"] self._maxzoom = scene["maxzoom"] self._minzoom = scene["minzoom"] self._name = scene["name"] def _build_catalog(source): return OINMetaCatalog(source["meta"]["source"].replace( "_warped.vrt", "_meta.json")) sources = list(reversed(scene["meta"]["sources"])) with futures.ThreadPoolExecutor( max_workers=multiprocessing.cpu_count() * 5) as executor: self._sources = list(executor.map(_build_catalog, sources))