Skip to content

Commit

Permalink
Prepare for Publishing Solution
Browse files Browse the repository at this point in the history
* service account custom settings
* README.md
* setup.py
* license
  • Loading branch information
swainn committed May 26, 2020
1 parent 8f7c71a commit 66c2b66
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 23 deletions.
11 changes: 11 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 10 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
24 changes: 24 additions & 0 deletions tethysapp/earth_engine/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tethys_sdk.base import TethysAppBase, url_map_maker
from tethys_sdk.app_settings import CustomSetting


class EarthEngine(TethysAppBase):
Expand Down Expand Up @@ -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

21 changes: 9 additions & 12 deletions tethysapp/earth_engine/gee/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={}):
Expand Down
2 changes: 0 additions & 2 deletions tethysapp/earth_engine/gee/params.py

This file was deleted.

0 comments on commit 66c2b66

Please sign in to comment.