@@ -82,35 +82,26 @@ def frequency_calibration(self, N):
82
82
output_array : np.array
83
83
array with correction coefficient for every frequency
84
84
"""
85
- # Calibration for Low Frequency Hydrophones
85
+ # Load calibation file and get appropriate calibration info
86
+ filename = os .path .dirname (ooipy .__file__ ) + \
87
+ '/hydrophone/calibration_by_assetID.csv'
88
+ # Use deployment CSV to determine asset_ID
89
+ assetID = self .get_asset_ID ()
90
+
91
+ # load calibration data as pandas dataframe
92
+ cal_by_assetID = pd .read_csv (filename , header = [0 , 1 ])
93
+
94
+ f_calib = cal_by_assetID [assetID ]['Freq (kHz)' ].to_numpy () * 1000
95
+ sens_calib_0 = cal_by_assetID [assetID ]['0 phase' ].to_numpy ()
96
+ sens_calib_90 = cal_by_assetID [assetID ]['90 phase' ].to_numpy ()
97
+ sens_calib = 0.5 * (sens_calib_0 + sens_calib_90 )
98
+ f = np .linspace (0 , round (self .stats .sampling_rate / 2 ), N )
99
+
100
+ # Convert calibration to correct units
86
101
if round (self .stats .sampling_rate ) == 200 :
87
- lf_cal = {
88
- 'HYSB1' : 2311.11 , 'HYS14' : 2499.09 , 'AXBA1' : 2257.3 ,
89
- 'AXEC2' : 2421.0 , 'AXCC1' : 2480.98 }
90
- f = np .linspace (0 , 100 , N )
91
- f_calib = np .array ([0 , 100 ])
92
- sens_calib_db = 20 * np .log10 (lf_cal [self .stats .station ] * 1e-6 )
93
- sens_calib = np .array ([sens_calib_db , sens_calib_db ])
94
-
95
- # Calibratino for Broadband Hydrophones
102
+ sens_calib = 20 * np .log10 (sens_calib * 1e-6 )
96
103
elif round (self .stats .sampling_rate ) == 64000 :
97
- filename = os .path .dirname (ooipy .__file__ ) + \
98
- '/hydrophone/calibration_by_assetID.pkl'
99
- # Use deployment CSV to determine asset_ID
100
- assetID = self .get_asset_ID ()
101
-
102
- # load calibration data as pandas dataframe
103
- with open (filename , 'rb' ) as f :
104
- cal_by_assetID = pickle .load (f )
105
-
106
- f_calib = cal_by_assetID [assetID ]['Freq (kHz)' ].to_numpy () * 1000
107
- sens_calib_0 = cal_by_assetID [assetID ]['0 phase' ].to_numpy ()
108
- sens_calib_90 = cal_by_assetID [assetID ]['90 phase' ].to_numpy ()
109
- # Average 0 and 90 degree phase response
110
- sens_calib = 0.5 * (sens_calib_0 + sens_calib_90 )
111
104
sens_calib = sens_calib + 128.9
112
- f = np .linspace (0 , 32000 , N )
113
-
114
105
else :
115
106
raise Exception ('Invalid sampling rate' )
116
107
@@ -306,14 +297,16 @@ def compute_spectrogram_mp(self, n_process=None, win='hann', L=4096,
306
297
temp_slice = self .slice (starttime = UTCDateTime (starttime ),
307
298
endtime = UTCDateTime (endtime ))
308
299
tmp_obj = HydrophoneData (data = temp_slice .data ,
309
- header = temp_slice .stats )
300
+ header = temp_slice .stats ,
301
+ node = self .stats .location )
310
302
ooi_hyd_data_list .append ((tmp_obj , win , L , avg_time , overlap ))
311
303
312
304
starttime = self .stats .starttime + datetime .timedelta (
313
305
seconds = (N - 1 ) * seconds_per_process )
314
306
temp_slice = self .slice (starttime = UTCDateTime (starttime ),
315
307
endtime = UTCDateTime (self .stats .endtime ))
316
- tmp_obj = HydrophoneData (data = temp_slice .data , header = temp_slice .stats )
308
+ tmp_obj = HydrophoneData (data = temp_slice .data , header = temp_slice .stats ,
309
+ node = self .stats .location )
317
310
ooi_hyd_data_list .append ((tmp_obj , win , L , avg_time , overlap ))
318
311
319
312
with mp .get_context ("spawn" ).Pool (n_process ) as p :
@@ -488,7 +481,8 @@ def compute_psd_welch_mp(self, split, n_process=None, win='hann', L=4096,
488
481
temp_slice = self .slice (starttime = UTCDateTime (starttime ),
489
482
endtime = UTCDateTime (endtime ))
490
483
tmp_obj = HydrophoneData (data = temp_slice .data ,
491
- header = temp_slice .stats )
484
+ header = temp_slice .stats ,
485
+ node = self .stats .location )
492
486
ooi_hyd_data_list .append (
493
487
(tmp_obj , win , L , overlap , avg_method , interpolate , scale ))
494
488
@@ -499,7 +493,8 @@ def compute_psd_welch_mp(self, split, n_process=None, win='hann', L=4096,
499
493
temp_slice = self .slice (starttime = UTCDateTime (starttime ),
500
494
endtime = UTCDateTime (self .stats .endtime ))
501
495
tmp_obj = HydrophoneData (data = temp_slice .data ,
502
- header = temp_slice .stats )
496
+ header = temp_slice .stats ,
497
+ node = self .stats .location )
503
498
ooi_hyd_data_list .append (
504
499
(tmp_obj , win , L , overlap , avg_method , interpolate , scale ))
505
500
# use segmentation specified by split
@@ -509,7 +504,8 @@ def compute_psd_welch_mp(self, split, n_process=None, win='hann', L=4096,
509
504
temp_slice = self .slice (starttime = UTCDateTime (row [0 ]),
510
505
endtime = UTCDateTime (row [1 ]))
511
506
tmp_obj = HydrophoneData (data = temp_slice .data ,
512
- header = temp_slice .stats )
507
+ header = temp_slice .stats ,
508
+ node = self .stats .location )
513
509
ooi_hyd_data_list .append (
514
510
(tmp_obj , win , L , overlap , avg_method , interpolate , scale ))
515
511
@@ -570,38 +566,61 @@ def wav_write(self, filename, norm=False, new_sample_rate=None):
570
566
wavfile .write (filename , int (sampling_rate ), data )
571
567
572
568
def get_asset_ID (self ):
573
- url = 'https://raw.githubusercontent.com/OOI-CabledArray/' \
574
- 'deployments/main/HYDBBA_deployments.csv'
575
- hyd_df = pd .read_csv (url )
576
-
577
- if self .stats .location == 'LJ01D' : # LJ01D'Oregon Shelf Base Seafloor
578
- ref = 'CE02SHBP-LJ01D-11-HYDBBA106'
579
- if self .stats .location == 'LJ01A' : # LJ01AOregon Slope Base Seafloor
580
- ref = 'RS01SLBS-LJ01A-09-HYDBBA102'
581
- if self .stats .location == 'PC01A' : # Oregan Slope Base Shallow
582
- ref = 'RS01SBPS-PC01A-08-HYDBBA103'
583
- if self .stats .location == 'PC03A' : # Axial Base Shallow Profiler
584
- ref = 'RS03AXPS-PC03A-08-HYDBBA303'
585
- if self .stats .location == 'LJ01C' : # Oregon Offshore Base Seafloor
586
- ref = 'CE04OSBP-LJ01C-11-HYDBBA105'
587
- if self .stats .location == 'LJ03A' : # Axial Base Seafloor
588
- ref = 'RS03AXBS-LJ03A-09-HYDBBA302'
589
-
590
- hyd_df ['referenceDesignator' ]
591
-
592
- df_ref = hyd_df .loc [hyd_df ['referenceDesignator' ] == ref ]
593
-
594
- df_start = df_ref .loc [(df_ref ['startTime' ] < self .stats .starttime ) &
595
- (df_ref ['endTime' ] > self .stats .starttime )]
596
- df_end = df_ref .loc [(df_ref ['startTime' ] < self .stats .endtime ) &
597
- (df_ref ['endTime' ] > self .stats .endtime )]
598
-
599
- if df_start .index .to_numpy () == df_end .index .to_numpy ():
600
- idx = df_start .index .to_numpy ()
601
- asset_ID = df_start ['assetID' ][int (idx )]
569
+ '''
570
+ get_asset_ID returns the hydrophone asset ID for a given data sample.
571
+ This data can be foun `here <https://raw.githubusercontent.com/
572
+ OOI-CabledArray/deployments/main/HYDBBA_deployments.csv'>`_ for
573
+ broadband hydrophones. Since Low frequency hydrophones remain
574
+ constant with location and time, if the hydrophone is low frequency,
575
+ the node ID is returned
576
+ '''
577
+ # Low frequency hydrophone
578
+ if round (self .stats .sampling_rate ) == 200 :
579
+ asset_ID = self .stats .location
580
+
581
+ elif round (self .stats .sampling_rate ) == 64000 :
582
+ url = 'https://raw.githubusercontent.com/OOI-CabledArray/' \
583
+ 'deployments/main/HYDBBA_deployments.csv'
584
+ hyd_df = pd .read_csv (url )
585
+
586
+ # LJ01D'Oregon Shelf Base Seafloor
587
+ if self .stats .location == 'LJ01D' :
588
+ ref = 'CE02SHBP-LJ01D-11-HYDBBA106'
589
+ # LJ01AOregon Slope Base Seafloor
590
+ if self .stats .location == 'LJ01A' :
591
+ ref = 'RS01SLBS-LJ01A-09-HYDBBA102'
592
+ # Oregan Slope Base Shallow
593
+ if self .stats .location == 'PC01A' :
594
+ ref = 'RS01SBPS-PC01A-08-HYDBBA103'
595
+ # Axial Base Shallow Profiler
596
+ if self .stats .location == 'PC03A' :
597
+ ref = 'RS03AXPS-PC03A-08-HYDBBA303'
598
+ # Oregon Offshore Base Seafloor
599
+ if self .stats .location == 'LJ01C' :
600
+ ref = 'CE04OSBP-LJ01C-11-HYDBBA105'
601
+ # Axial Base Seafloor
602
+ if self .stats .location == 'LJ03A' :
603
+ ref = 'RS03AXBS-LJ03A-09-HYDBBA302'
604
+
605
+ hyd_df ['referenceDesignator' ]
606
+
607
+ df_ref = hyd_df .loc [hyd_df ['referenceDesignator' ] == ref ]
608
+
609
+ df_start = df_ref .loc [(df_ref ['startTime' ] < self .stats .starttime )
610
+ & (df_ref ['endTime' ]
611
+ > self .stats .starttime )]
612
+ df_end = df_ref .loc [(df_ref ['startTime' ] < self .stats .endtime ) &
613
+ (df_ref ['endTime' ] > self .stats .endtime )]
614
+
615
+ if df_start .index .to_numpy () == df_end .index .to_numpy ():
616
+ idx = df_start .index .to_numpy ()
617
+ asset_ID = df_start ['assetID' ][int (idx )]
618
+ else :
619
+ raise Exception ('Hydrophone Data involves multiple'
620
+ 'deployments. Feature to be added later' )
602
621
else :
603
- raise Exception ('Hydrophone Data involves multiple deployments.'
604
- 'Feature to be added later' )
622
+ raise Exception ('Invalid hydrophone sampling rate' )
623
+
605
624
return asset_ID
606
625
607
626
0 commit comments