Commit 893bbc0b authored by Arman Khalatyan's avatar Arman Khalatyan
Browse files

Update app.py

parent 09031404
Pipeline #1160 passed with stages
......@@ -3,4 +3,181 @@ import pandas as pd
st.write("""
# My first app
Hello *world!*
""")
\ No newline at end of file
""")
import numpy as np
import matplotlib.pyplot as plt
import pyvo as vo
import pandas as pd
import matplotlib as mpl
@st.cache
def get_data_sql():
# init tap service
tap_service = vo.dal.TAPService('https://gaia.aip.de/tap')
#vo.utils.http.session.headers['Authorization'] = 'Your Token '
# manage the jobs yourself
jobs = []
limit = 100000
total = 200000
qstr="select source_id,xgal,ygal,zgal,rgal,ruwe,mg0,bprp0 from gdr2_contrib.starhorse as s where s.SH_OUTFLAG LIKE '00000' AND s.SH_GAIAFLAG LIKE '000' "
i=0
for offset in range(0, total, limit):
sql = qstr +' LIMIT %s OFFSET %s' % (limit, offset)
print(sql)
job = tap_service.submit_job(sql, language='postgresql', runid='batch'+str(i))
job.run()
jobs.append(job)
i=i+1
i=0
dfvec=[]
# collect the results
for job in jobs:
print('getting results:',i)
job.raise_if_error()
results = job.fetch_result()
dfvec.append(results.to_table().to_pandas())
i=i+1
i=0
print('combining...')
df=pd.concat(dfvec)
return df
import streamlit as st
# To make things easier later, we're also importing numpy and pandas for
# working with sample data.
import numpy as np
import pandas as pd
import plotly.express as px
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import norm
cols=[
'dist05', 'dist16', 'dist50', 'dist84', 'dist95',
'av05','av16', 'av50', 'av84', 'av95',
'teff16', 'teff50', 'teff84',
'logg16','logg50', 'logg84',
'met16', 'met50', 'met84',
'mass16', 'mass50','mass84',
'ag50', 'abp50', 'arp50',
'mg0', 'bprp0',
'xgal', 'ygal',
'zgal', 'rgal',
'ruwe'
]
map_cols=[
#'dist05', 'dist16',
'dist50',
#'dist84', 'dist95',
#'av05','av16',
#'av50',
#'av84', 'av95',
# 'teff16',
'teff50',
# 'teff84',
# 'logg16',
'logg50',
# 'logg84',
# 'met16',
'met50',
# 'met84',
# 'mass16',
'mass50',
# 'mass84',
# 'ag50',
# 'abp50',
# 'arp50',
'mg0', 'bprp0',
'xgal', 'ygal','zgal',
# 'rgal',
# 'ruwe'
]
#suppress_st_warning=True)
@st.cache
def gendata(Nstars=1000):
dfsh=pd.read_parquet(
"~/data/sh_tmp.parq",columns=cols).head(Nstars)#.sample(frac=0.02,random_state=42)
selection=dfsh.dist50<10
df = dfsh[selection]#pd.DataFrame(
#{"x":dfsh.xgal,"y":dfsh.ygal,"y":dfsh.ygal})
dflen=len(df)
df=genmap(df)
return df
def plot_figure_matplotlib(df, xname,yname,colorname):
plt.scatter(
df[xname].values, df[yname].values,
c=df[colorname], s=0.3, cmap='Spectral', alpha=1.0)
st.pyplot()
def plot_figure_plotly(df,xname,yname):
#df = gendata()
fig = px.scatter(df, x=xname, y=yname, title="title")
st.plotly_chart(fig)
## Main rendering part
st.title('The interactive maps')
st.write('## selected stars parameters')
N = st.slider("Pick a number", 1000, 1000000, 10000,100000)
df = get_data_sql()
Nstars=len(df)
st.markdown(f"N = **{Nstars}** stars selected by condition in **gendata()** function")
st.sidebar.markdown('## selected projection parameters')
st.sidebar.markdown('## Plotting parameters')
xname = st.sidebar.selectbox(
'Select the X axis',
map_cols,6)
yname = st.sidebar.selectbox(
'Select the Y axis',
map_cols,5)
colorname = st.sidebar.selectbox(
'Select the Color axis',
map_cols,3)
'You selected:', option
if st.checkbox('Show Scatter plot',value=False):
#plot_figure_plotly(df,xname,yname)
plot_figure_matplotlib(df, xname,yname,colorname)
if st.checkbox('Show pairwise relationships in a dataset'):
sns.pairplot(df[[xname,yname,colorname]])#, hue="a");
st.pyplot()
if st.checkbox('Warning: the KDE plots are very slow'):
g = sns.PairGrid(df[[xname,yname,colorname]])
g.map_diag(sns.kdeplot)
g.map_offdiag(sns.kdeplot, n_levels=8);
st.pyplot()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment