Skip to content

Instantly share code, notes, and snippets.

@jrhone
Created January 6, 2020 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrhone/be499fa40d961b03a19da003c9ce1f9b to your computer and use it in GitHub Desktop.
Save jrhone/be499fa40d961b03a19da003c9ce1f9b to your computer and use it in GitHub Desktop.
import streamlit as st
import altair as alt
import pandas as pd
import erddapy
from vega_datasets import data
# Connect to ERDDAP
st.title('SWOT Prawler Data')
e = erddapy.ERDDAP('http://heron.pmel.noaa.gov:8080/erddap', protocol='tabledap')
e.dataset_id = 'TELON001_PRAWC_N001' # Data Set to Use
@st.cache
def get_dfp():
# Pull Data from ERDDAP
dfp = e.to_pandas()
dfp['time (UTC)'] = pd.to_datetime(dfp['time (UTC)'])
return dfp
dfp = get_dfp()
# Create a subset of the datas
sub = dfp.loc[:,['time (UTC)', 'SB_Depth', 'SB_Temp', 'SB_Conductivity', 'wetlab_Chlorophyll']]
source = sub
brush = alt.selection(type='interval')
# dropdown to select y-axis
option = st.selectbox(
'Select a Dataset',
['SB_Temp:Q', 'SB_Conductivity:Q', 'Optode_Dissolved_O2:O', 'wetlab_Chlorophyll:Q']
)
# top panel to plot the data
c = (alt.Chart(source, title="SWOT Prawler Data")
.mark_circle(size=30)
.encode(
x=alt.X('time (UTC):T', scale=alt.Scale(clamp=True, padding=10)),
y=alt.Y('SB_Depth:Q',axis=alt.Axis(title='Depth (m)'), scale=alt.Scale(zero=False, padding=5, domain=[500,0])),
color=alt.condition(brush, option, alt.value('lightgray'))
)
.add_selection(brush)
.properties(width=700, height=300))
# 2nd chart
second = (alt.Chart(source, title="Zoomed in Plot")
.mark_circle(size=30)
.encode(
y=alt.Y('SB_Depth:Q', sort = "descending"),
color=alt.Color(option, sort = 'descending', scale=alt.Scale(scheme="redblue")),
x='time (UTC):T',
tooltip=[
alt.Tooltip('time (UTC):O', title='Datetime'),
alt.Tooltip('SB_Depth:O', title='Depth'),
alt.Tooltip(option, title=option)
]
)
.transform_filter(brush)
.properties(height=500, width=700)
.interactive())
c & second
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment