Skip to content

Commit 72081e7

Browse files
committed
.
1 parent bb8fb27 commit 72081e7

4 files changed

Lines changed: 93 additions & 31 deletions

File tree

notebooks/3.0-reduced-model.ipynb

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,70 @@
336336
},
337337
{
338338
"cell_type": "code",
339-
"outputs": [],
339+
"outputs": [
340+
{
341+
"ename": "ValueError",
342+
"evalue": "Length mismatch: Expected axis has 0 elements, new values have 1 elements",
343+
"output_type": "error",
344+
"traceback": [
345+
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
346+
"\u001B[0;31mValueError\u001B[0m Traceback (most recent call last)",
347+
"Cell \u001B[0;32mIn[53], line 4\u001B[0m\n\u001B[1;32m 2\u001B[0m \u001B[38;5;66;03m# E_ssC, seawater, E_ssI, soot_pollution, displacement)\u001B[39;00m\n\u001B[1;32m 3\u001B[0m result_df \u001B[38;5;241m=\u001B[39m pd\u001B[38;5;241m.\u001B[39mDataFrame(columns\u001B[38;5;241m=\u001B[39m[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mMCR\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mCDU\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mISB\u001B[39m\u001B[38;5;124m\"\u001B[39m])\n\u001B[0;32m----> 4\u001B[0m result_df\u001B[38;5;241m.\u001B[39mindex \u001B[38;5;241m=\u001B[39m [\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mRanking\u001B[39m\u001B[38;5;124m'\u001B[39m]\n\u001B[1;32m 5\u001B[0m result_df\u001B[38;5;241m.\u001B[39mappend(result)\n\u001B[1;32m 6\u001B[0m result_df\n",
348+
"File \u001B[0;32m~/Applications/anaconda3/envs/PhD_venv/lib/python3.11/site-packages/pandas/core/generic.py:6002\u001B[0m, in \u001B[0;36mNDFrame.__setattr__\u001B[0;34m(self, name, value)\u001B[0m\n\u001B[1;32m 6000\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 6001\u001B[0m \u001B[38;5;28mobject\u001B[39m\u001B[38;5;241m.\u001B[39m\u001B[38;5;21m__getattribute__\u001B[39m(\u001B[38;5;28mself\u001B[39m, name)\n\u001B[0;32m-> 6002\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mobject\u001B[39m\u001B[38;5;241m.\u001B[39m\u001B[38;5;21m__setattr__\u001B[39m(\u001B[38;5;28mself\u001B[39m, name, value)\n\u001B[1;32m 6003\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mAttributeError\u001B[39;00m:\n\u001B[1;32m 6004\u001B[0m \u001B[38;5;28;01mpass\u001B[39;00m\n",
349+
"File \u001B[0;32m~/Applications/anaconda3/envs/PhD_venv/lib/python3.11/site-packages/pandas/_libs/properties.pyx:69\u001B[0m, in \u001B[0;36mpandas._libs.properties.AxisProperty.__set__\u001B[0;34m()\u001B[0m\n",
350+
"File \u001B[0;32m~/Applications/anaconda3/envs/PhD_venv/lib/python3.11/site-packages/pandas/core/generic.py:730\u001B[0m, in \u001B[0;36mNDFrame._set_axis\u001B[0;34m(self, axis, labels)\u001B[0m\n\u001B[1;32m 725\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 726\u001B[0m \u001B[38;5;124;03mThis is called from the cython code when we set the `index` attribute\u001B[39;00m\n\u001B[1;32m 727\u001B[0m \u001B[38;5;124;03mdirectly, e.g. `series.index = [1, 2, 3]`.\u001B[39;00m\n\u001B[1;32m 728\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 729\u001B[0m labels \u001B[38;5;241m=\u001B[39m ensure_index(labels)\n\u001B[0;32m--> 730\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_mgr\u001B[38;5;241m.\u001B[39mset_axis(axis, labels)\n\u001B[1;32m 731\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_clear_item_cache()\n",
351+
"File \u001B[0;32m~/Applications/anaconda3/envs/PhD_venv/lib/python3.11/site-packages/pandas/core/internals/managers.py:225\u001B[0m, in \u001B[0;36mBaseBlockManager.set_axis\u001B[0;34m(self, axis, new_labels)\u001B[0m\n\u001B[1;32m 223\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mset_axis\u001B[39m(\u001B[38;5;28mself\u001B[39m, axis: AxisInt, new_labels: Index) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[1;32m 224\u001B[0m \u001B[38;5;66;03m# Caller is responsible for ensuring we have an Index object.\u001B[39;00m\n\u001B[0;32m--> 225\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_validate_set_axis(axis, new_labels)\n\u001B[1;32m 226\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39maxes[axis] \u001B[38;5;241m=\u001B[39m new_labels\n",
352+
"File \u001B[0;32m~/Applications/anaconda3/envs/PhD_venv/lib/python3.11/site-packages/pandas/core/internals/base.py:70\u001B[0m, in \u001B[0;36mDataManager._validate_set_axis\u001B[0;34m(self, axis, new_labels)\u001B[0m\n\u001B[1;32m 67\u001B[0m \u001B[38;5;28;01mpass\u001B[39;00m\n\u001B[1;32m 69\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m new_len \u001B[38;5;241m!=\u001B[39m old_len:\n\u001B[0;32m---> 70\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[1;32m 71\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mLength mismatch: Expected axis has \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mold_len\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m elements, new \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 72\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalues have \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mnew_len\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m elements\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 73\u001B[0m )\n",
353+
"\u001B[0;31mValueError\u001B[0m: Length mismatch: Expected axis has 0 elements, new values have 1 elements"
354+
]
355+
}
356+
],
340357
"source": [
341-
"\n"
358+
"result = y_pred1# rank_response_technologies(dispersion, E_ss, E_sl, E_sw, sufficient_mixing_energy,\n",
359+
" # E_ssC, seawater, E_ssI, soot_pollution, displacement)\n",
360+
"result_df = pd.DataFrame(columns=[\"MCR\", \"CDU\", \"ISB\"])\n",
361+
"result_df.index = ['Ranking']\n",
362+
"result_df.append(result)\n",
363+
"result_df\n",
364+
"#df.index = [100, 200, 300]"
342365
],
343366
"metadata": {
344367
"collapsed": false,
345368
"ExecuteTime": {
346-
"end_time": "2024-04-04T01:19:18.366288Z",
347-
"start_time": "2024-04-04T01:19:18.359548Z"
369+
"end_time": "2024-04-04T01:51:58.888234Z",
370+
"start_time": "2024-04-04T01:51:58.870534Z"
348371
}
349372
},
350373
"id": "3c2697ef4e9ecd16",
351-
"execution_count": 41
374+
"execution_count": 53
375+
},
376+
{
377+
"cell_type": "code",
378+
"outputs": [
379+
{
380+
"data": {
381+
"text/plain": " MCR CDU ISB\nRanking 1 1.23 Hello",
382+
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>MCR</th>\n <th>CDU</th>\n <th>ISB</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Ranking</th>\n <td>1</td>\n <td>1.23</td>\n <td>Hello</td>\n </tr>\n </tbody>\n</table>\n</div>"
383+
},
384+
"execution_count": 55,
385+
"metadata": {},
386+
"output_type": "execute_result"
387+
}
388+
],
389+
"source": [
390+
"data = dict(MCR=1, CDU=1.23, ISB='Hello')\n",
391+
"df = pd.DataFrame(data, index=['Ranking'])\n",
392+
"df"
393+
],
394+
"metadata": {
395+
"collapsed": false,
396+
"ExecuteTime": {
397+
"end_time": "2024-04-04T02:34:35.661616Z",
398+
"start_time": "2024-04-04T02:34:35.655914Z"
399+
}
400+
},
401+
"id": "c49aa451411cabc3",
402+
"execution_count": 55
352403
},
353404
{
354405
"cell_type": "code",
2.46 KB
Binary file not shown.
609 Bytes
Binary file not shown.

src/streamlit_app.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pandas as pd
77
import numpy as np
88

9-
import predict_model
9+
# import predict_model
1010
import streamlit as st
1111

1212
# import model
@@ -25,49 +25,60 @@ def rank_response_technologies(dispersion, E_ss, E_sl, E_sw, sufficient_mixing_e
2525
X1.columns = ['evaporation_and_natural_disperson', 'E_ss', 'E_sl', 'E_sw','sufficient_mixing_energy',
2626
'E_ssC', 'seawater', 'E_ssI', 'soot_pollution', 'displacement']
2727

28-
prediction = model.predict(X1)
29-
print(prediction)
28+
prediction = model.predict(X1).reshape(1,-1).flatten().tolist()
3029
return prediction
3130

3231

3332
def main():
34-
st.title("rank_response_technologies")
35-
html_temp = """
36-
<div style="background-color:tomato;padding:10px">
37-
<h2 style="color:white;text-align:center;">Ranking spill response technology: ML App </h2>
38-
</div>
39-
"""
40-
st.markdown(html_temp, unsafe_allow_html=True)
33+
# global result_df
34+
35+
html_temp = """<div style="background-color:tomato;padding:10px;height=20px">
36+
<h3 style="color:white;text-align:center;">Ranking spill response technology: ML App </h3>
37+
</div>"""
38+
st.markdown(html_temp, unsafe_allow_html=True)
4139

42-
col1, col2 = st.columns(2)
40+
input_title = """<div style="background-color:gray;padding:0px">
41+
<h4 style="color:white;text-align:center;">Input variables </h4>
42+
</div>"""
43+
st.markdown(input_title, unsafe_allow_html=True)
44+
col1, col2, col3 = st.columns(3)
4345
with col1:
4446
dispersion = st.number_input("Dispersion in %", min_value=10, max_value=99) # a value of 10-99 unit?"
45-
sufficient_mixing_energy = st.selectbox("Sufficient mixing energy", ("yes", "no"))
47+
sufficient_mixing_energy = st.selectbox("Sufficient mixing energy", ("yes", "no"), index=1)
4648
seawater = st.selectbox("Seawater volume", ("Small", "Large"))
4749
soot_pollution = st.selectbox("Soot pollution", ("YES soot pollution", "NO soot pollution"))
48-
displacement = st.selectbox("Displacement", ("yes", "no"))
50+
4951
with col2:
52+
displacement = st.selectbox("Displacement", ("yes", "no"), index=1)
5053
E_ss = st.radio("E_ss.mcr (Effect index of seasurface)", options=[-1, 0, 1], index=0)
51-
E_sl = st.selectbox('E_sl.mcr', options=[-1, 0, 1], index=0)
52-
E_sw = st.text_input("E_sw.mcr", options=[-1, 0, 1], index=0)
53-
E_ssC = st.text_input("E_ssC.cdu", options=[-1, 0, 1], index=1)
54-
E_ssI = st.text_input("E_ssI.isb", options=[-1, 0, 1], index=1)
54+
E_sl = st.radio('E_sl.mcr', options=[-1, 0, 1], index=0)
55+
with col3:
56+
E_sw = st.radio("E_sw.mcr", options=[-1, 0, 1], index=0)
57+
E_ssC = st.radio("E_ssC.cdu", options=[-1, 0, 1], index=1)
58+
E_ssI = st.radio("E_ssI.isb", options=[-1, 0, 1], index=1)
59+
60+
output_title = """<div style="background-color:grey;padding:0px">
61+
<h4 style="color:white;text-align:center;"> Result </h4>
62+
</div>"""
63+
st.markdown(output_title, unsafe_allow_html=True)
5564

5665
result = ""
5766
if st.button("Rank Technology"):
5867
result = rank_response_technologies(dispersion, E_ss, E_sl, E_sw, sufficient_mixing_energy,
5968
E_ssC, seawater, E_ssI, soot_pollution, displacement)
60-
result_df = pd.DataFrame(columns=["MCR", "CDU", "ISB"])
61-
result_df.index = ['Ranking']
62-
result_df.append(result)
63-
64-
st.success(result_df) # need to tab one level up?
6569

66-
if st.button("Publication"):
67-
st.text("Das, T., & Goerlandt, F. (2022). Bayesian inference modeling to rank response technologies in arctic marine oil spills. "
68-
"Marine Pollution Bulletin, 185, 114203")
69-
st.text("https://doi.org/10.1016/j.marpolbul.2022.114203")
70+
result_df1 = pd.DataFrame(columns=["MCR", "CDU", "ISB"])
71+
#result_df = pd.concat([result_df1, pd.DataFrame(result)], ignore_index=True, axis=0)
72+
result_df1.loc[len(result_df1.index)] = result
73+
result_df1.set_index([['Ranking'] * len(result_df1)],
74+
inplace=True) # df.set_index([['A']*len(df)], inplace=True)
75+
st.success(st.dataframe(result_df1)) # need to tab one level up?
7076

77+
paper_title = """<div style="background-color:None;padding:10px">
78+
<p style="color:None;text-align:left;"> Reference: Das, T., & Goerlandt, F. (2022). Bayesian inference modeling to rank response technologies in arctic marine oil spills. "
79+
"Marine Pollution Bulletin, 185, 114203 <a href="https://doi.org/10.1016/j.marpolbul.2022.114203"> (link) </a> </p>
80+
</div>"""
81+
st.markdown(paper_title, unsafe_allow_html=True)
7182

7283
if __name__ == '__main__':
7384
main()

0 commit comments

Comments
 (0)