-
Notifications
You must be signed in to change notification settings - Fork 5
/
noise_processing.py
47 lines (35 loc) · 1.43 KB
/
noise_processing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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
# 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.BUSH_POINT,
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'))
now = dt.datetime(2024, 11, 20, 10)
psd_path, broadband_path = pipeline.generate_parquet_file(now - dt.timedelta(hours = 10),
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)
# Create a new directory if it does not exist
if not os.path.exists('img'):
os.makedirs('img')
# Create and save psd plot
fig = plot_spec(psd_df)
fig.write_image('img/psd.png')
# Create and save bb plot
fig = plot_bb(bb_df)
fig.savefig('img/broadband.png')