Skip to content

Commit 4b2691f

Browse files
committed
adding model benchmarking workflow
1 parent b7bdfdc commit 4b2691f

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Model Benchmarking
2+
3+
on:
4+
pull request:
5+
types: ['opened']
6+
7+
env:
8+
pr_username: github.event.pull_request.user.login
9+
10+
# schedule:
11+
# - cron: '9 * * * *'
12+
13+
jobs:
14+
process:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.9.18'
22+
cache: 'pip'
23+
cache-dependency-path: ambient_sound_analysis/requirements_noise.txt
24+
25+
- name: Install Python dependencies
26+
run: |
27+
pip install -r ambient_sound_analysis/requirements_noise.txt
28+
29+
30+
# - name: Install ffmpeg
31+
# run: |
32+
# sudo apt-get update
33+
# sudo apt-get install ffmpeg
34+
35+
- uses: awalsh128/cache-apt-pkgs-action@latest
36+
with:
37+
packages: ffmpeg
38+
39+
- name: Create plots
40+
if: steps.cache.outputs.cache-hit != 'true'
41+
run: |
42+
python ambient_sound_analysis/model_benchmarking.py
43+
44+
45+
46+
- name: Append username
47+
run:|
48+
sed 's/$/ $pr_username/' 'csv/2024-06-01 17:00:00.csv' > 'csv/2024-06-01 17:00:00_new.csv'
49+
50+
- name: Upload to GitHub repo
51+
uses: stefanzweifel/git-auto-commit-action@v5
52+
with:
53+
commit_message: Commit to Github
54+
file_pattern: 'ambient_sound_analysis/csv/*.csv'
55+
56+
#- name: Upload as artifact
57+
# uses: actions/upload-artifact@v4
58+
# with:
59+
# name: ambient_sound_plots
60+
# path: ambient_sound_analysis/img/*.png
61+
62+
#- name: Upload to Google Drive
63+
# uses: AnimMouse/setup-rclone@v1
64+
# with:
65+
# rclone_config: ${{secrets.RCLONE_CONFIG}}
66+
67+
# - run: |
68+
# rclone copy ambient_sound_analysis/img/broadband.png mydrive:rclone_uploads/
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# importing general Python libraries
2+
import pandas as pd
3+
import datetime as dt
4+
import os
5+
import matplotlib.pyplot as plt
6+
import pytz
7+
import plotly.graph_objects as go
8+
import numpy as np
9+
10+
# importing orcasound_noise libraries
11+
from orcasound_noise.pipeline.pipeline import NoiseAnalysisPipeline
12+
from orcasound_noise.utils import Hydrophone
13+
from orcasound_noise.pipeline.acoustic_util import plot_spec, plot_bb
14+
15+
16+
# Set Location and Resolution
17+
# Port Townsend, 1 Hz Frequency, 60-second samples
18+
if __name__ == '__main__':
19+
pipeline = NoiseAnalysisPipeline(Hydrophone.ORCASOUND_LAB,
20+
delta_f=10, bands=None,
21+
delta_t=60, mode='safe')
22+
23+
24+
25+
26+
# Generate parquet dataframes with noise levels for a time period
27+
28+
# now = dt.datetime.now(pytz.timezone('US/Pacific'))
29+
# fix time
30+
now = dt.datetime(2024, 6, 1, 17, 0, 0)
31+
psd_path, broadband_path = pipeline.generate_parquet_file(now - dt.timedelta(hours = 13),
32+
now - dt.timedelta(hours = 8),
33+
upload_to_s3=False)
34+
35+
# Read the parquet files
36+
# psd_df = pd.read_parquet(psd_path)
37+
bb_df = pd.read_parquet(broadband_path)
38+
39+
# set threshold
40+
threshold = 5
41+
42+
import numpy as np
43+
nof_ships = (np.diff((bb_df['0']>threshold).astype('uint8'))==1).sum()
44+
45+
46+
# Create a new directory if it does not exist
47+
if not os.path.exists('ambient_sound_analysis/csv'):
48+
os.makedirs('ambient_sound_analysis/csv')
49+
50+
pd.DataFrame(nof_ships).to_csv('csv/'+str(now)+'.csv', header=False, index=False)
51+
52+
53+
54+
55+
# Create and save psd plot
56+
# fig = plot_spec(psd_df)
57+
# fig.write_image('ambient_sound_analysis/img/psd.png')
58+
59+
# Create and save bb plot
60+
# fig = plot_bb(bb_df)
61+
# fig.savefig('ambient_sound_analysis/img/broadband.png')

0 commit comments

Comments
 (0)