1
- import pandas as pd
2
- from orcasound_noise .pipeline .pipeline import NoiseAnalysisPipeline
3
- from orcasound_noise .utils import Hydrophone
4
1
import datetime as dt
5
2
import os
6
3
7
- import pandas as pd
8
4
import 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
15
6
import 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
16
11
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
+ )
22
17
23
18
24
- now = dt .datetime .now (pytz .timezone (' US/Pacific' ))
19
+ now = dt .datetime .now (pytz .timezone (" US/Pacific" ))
25
20
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
+ )
29
24
30
25
31
26
psd_df = pd .read_parquet (psd_path )
32
27
bb_df = pd .read_parquet (broadband_path )
33
28
34
29
35
30
# 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
+
38
34
39
35
def plot_spec (psd_df ):
40
36
"""
@@ -48,17 +44,24 @@ def plot_spec(psd_df):
48
44
"""
49
45
50
46
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
+ )
53
55
fig .update_layout (
54
56
title = "Hydrophone Power Spectral Density" ,
55
57
xaxis_title = "Time" ,
56
58
yaxis_title = "Frequency (Hz)" ,
57
- legend_title = "Magnitude"
59
+ legend_title = "Magnitude" ,
58
60
)
59
61
fig .update_yaxes (type = "log" )
60
62
fig .show ()
61
- return (fig )
63
+ return fig
64
+
62
65
63
66
def plot_bb (bb_df ):
64
67
"""
@@ -71,19 +74,17 @@ def plot_bb(bb_df):
71
74
"""
72
75
plt .figure ()
73
76
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 )
78
81
# plt.show()
79
- return (plt .gcf ())
80
-
82
+ return plt .gcf ()
81
83
82
84
83
85
fig = plot_spec (psd_df )
84
- fig .write_image ('img/psd.png' )
85
-
86
+ fig .write_image ("img/psd.png" )
86
87
87
88
88
89
fig = plot_bb (bb_df )
89
- fig .savefig (' img/broadband.png' )
90
+ fig .savefig (" img/broadband.png" )
0 commit comments