Skip to content

Commit

Permalink
Updates for Tethys 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
swainn committed Jan 20, 2023
1 parent f96bfbf commit f2ac8dc
Show file tree
Hide file tree
Showing 26 changed files with 263 additions and 308 deletions.
6 changes: 5 additions & 1 deletion install.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file should be committed to your app code.
version: 1.0
# This should be greater or equal to your tethys-platform in your environment
tethys_version: ">=4.0.0"
# This should match the app - package name in your setup.py
name: earth_engine

Expand All @@ -15,4 +17,6 @@ requirements:
- geojson
pip:

post:
npm:

post:
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from setuptools import setup, find_namespace_packages
from tethys_apps.app_installation import find_resource_files
from tethys_apps.app_installation import find_all_resource_files
from tethys_apps.base.app_base import TethysAppBase

# -- Apps Definition -- #
app_package = 'earth_engine'
release_package = 'tethysapp-' + app_package
release_package = f'{TethysAppBase.package_namespace}-{app_package}'

# -- Python Dependencies -- #
dependencies = []

# -- Get Resource File -- #
resource_files = find_resource_files('tethysapp/' + app_package + '/templates', 'tethysapp/' + app_package)
resource_files += find_resource_files('tethysapp/' + app_package + '/public', 'tethysapp/' + app_package)
resource_files = find_all_resource_files(app_package, TethysAppBase.package_namespace)


setup(
Expand Down
2 changes: 1 addition & 1 deletion tethysapp/earth_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Included for native namespace package support
# Included for native namespace package support
50 changes: 7 additions & 43 deletions tethysapp/earth_engine/app.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,18 @@
from tethys_sdk.base import TethysAppBase, url_map_maker
from tethys_sdk.base import TethysAppBase


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

name = 'Earth Engine'
index = 'earth_engine:home'
icon = 'earth_engine/images/earth-engine-logo.png'
package = 'earth_engine'
name = 'Google Earth Engine Tutorial'
description = ''
package = 'earth_engine' # WARNING: Do not change this value
index = 'home'
icon = f'{package}/images/earth-engine-logo.png'
root_url = 'earth-engine'
color = '#524745'
description = ''
tags = ''
enable_feedback = False
feedback_emails = []

def url_maps(self):
"""
Add controllers
"""
UrlMap = url_map_maker(self.root_url)

url_maps = (
UrlMap(
name='home',
url='earth-engine',
controller='earth_engine.controllers.home'
),
UrlMap(
name='viewer',
url='earth-engine/viewer',
controller='earth_engine.controllers.viewer'
),
UrlMap(
name='get_image_collection',
url='earth-engine/viewer/get-image-collection',
controller='earth_engine.controllers.get_image_collection'
),
UrlMap(
name='get_time_series_plot',
url='earth-engine/viewer/get-time-series-plot',
controller='earth_engine.controllers.get_time_series_plot'
),
UrlMap(
name='about',
url='earth-engine/about',
controller='earth_engine.controllers.about'
)
)

return url_maps
feedback_emails = []
52 changes: 26 additions & 26 deletions tethysapp/earth_engine/controllers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import logging
import datetime as dt
import geojson
import logging
from simplejson.errors import JSONDecodeError
from django.http import JsonResponse, HttpResponseNotAllowed
from django.shortcuts import render
from simplejson.errors import JSONDecodeError
from tethys_sdk.routing import controller
from tethys_sdk.gizmos import SelectInput, DatePicker, Button, MapView, MVView, PlotlyView, MVDraw
from tethys_sdk.permissions import login_required
from .helpers import generate_figure
from .gee.methods import get_image_collection_asset, get_time_series_from_image_collection
from .gee.products import EE_PRODUCTS
from .helpers import generate_figure

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


@login_required()
@controller
def home(request):
"""
Controller for the app home page.
Expand All @@ -22,7 +22,7 @@ def home(request):
return render(request, 'earth_engine/home.html', context)


@login_required()
@controller
def about(request):
"""
Controller for the app about page.
Expand All @@ -31,10 +31,10 @@ def about(request):
return render(request, 'earth_engine/about.html', context)


@login_required()
@controller
def viewer(request):
"""
Controller for the app viewer page.
Controller for the app home page.
"""
default_platform = 'modis'
default_sensors = EE_PRODUCTS[default_platform]
Expand Down Expand Up @@ -138,24 +138,10 @@ def viewer(request):
load_button = Button(
name='load_map',
display_text='Load',
style='default',
style='outline-secondary',
attributes={'id': 'load_map'}
)

clear_button = Button(
name='clear_map',
display_text='Clear',
style='default',
attributes={'id': 'clear_map'}
)

plot_button = Button(
name='load_plot',
display_text='Plot AOI',
style='default',
attributes={'id': 'load_plot'}
)

map_view = MapView(
height='100%',
width='100%',
Expand Down Expand Up @@ -187,6 +173,21 @@ def viewer(request):
)
)

clear_button = Button(
name='clear_map',
display_text='Clear',
style='outline-secondary',
attributes={'id': 'clear_map'},
classes='mt-2',
)

plot_button = Button(
name='load_plot',
display_text='Plot AOI',
style='outline-secondary',
attributes={'id': 'load_plot'},
)

context = {
'platform_select': platform_select,
'sensor_select': sensor_select,
Expand All @@ -204,7 +205,7 @@ def viewer(request):
return render(request, 'earth_engine/viewer.html', context)


@login_required()
@controller(url='viewer/get-image-collection')
def get_image_collection(request):
"""
Controller to handle image collection requests.
Expand Down Expand Up @@ -245,8 +246,7 @@ def get_image_collection(request):

return JsonResponse(response_data)


@login_required()
@controller(url='viewer/get-time-series-plot')
def get_time_series_plot(request):
context = {'success': False}

Expand Down
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 @@ -3,7 +3,7 @@

def mask_l8_sr(image):
"""
Derived From: https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LC08_C01_T1_SR
Cloud Mask for Landsat 8 surface reflectance. Derived From: https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LC08_C01_T1_SR
"""
# Bits 3 and 5 are cloud shadow and cloud, respectively.
cloudShadowBitMask = (1 << 3)
Expand All @@ -19,7 +19,7 @@ def mask_l8_sr(image):

def cloud_mask_l457(image):
"""
Derived From: https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LE07_C01_T1_SR
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')

Expand All @@ -35,7 +35,7 @@ def cloud_mask_l457(image):

def mask_s2_clouds(image):
"""
Derived from: https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2
Cloud Mask for Sentinel 2 surface reflectance. Derived from: https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2
"""
qa = image.select('QA60')

Expand Down
3 changes: 1 addition & 2 deletions tethysapp/earth_engine/gee/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from ee.ee_exception import EEException
import geojson
import pandas as pd
from .products import EE_PRODUCTS
from . import params as gee_account
from . import cloud_mask as cm
from .products import EE_PRODUCTS


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

Expand Down
3 changes: 0 additions & 3 deletions tethysapp/earth_engine/handoff.py

This file was deleted.

20 changes: 0 additions & 20 deletions tethysapp/earth_engine/public/css/disclaimer_modal.css

This file was deleted.

6 changes: 5 additions & 1 deletion tethysapp/earth_engine/public/css/home.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#inner-app-content {
padding: 0;
}

.info-container {
background-color: #0000009f;
box-shadow: 3px 5px 3px rgba(0,0,0,0.35);
Expand Down Expand Up @@ -69,4 +73,4 @@
background-color: #d2dadc;
background-position: center;
background-repeat: no-repeat
}
}
2 changes: 1 addition & 1 deletion tethysapp/earth_engine/public/css/loader.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

#loader.show {
display: block;
}
}
2 changes: 1 addition & 1 deletion tethysapp/earth_engine/public/css/main.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Remove padding on bottom where app-actions section used to be */
#app-content-wrapper #app-content {
padding-bottom: 0;
}
}
2 changes: 1 addition & 1 deletion tethysapp/earth_engine/public/css/map.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#inner-app-content {
height: 100%;
padding: 0;
}
}
16 changes: 0 additions & 16 deletions tethysapp/earth_engine/public/css/no_nav.css

This file was deleted.

11 changes: 10 additions & 1 deletion tethysapp/earth_engine/public/css/plot.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#plot-loader {
margin: 65px 84px;
display: flex;
align-items: center;
width: 100%;
justify-content: center;
flex-direction: column;
}

#plot-loader p {
Expand All @@ -9,3 +13,8 @@
#plot-modal .modal-body {
min-height: 480px;
}

.modal-dialog {
max-width: 70vw;
margin: 1.75rem auto;
}
Binary file removed tethysapp/earth_engine/public/images/icon.gif
Binary file not shown.
Loading

0 comments on commit f2ac8dc

Please sign in to comment.