From 0e2fac614ba648d5db93abfebcc1c7132b6a5203 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:25:46 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/noise_processing.yml | 9 ++-- noise_processing.py | 69 +++++++++++++------------- tests/test_ooi.py | 1 + tests/test_spectrograms.py | 1 + 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/.github/workflows/noise_processing.yml b/.github/workflows/noise_processing.yml index e0f87ea0..e0e8103d 100644 --- a/.github/workflows/noise_processing.yml +++ b/.github/workflows/noise_processing.yml @@ -5,10 +5,10 @@ on: # workflow_dispatch: schedule: - cron: '9 * * * *' - + workflow_dispatch: - - + + jobs: process: runs-on: ubuntu-latest @@ -27,7 +27,7 @@ jobs: python -m pip install orcasound_noise@git+https://github.com/orcasound/ambient-sound-analysis python -m pip install kaleido - + - name: Install ffmpeg run: | sudo apt-get update @@ -48,4 +48,3 @@ jobs: with: commit_message: Commit to Github file_pattern: 'img/*.png' - diff --git a/noise_processing.py b/noise_processing.py index f88023e4..31e54e8d 100644 --- a/noise_processing.py +++ b/noise_processing.py @@ -1,31 +1,26 @@ -import pandas as pd -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 -import pytz - - -from orcasound_noise.pipeline.acoustic_util import plot_spec, plot_bb - - +import pandas as pd import plotly.graph_objects as go +import pytz +from orcasound_noise.pipeline.acoustic_util import plot_bb, plot_spec +from orcasound_noise.pipeline.pipeline import NoiseAnalysisPipeline +from orcasound_noise.utils import Hydrophone -#Example 1: Port Townsend, 1 Hz Frequency, 60-second samples -if __name__ == '__main__': - pipeline = NoiseAnalysisPipeline(Hydrophone.PORT_TOWNSEND, - delta_f=10, bands=None, - delta_t=60, mode='safe') +# Example 1: Port Townsend, 1 Hz Frequency, 60-second samples +if __name__ == "__main__": + pipeline = NoiseAnalysisPipeline( + Hydrophone.PORT_TOWNSEND, delta_f=10, bands=None, delta_t=60, mode="safe" + ) -now = dt.datetime.now(pytz.timezone('US/Pacific')) +now = dt.datetime.now(pytz.timezone("US/Pacific")) -psd_path, broadband_path = pipeline.generate_parquet_file(now - dt.timedelta(hours = 6), - now - dt.timedelta(hours = 1), - upload_to_s3=False) +psd_path, broadband_path = pipeline.generate_parquet_file( + now - dt.timedelta(hours=6), now - dt.timedelta(hours=1), upload_to_s3=False +) psd_df = pd.read_parquet(psd_path) @@ -33,8 +28,9 @@ # Create a new directory because it does not exist -if not os.path.exists('img'): - os.makedirs('img') +if not os.path.exists("img"): + os.makedirs("img") + def plot_spec(psd_df): """ @@ -48,17 +44,24 @@ def plot_spec(psd_df): """ fig = go.Figure( - data=go.Heatmap(x=psd_df.index, y=psd_df.columns, z=psd_df.values.transpose(), colorscale='Viridis', - colorbar={"title": 'Magnitude'})) + 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" + legend_title="Magnitude", ) fig.update_yaxes(type="log") fig.show() - return(fig) + return fig + def plot_bb(bb_df): """ @@ -71,19 +74,17 @@ def plot_bb(bb_df): """ plt.figure() plt.plot(bb_df) - plt.title('Relative Broadband Levels') - plt.xlabel('Time') - plt.ylabel('Relative Decibels') - plt.xticks(rotation = 45) + plt.title("Relative Broadband Levels") + plt.xlabel("Time") + plt.ylabel("Relative Decibels") + plt.xticks(rotation=45) # plt.show() - return(plt.gcf()) - + return plt.gcf() fig = plot_spec(psd_df) -fig.write_image('img/psd.png') - +fig.write_image("img/psd.png") fig = plot_bb(bb_df) -fig.savefig('img/broadband.png') +fig.savefig("img/broadband.png") diff --git a/tests/test_ooi.py b/tests/test_ooi.py index 941e2773..ee9dda6f 100644 --- a/tests/test_ooi.py +++ b/tests/test_ooi.py @@ -1,4 +1,5 @@ """Unit tests for OOI workflow""" + import datetime import os import shutil diff --git a/tests/test_spectrograms.py b/tests/test_spectrograms.py index f33787aa..75a319c8 100644 --- a/tests/test_spectrograms.py +++ b/tests/test_spectrograms.py @@ -1,4 +1,5 @@ """Unit tests for various util functions relating to spectrogram creation""" + import os.path import matplotlib.pyplot as plt