Skip to content

Commit

Permalink
Merge pull request #20 from uwescience/model_versioning
Browse files Browse the repository at this point in the history
adding model benchmarking workflow
  • Loading branch information
valentina-s authored Jul 1, 2024
2 parents 49ce33e + 5ad32ec commit 4681549
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/create_website_benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Create Benchmark Website

on:
# Runs on pushes targeting the default branch
push:
branches: ["main", "model_versioning"]
pull_request:
types: ["opened", "reopened", "synchronize", "edited"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
pages: write
id-token: write

jobs:
# Build Website
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.11'



- name: Install Python dependencies
run: |
pip install "dask[dataframe]"
pip install ipykernel
pip install nbconvert
- name: Build Website
shell: bash -el {0}
run: |
cd ambient_sound_analysis
jupyter nbconvert display_benchmarks.ipynb --execute --to html --output-dir=_build/html --no-input
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ambient_sound_analysis/_build/html


# Publish Website to GitHub Pages if built successfully
deploy:
needs: build
# if: github.ref == 'refs/heads/model_versioning'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Setup Pages
uses: actions/configure-pages@v5

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
70 changes: 70 additions & 0 deletions .github/workflows/model_benchmarking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Model Benchmarking
on:
pull_request:
types: [opened, synchronize, edited, reopened]

env:
pr_username: github.event.pull_request.user.login

# schedule:
# - cron: '9 * * * *'

jobs:
process:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.9.18'
cache: 'pip'
cache-dependency-path: ambient_sound_analysis/requirements_noise.txt

- name: Install Python dependencies
run: |
pip install -r ambient_sound_analysis/requirements_noise.txt
# - name: Install ffmpeg
# run: |
# sudo apt-get update
# sudo apt-get install ffmpeg

- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: ffmpeg

- name: Create plots
if: steps.cache.outputs.cache-hit != 'true'
run: |
python ambient_sound_analysis/model_benchmarking.py
- name: Append username
run: |
# sed 's/$/ test trigger/' 'ambient_sound_analysis/csv/2024-06-01 17:00:00.csv' > 'ambient_sound_analysis/csv/2024-06-01 17:00:00_new.csv'
export output_file="score_${{ github.event.pull_request.head.sha }}.csv"
sed 's/$/, ${{ github.event.pull_request.user.login }}, ${{ github.event.pull_request.head.sha }}, ${{github.event.pull_request.title}}/' 'ambient_sound_analysis/csv/test.csv' > "ambient_sound_analysis/csv/$output_file"
- name: Upload to GitHub repo
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Commit to Github
file_pattern: 'ambient_sound_analysis/csv/score*.csv'

#- name: Upload as artifact
# uses: actions/upload-artifact@v4
# with:
# name: ambient_sound_plots
# path: ambient_sound_analysis/img/*.png

#- name: Upload to Google Drive
# uses: AnimMouse/setup-rclone@v1
# with:
# rclone_config: ${{secrets.RCLONE_CONFIG}}

# - run: |
# rclone copy ambient_sound_analysis/img/broadband.png mydrive:rclone_uploads/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17, valentina-s, 1f3ac5bc8b3a4914606ceebcbd910a5aac64e50e, adding model benchmarking workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17, valentina-s, 28401087ddea6a1ac2829d708423b362b8d3840f, adding model benchmarking workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17, valentina-s, 42aa52eddaf7494cf272de17396907146982e1fd, adding model benchmarking workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17, valentina-s, 66b46ac47aa1c2bcbda573e147f3a16eeed61dcd, adding model benchmarking workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17, valentina-s, 71236d3146ee8b3354b3d8fea71d69028b83126b, adding model benchmarking workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1, valentina-s, 72b13caee35f09369b3d3c6b082e71bac68316c0, adding model benchmarking workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17, valentina-s, a3d0ab1feae8b9b91c923229c4cf3d5b06e05f98, adding model benchmarking workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17, valentina-s, cd12ce8cad03004c315e2c175fd61b3ebecdc3be, adding model benchmarking workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17, valentina-s, f38875f0d0e246c9035abb2f76602e1a89479171, adding model benchmarking workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17, valentina-s, fc9e91bb543073453639b8989614702fdeaaa1e4, adding model benchmarking workflow
144 changes: 144 additions & 0 deletions ambient_sound_analysis/display_benchmarks.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "13bdddf3-f048-4bb2-801d-6a8473fa7d9d",
"metadata": {},
"source": [
"# Latest Benchmarks"
]
},
{
"cell_type": "code",
"execution_count": 68,
"id": "9b8f9eff-5009-4d4e-9e17-a9f14960c073",
"metadata": {},
"outputs": [],
"source": [
"import dask.dataframe as ddf"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "dad42a94-20aa-4976-8ab3-558dc11c67c7",
"metadata": {},
"outputs": [],
"source": [
"df = ddf.read_csv(\"csv/*.csv\", header=None, index_col=False)"
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "ae56d8d7-aea5-4a09-971d-a05afcfad2ac",
"metadata": {},
"outputs": [],
"source": [
"df = df.compute().reset_index(drop=True)"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "f4354a33-83ca-4878-bb15-2ea116f32996",
"metadata": {},
"outputs": [],
"source": [
"df.columns = [\"# Ships\", \"username\", \"SHA\", \"title\"]"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "a22b796f-9a02-4d3c-a3b4-335270e0e347",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th># Ships</th>\n",
" <th>username</th>\n",
" <th>SHA</th>\n",
" <th>title</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>valentina-s</td>\n",
" <td>1dbb9106cd9ff69b73a7171f938285650a97d0bb</td>\n",
" <td>$ {{github.event.pull_request.title}}</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>valentina-s</td>\n",
" <td>72b13caee35f09369b3d3c6b082e71bac68316c0</td>\n",
" <td>adding model benchmarking workflow</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" # Ships username SHA \\\n",
"0 1 valentina-s 1dbb9106cd9ff69b73a7171f938285650a97d0bb \n",
"1 1 valentina-s 72b13caee35f09369b3d3c6b082e71bac68316c0 \n",
"\n",
" title \n",
"0 $ {{github.event.pull_request.title}} \n",
"1 adding model benchmarking workflow "
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
66 changes: 66 additions & 0 deletions ambient_sound_analysis/model_benchmarking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# importing general Python libraries
import pandas as pd
import datetime as dt
import os
import matplotlib.pyplot as plt
import pytz
import plotly.graph_objects as go
import numpy as np

# importing orcasound_noise libraries
from orcasound_noise.pipeline.pipeline import NoiseAnalysisPipeline
from orcasound_noise.utils import Hydrophone
from orcasound_noise.pipeline.acoustic_util import plot_spec, plot_bb


# Set Location and Resolution
# Port Townsend, 1 Hz Frequency, 60-second samples
if __name__ == '__main__':
pipeline = NoiseAnalysisPipeline(Hydrophone.ORCASOUND_LAB,
delta_f=10, bands=None,
delta_t=60, mode='safe')




# Generate parquet dataframes with noise levels for a time period

# now = dt.datetime.now(pytz.timezone('US/Pacific'))
# fix time
now = dt.datetime(2024, 6, 1, 17, 0, 0)
psd_path, broadband_path = pipeline.generate_parquet_file(now - dt.timedelta(hours = 13),
now - dt.timedelta(hours = 8),
upload_to_s3=False)

# Read the parquet files
# psd_df = pd.read_parquet(psd_path)
bb_df = pd.read_parquet(broadband_path)

# set threshold
threshold = 5

import numpy as np
nof_ships = (np.diff((bb_df['0']>threshold).astype('uint8'))==1).sum()


# Create a new directory if it does not exist
if not os.path.exists('ambient_sound_analysis/csv'):
os.makedirs('ambient_sound_analysis/csv')

# pd.DataFrame([nof_ships]).to_csv('ambient_sound_analysis/csv/'+str(now)+'.csv', header=False, index=False)

print("Nof Ships: "+str(nof_ships))
pd.DataFrame([nof_ships]).to_csv('ambient_sound_analysis/csv/test.csv', header=False, index=False)






# Create and save psd plot
# fig = plot_spec(psd_df)
# fig.write_image('ambient_sound_analysis/img/psd.png')

# Create and save bb plot
# fig = plot_bb(bb_df)
# fig.savefig('ambient_sound_analysis/img/broadband.png')

0 comments on commit 4681549

Please sign in to comment.