1- import pandas as pd
2- from orcasound_noise .pipeline .pipeline import NoiseAnalysisPipeline
3- from orcasound_noise .utils import Hydrophone
41import datetime as dt
52import os
63
7- import pandas as pd
84import matplotlib .pyplot as plt
9- import pytz
10-
11-
12- from orcasound_noise .pipeline .acoustic_util import plot_spec , plot_bb
13-
14-
5+ import pandas as pd
156import plotly .graph_objects as go
7+ import pytz
8+ from orcasound_noise .pipeline .acoustic_util import plot_bb , plot_spec
9+ from orcasound_noise .pipeline .pipeline import NoiseAnalysisPipeline
10+ from orcasound_noise .utils import Hydrophone
1611
17- #Example 1: Port Townsend, 1 Hz Frequency, 60-second samples
18- if __name__ == ' __main__' :
19- pipeline = NoiseAnalysisPipeline (Hydrophone . PORT_TOWNSEND ,
20- delta_f = 10 , bands = None ,
21- delta_t = 60 , mode = 'safe' )
12+ # Example 1: Port Townsend, 1 Hz Frequency, 60-second samples
13+ if __name__ == " __main__" :
14+ pipeline = NoiseAnalysisPipeline (
15+ Hydrophone . PORT_TOWNSEND , delta_f = 10 , bands = None , delta_t = 60 , mode = "safe"
16+ )
2217
2318
24- now = dt .datetime .now (pytz .timezone (' US/Pacific' ))
19+ now = dt .datetime .now (pytz .timezone (" US/Pacific" ))
2520
26- psd_path , broadband_path = pipeline .generate_parquet_file (now - dt . timedelta ( hours = 6 ),
27- now - dt .timedelta (hours = 1 ),
28- upload_to_s3 = False )
21+ psd_path , broadband_path = pipeline .generate_parquet_file (
22+ now - dt . timedelta ( hours = 6 ), now - dt .timedelta (hours = 1 ), upload_to_s3 = False
23+ )
2924
3025
3126psd_df = pd .read_parquet (psd_path )
3227bb_df = pd .read_parquet (broadband_path )
3328
3429
3530# Create a new directory because it does not exist
36- if not os .path .exists ('img' ):
37- os .makedirs ('img' )
31+ if not os .path .exists ("img" ):
32+ os .makedirs ("img" )
33+
3834
3935def plot_spec (psd_df ):
4036 """
@@ -48,17 +44,24 @@ def plot_spec(psd_df):
4844 """
4945
5046 fig = go .Figure (
51- data = go .Heatmap (x = psd_df .index , y = psd_df .columns , z = psd_df .values .transpose (), colorscale = 'Viridis' ,
52- colorbar = {"title" : 'Magnitude' }))
47+ data = go .Heatmap (
48+ x = psd_df .index ,
49+ y = psd_df .columns ,
50+ z = psd_df .values .transpose (),
51+ colorscale = "Viridis" ,
52+ colorbar = {"title" : "Magnitude" },
53+ )
54+ )
5355 fig .update_layout (
5456 title = "Hydrophone Power Spectral Density" ,
5557 xaxis_title = "Time" ,
5658 yaxis_title = "Frequency (Hz)" ,
57- legend_title = "Magnitude"
59+ legend_title = "Magnitude" ,
5860 )
5961 fig .update_yaxes (type = "log" )
6062 fig .show ()
61- return (fig )
63+ return fig
64+
6265
6366def plot_bb (bb_df ):
6467 """
@@ -71,19 +74,17 @@ def plot_bb(bb_df):
7174 """
7275 plt .figure ()
7376 plt .plot (bb_df )
74- plt .title (' Relative Broadband Levels' )
75- plt .xlabel (' Time' )
76- plt .ylabel (' Relative Decibels' )
77- plt .xticks (rotation = 45 )
77+ plt .title (" Relative Broadband Levels" )
78+ plt .xlabel (" Time" )
79+ plt .ylabel (" Relative Decibels" )
80+ plt .xticks (rotation = 45 )
7881 # plt.show()
79- return (plt .gcf ())
80-
82+ return plt .gcf ()
8183
8284
8385fig = plot_spec (psd_df )
84- fig .write_image ('img/psd.png' )
85-
86+ fig .write_image ("img/psd.png" )
8687
8788
8889fig = plot_bb (bb_df )
89- fig .savefig (' img/broadband.png' )
90+ fig .savefig (" img/broadband.png" )
0 commit comments