From cbe2aafc423a8e0bfd4e6e05deced6389a957def Mon Sep 17 00:00:00 2001 From: DanielJDufour Date: Fri, 10 Jul 2020 16:16:03 -0500 Subject: [PATCH] Added pixels to Source NamedTuple --- marblecutter/mosaic.py | 6 +++++- marblecutter/recipes.py | 3 ++- marblecutter/utils.py | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/marblecutter/mosaic.py b/marblecutter/mosaic.py index 7178719..2e2afc4 100644 --- a/marblecutter/mosaic.py +++ b/marblecutter/mosaic.py @@ -14,6 +14,8 @@ LOG = logging.getLogger(__name__) +MAX_WORKERS = multiprocessing.cpu_count() * 5 + def composite(sources, bounds, shape, target_crs, expand): """Composite data from sources into a single raster covering bounds, but in @@ -33,6 +35,8 @@ def composite(sources, bounds, shape, target_crs, expand): sources = recipes.preprocess(sources, resolution=resolution) def _read_window(source): + if hasattr(source, "pixels") and source.pixels is not None: + return (source, source.pixels) with get_source(source.url) as src: LOG.info( "Fetching %s (%s) as band %s", @@ -82,7 +86,7 @@ def _read_window(source): # iterate over available sources, sorted by decreasing "quality" with futures.ThreadPoolExecutor( - max_workers=multiprocessing.cpu_count() * 5 + max_workers=MAX_WORKERS ) as executor: ws = executor.map(_read_window, sources) diff --git a/marblecutter/recipes.py b/marblecutter/recipes.py index 3b9b370..be29355 100644 --- a/marblecutter/recipes.py +++ b/marblecutter/recipes.py @@ -239,7 +239,8 @@ def postprocess(windows): windows = list(filter(None, windows)) - landsat_windows = filter(lambda sw: "LC08_" in sw[0].url, windows) + # wrap url in str because url could be None + landsat_windows = filter(lambda sw: "LC08_" in str(sw[0].url), windows) landsat_windows = dict( [ (k, list(v)) diff --git a/marblecutter/utils.py b/marblecutter/utils.py index 4554f6b..8fdee07 100644 --- a/marblecutter/utils.py +++ b/marblecutter/utils.py @@ -25,11 +25,12 @@ "filename", "min_zoom", "max_zoom", - "expr" + "expr", + "pixels" ], ) Source.__new__.__defaults__ = ( - {}, {}, {}, None, None, None, None, None, None, None, None, None, None + {}, {}, {}, None, None, None, None, None, None, None, None, None, None, None )