-
Notifications
You must be signed in to change notification settings - Fork 6
/
noise_processing.py
46 lines (34 loc) · 1.4 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
# 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.PORT_TOWNSEND,
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'))
psd_path, broadband_path = pipeline.generate_parquet_file(now - dt.timedelta(hours = 6),
now - dt.timedelta(hours = 1),
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')