Upload app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,6 @@ with st.expander("App Information", expanded=False):
|
|
26 |
- This app is for educational purposes and not intended for professional use.
|
27 |
""")
|
28 |
|
29 |
-
# Initialize session state variables
|
30 |
default_values = {
|
31 |
'current_tab': "Instructions",
|
32 |
'current_rt': {},
|
@@ -639,7 +638,7 @@ def display_final_rt60_compliance_check():
|
|
639 |
|
640 |
def display_intelligibility_noise_reduction():
|
641 |
st.write('''## Intelligibility Noise Reduction''')
|
642 |
-
|
643 |
st.write('''On this tab, you will calculate noise reduction using existing and new materials sound absorption
|
644 |
coefficients and surface areas that were provided for reverberation time analysis. The relevant data
|
645 |
have copied to this tab for ease of reference. Note that you can update the new materials data by adding new rows
|
@@ -671,18 +670,20 @@ def display_intelligibility_noise_reduction():
|
|
671 |
st.info('''The data below is a duplicate of the current room sound absorption calculated for reverberation time
|
672 |
analysis. It is provided here as a reminder of the existing materials in the room and their calculated sound
|
673 |
absorptions.''')
|
674 |
-
if
|
675 |
st.dataframe(st.session_state.df_current_absorption, use_container_width=True)
|
|
|
|
|
676 |
|
677 |
st.write("#### Editable new materials data")
|
678 |
st.info('''The editable table below is a duplicate of the new materials data from reverberation time
|
679 |
analysis. You can edit this table by adding new rows, deleting existing rows, or directly editing any
|
680 |
information in the table. Click check box on the left to delete a row. Hover over the table and click + at the
|
681 |
-
top or bottom to add new rows. Note that any changes made here will automatically
|
682 |
on this tab and also update the new materials data for reverberation time and other reverberation time
|
683 |
calculations that are connected to that data.''')
|
684 |
|
685 |
-
if
|
686 |
edited_df = st.data_editor(st.session_state.df_new_materials, num_rows="dynamic")
|
687 |
st.session_state.df_new_materials = edited_df
|
688 |
|
@@ -716,10 +717,13 @@ def display_intelligibility_noise_reduction():
|
|
716 |
Editable new materials data above''')
|
717 |
st.dataframe(df_new_absorption, use_container_width=True)
|
718 |
st.session_state.df_new_absorption = df_new_absorption.copy() # Save a copy of new absorption data
|
|
|
|
|
719 |
|
720 |
st.write("#### Calculated Noise Reduction")
|
721 |
-
if
|
722 |
-
current_total_absorption = st.session_state.df_current_absorption.loc[:,
|
|
|
723 |
new_total_absorption = st.session_state.df_new_absorption.loc[:, st.session_state.frequencies].sum().sum()
|
724 |
if current_total_absorption > 0:
|
725 |
noise_reduction = 10 * np.log10(new_total_absorption / current_total_absorption)
|
@@ -728,11 +732,12 @@ def display_intelligibility_noise_reduction():
|
|
728 |
st.info('''The above noise reduction value is calculated total sound absorption for existing and new
|
729 |
material above. The noise reduction formula is shown below:
|
730 |
NR = 10 * Log10(new materials total absorption/existing materials total absorption)
|
731 |
-
|
732 |
-
The above formula is the same as 10 * Log10(S alpha after/S alpha before''')
|
733 |
|
|
|
734 |
else:
|
735 |
st.error("Current total absorption is zero, which is not possible. Please check your data.")
|
|
|
|
|
736 |
|
737 |
if st.session_state.df_sound_pressure is not None and 'noise_reduction' in st.session_state:
|
738 |
st.write("#### Updated Sound Pressure Levels")
|
@@ -746,7 +751,8 @@ def display_intelligibility_noise_reduction():
|
|
746 |
|
747 |
# Subtract noise reduction from each sound pressure level using log subtraction
|
748 |
for col in updated_df.columns:
|
749 |
-
updated_df[col] = updated_df[col].apply(
|
|
|
750 |
updated_df[col] = updated_df[col].apply(lambda x: 10 * np.log10(x) if x > 0 else 0)
|
751 |
|
752 |
st.write("Updated Sound Pressure Levels:")
|
@@ -776,7 +782,7 @@ def display_intelligibility_noise_reduction():
|
|
776 |
)
|
777 |
st.download_button(label="Download PDF", data=pdf, file_name="Room_Acoustics_Report.pdf",
|
778 |
mime="application/pdf")
|
779 |
-
|
780 |
# Main content display based on the current tab
|
781 |
if st.session_state.current_tab == "Instructions":
|
782 |
display_instructions()
|
|
|
26 |
- This app is for educational purposes and not intended for professional use.
|
27 |
""")
|
28 |
|
|
|
29 |
default_values = {
|
30 |
'current_tab': "Instructions",
|
31 |
'current_rt': {},
|
|
|
638 |
|
639 |
def display_intelligibility_noise_reduction():
|
640 |
st.write('''## Intelligibility Noise Reduction''')
|
641 |
+
|
642 |
st.write('''On this tab, you will calculate noise reduction using existing and new materials sound absorption
|
643 |
coefficients and surface areas that were provided for reverberation time analysis. The relevant data
|
644 |
have copied to this tab for ease of reference. Note that you can update the new materials data by adding new rows
|
|
|
670 |
st.info('''The data below is a duplicate of the current room sound absorption calculated for reverberation time
|
671 |
analysis. It is provided here as a reminder of the existing materials in the room and their calculated sound
|
672 |
absorptions.''')
|
673 |
+
if st.session_state.df_current_absorption is not None:
|
674 |
st.dataframe(st.session_state.df_current_absorption, use_container_width=True)
|
675 |
+
else:
|
676 |
+
st.write("No data available for current room sound absorption. Please complete the previous steps.")
|
677 |
|
678 |
st.write("#### Editable new materials data")
|
679 |
st.info('''The editable table below is a duplicate of the new materials data from reverberation time
|
680 |
analysis. You can edit this table by adding new rows, deleting existing rows, or directly editing any
|
681 |
information in the table. Click check box on the left to delete a row. Hover over the table and click + at the
|
682 |
+
top or bottom to add new rows. Note that any changes made here will automatically update all the calculations
|
683 |
on this tab and also update the new materials data for reverberation time and other reverberation time
|
684 |
calculations that are connected to that data.''')
|
685 |
|
686 |
+
if st.session_state.df_new_materials is not None:
|
687 |
edited_df = st.data_editor(st.session_state.df_new_materials, num_rows="dynamic")
|
688 |
st.session_state.df_new_materials = edited_df
|
689 |
|
|
|
717 |
Editable new materials data above''')
|
718 |
st.dataframe(df_new_absorption, use_container_width=True)
|
719 |
st.session_state.df_new_absorption = df_new_absorption.copy() # Save a copy of new absorption data
|
720 |
+
else:
|
721 |
+
st.write("No data available for new materials. Please upload new materials data.")
|
722 |
|
723 |
st.write("#### Calculated Noise Reduction")
|
724 |
+
if st.session_state.df_current_absorption is not None and st.session_state.df_new_absorption is not None:
|
725 |
+
current_total_absorption = st.session_state.df_current_absorption.loc[:,
|
726 |
+
st.session_state.frequencies].sum().sum()
|
727 |
new_total_absorption = st.session_state.df_new_absorption.loc[:, st.session_state.frequencies].sum().sum()
|
728 |
if current_total_absorption > 0:
|
729 |
noise_reduction = 10 * np.log10(new_total_absorption / current_total_absorption)
|
|
|
732 |
st.info('''The above noise reduction value is calculated total sound absorption for existing and new
|
733 |
material above. The noise reduction formula is shown below:
|
734 |
NR = 10 * Log10(new materials total absorption/existing materials total absorption)
|
|
|
|
|
735 |
|
736 |
+
The above formula is the same as 10 * Log10(S alpha after/S alpha before''')
|
737 |
else:
|
738 |
st.error("Current total absorption is zero, which is not possible. Please check your data.")
|
739 |
+
else:
|
740 |
+
st.write("No data available to calculate noise reduction. Please complete the previous steps.")
|
741 |
|
742 |
if st.session_state.df_sound_pressure is not None and 'noise_reduction' in st.session_state:
|
743 |
st.write("#### Updated Sound Pressure Levels")
|
|
|
751 |
|
752 |
# Subtract noise reduction from each sound pressure level using log subtraction
|
753 |
for col in updated_df.columns:
|
754 |
+
updated_df[col] = updated_df[col].apply(
|
755 |
+
lambda x: 10 ** (x / 10) - 10 ** (st.session_state.noise_reduction / 10))
|
756 |
updated_df[col] = updated_df[col].apply(lambda x: 10 * np.log10(x) if x > 0 else 0)
|
757 |
|
758 |
st.write("Updated Sound Pressure Levels:")
|
|
|
782 |
)
|
783 |
st.download_button(label="Download PDF", data=pdf, file_name="Room_Acoustics_Report.pdf",
|
784 |
mime="application/pdf")
|
785 |
+
|
786 |
# Main content display based on the current tab
|
787 |
if st.session_state.current_tab == "Instructions":
|
788 |
display_instructions()
|