diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..508a3fc --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +Copyright 2020 Aquaveo, LLC + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b4a2da5 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Earth Engine App + +The Earth Engine is a Tethys App that demonstrates how to use Google Earth Engine to visualize remotely sensed datasets. + +## Installation + +Install the app with the Tethys Platform environment activated as follows: + +``` +# For development installations +tethys install -d + +# For production installations +tethys install +``` + +## Settings + +The app has two Custom Settings that can be used to configure the app to use a [Google Earth Engine service account](https://developers.google.com/earth-engine/service_account): + +* **service_account_email**: Email associated with the service account. +* **private_key_file**: Path to service account JSON file containing the private key. + +## Authenticate for Development + +Alternatively, you can authenticate with your personal Google Earth Engine account by running the following command: + +``` +earthengine authenticate +``` + +**WARNING**: Do not use personal Google Earth Engine credentials for a production installation. diff --git a/setup.py b/setup.py index 90a817f..8ed236b 100644 --- a/setup.py +++ b/setup.py @@ -12,20 +12,21 @@ resource_files = find_resource_files('tethysapp/' + app_package + '/templates', 'tethysapp/' + app_package) resource_files += find_resource_files('tethysapp/' + app_package + '/public', 'tethysapp/' + app_package) +with open('README.md', 'r') as f: + long_description = f.read() setup( name=release_package, - version='0.0.1', - description='', - long_description='', - keywords='', - author='', - author_email='', - url='', - license='', + version='1.0.0', + description='A Google Earth Engine demonstration Tethys App.', + long_description=long_description, + author='Nathan Swain', + author_email='nswain@aquaveo.com', + url='', # The URL will be set in a future step. + license='BSD 3-Clause', packages=find_namespace_packages(), package_data={'': resource_files}, include_package_data=True, zip_safe=False, install_requires=dependencies, -) \ No newline at end of file +) diff --git a/tethysapp/earth_engine/app.py b/tethysapp/earth_engine/app.py index f47105e..fdc11c2 100644 --- a/tethysapp/earth_engine/app.py +++ b/tethysapp/earth_engine/app.py @@ -1,4 +1,5 @@ from tethys_sdk.base import TethysAppBase, url_map_maker +from tethys_sdk.app_settings import CustomSetting class EarthEngine(TethysAppBase): @@ -57,3 +58,26 @@ def url_maps(self): ) return url_maps + + def custom_settings(self): + """ + Custom settings. + """ + custom_settings = ( + CustomSetting( + name='service_account_email', + type=CustomSetting.TYPE_STRING, + description='Email associated with the service account.', + default='', + required=False, + ), + CustomSetting( + name='private_key_file', + type=CustomSetting.TYPE_STRING, + description='Path to service account JSON file containing the private key.', + default='', + required=False, + ), + ) + return custom_settings + diff --git a/tethysapp/earth_engine/gee/methods.py b/tethysapp/earth_engine/gee/methods.py index 3835232..9a71bad 100644 --- a/tethysapp/earth_engine/gee/methods.py +++ b/tethysapp/earth_engine/gee/methods.py @@ -5,31 +5,28 @@ from ee.ee_exception import EEException import geojson import pandas as pd -from . import params as gee_account from . import cloud_mask as cm from .products import EE_PRODUCTS +from ..app import EarthEngine as app log = logging.getLogger(f'tethys.apps.{__name__}') -if gee_account.service_account: +service_account = app.get_custom_setting('service_account_email') +private_key_path = app.get_custom_setting('private_key_file') + +if service_account and private_key_path and os.path.isfile(private_key_path): try: - credentials = ee.ServiceAccountCredentials(gee_account.service_account, gee_account.private_key) + credentials = ee.ServiceAccountCredentials(service_account, private_key_path) ee.Initialize(credentials) + log.info('Successfully initialized GEE using service account.') except EEException as e: - print(str(e)) + log.warning('Unable to initialize GEE using service account. If installing ignore this warning.') else: try: ee.Initialize() except EEException as e: - from oauth2client.service_account import ServiceAccountCredentials - credentials = ServiceAccountCredentials.from_p12_keyfile( - service_account_email='', - filename='', - private_key_password='notasecret', - scopes=ee.oauth.SCOPE + ' https://www.googleapis.com/auth/drive ' - ) - ee.Initialize(credentials) + log.warning('Unable to initialize GEE with local credentials. If installing ignore this warning.') def image_to_map_id(image_name, vis_params={}): diff --git a/tethysapp/earth_engine/gee/params.py b/tethysapp/earth_engine/gee/params.py deleted file mode 100644 index aa7e8d3..0000000 --- a/tethysapp/earth_engine/gee/params.py +++ /dev/null @@ -1,2 +0,0 @@ -service_account = '' # your google service account -private_key = '' # path to the json private key for the service account