Upload 9 files
Browse files- .gitattributes +35 -0
- README.md +13 -0
- app.py +52 -0
- config.py +44 -0
- dots_graph2.jpg +0 -0
- helpers.py +72 -0
- report.py +72 -0
- requirements.txt +14 -0
- sections.py +681 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Building Acoustics Analysis TestLab
|
3 |
+
emoji: π
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: pink
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.37.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
2 |
+
# Building Acoustics Analysis Tool Β· Streamlit 1.35
|
3 |
+
# RT60 Β· Background-Noise Β· Speech-Intelligibility
|
4 |
+
# Version: V4-2025
|
5 |
+
# Date: July 2025
|
6 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
7 |
+
|
8 |
+
import streamlit as st
|
9 |
+
from config import MAJOR_TABS, DEFAULTS
|
10 |
+
from sections import (
|
11 |
+
section_instructions, section_initial_data, section_initial_checks,
|
12 |
+
section_acoustic_treatment, section_final_checks, section_faq,
|
13 |
+
nav_to, nav_buttons
|
14 |
+
)
|
15 |
+
from report import generate_docx
|
16 |
+
|
17 |
+
# ββ page config (unchanged) ββββββββββββββββββββββββββββββββββββββββββββββββ
|
18 |
+
st.set_page_config("Building Acoustics Analysis Tool", "π«",
|
19 |
+
layout="wide", initial_sidebar_state="expanded")
|
20 |
+
|
21 |
+
# ββ ensure session-state keys exist ββββββββββββββββββββββββββββββββββββββββ
|
22 |
+
for k, v in DEFAULTS.items():
|
23 |
+
st.session_state.setdefault(k, v)
|
24 |
+
|
25 |
+
# ββ sidebar navigation βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
26 |
+
with st.sidebar:
|
27 |
+
st.header("Navigation")
|
28 |
+
for tab in MAJOR_TABS:
|
29 |
+
st.button(tab, on_click=nav_to, args=(tab,))
|
30 |
+
st.markdown("---")
|
31 |
+
st.write("Version: V4-2025")
|
32 |
+
if st.session_state.major_tab == "Final Compliance Checks":
|
33 |
+
st.download_button("π₯ Word Report",
|
34 |
+
generate_docx(),
|
35 |
+
"Acoustics_Report.docx",
|
36 |
+
"application/vnd.openxmlformats-officedocument."
|
37 |
+
"wordprocessingml.document")
|
38 |
+
|
39 |
+
# ββ router βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
40 |
+
ROUTES = {
|
41 |
+
"Instructions": section_instructions,
|
42 |
+
"Initial Data Entry": section_initial_data,
|
43 |
+
"Initial Compliance Checks": section_initial_checks,
|
44 |
+
"Acoustic Treatment": section_acoustic_treatment,
|
45 |
+
"Final Compliance Checks": section_final_checks,
|
46 |
+
"FAQ / Help": section_faq,
|
47 |
+
}
|
48 |
+
ROUTES[st.session_state.major_tab]()
|
49 |
+
|
50 |
+
# ββ footer βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
51 |
+
st.write("---")
|
52 |
+
st.write("Developed by Dr Abdul-Manan Sadick Β· Deakin University Β· 2025")
|
config.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Global constants and initial session-state defaults."""
|
2 |
+
from typing import List
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
FREQUENCIES: List[int] = [125, 250, 500, 1000, 2000, 4000]
|
6 |
+
TOTAL_DOTS = 200
|
7 |
+
AI_BANDS = {
|
8 |
+
(0.00, 0.24): "None",
|
9 |
+
(0.25, 0.40): "Fair",
|
10 |
+
(0.41, 0.60): "Good",
|
11 |
+
(0.61, 1.00): "Excellent",
|
12 |
+
}
|
13 |
+
MAJOR_TABS = [
|
14 |
+
"Instructions",
|
15 |
+
"Initial Data Entry",
|
16 |
+
"Initial Compliance Checks",
|
17 |
+
"Acoustic Treatment",
|
18 |
+
"Final Compliance Checks",
|
19 |
+
"FAQ / Help",
|
20 |
+
]
|
21 |
+
|
22 |
+
# ββ Streamlit-session defaults ββββββββββββββββββββββββββββββββββββββββββββ
|
23 |
+
DEFAULTS = dict(
|
24 |
+
major_tab=MAJOR_TABS[0],
|
25 |
+
# uploads / inputs
|
26 |
+
df_current_rt=None, df_existing_mat=None, room_volume=0.0,
|
27 |
+
df_background_noise=pd.DataFrame(columns=["Location", "dBA"]),
|
28 |
+
bn_input_loc="", bn_input_val=0.0,
|
29 |
+
df_spl=None,
|
30 |
+
# compliance params
|
31 |
+
rt_min=0.0, rt_max=0.0, bn_min=0.0, bn_max=0.0,
|
32 |
+
# multi-location AI dictionaries
|
33 |
+
dots_init_dict={}, ai_init_dict={},
|
34 |
+
dots_final_dict={}, ai_final_dict={},
|
35 |
+
# acoustic-treatment data
|
36 |
+
desired_rt_df=pd.DataFrame(
|
37 |
+
{"Frequency": FREQUENCIES, "Desired RT60": [0.01]*6}
|
38 |
+
),
|
39 |
+
df_new_mat=None,
|
40 |
+
# derived absorption & figures
|
41 |
+
current_absorption={}, new_absorption={},
|
42 |
+
fig_rt_initial=None, fig_bn_initial=None,
|
43 |
+
fig_rt_final=None, fig_bn_final=None,
|
44 |
+
)
|
dots_graph2.jpg
ADDED
![]() |
helpers.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Utility functions shared by all modules."""
|
2 |
+
import io, re, numpy as np, pandas as pd
|
3 |
+
import plotly.graph_objects as go
|
4 |
+
import streamlit as st
|
5 |
+
from config import FREQUENCIES, TOTAL_DOTS, AI_BANDS
|
6 |
+
|
7 |
+
# ββ misc helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
8 |
+
def slugify(txt: str) -> str:
|
9 |
+
return re.sub(r"[^0-9a-zA-Z_]+", "_", txt)
|
10 |
+
|
11 |
+
def standardise_freq_cols(df: pd.DataFrame) -> pd.DataFrame:
|
12 |
+
m = {"125Hz": "125", "250Hz": "250", "500Hz": "500", "1000Hz": "1000",
|
13 |
+
"1KHz": "1000", "2KHz": "2000", "4KHz": "4000"}
|
14 |
+
df.columns = [m.get(str(c).replace(" Hz", "").replace("KHz", "000").strip(),
|
15 |
+
str(c).strip()) for c in df.columns]
|
16 |
+
df.columns = pd.to_numeric(df.columns, errors="ignore")
|
17 |
+
return df
|
18 |
+
|
19 |
+
def validate_numeric(df): # True if all numeric
|
20 |
+
return not df.empty and df.applymap(np.isreal).all().all()
|
21 |
+
|
22 |
+
@st.cache_data(show_spinner=False)
|
23 |
+
def read_upload(upload, *, header=0, index_col=None):
|
24 |
+
raw = upload.getvalue()
|
25 |
+
if upload.name.endswith(".csv"):
|
26 |
+
return pd.read_csv(io.BytesIO(raw), header=header, index_col=index_col)
|
27 |
+
return pd.read_excel(io.BytesIO(raw), header=header, index_col=index_col)
|
28 |
+
|
29 |
+
def calc_abs_area(volume_m3, rt_s):
|
30 |
+
return float("inf") if rt_s == 0 else 0.16 * volume_m3 / rt_s
|
31 |
+
|
32 |
+
# ββ plotting helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
33 |
+
def plot_rt_band(y_cur, y_min, y_max, title):
|
34 |
+
f = go.Figure()
|
35 |
+
f.add_trace(go.Scatter(x=FREQUENCIES, y=y_cur, mode="lines+markers",
|
36 |
+
name="Current", marker_color="#1f77b4"))
|
37 |
+
f.add_trace(go.Scatter(x=FREQUENCIES, y=y_max, mode="lines",
|
38 |
+
name="Max Std", line=dict(dash="dash", color="#ff7f0e")))
|
39 |
+
f.add_trace(go.Scatter(x=FREQUENCIES, y=y_min, mode="lines",
|
40 |
+
name="Min Std", line=dict(dash="dash", color="#2ca02c"),
|
41 |
+
fill="tonexty", fillcolor="rgba(44,160,44,0.15)"))
|
42 |
+
f.update_layout(template="plotly_white", title=title,
|
43 |
+
xaxis_title="Frequency (Hz)",
|
44 |
+
yaxis_title="Reverberation Time (s)",
|
45 |
+
legend=dict(orientation="h", y=-0.2))
|
46 |
+
return f
|
47 |
+
|
48 |
+
def plot_bn_band(x, y_meas, y_min, y_max, title):
|
49 |
+
f = go.Figure()
|
50 |
+
f.add_trace(go.Bar(x=x, y=y_meas, name="Measured",
|
51 |
+
marker_color="#1f77b4", opacity=0.6))
|
52 |
+
f.add_shape(type="rect", x0=-.5, x1=len(x)-.5, y0=y_min, y1=y_max,
|
53 |
+
fillcolor="rgba(255,0,0,0.15)", line=dict(width=0), layer="below")
|
54 |
+
for y, c, lbl in [(y_max, "#ff0000", "Max Std"),
|
55 |
+
(y_min, "#ff0000", "Min Std")]:
|
56 |
+
f.add_shape(type="line", x0=-.5, x1=len(x)-.5, y0=y, y1=y,
|
57 |
+
line=dict(color=c, dash="dash"))
|
58 |
+
f.add_trace(go.Scatter(x=[None], y=[None], mode="lines",
|
59 |
+
line=dict(color=c, dash="dash"),
|
60 |
+
showlegend=True, name=lbl))
|
61 |
+
f.update_layout(template="plotly_white", title=title,
|
62 |
+
xaxis_title="Location", yaxis_title="Sound Level (dBA)",
|
63 |
+
legend=dict(orientation="h", y=-0.2))
|
64 |
+
return f
|
65 |
+
|
66 |
+
# ββ speech-intelligibility βββββββββββββββββββββββββββββββββββββββββββββββββ
|
67 |
+
def articulation_index(dots: int):
|
68 |
+
ai = dots / TOTAL_DOTS
|
69 |
+
for (lo, hi), lbl in AI_BANDS.items():
|
70 |
+
if lo <= ai <= hi:
|
71 |
+
return ai, lbl
|
72 |
+
return ai, "Out of range"
|
report.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Generate the downloadable Word report."""
|
2 |
+
import io, tempfile
|
3 |
+
from docx import Document
|
4 |
+
from docx.shared import Inches
|
5 |
+
import streamlit as st
|
6 |
+
from config import FREQUENCIES
|
7 |
+
from helpers import calc_abs_area
|
8 |
+
|
9 |
+
def generate_docx() -> bytes:
|
10 |
+
doc = Document()
|
11 |
+
doc.add_heading("Room Acoustics Analysis Report", 0)
|
12 |
+
|
13 |
+
# 1 β Input data
|
14 |
+
doc.add_heading("1 Input Data", 1)
|
15 |
+
doc.add_paragraph(f"Room volume: {st.session_state.room_volume:.2f} mΒ³")
|
16 |
+
|
17 |
+
if st.session_state.df_current_rt is not None:
|
18 |
+
doc.add_heading("Current Reverberation Time", 2)
|
19 |
+
doc.add_paragraph(st.session_state.df_current_rt.to_string(index=False))
|
20 |
+
|
21 |
+
if st.session_state.df_existing_mat is not None:
|
22 |
+
doc.add_heading("Existing Materials β Coefficients & Areas", 2)
|
23 |
+
doc.add_paragraph(st.session_state.df_existing_mat.to_string(index=False))
|
24 |
+
|
25 |
+
if not st.session_state.df_background_noise.empty:
|
26 |
+
doc.add_heading("Background-Noise Measurements", 2)
|
27 |
+
doc.add_paragraph(st.session_state.df_background_noise.to_string(index=False))
|
28 |
+
|
29 |
+
if st.session_state.df_spl is not None:
|
30 |
+
doc.add_heading("Sound-Pressure Levels (SPL)", 2)
|
31 |
+
doc.add_paragraph(st.session_state.df_spl.to_string())
|
32 |
+
|
33 |
+
# 2 β Speech-intelligibility (Dots & AI)
|
34 |
+
doc.add_heading("2 Speech-Intelligibility (Dots & AI)", 1)
|
35 |
+
|
36 |
+
if st.session_state.dots_init_dict:
|
37 |
+
doc.add_heading("Initial Compliance Check", 2)
|
38 |
+
for loc, dots in st.session_state.dots_init_dict.items():
|
39 |
+
ai, interp = st.session_state.ai_init_dict.get(loc, (None, ""))
|
40 |
+
line = f"{loc}: Dots = {dots}"
|
41 |
+
if ai is not None:
|
42 |
+
line += f" β AI = {ai:.2f} ({interp})"
|
43 |
+
doc.add_paragraph(line)
|
44 |
+
|
45 |
+
if st.session_state.dots_final_dict:
|
46 |
+
doc.add_heading("Final Compliance Check", 2)
|
47 |
+
for loc, dots in st.session_state.dots_final_dict.items():
|
48 |
+
ai, interp = st.session_state.ai_final_dict.get(loc, (None, ""))
|
49 |
+
line = f"{loc}: Dots = {dots}"
|
50 |
+
if ai is not None:
|
51 |
+
line += f" β AI = {ai:.2f} ({interp})"
|
52 |
+
doc.add_paragraph(line)
|
53 |
+
|
54 |
+
# 3 β Figures
|
55 |
+
doc.add_heading("3 Figures", 1)
|
56 |
+
|
57 |
+
def _add(fig, caption):
|
58 |
+
if fig is None: return
|
59 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
60 |
+
fig.write_image(tmp.name, scale=4)
|
61 |
+
doc.add_picture(tmp.name, width=Inches(6))
|
62 |
+
doc.paragraphs[-1].alignment = 1
|
63 |
+
doc.add_paragraph(caption, style="Caption")
|
64 |
+
|
65 |
+
_add(st.session_state.fig_rt_initial, "Fig 1 Initial RT60 vs Standard Range")
|
66 |
+
_add(st.session_state.fig_bn_initial, "Fig 2 Initial Background-Noise vs Standard Range")
|
67 |
+
_add(st.session_state.fig_rt_final, "Fig 3 Final RT60 vs Standard Range")
|
68 |
+
_add(st.session_state.fig_bn_final, "Fig 4 Final Background-Noise vs Standard Range")
|
69 |
+
|
70 |
+
buf = io.BytesIO()
|
71 |
+
doc.save(buf)
|
72 |
+
return buf.getvalue()
|
requirements.txt
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Core web-app stack
|
2 |
+
streamlit==1.35.0
|
3 |
+
plotly==5.20.0
|
4 |
+
kaleido==0.2.1
|
5 |
+
|
6 |
+
# Data analysis
|
7 |
+
pandas==2.2.2
|
8 |
+
numpy==1.26.4
|
9 |
+
openpyxl==3.1.2
|
10 |
+
|
11 |
+
# Word-report generation
|
12 |
+
python-docx==1.1.0
|
13 |
+
|
14 |
+
altair<5
|
sections.py
ADDED
@@ -0,0 +1,681 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
sections.py
|
3 |
+
===========
|
4 |
+
|
5 |
+
All Streamlit UI page/section functions for the Building Acoustics Analysis
|
6 |
+
Tool. No functional changes have been introduced.
|
7 |
+
"""
|
8 |
+
from __future__ import annotations
|
9 |
+
|
10 |
+
# ββ third-party ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
11 |
+
import numpy as np
|
12 |
+
import pandas as pd
|
13 |
+
import plotly.graph_objects as go
|
14 |
+
import streamlit as st
|
15 |
+
|
16 |
+
# ββ local imports βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
17 |
+
from config import FREQUENCIES, MAJOR_TABS, TOTAL_DOTS
|
18 |
+
from helpers import (
|
19 |
+
slugify,
|
20 |
+
standardise_freq_cols,
|
21 |
+
validate_numeric,
|
22 |
+
read_upload,
|
23 |
+
calc_abs_area,
|
24 |
+
plot_rt_band,
|
25 |
+
plot_bn_band,
|
26 |
+
articulation_index,
|
27 |
+
)
|
28 |
+
|
29 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
30 |
+
# Navigation helpers (used by several sections)
|
31 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
32 |
+
def nav_to(tab: str) -> None:
|
33 |
+
"""Switch the major tab in session-state."""
|
34 |
+
st.session_state.major_tab = tab
|
35 |
+
|
36 |
+
|
37 |
+
def nav_buttons() -> None:
|
38 |
+
"""Render β / β buttons with explicit section names."""
|
39 |
+
idx = MAJOR_TABS.index(st.session_state.major_tab)
|
40 |
+
c1, _, c3 = st.columns([2, 6, 2])
|
41 |
+
if idx > 0:
|
42 |
+
c1.button(f"β {MAJOR_TABS[idx-1]}", on_click=nav_to,
|
43 |
+
args=(MAJOR_TABS[idx-1],))
|
44 |
+
if idx < len(MAJOR_TABS) - 1:
|
45 |
+
c3.button(f"{MAJOR_TABS[idx+1]} β", on_click=nav_to,
|
46 |
+
args=(MAJOR_TABS[idx+1],))
|
47 |
+
|
48 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
49 |
+
# Individual sections (exact logic preserved)
|
50 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
51 |
+
def section_instructions() -> None:
|
52 |
+
st.title("π Building Acoustics Analysis Tool")
|
53 |
+
|
54 |
+
with st.expander("App Information", expanded=False):
|
55 |
+
st.write("""
|
56 |
+
- Welcome to the Building Acoustics Analysis Tool.
|
57 |
+
- This app was developed to help Deakin University Construction Management students complete a building acoustics assignment in SRT757 Building Systems and Environment.
|
58 |
+
- This app is intended for a retrofitting task and assumes that you have measured the current reverberation of the room to be assessed.
|
59 |
+
- The app helps to analyze and modify room reverberation times to fall within standard ranges using the Sabine equation.
|
60 |
+
- This app is intended for educational purposes only and should not be used for professional purposes.
|
61 |
+
""")
|
62 |
+
|
63 |
+
# Example DataFrames
|
64 |
+
df_current_reverberation_times = pd.DataFrame({
|
65 |
+
'125': [0.8], '250': [0.7], '500': [0.6],
|
66 |
+
'1000': [0.5], '2000': [0.4], '4000': [0.3]
|
67 |
+
})
|
68 |
+
|
69 |
+
df_existing_materials = pd.DataFrame({
|
70 |
+
'Material Name': ['Carpet', 'Curtain'],
|
71 |
+
'Area_No': [50, 30],
|
72 |
+
'125': [0.1, 0.2], '250': [0.15, 0.25], '500': [0.2, 0.3],
|
73 |
+
'1000': [0.3, 0.35], '2000': [0.4, 0.45], '4000': [0.5, 0.55]
|
74 |
+
})
|
75 |
+
|
76 |
+
df_new_materials = pd.DataFrame({
|
77 |
+
'Material Name': ['Acoustic Panel', 'Foam'],
|
78 |
+
'Area_No': [40, 20],
|
79 |
+
'125': [0.3, 0.25], '250': [0.35, 0.3], '500': [0.4, 0.35],
|
80 |
+
'1000': [0.45, 0.4], '2000': [0.5, 0.45], '4000': [0.6, 0.55]
|
81 |
+
})
|
82 |
+
|
83 |
+
df_sound_pressure_levels = pd.DataFrame({
|
84 |
+
'Location': ['Location 1', 'Location 2'],
|
85 |
+
'125': [60, 62], '250': [58, 59], '500': [55, 56],
|
86 |
+
'1000': [52, 53], '2000': [50, 51], '4000': [48, 49]
|
87 |
+
})
|
88 |
+
|
89 |
+
st.write("## Instructions")
|
90 |
+
|
91 |
+
st.markdown("""
|
92 |
+
Welcome to the **Building Acoustics Analysis Tool**. This educational application supports students in analyzing and improving room acoustics by addressing:
|
93 |
+
- **Reverberation Time (RT60)**
|
94 |
+
- **Background Noise**
|
95 |
+
- **Speech Intelligibility (Articulation Index)**
|
96 |
+
|
97 |
+
The tool is structured around Sabine's theory and common acoustic assessment standards, using six standard frequencies (125 Hz, 250 Hz, 500 Hz, 1000 Hz, 2000 Hz, and 4000 Hz). It is designed to help users diagnose and treat acoustic deficiencies by uploading and modifying material and noise-related inputs.
|
98 |
+
|
99 |
+
β οΈ **Note:** This tool is intended for educational purposes and should not be used for professional certification or compliance without additional verification.
|
100 |
+
|
101 |
+
### Reverberation Time (RT60)
|
102 |
+
RT60 represents the time required for a sound to decay by 60 dB after the source stops. An optimal RT60 enhances clarity and acoustic comfort:
|
103 |
+
- **Short RT60**: Suitable for classrooms, meeting rooms, and lecture halls.
|
104 |
+
- **Longer RT60**: More acceptable in concert halls and religious buildings.
|
105 |
+
|
106 |
+
#### RT60 Calculation β Sabineβs Equation
|
107 |
+
**RT60 = (0.16 Γ V) / A**
|
108 |
+
|
109 |
+
Where:
|
110 |
+
- `V` = Room volume (mΒ³)
|
111 |
+
- `A` = Total absorption (mΒ² Sabins)
|
112 |
+
|
113 |
+
**Example**:
|
114 |
+
If a 100 mΒ³ room has total absorption of 10 mΒ²:
|
115 |
+
**RT60 = (0.16 Γ 100) / 10 = 1.60 seconds**
|
116 |
+
|
117 |
+
### Background Noise
|
118 |
+
Background noise refers to ambient sound levels in a room, typically measured in **dBA**. Excessive background noise can mask speech and reduce communication effectiveness, even in acoustically treated rooms.
|
119 |
+
|
120 |
+
The app allows users to enter measured **background noise levels** for one or more locations and compare them with recommended standard ranges. You can visualize these using bar plots and identify areas needing improvement.
|
121 |
+
|
122 |
+
- **Sources**: HVAC systems, outside traffic, or adjacent room activities.
|
123 |
+
- **Goal**: Maintain noise levels within acceptable limits (as defined by relevant standards).
|
124 |
+
|
125 |
+
### Speech Intelligibility
|
126 |
+
Speech intelligibility is the measure of how clearly speech can be understood within a room. This tool uses the **Articulation Index (AI)** method:
|
127 |
+
- Based on βDots Above a Curveβ from sound pressure level data
|
128 |
+
- User inputs number of audible speech "dots" above noise thresholds
|
129 |
+
- AI is computed and interpreted (None, Fair, Good, Excellent)
|
130 |
+
|
131 |
+
Higher AI scores suggest better speech transmission. This measure is particularly important in educational, healthcare, and public spaces.
|
132 |
+
|
133 |
+
### App Functionality
|
134 |
+
The app guides users through six key stages:
|
135 |
+
1. **Initial Data Entry** β Upload baseline acoustic data (RT60, materials, background noise, SPL).
|
136 |
+
2. **Initial Compliance Checks** β Review current RT60, noise levels, and speech intelligibility.
|
137 |
+
3. **Desired RT60** β Define preferred RT60 per frequency to guide treatment.
|
138 |
+
4. **Acoustic Treatment** β Add new materials to adjust absorption.
|
139 |
+
5. **Final Compliance Checks** β Evaluate impact on RT60, noise, and intelligibility.
|
140 |
+
6. **FAQ / Help** β Access help content and export a summary report.
|
141 |
+
|
142 |
+
### Formatting Input Data
|
143 |
+
|
144 |
+
β οΈ **Use CSV or Excel, following the formats shown below without.**
|
145 |
+
|
146 |
+
#### Current Reverberation Times
|
147 |
+
- **Format**: One row, column headers = frequencies
|
148 |
+
""")
|
149 |
+
st.write(df_current_reverberation_times)
|
150 |
+
|
151 |
+
st.markdown("""
|
152 |
+
#### Existing Materials β Absorption Coefficients and Areas
|
153 |
+
- **Format**: Material name, surface area, absorption coefficients
|
154 |
+
""")
|
155 |
+
st.write(df_existing_materials)
|
156 |
+
|
157 |
+
st.markdown("""
|
158 |
+
#### New Materials β Absorption Coefficients and Areas
|
159 |
+
- **Format**: Same structure as existing materials
|
160 |
+
""")
|
161 |
+
st.write(df_new_materials)
|
162 |
+
|
163 |
+
st.markdown("""
|
164 |
+
#### Sound Pressure Levels (SPL)
|
165 |
+
- **Format**: Location name in first column; SPLs at frequencies as columns
|
166 |
+
""")
|
167 |
+
st.write(df_sound_pressure_levels)
|
168 |
+
|
169 |
+
st.markdown("""
|
170 |
+
### Navigation Summary
|
171 |
+
|
172 |
+
- **Instructions** β You are here. Read all information before starting.
|
173 |
+
- **Initial Data Entry** β Upload all your acoustic data. Room volume, RT60, background noise, and SPLs are required.
|
174 |
+
- **Initial Compliance Checks** β Visualize current RT60, compare background noise with limits, and assess initial speech intelligibility.
|
175 |
+
- **Desired RT60** β Define target reverberation levels per frequency. This guides treatment planning.
|
176 |
+
- **Acoustic Treatment** β Upload and experiment with new materials to modify absorption and reduce noise.
|
177 |
+
- **Final Compliance Checks** β Review the combined impact of old and new materials on RT60, noise, and speech clarity.
|
178 |
+
|
179 |
+
### General Tips
|
180 |
+
- Keep filenames and headings clean and consistent.
|
181 |
+
- Use the six standard frequencies.
|
182 |
+
- Adjust materials iteratively to achieve compliance.
|
183 |
+
- Download your report after completing all sections.
|
184 |
+
|
185 |
+
For further clarification or examples, please consult the FAQ tab or contact your instructor.
|
186 |
+
""")
|
187 |
+
st.info("After reviewing the instructions, proceed to the **Initial Data Entry** tab.")
|
188 |
+
|
189 |
+
nav_buttons()
|
190 |
+
|
191 |
+
|
192 |
+
# ---------------------------------------------------------------------------
|
193 |
+
def section_initial_data() -> None:
|
194 |
+
st.title("π Building Acoustics Analysis Tool")
|
195 |
+
|
196 |
+
with st.expander("App Information", expanded=False):
|
197 |
+
st.write("""
|
198 |
+
- This app is intended for educational purposes only and should not be used for professional purposes.
|
199 |
+
""")
|
200 |
+
|
201 |
+
st.header("π₯ Initial Data Entry")
|
202 |
+
t_rt, t_bn, t_si = st.tabs(
|
203 |
+
["Reverberation Time", "Background Noise", "Speech Intelligibility"])
|
204 |
+
|
205 |
+
# ββ RT60 + materials βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
206 |
+
with t_rt:
|
207 |
+
|
208 |
+
st.write('''The primary objective here is to provide all the initial input data needed to
|
209 |
+
start RT60 analysis. See the 'Instructions' on the left for formatting information.''')
|
210 |
+
|
211 |
+
c1, c2 = st.columns(2)
|
212 |
+
u_rt = c1.file_uploader("Current RT60 data (CSV/XLSX)", type=["csv", "xlsx"])
|
213 |
+
if u_rt:
|
214 |
+
df = standardise_freq_cols(read_upload(u_rt))
|
215 |
+
st.session_state.df_current_rt = df if validate_numeric(df) else None
|
216 |
+
|
217 |
+
u_mat = c2.file_uploader("Existing materials (CSV/XLSX)",
|
218 |
+
type=["csv", "xlsx"])
|
219 |
+
if u_mat:
|
220 |
+
dfm = standardise_freq_cols(read_upload(u_mat))
|
221 |
+
st.session_state.df_existing_mat = (
|
222 |
+
dfm if validate_numeric(dfm.iloc[:, 2:]) else None
|
223 |
+
)
|
224 |
+
|
225 |
+
st.session_state.room_volume = st.number_input(
|
226 |
+
"Room volume [mΒ³]",
|
227 |
+
value=st.session_state.room_volume,
|
228 |
+
min_value=0.0,
|
229 |
+
step=0.1,
|
230 |
+
)
|
231 |
+
|
232 |
+
# warnings
|
233 |
+
if st.session_state.df_current_rt is None:
|
234 |
+
st.warning("β οΈ Upload *Current RT60* data.")
|
235 |
+
if st.session_state.df_existing_mat is None:
|
236 |
+
st.warning("β οΈ Upload *Existing Materials* data.")
|
237 |
+
if st.session_state.room_volume == 0:
|
238 |
+
st.warning("β οΈ Enter a non-zero room volume.")
|
239 |
+
|
240 |
+
if st.session_state.df_current_rt is not None:
|
241 |
+
st.dataframe(st.session_state.df_current_rt, use_container_width=True)
|
242 |
+
if st.session_state.df_existing_mat is not None:
|
243 |
+
st.dataframe(st.session_state.df_existing_mat, use_container_width=True)
|
244 |
+
|
245 |
+
# ββ Background noise βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
246 |
+
with t_bn:
|
247 |
+
|
248 |
+
st.write('''The primary objective here is to provide the initial input data needed to
|
249 |
+
start background noise analysis. See the 'Instructions' on the left for formatting information''')
|
250 |
+
|
251 |
+
c1, c2, c3 = st.columns([3, 2, 1])
|
252 |
+
st.session_state.bn_input_loc = c1.text_input(
|
253 |
+
"Location", st.session_state.bn_input_loc)
|
254 |
+
st.session_state.bn_input_val = c2.number_input(
|
255 |
+
"dBA", value=st.session_state.bn_input_val, min_value=0.0, step=0.1)
|
256 |
+
|
257 |
+
if c3.button("Add / Update"):
|
258 |
+
loc = st.session_state.bn_input_loc.strip()
|
259 |
+
if loc:
|
260 |
+
df = st.session_state.df_background_noise
|
261 |
+
if loc in df["Location"].values:
|
262 |
+
df.loc[df["Location"] == loc, "dBA"] = st.session_state.bn_input_val
|
263 |
+
else:
|
264 |
+
df.loc[len(df)] = [loc, st.session_state.bn_input_val]
|
265 |
+
st.session_state.df_background_noise = df
|
266 |
+
|
267 |
+
if st.session_state.df_background_noise.empty:
|
268 |
+
st.warning("β οΈ Enter at least one background-noise measurement.")
|
269 |
+
|
270 |
+
st.dataframe(st.session_state.df_background_noise, use_container_width=True)
|
271 |
+
|
272 |
+
# ββ SPL upload βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
273 |
+
with t_si:
|
274 |
+
|
275 |
+
st.write('''The primary objective here is to provide the initial input data needed to
|
276 |
+
start speech intelligibility analysis. See the 'Instructions' on the left for
|
277 |
+
formatting information''')
|
278 |
+
|
279 |
+
u = st.file_uploader("Current sound pressure level data (CSV/XLSX)", type=["csv", "xlsx"])
|
280 |
+
if u:
|
281 |
+
df = standardise_freq_cols(read_upload(u, header=0, index_col=0))
|
282 |
+
df.columns = [int(c) for c in df.columns]
|
283 |
+
st.session_state.df_spl = (
|
284 |
+
df if set(df.columns) >= set(FREQUENCIES) else None
|
285 |
+
)
|
286 |
+
# reset AI dicts on new upload
|
287 |
+
st.session_state.dots_init_dict, st.session_state.ai_init_dict = {}, {}
|
288 |
+
st.session_state.dots_final_dict, st.session_state.ai_final_dict = {}, {}
|
289 |
+
|
290 |
+
if st.session_state.df_spl is None:
|
291 |
+
st.warning("β οΈ Upload *SPL* data with columns 125β4000 Hz.")
|
292 |
+
else:
|
293 |
+
st.dataframe(st.session_state.df_spl, use_container_width=True)
|
294 |
+
|
295 |
+
nav_buttons()
|
296 |
+
|
297 |
+
|
298 |
+
# ---------------------------------------------------------------------------
|
299 |
+
def section_initial_checks() -> None:
|
300 |
+
st.title("π Building Acoustics Analysis Tool")
|
301 |
+
|
302 |
+
with st.expander("App Information", expanded=False):
|
303 |
+
st.write("""
|
304 |
+
- This app is intended for educational purposes only and should not be used for professional purposes.
|
305 |
+
""")
|
306 |
+
|
307 |
+
st.header("β
Initial Compliance Checks")
|
308 |
+
st.write("""The purpose of initial complaince checks to verify if the acoustic properties
|
309 |
+
of the space complies with standards. If the space complies, acoustic treatment may not
|
310 |
+
be required. """)
|
311 |
+
t_rt, t_bn, t_si = st.tabs(
|
312 |
+
["Reverberation Time", "Background Noise", "Speech Intelligibility"])
|
313 |
+
|
314 |
+
# early global warnings
|
315 |
+
if (st.session_state.df_current_rt is None or
|
316 |
+
st.session_state.df_existing_mat is None):
|
317 |
+
st.warning("β οΈ Current RT60 and/or Materials data missing "
|
318 |
+
"(see *Initial Data Entry*).")
|
319 |
+
if st.session_state.df_background_noise.empty:
|
320 |
+
st.warning("β οΈ Background-noise data missing "
|
321 |
+
"(see *Initial Data Entry*).")
|
322 |
+
if st.session_state.df_spl is None:
|
323 |
+
st.warning("β οΈ Sound pressure level (SPL) data missing (see *Initial Data Entry*).")
|
324 |
+
|
325 |
+
# ββ RT60 check βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
326 |
+
with t_rt:
|
327 |
+
st.write("""Privide the min and max standard RT60 for your space type to complete
|
328 |
+
initial RT60 compliance check.""")
|
329 |
+
c1, c2 = st.columns(2)
|
330 |
+
st.session_state.rt_min = c1.number_input(
|
331 |
+
"Min standard RT60 [s]", value=st.session_state.rt_min, min_value=0.0, step=0.01)
|
332 |
+
st.session_state.rt_max = c2.number_input(
|
333 |
+
"Max standard RT60 [s]", value=st.session_state.rt_max, min_value=0.0, step=0.01)
|
334 |
+
|
335 |
+
if st.session_state.rt_max <= st.session_state.rt_min:
|
336 |
+
st.warning("β οΈ Max RT60 must be greater than Min RT60.")
|
337 |
+
|
338 |
+
if st.session_state.df_existing_mat is not None:
|
339 |
+
@st.cache_data(show_spinner=False)
|
340 |
+
def _abs(df):
|
341 |
+
acc = {f: 0.0 for f in FREQUENCIES}
|
342 |
+
for _, r in df.iterrows():
|
343 |
+
area = r[1]
|
344 |
+
for f, coeff in zip(FREQUENCIES, r[2:]):
|
345 |
+
acc[f] += coeff * area
|
346 |
+
return acc
|
347 |
+
|
348 |
+
st.markdown("""###### Sound absorption based initial matrials""")
|
349 |
+
st.session_state.current_absorption = _abs(
|
350 |
+
st.session_state.df_existing_mat)
|
351 |
+
st.dataframe(pd.DataFrame([st.session_state.current_absorption]),
|
352 |
+
use_container_width=True)
|
353 |
+
|
354 |
+
if (st.session_state.df_current_rt is not None and
|
355 |
+
st.session_state.rt_max > st.session_state.rt_min):
|
356 |
+
y_cur = [float(st.session_state.df_current_rt.iloc[0][f])
|
357 |
+
for f in FREQUENCIES]
|
358 |
+
fig = plot_rt_band(
|
359 |
+
y_cur,
|
360 |
+
[st.session_state.rt_min]*6,
|
361 |
+
[st.session_state.rt_max]*6,
|
362 |
+
"Initial RT60 vs Standard RT60 Range",
|
363 |
+
)
|
364 |
+
st.plotly_chart(fig, use_container_width=True)
|
365 |
+
st.session_state.fig_rt_initial = fig
|
366 |
+
|
367 |
+
# ββ Background noise check βββββββββββββββββββββββββββββββββββββββββββββ
|
368 |
+
with t_bn:
|
369 |
+
st.write("""Provide the min and max standard background noise for your space type to
|
370 |
+
complete complaince check.""")
|
371 |
+
c1, c2 = st.columns(2)
|
372 |
+
st.session_state.bn_min = c1.number_input(
|
373 |
+
"Min standard background noise [dBA]", value=st.session_state.bn_min, min_value=0.0, step=0.1)
|
374 |
+
st.session_state.bn_max = c2.number_input(
|
375 |
+
"Max standard background noise [dBA]", value=st.session_state.bn_max, min_value=0.0, step=0.1)
|
376 |
+
|
377 |
+
if st.session_state.bn_max <= st.session_state.bn_min:
|
378 |
+
st.warning("β οΈ Max background noise must be greater than Min background noise.")
|
379 |
+
|
380 |
+
df = st.session_state.df_background_noise
|
381 |
+
if (not df.empty and st.session_state.bn_max > st.session_state.bn_min):
|
382 |
+
fig = plot_bn_band(
|
383 |
+
df["Location"], df["dBA"],
|
384 |
+
st.session_state.bn_min, st.session_state.bn_max,
|
385 |
+
"Initial Background Noise vs Standard Background Noise Range",
|
386 |
+
)
|
387 |
+
st.plotly_chart(fig, use_container_width=True)
|
388 |
+
st.session_state.fig_bn_initial = fig
|
389 |
+
|
390 |
+
# ββ Speech-intelligibility check βββββββββββββββββββββββββββββββββββββββ
|
391 |
+
with t_si:
|
392 |
+
col_text, col_img = st.columns([3,2])
|
393 |
+
with col_text:
|
394 |
+
st.write("""Manually plot the sound pressure values below on the dots graph
|
395 |
+
(see Fig 1) and count the dots above the line for
|
396 |
+
articluation index calculation below. You must plot a dot graph for each
|
397 |
+
location in the sound pressure levels table below.""")
|
398 |
+
|
399 |
+
if st.session_state.df_spl is not None:
|
400 |
+
st.markdown("###### current sound pressure levels")
|
401 |
+
st.dataframe(st.session_state.df_spl, use_container_width=True)
|
402 |
+
|
403 |
+
with col_img:
|
404 |
+
st.image("dots_graph2.jpg", caption="Fig 1: Dots graph",
|
405 |
+
use_column_width=False)
|
406 |
+
|
407 |
+
if st.session_state.df_spl is not None:
|
408 |
+
# st.markdown("###### current sound pressure levels")
|
409 |
+
# st.dataframe(st.session_state.df_spl, use_container_width=True)
|
410 |
+
ai_rows = []
|
411 |
+
st.markdown("###### Articulation Index (AI) calculation")
|
412 |
+
for loc in st.session_state.df_spl.index:
|
413 |
+
key = slugify(f"dots_init_{loc}")
|
414 |
+
default = st.session_state.dots_init_dict.get(loc, 0)
|
415 |
+
dots = st.number_input(
|
416 |
+
f"Dots above ({loc})", 0, TOTAL_DOTS,
|
417 |
+
step=1, value=default, key=key)
|
418 |
+
st.session_state.dots_init_dict[loc] = dots
|
419 |
+
ai, interp = articulation_index(dots) if dots else (None, "")
|
420 |
+
st.session_state.ai_init_dict[loc] = (ai, interp)
|
421 |
+
ai_rows.append({
|
422 |
+
"Location": loc,
|
423 |
+
"Articulation Index (AI)": f"{ai:.2f}" if ai is not None else "",
|
424 |
+
"Interpretation": interp,
|
425 |
+
})
|
426 |
+
st.dataframe(pd.DataFrame(ai_rows), use_container_width=True)
|
427 |
+
|
428 |
+
nav_buttons()
|
429 |
+
|
430 |
+
# ---------------------------------------------------------------------------
|
431 |
+
def section_acoustic_treatment() -> None:
|
432 |
+
st.title("π Building Acoustics Analysis Tool")
|
433 |
+
|
434 |
+
with st.expander("App Information", expanded=False):
|
435 |
+
st.write("""
|
436 |
+
- This app is intended for educational purposes only and should not be used for professional purposes.
|
437 |
+
""")
|
438 |
+
|
439 |
+
st.header("π Acoustic Treatment")
|
440 |
+
tab_desired, tab_mat = st.tabs(["Desired RT60", "New Materials"])
|
441 |
+
|
442 |
+
# ββ Desired RT60 entry βββββββββββββββββββββββββββββββββββββββββββββββββ
|
443 |
+
with tab_desired:
|
444 |
+
|
445 |
+
st.write('''At this point in the analysis, you would need to define your desired RT60,
|
446 |
+
which would be used to calculate the desired sound absorption needed to achieve the
|
447 |
+
desired RT60. Compare the total frequency values in the table below to the calculated current
|
448 |
+
room sound absorption on the Initial RT60 Compliance Check tab to inform your selection
|
449 |
+
of new materials in the next step of the analysis''')
|
450 |
+
|
451 |
+
if st.session_state.rt_max == 0:
|
452 |
+
st.warning("β οΈ Define RT60 standard range in *Initial Compliance Checks* first.")
|
453 |
+
|
454 |
+
st.info("Enter the desired RT60 for each frequency.")
|
455 |
+
desired = {}
|
456 |
+
for freq in FREQUENCIES:
|
457 |
+
default = float(
|
458 |
+
st.session_state.desired_rt_df[
|
459 |
+
st.session_state.desired_rt_df["Frequency"] == freq
|
460 |
+
]["Desired RT60"].values[0]
|
461 |
+
)
|
462 |
+
val = st.number_input(
|
463 |
+
f"{freq} Hz", min_value=0.01, step=0.01,
|
464 |
+
value=default, key=f"des_rt_{freq}")
|
465 |
+
desired[freq] = val
|
466 |
+
|
467 |
+
st.session_state.desired_rt_df["Desired RT60"] = (
|
468 |
+
st.session_state.desired_rt_df["Frequency"].map(desired)
|
469 |
+
)
|
470 |
+
|
471 |
+
within = all(
|
472 |
+
st.session_state.rt_min <= v <= st.session_state.rt_max
|
473 |
+
for v in desired.values()
|
474 |
+
)
|
475 |
+
if within:
|
476 |
+
df_abs = pd.DataFrame([{
|
477 |
+
f: calc_abs_area(st.session_state.room_volume, v)
|
478 |
+
for f, v in desired.items()
|
479 |
+
}], index=["Required absorption"])
|
480 |
+
st.markdown("###### Sound absorption based on Desired RT60")
|
481 |
+
st.dataframe(df_abs, use_container_width=True)
|
482 |
+
else:
|
483 |
+
st.error("Each Desired RT60 must lie within the standard range.")
|
484 |
+
|
485 |
+
if st.session_state.room_volume == 0:
|
486 |
+
st.warning("β οΈ Enter a non-zero room volume (see *Initial Data Entry*).")
|
487 |
+
|
488 |
+
# ββ New materials ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
489 |
+
with tab_mat:
|
490 |
+
|
491 |
+
st.write("""The desired sound absorption calculated on the Desired RT60 tab is the target
|
492 |
+
sound absorption you are aiming to achieve. You now have to start working towards achieving
|
493 |
+
the target absorptions. Based on the differences between the desired sound absorptions
|
494 |
+
(see Desired RT60 tab) and the calculated current room sound absorptions
|
495 |
+
(see Initial RT60 Compliance Check tab), you would need to introduce new materials to either
|
496 |
+
increase or decrease sound absorption for some frequencies. Note that sound absorption
|
497 |
+
coefficients of a material are not the same for all frequencies. Therefore, you need to
|
498 |
+
strategically select your materials. You may need to repeat the material selection process
|
499 |
+
several times to ensure that the room passes the final RT60 compliance check.
|
500 |
+
Your project brief may place limitations on the number of structural changes
|
501 |
+
(like changing the wall or concrete floor) you are allowed to make. For a retrofit project,
|
502 |
+
you can change non-structural elements like carpet and ceiling tiles. Additionally, you
|
503 |
+
can introduce new materials like curtains.
|
504 |
+
""")
|
505 |
+
|
506 |
+
|
507 |
+
u = st.file_uploader("New materials data (CSV/XLSX)", type=["csv", "xlsx"])
|
508 |
+
if u:
|
509 |
+
st.session_state.df_new_mat = standardise_freq_cols(read_upload(u))
|
510 |
+
|
511 |
+
if st.session_state.df_new_mat is None:
|
512 |
+
st.warning("β οΈ Upload or add at least one new material.")
|
513 |
+
else:
|
514 |
+
st.info("""You can add or delete rows and modify the values in the table below.
|
515 |
+
Changes will be applied and will instantly impact sound absorption
|
516 |
+
and Final Compliance Checks.""")
|
517 |
+
|
518 |
+
df_edit = st.data_editor(
|
519 |
+
st.session_state.df_new_mat, num_rows="dynamic",
|
520 |
+
use_container_width=True, key="edit_newmat")
|
521 |
+
st.session_state.df_new_mat = df_edit
|
522 |
+
|
523 |
+
new_abs = {f: 0.0 for f in FREQUENCIES}
|
524 |
+
for _, r in df_edit.iterrows():
|
525 |
+
area = r[1]
|
526 |
+
for f, coeff in zip(FREQUENCIES, r[2:]):
|
527 |
+
new_abs[f] += coeff * area
|
528 |
+
st.session_state.new_absorption = new_abs
|
529 |
+
st.markdown("###### Sound absorption based on new materials")
|
530 |
+
st.dataframe(pd.DataFrame([new_abs], index=["New absorption"]),
|
531 |
+
use_container_width=True)
|
532 |
+
|
533 |
+
nav_buttons()
|
534 |
+
|
535 |
+
|
536 |
+
# ---------------------------------------------------------------------------
|
537 |
+
def section_final_checks() -> None:
|
538 |
+
st.title("π Building Acoustics Analysis Tool")
|
539 |
+
|
540 |
+
with st.expander("App Information", expanded=False):
|
541 |
+
st.write("""
|
542 |
+
- This app is intended for educational purposes only and should not be used for professional purposes.
|
543 |
+
""")
|
544 |
+
|
545 |
+
st.header("π¦ Final Compliance Checks")
|
546 |
+
t_rt, t_bn, t_si = st.tabs(
|
547 |
+
["Reverberation Time", "Background Noise", "Speech Intelligibility"])
|
548 |
+
|
549 |
+
combined = {
|
550 |
+
f: st.session_state.current_absorption.get(f, 0)
|
551 |
+
+ st.session_state.new_absorption.get(f, 0)
|
552 |
+
for f in FREQUENCIES
|
553 |
+
}
|
554 |
+
|
555 |
+
# ββ RT60 final check βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
556 |
+
with t_rt:
|
557 |
+
if st.session_state.room_volume == 0 or not combined:
|
558 |
+
st.warning("β οΈ Provide volume + materials, then run Acoustic Treatment.")
|
559 |
+
else:
|
560 |
+
new_rt = {f: calc_abs_area(st.session_state.room_volume, a)
|
561 |
+
for f, a in combined.items()}
|
562 |
+
st.markdown("New RT60 values after acoustic treatment")
|
563 |
+
st.dataframe(pd.DataFrame([new_rt], index=["New RT60"]),
|
564 |
+
use_container_width=True)
|
565 |
+
|
566 |
+
y_cur = ([float(st.session_state.df_current_rt.iloc[0][f])
|
567 |
+
for f in FREQUENCIES]
|
568 |
+
if st.session_state.df_current_rt is not None else [None]*6)
|
569 |
+
|
570 |
+
fig = plot_rt_band(
|
571 |
+
y_cur,
|
572 |
+
[st.session_state.rt_min]*6,
|
573 |
+
[st.session_state.rt_max]*6,
|
574 |
+
"Final RT60 vs Standard Range",
|
575 |
+
)
|
576 |
+
fig.add_trace(go.Scatter(
|
577 |
+
x=FREQUENCIES,
|
578 |
+
y=[new_rt[f] for f in FREQUENCIES],
|
579 |
+
mode="lines+markers",
|
580 |
+
name="New",
|
581 |
+
marker_color="#d62728",
|
582 |
+
))
|
583 |
+
st.plotly_chart(fig, use_container_width=True)
|
584 |
+
st.session_state.fig_rt_final = fig
|
585 |
+
|
586 |
+
# ββ Background noise final check βββββββββββββββββββββββββββββββββββββββ
|
587 |
+
with t_bn:
|
588 |
+
st.write("""When you apply acoustic treatment to a room, the noise reduction
|
589 |
+
resulting from increased sound absorption will deacrease background noise.""")
|
590 |
+
df = st.session_state.df_background_noise
|
591 |
+
if df.empty or not combined:
|
592 |
+
st.warning("β οΈ Provide background-noise data and run Acoustic Treatment.")
|
593 |
+
else:
|
594 |
+
before = sum(st.session_state.current_absorption.values())
|
595 |
+
after = sum(combined.values())
|
596 |
+
if before == 0:
|
597 |
+
st.error("Existing absorption sum is zero.")
|
598 |
+
else:
|
599 |
+
nr = 10 * np.log10(after / before)
|
600 |
+
st.metric("Noise Reduction", f"{nr:.2f} dB",
|
601 |
+
help="Noise reduction due to acoustic treatment" )
|
602 |
+
df_new = df.copy()
|
603 |
+
df_new["dBA"] = df_new["dBA"] - nr
|
604 |
+
fig = plot_bn_band(
|
605 |
+
df_new["Location"], df_new["dBA"],
|
606 |
+
st.session_state.bn_min, st.session_state.bn_max,
|
607 |
+
"Final Background Noise vs Standard Range",
|
608 |
+
)
|
609 |
+
st.plotly_chart(fig, use_container_width=True)
|
610 |
+
st.session_state.fig_bn_final = fig
|
611 |
+
|
612 |
+
# ββ AI final check βββββββββββββββββββββββββββββββββββββββββββββββββββββ-
|
613 |
+
with t_si:
|
614 |
+
st.write("""When you apply acoustic treatment to a room, the noise reduction
|
615 |
+
resulting from increased sound absorption will deacrease the sound pressure
|
616 |
+
levels used in calcuating AI""")
|
617 |
+
if st.session_state.df_spl is None or not combined:
|
618 |
+
st.warning("β οΈ Upload SPL data and run Acoustic Treatment first.")
|
619 |
+
else:
|
620 |
+
before = sum(st.session_state.current_absorption.values())
|
621 |
+
after = sum(combined.values())
|
622 |
+
nr_db = 10 * np.log10(after / before) if before else 0
|
623 |
+
df_new_spl = st.session_state.df_spl - nr_db
|
624 |
+
st.markdown("###### New sound pressure levels after acoustic treatment")
|
625 |
+
st.write("""For each location in the table below, plot the new sound pressure
|
626 |
+
levels on the dots graph, count dots above the line, and calculate AI below.""")
|
627 |
+
st.dataframe(df_new_spl, use_container_width=True)
|
628 |
+
|
629 |
+
st.markdown("Articulation Index (AI) calculation")
|
630 |
+
ai_rows = []
|
631 |
+
for loc in df_new_spl.index:
|
632 |
+
key = slugify(f"dots_final_{loc}")
|
633 |
+
default = st.session_state.dots_final_dict.get(loc, 0)
|
634 |
+
dots = st.number_input(
|
635 |
+
f"Dots above ({loc})", 0, TOTAL_DOTS,
|
636 |
+
step=1, value=default, key=key)
|
637 |
+
st.session_state.dots_final_dict[loc] = dots
|
638 |
+
ai, interp = articulation_index(dots) if dots else (None, "")
|
639 |
+
st.session_state.ai_final_dict[loc] = (ai, interp)
|
640 |
+
ai_rows.append({
|
641 |
+
"Location": loc,
|
642 |
+
"AI": f"{ai:.2f}" if ai is not None else "",
|
643 |
+
"Interpretation": interp,
|
644 |
+
})
|
645 |
+
st.dataframe(pd.DataFrame(ai_rows), use_container_width=True)
|
646 |
+
|
647 |
+
nav_buttons()
|
648 |
+
|
649 |
+
|
650 |
+
# ---------------------------------------------------------------------------
|
651 |
+
def section_faq() -> None:
|
652 |
+
st.title("π Building Acoustics Analysis Tool")
|
653 |
+
|
654 |
+
with st.expander("App Information", expanded=False):
|
655 |
+
st.write("""
|
656 |
+
- This app is intended for educational purposes only and should not be used for professional purposes.
|
657 |
+
""")
|
658 |
+
|
659 |
+
st.header("β FAQ / Help")
|
660 |
+
faq_content = """
|
661 |
+
### Frequently Asked Questions
|
662 |
+
**Q1: What should I do if the data upload fails?**
|
663 |
+
Ensure your file is in the correct format (CSV or Excel). Check that the column headings are consistent with the expected format (e.g., `125`, `250`, `500`, `1000`, `2000`, `4000` or `125Hz`, `250Hz`, `500Hz`, `1KHz`, `2KHz`, `4KHz`). Remove any extra rows or columns that do not contain relevant data.
|
664 |
+
**Q2: How do I interpret the RT60 values?**
|
665 |
+
RT60 values represent the time it takes for the sound to decay by 60 dB in a room. Lower RT60 values indicate faster sound decay and are preferable for environments where speech intelligibility is important. Higher RT60 values might be suitable for spaces intended for musical performances.
|
666 |
+
**Q3: Why is my calculated RT60 not within the standard range?**
|
667 |
+
This may occur if the room's current materials are not adequately absorbing sound. You may need to introduce new materials with higher absorption coefficients or increase the surface area of existing materials.
|
668 |
+
**Q4: What should I do if the app does not accept my frequency columns?**
|
669 |
+
The app standardizes frequency columns to numerical values (e.g., `125`, `250`) regardless of their initial format (e.g., `125Hz`, `125 Hz`). Ensure that the frequency values in your uploaded file are correctly formatted and consistent.
|
670 |
+
**Q5: How can I improve speech intelligibility in my room?**
|
671 |
+
To improve speech intelligibility, aim for a lower RT60 across the relevant frequencies, particularly in the range of 500 Hz to 4000 Hz. This can be achieved by adding more sound-absorbing materials, such as acoustic panels or curtains.
|
672 |
+
**Q6: How can I save my analysis results?**
|
673 |
+
You can download the PDF report, which includes all the data and graphs from your analysis. Click the "Download PDF Report" button at the end of your analysis to save the report to your device.
|
674 |
+
### Troubleshooting Tips
|
675 |
+
- **Data Upload Issues**: If you encounter issues uploading data, double-check the format and structure of your file. Ensure the first row contains column headings and the data is organized as per the examples provided.
|
676 |
+
- **Unexpected Results**: If your analysis results seem incorrect, verify the accuracy of the input data, including the room volume and material properties. Incorrect input data can lead to erroneous calculations.
|
677 |
+
- **App Performance**: If the app is running slowly, consider optimizing your data size and complexity. Large datasets or highly detailed input may impact performance.
|
678 |
+
|
679 |
+
"""
|
680 |
+
st.markdown(faq_content)
|
681 |
+
nav_buttons()
|