Skip to content

Commit

Permalink
Testing deployment pipeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiabernat committed Oct 7, 2024
1 parent 3a1ad60 commit 97c2d16
Show file tree
Hide file tree
Showing 26 changed files with 293 additions and 2,584 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,28 @@ Also, GRIDCERF most importantly requires **Dash version >=2.9.2**. Dash >=2.9.2

The `requirements.txt` in `dash_app` lists Python packages and their versions needed to run GRIDCERF following Python installation. We suggest your environment reflects these package versions.

![](https://img.shields.io/badge/bokeh-3.3.4-darkgrey)
![](https://img.shields.io/badge/boto3-1.34.112-darkgrey)
![](https://img.shields.io/badge/pydeck-0.9.1-darkgrey)
![](https://img.shields.io/badge/dash-2.14.2-darkgrey)
![](https://img.shields.io/badge/dash_bootstrap_components-1.5.0-darkgrey)
![](https://img.shields.io/badge/dash_daq-0.5.0-darkgrey)
![](https://img.shields.io/badge/dash_leaflet-1.0.15-darkgrey)
![](https://img.shields.io/badge/dash_deck-0.5.0-darkgrey)
![](https://img.shields.io/badge/dash_daq-0.0.1-darkgrey)
![](https://img.shields.io/badge/dash_html_components-2.0.0-darkgrey)
![](https://img.shields.io/badge/dash_resizable_panels-0.1.0-darkgrey)
![](https://img.shields.io/badge/dash_svg-0.0.12-darkgrey)
![](https://img.shields.io/badge/holoviews-1.18.3-darkgrey)
![](https://img.shields.io/badge/hvplot-0.9.2-darkgrey)
![](https://img.shields.io/badge/Flask-3.0.3-darkgrey)
![](https://img.shields.io/badge/Flask_Caching-2.3.0-darkgrey) ![](https://img.shields.io/badge/Flask_Compress-1.15-darkgrey)
![](https://img.shields.io/badge/Requests-2.32.3-darkgrey) ![](https://img.shields.io/badge/httpx-0.27.2-darkgrey)
![](https://img.shields.io/badge/pandas-2.2.1-darkgrey)
![](https://img.shields.io/badge/geopandas-0.14.2-darkgrey)
![](https://img.shields.io/badge/numpy-1.26.4-darkgrey)
![](https://img.shields.io/badge/plotly-5.18.0-darkgrey)
![](https://img.shields.io/badge/rasterio-1.3.9-darkgrey)
![](https://img.shields.io/badge/xarray-2024.1.1-darkgrey)
![](https://img.shields.io/badge/rioxarray-0.15.5-darkgrey)
![](https://img.shields.io/badge/Pillow-10.4.0-darkgrey)
![](https://img.shields.io/badge/pyproj-10.4.0-darkgrey)
![](https://img.shields.io/badge/PyYAML-6.0.1-darkgrey)
![](https://img.shields.io/badge/Shapely-2.0.6-darkgrey)

## Run GRIDCERF Locally <a name="local"></a>

Expand Down
99 changes: 23 additions & 76 deletions dash_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,35 @@
# -*- coding: utf-8 -*-

# -------------------------------------------------------------------------------------
# GRIDCERF, data tool and app that runs visuals on Closed-Loop Geothermal Data
# GRIDCERF, U.S energy feasibility mapper and database explorer
# -------------------------------------------------------------------------------------

# https://dash.gallery/dash-deck-explorer/globe-view

# THIS is what I want for a quick introduction to JavaScript
# https://github.com/Esri/quickstart-map-js


# https://blog.mapbox.com/visualizing-radar-data-with-vector-tiles-117bc5ee9a5a

# LIBRARIES

# standard libraries
## standard libraries
import os
import sys
import yaml

# data manipulation
import pandas as pd
import numpy as np
import xarray as xr
from functools import reduce

# web visualization and interactive libraries
## web visualization and interactive libraries
from dash.dependencies import Input, Output, State
from dash import Dash, html
from dash import ctx
from dash.exceptions import PreventUpdate
from dash import dcc
import holoviews as hv
hv.extension('bokeh')
from holoviews.plotting.plotly.dash import to_dash

# SOURCED SCRIPTS
from definitions import CONNECT_TO_LAMBDA, PORT, plotly_config, CMAP_BLACK, token
from definitions import CONNECT_TO_LAMBDA, PORT, COMPILED_DIR, OUTDIR
if CONNECT_TO_LAMBDA:
from msdlive_utils import get_bytes
from io import BytesIO

from src.reader import open_as_raster
from src.utilities import create_datashaded_scatterplot #, get_map_data
from src.imshow import plot_imshow_map
from src.datashader_mapbox import plot_ds_mapbox_map
from src.datashader_holoviews import plot_ds_holoviews_map
from src.leaflet_titiler import plot_leaflet_map
from src.mapbox_raster import plot_mapbox_map
from src.deckgl import plot_deckgl_map
from layout import app, tech_pathways_df, src_meta, all_options, OUTDIR, COMPILED_DIR
from layout import app, tech_pathways_df, src_meta, all_options

# -----------------------------------------------------------------------------
# Define dash app plotting callbacks.
# Define dash app callbacks.
# -----------------------------------------------------------------------------

@app.callback(
Expand Down Expand Up @@ -154,8 +131,6 @@ def set_level2_value(available_options):

def show_hide_element(feature, is_ccs, cooling, capacity_factor):

# eventually integrate this into the above callbacks

feature_show = {'display': 'block'}
is_css_show = {'display': 'block'}
cooling_show = {'display': 'block'}
Expand All @@ -179,34 +154,29 @@ def show_hide_element(feature, is_ccs, cooling, capacity_factor):
@app.callback(
Output(component_id="map", component_property="children"),
[
Input(component_id="map-select", component_property="value"),
# Input(component_id="state-select", component_property="value"),
Input(component_id="year-select", component_property="value"),
Input(component_id="ssp-select", component_property="value"), # Socioeconomic scenario (SSP)
Input(component_id="ssp-select", component_property="value"),
Input(component_id="tech-select", component_property="value"),
Input(component_id="subtech-select", component_property="value"),
Input(component_id="feature-select", component_property="value"),
Input(component_id="carbon-capture-select", component_property="value"),
Input(component_id="cooling-type-select", component_property="value"),
Input(component_id="capacity-factor-select", component_property="value"),
# e.g., communications perspective: Land Management/Native Habitats
# Input vs. Compiled (will always be compiled)
Input(component_id="layer-selector", component_property="value")
],
)

def map(maptool, #state,
year, ssp,
tech, subtech, feature,
is_ccs, coolingtype, capacity_factor):
def map(year, ssp,
tech, subtech, feature,
is_ccs, coolingtype, capacity_factor, selected_layers):

# -----------------------------------------------------------------------------
# Creates and displays map by querying a "database" table of all pathways
# to their filenames.
# -----------------------------------------------------------------------------

year = str(year)

print(" --------------------------------------------------------------- ")
year = str(year)
print([ssp, year, tech, subtech, feature, is_ccs, coolingtype, capacity_factor])
query_df = tech_pathways_df.query("ui_ssp in @ssp and \
ui_year in @year and \
Expand All @@ -218,45 +188,15 @@ def map(maptool, #state,
ui_capacity_factor in @capacity_factor")

fpaths = query_df["fpath"].values
# print(len(fpaths))

# i = 0
# for fpath in fpaths:

# TIFPATH = os.path.join(COMPILED_DIR, fpath)
# data_array, array, source_crs, df_coors_long, boundingbox, img = open_as_raster(TIFPATH=TIFPATH, is_reproject=False, is_convert_to_png=False)
# i += 1

if maptool == "Plotly-datashader, mapbox":

fig_div = plot_ds_mapbox_map(COMPILED_DIR=COMPILED_DIR, fpaths=fpaths)

if maptool == "Plotly-datashader, holoviews":

fig = plot_ds_holoviews_map(COMPILED_DIR=COMPILED_DIR, fpaths=fpaths)

components = to_dash(app, [fig]) # breaks here, reset_button=True

fig_div = html.Div(id="energy-map3",
children=components.children
)
print("HOLOVIEWS PLOTTED")

if maptool == "Leaflet and TiTiler":

fig_div = plot_leaflet_map(COMPILED_DIR=COMPILED_DIR, fpaths=fpaths)

if maptool == "Mapbox":

fig_div = plot_mapbox_map(COMPILED_DIR=COMPILED_DIR, fpaths=fpaths)

if maptool == "Plotly-imshow":

fig_div = plot_imshow_map(COMPILED_DIR=COMPILED_DIR, fpaths=fpaths)

if maptool == "DeckGL":

fig_div = plot_deckgl_map(COMPILED_DIR=COMPILED_DIR, fpaths=fpaths)
# DeckGL
fig_div = plot_deckgl_map(COMPILED_DIR=COMPILED_DIR, fpaths=fpaths, selected_layers=selected_layers)

return fig_div

Expand Down Expand Up @@ -293,8 +233,15 @@ def output_string(active_cell):
layer_methodology = src_meta.loc[data_row, "layer_methodology"]
citation = src_meta.loc[data_row, "source_data_citation"]
data_link = src_meta.loc[data_row, "source_data_link"]

# tag_id = "TAG ID: " + str(tag_id)

return str(title), str(tag_id), str(src_type), str(desc), str(date_updated), str(data_accessed), str(layer_methodology), str(citation), str(data_link)

# -----------------------------------------------------------------------------
# App runs here. Define configurations, proxies, etc.
# -----------------------------------------------------------------------------

if CONNECT_TO_LAMBDA:
print("Sending app to the get_wsgi_handler ... ")
else:
if __name__ == "__main__":
app.run_server(port=PORT, debug=True)
4 changes: 4 additions & 0 deletions dash_app/assets/map.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@
/* 800*/
/* width: 1300px; */
}

/* .loader-wrapper > div {
visibility: visible !important;
} */
67 changes: 17 additions & 50 deletions dash_app/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,33 @@
# -*- coding: utf-8 -*-

import os
import matplotlib.colors as mcolors

# client (browser) paths
# CLIENT (BROWSER) PATHS
PORT = int(os.environ.get("PORT", 8060))
REQUESETS_PATHNAME_PREFIX = "/"

CONNECT_TO_LAMBDA = False
CONNECT_TO_LAMBDA = True

# FILE PATHS
if CONNECT_TO_LAMBDA:
DATASET_ID = "1ffea-emt93" # MSD-LIVE added dataset id that goes to DEV

REMINDER = "It's coors = (lat, lon) and ... LON = COLS = X ... LAT = ROWS = Y"


CMAP_BLACK = mcolors.ListedColormap(['black'])
# CMAP_BLACK = mcolors.ListedColormap((0,0,0,0.8))
# https://gridcerf.dev.msdlive.org/

token = open("../../mapbox_token.py").read() # mapbox_api_token = os.getenv("MAPBOX_ACCESS_TOKEN")

plotly_config = {'displaylogo': False,
'modeBarButtonsToRemove': ['autoScale', 'resetScale'], # High-level: zoom, pan, select, zoomIn, zoomOut, autoScale, resetScale
'toImageButtonOptions': {
'format': 'png', # one of png, svg, jpeg, webp
'filename': 'custom_image',
'height': None,
'width': None,
'scale': 6 # Multiply title/legend/axis/canvas sizes by this factor
}
}
DATASET_ID = "1ffea-emt93" # MSD-LIVE added dataset id that goes to DEV
DATA_DIR = ""
LAMBDA_TASK_ROOT = os.getenv('LAMBDA_TASK_ROOT')

if LAMBDA_TASK_ROOT is None:
METADATA_DIR = './metadata'
else:
METADATA_DIR = os.path.join(LAMBDA_TASK_ROOT, "dash_app", "metadata")

# https://medium.com/plotly/introducing-dash-holoviews-6a05c088ebe5
# https://examples.holoviz.org/gallery/nyc_taxi/nyc_taxi.html
# https://towardsdatascience.com/displaying-a-gridded-dataset-on-a-web-based-map-ad6bbe90247f
# https://holoviews.org/getting_started/Customization.html
# https://holoviews.org/reference/elements/matplotlib/Points.html
# https://stackoverflow.com/questions/57588857/matplotlib-listedcolormap-transparent-color
# https://datashader.org/getting_started/Pipeline.html
# https://holoviews.org/_modules/holoviews/operation/datashader.html
# https://discourse.holoviz.org/t/how-to-set-geoviews-map-extent-programmatically-in-panel-dashboard/1181
# https://geog-312.gishub.org/book/geospatial/leafmap.html
# https://leafmap.org/get-started/
# https://ai-incubator.pnnl.gov/chat/fy0s5mBnqiTK9YE6C4xB8YrmQv0YMnyLsjA7
# https://www.google.com/search?q=holoviews+albers+conic&rlz=1C5CHFA_enUS1091US1091&oq=holoviews+albers+conic&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIHCAEQIRigATIHCAIQIRigATIHCAMQIRigATIHCAQQIRigAdIBCDQ0NTdqMGo3qAIAsAIA&sourceid=chrome&ie=UTF-8
# https://geoviews.org/user_guide/Projections.html
else:
DATA_DIR = "../../data/msdlive-gridcerf"
METADATA_DIR = "./metadata"


# https://plotly.com/python/mapbox-layers/
# learn Mapbox GL JS: https://docs.mapbox.com/mapbox-gl-js/guides/migrate/
# layer building in holoviz: https://github.com/holoviz/holoviews/issues/3882
# remove frame around plot: https://discourse.holoviz.org/t/remove-frame-around-plot/4023/3
# LINKED SELECTIONS ** https://medium.com/plotly/introducing-dash-holoviews-6a05c088ebe5
# foreal example:
# https://github.com/niowniow/foreal/blob/ea0cb314f3a408f7fd544528ce83e03ca2269b12/foreal/webportal/app.py#L48
# https://github.com/niowniow/foreal/blob/ea0cb314f3a408f7fd544528ce83e03ca2269b12/foreal/webportal/app.py#L48
# https://github.com/niowniow/foreal/blob/ea0cb314f3a408f7fd544528ce83e03ca2269b12/foreal/webportal/__init__.py
# https://github.com/niowniow/foreal/blob/ea0cb314f3a408f7fd544528ce83e03ca2269b12/foreal/webportal/shared.py
COMPILED_DIR = os.path.join(DATA_DIR, "gridcerf/compiled/compiled_technology_layers")
OUTDIR = "tmp"

# stocknews example:
# https://github.com/troyscribner/stocknews/tree/6565a854a3469c93b42f2a871301469aa6b9bd04
# of interest: mapboxgl dash python
# click event: does dash python support mapboxgl
#
# REMINDER = "It's coors = (lat, lon) and ... LON = COLS = X ... LAT = ROWS = Y"
66 changes: 0 additions & 66 deletions dash_app/holoview_plot.html

This file was deleted.

66 changes: 0 additions & 66 deletions dash_app/holoview_plot2.html

This file was deleted.

Loading

0 comments on commit 97c2d16

Please sign in to comment.