AmrGharieb's picture
Upload 6 files
1a9ac32 verified
from pathlib import Path
import streamlit as st
from functions import *
# Initialize session state
if 'pumping_file' not in st.session_state:
st.session_state.pumping_file = None
if 'pumping_df' not in st.session_state:
st.session_state.pumping_df = None
if 'cwt_df' not in st.session_state:
st.session_state.cwt_df = None
if 'ms_df' not in st.session_state:
st.session_state.ms_df = None
if 'mc_events_predicted_df' not in st.session_state:
st.session_state.mc_events_predicted_df = None
if 'date_col' not in st.session_state:
st.session_state.date_col = None
if 'pressure_col' not in st.session_state:
st.session_state.pressure_col = None
if 'rate_col' not in st.session_state:
st.session_state.rate_col = None
if 'start_date' not in st.session_state:
st.session_state.start_date = None
if 'start_time' not in st.session_state:
st.session_state.start_time = None
if 'end_date' not in st.session_state:
st.session_state.end_date = None
if 'end_time' not in st.session_state:
st.session_state.end_time = None
if 'east' not in st.session_state:
st.session_state.east = None
if 'north' not in st.session_state:
st.session_state.north = None
if 'depth' not in st.session_state:
st.session_state.depth = None
if 'start_datetime_selector' not in st.session_state:
st.session_state.start_datetime_selector = False
if 'end_datetime_selector' not in st.session_state:
st.session_state.end_datetime_selector = False
x_names = [str(i) for i in range(1,257)]
y_names=['delta_east', 'delta_north', 'delta_depth']
#Main decoration
st.set_page_config(page_title='Microseismic Prediction',
layout="wide",page_icon='πŸ“ˆ')
st.title('Microseismic Prediction')
st.markdown('Predict Microseismic Events (X, Y, Z)')
image_path = Path('uh-primary.png')
st.sidebar.image(str(image_path))
click_event_container = st.empty()
# Define tab titles
tab_titles = ["Pumping pressure table", "Pumping pressure chart", "Adjusted chart" , "Predicted Microseismic Events","Quality Check"]
# Create tabs using st.tabs
tabs = st.tabs(tab_titles)
uploaded_pumping_file = st.sidebar.\
file_uploader("Please upload pumping XLSX file", type=["xlsx"])
# Add content to each tab
with tabs[0]:
st.header("Table of pumping data")
pumping_data_frame_container = st.empty()
if uploaded_pumping_file:
#create a pumping dataframe
pumping_data_frame_container.\
dataframe(st.session_state.pumping_df, use_container_width=True)
with tabs[1]:
st.header("Pumping pressure and rate chart")
with st.container():
#check box with date selector
option = st.radio("Which date you want to select?", ("Start date", "End date"),captions=("Select start date and time", "Select end date and time"))
if option == "Start date":
st.session_state.start_datetime_selector = True
st.session_state.end_datetime_selector = False
elif option == "End date":
st.session_state.start_datetime_selector = False
st.session_state.end_datetime_selector = True
with st.form(key='pumping_chart_form'):
if st.session_state.pumping_df is not None:
fig = plot_pumping_data(st.session_state.pumping_df, \
st.session_state.date_col, st.session_state.pressure_col,\
st.session_state.rate_col)
st.empty()
selected_events = plotly_events(fig)
if selected_events:
click_event = selected_events[0]
x_value = click_event['x']
if st.session_state.start_datetime_selector:
#convert x_value to datetime
x_value = pd.to_datetime(x_value)
#extract date and time then assign to start_date and start_time
st.session_state.start_date = x_value.date()
st.session_state.start_time = x_value.time()
st.write(f"Start date: {st.session_state.start_date}")
st.write(f"Start time: {st.session_state.start_time}")
if st.session_state.end_datetime_selector:
#convert x_value to datetime
x_value = pd.to_datetime(x_value)
#extract date and time then assign to end_date and end_time
st.session_state.end_date = x_value.date()
st.session_state.end_time = x_value.time()
st.write(f"End date: {st.session_state.end_date}")
st.write(f"End time: {st.session_state.end_time}")
#open tab 3
st.form_submit_button(label = "Transfer new chart")
with tabs[2]:
if st.session_state.pumping_df is not None:
fig = plot_pumping_data(st.session_state.pumping_df, \
st.session_state.date_col, st.session_state.pressure_col,st.session_state.rate_col)
st.plotly_chart(fig, use_container_width=True)
with st.form(key='adjusted_chart_form'):
st.empty()
st.write("Please provide the x, y, z for mid perforation")
col1, col2, col3 = st.columns(3)
with col1:
st.session_state.east = st.number_input("East", value=0.0)
with col2:
st.session_state.north = st.number_input("North", value=0.0)
with col3:
st.session_state.depth = st.number_input("Depth", value=0.0)
calc_cwt = st.form_submit_button(label = "Predict Microseismic Events")
if calc_cwt:
st.session_state.cwt_df = calculate_cwt(st.session_state.pumping_df, st.session_state.date_col, st.session_state.pressure_col)
st.write("CWT calculated")
with st.expander("CWT Data"):
st.dataframe(st.session_state.cwt_df)
with tabs[3]:
if st.session_state.cwt_df is not None:
with st.container():
st.session_state.mc_events_predicted_df = predict_microseismic_events(\
st.session_state.cwt_df,x_names, y_names,\
st.session_state.east, st.session_state.north, st.session_state.depth)
with st.expander("Microseismic Events"):
st.dataframe( st.session_state.mc_events_predicted_df)
fig = plot_microseismic_events( st.session_state.mc_events_predicted_df)
st.plotly_chart(fig, use_container_width=True)
else:
st.write("Please calculate CWT first")
with tabs[4]:
#upload file
with st.container():
actual_ms_uploaded_file = \
st.file_uploader("Please upload actual Micro Seismic events XLSX file", type=["xlsx"])
if actual_ms_uploaded_file:
st.session_state.ms_df = convert_ms_to_df(actual_ms_uploaded_file)
col1, col2, col3,col4 = st.columns(4)
ms_east_col = col1.selectbox("Select the east column", st.session_state.ms_df.columns)
ms_north_col = col2.selectbox("Select the north column", st.session_state.ms_df.columns)
ms_depth_col = col3.selectbox("Select the depth column", st.session_state.ms_df.columns)
depth_shift = col4.number_input("Depth shift", value=0.0)
with st.form('compare_form'):
if st.session_state.mc_events_predicted_df is not None:
fig = compare_microseismic_events(st.session_state.mc_events_predicted_df,\
st.session_state.ms_df,\
ms_east_col,ms_north_col,ms_depth_col,depth_shift)
compare_btn = st.form_submit_button(label = "Compare")
if compare_btn:
st.plotly_chart(fig, use_container_width=True)
if uploaded_pumping_file:
st.session_state.pumping_file = uploaded_pumping_file
st.session_state.pumping_df = convert_pumping_data_to_df(st.session_state.pumping_file)
st.session_state.date_col = st.sidebar.selectbox("Select the date column", st.session_state.pumping_df.columns)
st.session_state.pressure_col = st.sidebar.selectbox("Select the pressure column", st.session_state.pumping_df.columns)
st.session_state.rate_col = st.sidebar.selectbox("Select the rate column", st.session_state.pumping_df.columns)
#view pumping data via clicking the button
view_pumping_data_btn = st.sidebar.button("View pumping Data")
if view_pumping_data_btn:
try:
#create a pumping dataframe
pumping_data_frame_container.\
dataframe(st.session_state.pumping_df, use_container_width=True)
except:
pass