Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 25, 2024
1 parent d26e37c commit 9de49cb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/noise_processing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
# workflow_dispatch:
schedule:
- cron: '9 * * * *'

workflow_dispatch:


jobs:
process:
runs-on: ubuntu-latest
Expand All @@ -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
Expand All @@ -48,4 +48,3 @@ jobs:
with:
commit_message: Commit to Github
file_pattern: 'img/*.png'

69 changes: 35 additions & 34 deletions noise_processing.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
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)
bb_df = pd.read_parquet(broadband_path)


# 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):
"""
Expand All @@ -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):
"""
Expand All @@ -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")
1 change: 1 addition & 0 deletions tests/test_ooi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for OOI workflow"""

import datetime
import os
import shutil
Expand Down
1 change: 1 addition & 0 deletions tests/test_spectrograms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for various util functions relating to spectrogram creation"""

import os.path

import matplotlib.pyplot as plt
Expand Down

0 comments on commit 9de49cb

Please sign in to comment.