diff --git a/broadband.png b/broadband.png deleted file mode 100644 index e3eea5e4..00000000 Binary files a/broadband.png and /dev/null differ diff --git a/img/broadband.png b/img/broadband.png new file mode 100644 index 00000000..11029572 Binary files /dev/null and b/img/broadband.png differ diff --git a/img/psd.png b/img/psd.png new file mode 100644 index 00000000..2be079f0 Binary files /dev/null and b/img/psd.png differ diff --git a/noise_processing.py b/noise_processing.py index 6fdd7db9..8d29a117 100644 --- a/noise_processing.py +++ b/noise_processing.py @@ -2,12 +2,15 @@ from orcasound_noise.pipeline.pipeline import NoiseAnalysisPipeline from orcasound_noise.utils import Hydrophone import datetime as dt +import os import pandas as pd import matplotlib.pyplot as plt from orcasound_noise.pipeline.acoustic_util import plot_spec, plot_bb +import plotly.graph_objects as go + #Example 1: Port Townsend, 1 Hz Frequency, 60-second samples if __name__ == '__main__': pipeline = NoiseAnalysisPipeline(Hydrophone.PORT_TOWNSEND, @@ -25,8 +28,59 @@ psd_df = pd.read_parquet(psd_path) bb_df = pd.read_parquet(broadband_path) -plot_spec(psd_df) -plot_bb(bb_df) -plt.xticks(rotation=45) -plt.savefig('broadband.png') +# Create a new directory because it does not exist +if not os.path.exists('img'): + os.makedirs('img') + +def plot_spec(psd_df): + """ + This function converts a table of power spectral data, having the columns represent frequency bins and the rows + represent time segments, to a spectrogram. + + Args: + psd_df: Dataframe of power spectral data. + + Returns: Spectral plot + """ + + fig = go.Figure( + data=go.Heatmap(x=psd_df.index, y=psd_df.columns, z=psd_df.values.transpose(), colorscale='Viridis', + colorbar={"title": 'Magnitude'})) + fig.update_layout( + title="Hydrophone Power Spectral Density", + xaxis_title="Time", + yaxis_title="Frequency (Hz)", + legend_title="Magnitude" + ) + fig.update_yaxes(type="log") + fig.show() + return(fig) + +def plot_bb(bb_df): + """ + This function plots the broadband levels in relative decibels. + + Args: + bb_df: Dataframe of broadband levels. + + Returns: Time series of broadband levels. + """ + plt.figure() + plt.plot(bb_df) + plt.title('Relative Broadband Levels') + plt.xlabel('Time') + plt.ylabel('Relative Decibels') + plt.xticks(rotation = 45) + # plt.show() + return(plt.gcf()) + + + +fig = plot_spec(psd_df) +fig.write_image('img/psd.png') + + + +fig = plot_bb(bb_df) +fig.savefig('img/broadband.png')