Skip to content

Instantly share code, notes, and snippets.

@nbren12
Created November 19, 2020 22:13
Show Gist options
  • Save nbren12/6f68071dee30f5e8751f08700884a110 to your computer and use it in GitHub Desktop.
Save nbren12/6f68071dee30f5e8751f08700884a110 to your computer and use it in GitHub Desktop.
from numpy.core.fromnumeric import var
from numpy.lib.function_base import place
import streamlit as st
import intake
import xarray as xr
import cloudpickle
import matplotlib.pyplot as plt
from collections import defaultdict
st.header("Modern `ncview` (of course it's slower!)")
url = "gs://vcm-ml-raw/2020-10-19-40-day-unperturbed-C384-to-C48-diagnostics-20170801.00Z/atmos_8xdaily_C384_to_C48.zarr"
@st.cache(hash_funcs={xr.Dataset: cloudpickle.dumps})
def open_url(url):
return intake.open_zarr(url, consolidated=True).to_dask()
url = st.text_input("url", value=url)
sliders = st.beta_container()
ds = open_url(url)
variable = st.selectbox("Variable", list(ds))
cmap = st.selectbox("cmap", [None,
'viridis', 'plasma', 'inferno', 'magma', 'cividis',
'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn',
'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic',
'default'
], index=0)
array = ds[variable]
col1, col2 = st.beta_columns(2)
x_dim = col1.radio("x", list(array.dims))
y_dim = col2.radio("y", list(set(array.dims)- {x_dim}))
other_dims = list(set(array.dims) - {x_dim, y_dim})
coords = {}
with sliders:
for dim in other_dims:
coords[dim] = st.slider(dim, 0, len(array[dim])-1)
# fig = plot(coords)
with sliders:
pane = array.isel(coords)
pane.plot(x=x_dim, y=y_dim, cmap=cmap)
fig = plt.gcf()
sliders.pyplot(fig)
streamlit
xarray
zarr
intake
fsspec
intake_xarray
gcsfs
cloudpickle
matplotlib
@nbren12
Copy link
Author

nbren12 commented Nov 19, 2020

Install the dependencies with pip install -r requirement.txt and run the webapp with steamlit run ncview.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment