From 91d77003add4655eb6621d4549ada230290b5212 Mon Sep 17 00:00:00 2001 From: Ian Dees Date: Thu, 29 Jun 2017 19:48:55 -0400 Subject: [PATCH 1/2] Add a GeoTIFF transform that doesn't do anything to help with caching --- examples/render_pyramid.py | 9 ++++++--- marblecutter/transformations/__init__.py | 3 ++- marblecutter/transformations/geotiff.py | 17 +++++++++++++++++ marblecutter/transformations/terrarium.py | 5 +++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 marblecutter/transformations/geotiff.py diff --git a/examples/render_pyramid.py b/examples/render_pyramid.py index fa704c2..6aa8b9f 100644 --- a/examples/render_pyramid.py +++ b/examples/render_pyramid.py @@ -23,6 +23,7 @@ from marblecutter.stats import Timer from marblecutter.formats import PNG, GeoTIFF from marblecutter.transformations import Normal, Terrarium +from marblecutter.transformations import GeoTIFF as GeoTIFFTransform logging.basicConfig(level=logging.INFO) # Quieting boto messages down a little @@ -37,14 +38,16 @@ GEOTIFF_FORMAT = GeoTIFF() PNG_FORMAT = PNG() + +GEOTIFF_TRANSFORMATION = GeoTIFFTransform() NORMAL_TRANSFORMATION = Normal() TERRARIUM_TRANSFORMATION = Terrarium() RENDER_COMBINATIONS = [ - ("normal", NORMAL_TRANSFORMATION, PNG_FORMAT, ".png"), - ("terrarium", TERRARIUM_TRANSFORMATION, PNG_FORMAT, ".png"), - ("geotiff", None, GEOTIFF_FORMAT, ".tif"), + ("normal", NORMAL_TRANSFORMATION, PNG_FORMAT, ".png"), + ("terrarium", TERRARIUM_TRANSFORMATION, PNG_FORMAT, ".png"), + ("geotiff", GEOTIFF_TRANSFORMATION, GEOTIFF_FORMAT, ".tif"), ] diff --git a/marblecutter/transformations/__init__.py b/marblecutter/transformations/__init__.py index 8a67f56..258aacc 100644 --- a/marblecutter/transformations/__init__.py +++ b/marblecutter/transformations/__init__.py @@ -2,8 +2,9 @@ # coding=utf-8 from __future__ import absolute_import -from . import hillshade, normal, terrarium +from . import geotiff, hillshade, normal, terrarium +GeoTIFF = geotiff.transformation Hillshade = hillshade.transformation Normal = normal.transformation Terrarium = terrarium.transformation diff --git a/marblecutter/transformations/geotiff.py b/marblecutter/transformations/geotiff.py new file mode 100644 index 0000000..023a3b1 --- /dev/null +++ b/marblecutter/transformations/geotiff.py @@ -0,0 +1,17 @@ +# noqa +# coding=utf-8 +from __future__ import absolute_import, division, print_function + +# Keeping consistent buffer with other transforms +# so that we can more effectively cache the call to mosaic.compsoite() +BUFFER = 4 + + +def transformation(): + def _transform((data, (bounds, crs))): + # GeoTIFF transform does nothing. + + return (data, 'raw') + + _transform.buffer = BUFFER + return _transform diff --git a/marblecutter/transformations/terrarium.py b/marblecutter/transformations/terrarium.py index f57b2ac..ed771a7 100644 --- a/marblecutter/transformations/terrarium.py +++ b/marblecutter/transformations/terrarium.py @@ -4,6 +4,10 @@ import numpy as np +# Keeping consistent buffer with other transforms +# so that we can more effectively cache the call to mosaic.compsoite() +BUFFER = 4 + def transformation(): def _transform((data, (bounds, crs))): @@ -33,4 +37,5 @@ def _transform((data, (bounds, crs))): return (np.dstack((r, g, b)), 'RGB') + _transform.buffer = BUFFER return _transform From d535d93d1e284c7838be0c48864e1b86a06e6b81 Mon Sep 17 00:00:00 2001 From: Ian Dees Date: Thu, 29 Jun 2017 19:49:57 -0400 Subject: [PATCH 2/2] Switch the args to composite() to tuples in prep for caching --- marblecutter/__init__.py | 8 ++++---- marblecutter/sources.py | 4 ++-- requirements.txt | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/marblecutter/__init__.py b/marblecutter/__init__.py index c0295e9..2eb26c7 100644 --- a/marblecutter/__init__.py +++ b/marblecutter/__init__.py @@ -255,10 +255,10 @@ def render( # apply buffer bounds_orig = bounds - shape = [dim + (2 * effective_buffer) for dim in shape] - bounds = [p - (effective_buffer * resolution[i % 2]) if i < 2 else - p + (effective_buffer * resolution[i % 2]) - for i, p in enumerate(bounds)] + shape = tuple(dim + (2 * effective_buffer) for dim in shape) + bounds = tuple(p - (effective_buffer * resolution[i % 2]) if i < 2 else + p + (effective_buffer * resolution[i % 2]) + for i, p in enumerate(bounds)) left = right = bottom = top = offset diff --git a/marblecutter/sources.py b/marblecutter/sources.py index 75741e6..2cce001 100644 --- a/marblecutter/sources.py +++ b/marblecutter/sources.py @@ -56,10 +56,10 @@ def get_sources(self, (bounds, bounds_crs), resolution): ] # Pick only the attributes we care about - results = [ + results = ( (attr['url'], attr['source'], attr['resolution']) for (geom, attr) in results - ] + ) return results diff --git a/requirements.txt b/requirements.txt index 79caea4..2ef15e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ arrow boto3 +cachetools click flask flask-cors