Skip to content

Commit

Permalink
updates for tethys 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeymac committed Aug 17, 2024
1 parent fa7023a commit 1cecc83
Show file tree
Hide file tree
Showing 29 changed files with 105 additions and 208 deletions.
11 changes: 0 additions & 11 deletions .gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions install.yml

This file was deleted.

31 changes: 0 additions & 31 deletions setup.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 3 additions & 4 deletions tethysapp/earth_engine/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from tethys_sdk.base import TethysAppBase


class EarthEngine(TethysAppBase):
class App(TethysAppBase):
"""
Tethys app class for Earth Engine.
"""

name = 'Google Earth Engine Tutorial'
name = 'Earth Engine'
description = ''
package = 'earth_engine' # WARNING: Do not change this value
index = 'home'
Expand All @@ -15,4 +14,4 @@ class EarthEngine(TethysAppBase):
color = '#524745'
tags = ''
enable_feedback = False
feedback_emails = []
feedback_emails = []
57 changes: 27 additions & 30 deletions tethysapp/earth_engine/controllers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import datetime as dt
import logging
from django.http import JsonResponse, HttpResponseNotAllowed
from django.shortcuts import render
from tethys_sdk.routing import controller
from tethys_sdk.gizmos import SelectInput, DatePicker, Button
from tethys_sdk.gizmos import MapView, MVView
from .gee.methods import get_image_collection_asset
from tethys_sdk.gizmos import SelectInput, DatePicker, Button, MapView, MVView
from .gee.products import EE_PRODUCTS
from .gee.methods import get_image_collection_asset
from .app import App

log = logging.getLogger(f'tethys.apps.{__name__}')


@controller
def home(request):
"""
Expand Down Expand Up @@ -121,30 +119,29 @@ def home(request):
style='outline-secondary',
attributes={'id': 'load_map'}
)

map_view = MapView(
height='100%',
width='100%',
controls=[
'ZoomSlider', 'Rotate', 'FullScreen',
{'ZoomToExtent': {
'projection': 'EPSG:4326',
'extent': [29.25, -4.75, 46.25, 5.2] #: Kenya
}}
],
basemap=[
'CartoDB',
{'CartoDB': {'style': 'dark'}},
'OpenStreetMap',
'Stamen',
'ESRI'
],
view=MVView(
projection='EPSG:4326',
center=[37.880859, 0.219726],
zoom=7,
maxZoom=18,
minZoom=2
height='100%',
width='100%',
controls=[
'ZoomSlider', 'Rotate', 'FullScreen',
{'ZoomToExtent': {
'projection': 'EPSG:4326',
'extent': [29.25, -4.75, 46.25, 5.2] #: Kenya
}}
],
basemap=[
'CartoDB',
{'CartoDB': {'style': 'dark'}},
'OpenStreetMap',
'Stamen',
'ESRI'
],
view=MVView(
projection='EPSG:4326',
center=[37.880859, 0.219726],
zoom=7,
maxZoom=18,
minZoom=2
)
)

Expand All @@ -169,8 +166,8 @@ def home(request):
'map_view': map_view
}

return render(request, 'earth_engine/home.html', context)

return App.render(request, 'home.html', context)

@controller
def get_image_collection(request):
Expand Down Expand Up @@ -211,4 +208,4 @@ def get_image_collection(request):
except Exception as e:
response_data['error'] = f'Error Processing Request: {e}'

return JsonResponse(response_data)
return JsonResponse(response_data)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions tethysapp/earth_engine/gee/cloud_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def mask_l8_sr(image):
cloudsBitMask = (1 << 5)

# Get the pixel QA band.
qa = image.select('pixel_qa')
qa = image.select('QA_PIXEL')

# Both flags should be set to zero, indicating clear conditions.
mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).And(qa.bitwiseAnd(cloudsBitMask).eq(0))
Expand All @@ -21,7 +21,7 @@ def cloud_mask_l457(image):
"""
Cloud Mask for Landsat 7 surface reflectance. Derived From: https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LE07_C01_T1_SR
"""
qa = image.select('pixel_qa')
qa = image.select('QA_PIXEL')

# If the cloud bit (5) is set and the cloud confidence (7) is high
# or the cloud shadow bit is set (3), then it's a bad pixel.
Expand All @@ -46,4 +46,4 @@ def mask_s2_clouds(image):
# Both flags should be set to zero, indicating clear conditions.
mask = qa.bitwiseAnd(cloudBitMask).eq(0).And(qa.bitwiseAnd(cirrusBitMask).eq(0))

return image.updateMask(mask).divide(10000)
return image.updateMask(mask).divide(10000)
15 changes: 4 additions & 11 deletions tethysapp/earth_engine/gee/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@
try:
credentials = ee.ServiceAccountCredentials(gee_account.service_account, gee_account.private_key)
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 All @@ -40,7 +34,6 @@ def image_to_map_id(image_name, vis_params={}):
except EEException:
log.exception('An error occurred while attempting to retrieve the map id.')


def get_image_collection_asset(platform, sensor, product, date_from=None, date_to=None, reducer='median'):
"""
Get tile url for image collection asset.
Expand Down Expand Up @@ -79,4 +72,4 @@ def get_image_collection_asset(platform, sensor, product, date_from=None, date_t
return tile_url

except EEException:
log.exception('An error occurred while attempting to retrieve the image collection asset.')
log.exception('An error occurred while attempting to retrieve the image collection asset.')
2 changes: 2 additions & 0 deletions tethysapp/earth_engine/gee/params.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from pathlib import Path

service_account = '' # your google service account
private_key = '' # path to the json private key for the service account
88 changes: 30 additions & 58 deletions tethysapp/earth_engine/gee/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'terra': {
'snow': {
'display': 'Snow Cover Daily Global 500m',
'collection': 'MODIS/006/MOD10A1',
'collection': 'MODIS/061/MOD10A1',
'index': 'NDSI_Snow_Cover',
'vis_params': {
'min': 0.0,
Expand All @@ -15,7 +15,7 @@
},
'temperature': {
'display': 'Land Surface Temperature and Emissivity Daily Global 1km',
'collection': 'MODIS/006/MOD11A1',
'collection': 'MODIS/061/MOD11A1',
'index': 'LST_Day_1km',
'vis_params': {
'min': 13000.0,
Expand Down Expand Up @@ -98,91 +98,63 @@
}
},
'landsat': {
'7': {
'8': {
'surface': {
'display': 'Surface Reflectance',
'collection': 'LANDSAT/LE07/C01/T1_SR',
'collection': 'LANDSAT/LC08/C02/T1_L2',
'index': None,
'vis_params': {
'bands': ['B3', 'B2', 'B1'],
'bands': ['SR_B4', 'SR_B3', 'SR_B2'],
'min': 0,
'max': 3000,
'gamma': 1.4,
},
'cloud_mask': 'cloud_mask_l457',
'start_date': '1999-01-01',
'end_date': None # to present
},
'evi': {
'display': '8-day Enhanced Vegetation Index (EVI)',
'collection': 'LANDSAT/LE07/C01/T1_8DAY_EVI',
'index': 'EVI',
'vis_params': {
'min': 0.0,
'max': 1.0,
'palette': [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
'66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
'012E01', '011D01', '011301'
],
},
'start_date': '1999-01-01',
'cloud_mask': 'mask_l8_sr',
'start_date': '2013-04-01',
'end_date': None # to present
},
'ndwi': {
'display': '8-day Normalized Difference Water Index (NDWI)',
'collection': 'LANDSAT/LE07/C01/T1_8DAY_NDWI',
'index': 'NDWI',
'toa': {
'display': 'Top-of-Atmosphere(TOA) Reflectance',
'collection': 'LANDSAT/LC08/C02/T1_TOA',
'index': None,
'vis_params': {
'min': 0.0,
'max': 1.0,
'palette': ['0000ff', '00ffff', 'ffff00', 'ff0000', 'ffffff'],
'bands': ['B4', 'B3', 'B2'],
'min': 0,
'max': 3000,
'gamma': 1.4,
},
'start_date': '1999-01-01',
'start_date': '2013-04-01',
'end_date': None # to present
},
},
'8': {
'9': {
'surface': {
'display': 'Surface Reflectance',
'collection': 'LANDSAT/LC08/C01/T1_SR',
'collection': 'LANDSAT/LC09/C02/T1_L2',
'index': None,
'vis_params': {
'bands': ['B4', 'B3', 'B2'],
'bands': ['SR_B4', 'SR_B3', 'SR_B2'],
'min': 0,
'max': 3000,
'gamma': 1.4,
},
'cloud_mask': 'mask_l8_sr',
'start_date': '2013-04-01',
'start_date': '2021-10-31',
'end_date': None # to present
},
'ndvi': {
'display': '8-day Normalized Difference Vegetation (NDVI)',
'collection': 'LANDSAT/LC08/C01/T1_8DAY_NDVI',
'index': 'NDVI',
'vis_params': {
'min': 0.0,
'max': 1.0,
'palette': [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
'66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
'012E01', '011D01', '011301'
],
},
'start_date': '2013-04-01',
'end_date': None # to present
},
'ndsi': {
'display': '8-day Normalized Difference Snow Index (NDSI)',
'collection': 'LANDSAT/LC08/C01/T1_8DAY_NDSI',
'index': 'NDSI',
'toa': {
'display': 'Top-of-Atmosphere(TOA) Reflectance',
'collection': 'LANDSAT/LC09/C02/T1_TOA',
'index': None,
'vis_params': {
'palette': ['000088', '0000FF', '8888FF', 'FFFFFF'],
'bands': ['B4', 'B3', 'B2'],
'min': 0,
'max': 3000,
'gamma': 1.4,
},
'start_date': '2013-04-01',
'start_date': '2021-10-31',
'end_date': None # to present
},
}
}
}
}
Binary file added tethysapp/earth_engine/public/images/icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tethysapp/earth_engine/public/images/map-loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1cecc83

Please sign in to comment.