Repository navigation
Expand file tree
/
Copy pathPAM2Py.py
More file actions
1121 lines (1116 loc) · 62.2 KB
/
Copy pathPAM2Py.py
File metadata and controls
1121 lines (1116 loc) · 62.2 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# PAM2Py Python ToolBox
# Version 5.0
# JONAS Project
# Written by Orlando Camargo Rodriguez
# Based on PAMGuide.m by Nathan D. Merchant
# Faro, Dom 08 Mai 2022 18:56:08 WEST
#==========================================================================
# Don't like it? Don't use it...
#==========================================================================
# YUP, I DO NOT USE NAMESPACES!!!!!!!
# TKinter stuff:
from tkinter import * # standard binding to Tk
from tkinter import ttk # Python's binding to the newer "themed widgets"
from tkinter import filedialog
from tkinter import messagebox
# Numpy and Scipy stuff:
from numpy import *
from scipy.io import loadmat
# FLAC, WAV support:
import soundfile as sf
# Matplotlib:
from matplotlib.pyplot import *
# OS stuff
import os
# PAMGuide stuff:
from PG_Func import *
from write_edf import *
#======================================================================
#======================================================================
# GUI for the processing of experimental data:
#======================================================================
#======================================================================
def gui_experimental():
Data_Type.set('Experimental')
jge.set( jge.get() + 1 )
ngui = jge.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
GExperimental = Toplevel(root, borderwidth=10, relief=GROOVE)
GExperimental.title("Experimental Data")
GExperimental.grab_set()
ttk.Label(GExperimental, text='Select File Type:', style='TE.TLabel').grid(column=1,row=1)
ttk.Radiobutton(GExperimental, text="FLAC", style='RE2.TRadiobutton', variable=sndtype, value='FLAC').grid(column=1, row=2)
ttk.Radiobutton(GExperimental, text="WAV" , style='RE2.TRadiobutton', variable=sndtype, value='WAV' ).grid(column=1, row=3)
ttk.Button(GExperimental, text="Single File", style='GE.TButton', command=gui_experimentals).grid(column=1, row=4, padx=5, pady=5)
ttk.Button(GExperimental, text="Batch", style='GE.TButton', command=gui_experimentala).grid(column=1, row=5, padx=5, pady=5)
ttk.Button(GExperimental, text="Close", style='CB.TButton', command=lambda:[jge.set(0),GExperimental.grab_release(),GExperimental.destroy()]).grid(column=1, row=6, padx=5, pady=5)
return
#======================================================================
#======================================================================
# GUI for the processing of experimental data (single file):
#======================================================================
#======================================================================
def gui_experimentals():
jges.set( jges.get() + 1 )
ngui = jges.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
GExperimentalS = Toplevel(root, borderwidth=10, relief=GROOVE)
GExperimentalS.title("Experimental Data - Single File")
GExperimentalS.grab_set()
ttk.Button(GExperimentalS, text="Select File", style='GE.TButton', command=infosnd).grid(column=1, row=1, padx=5, pady=5)
ttk.Button(GExperimentalS, text="Calibration", style='GE.TButton', command=gui_calib).grid(column=1, row=2, padx=5, pady=5)
ttk.Button(GExperimentalS, text="Analysis", style='GE.TButton', command=gui_analysis).grid(column=1, row=3, padx=5, pady=5)
ttk.Button(GExperimentalS, text="RUN", style='RB.TButton', command=run_analysis).grid(column=1, row=4, padx=5,pady=5)
ttk.Button(GExperimentalS, text="Write CSV/EDF?", style='CB.TButton', command=gui_writeout).grid(column=1, row=5, padx=5,pady=5)
ttk.Button(GExperimentalS, text="Close", style='CB.TButton', command=lambda:[jges.set(0),GExperimentalS.grab_release(),GExperimentalS.destroy()]).grid(column=1, row=6, padx=5, pady=5)
return
#======================================================================
#======================================================================
# GUI for the processing of experimental data (batch):
#======================================================================
#======================================================================
def gui_experimentala():
jgea.set( jgea.get() + 1 )
ngui = jgea.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
GExperimentalA = Toplevel(root, borderwidth=10, relief=GROOVE)
GExperimentalA.title("Experimental Data - Batch")
GExperimentalA.grab_set()
ttk.Button(GExperimentalA, text="Select Directory", style='GE.TButton', command=infodir).grid(column=1, row=1, padx=5, pady=5)
ttk.Button(GExperimentalA, text="Calibration", style='GE.TButton', command=gui_calib).grid(column=1, row=2, padx=5, pady=5)
ttk.Button(GExperimentalA, text="Analysis", style='GE.TButton', command=gui_analysis).grid(column=1, row=3, padx=5, pady=5)
ttk.Button(GExperimentalA, text="RUN", style='RB.TButton', command=run_analysisb).grid(column=1, row=4, padx=5,pady=5)
ttk.Button(GExperimentalA, text="Write CSV/EDF?", style='CB.TButton', command=gui_writeoutb).grid(column=1, row=5, padx=5,pady=5)
ttk.Button(GExperimentalA, text="Close", style='CB.TButton', command=lambda:[jgea.set(0),GExperimentalA.grab_release(),GExperimentalA.destroy()]).grid(column=1, row=6, padx=5, pady=5)
return
#======================================================================
#======================================================================
# GUI for the processing of numerical data:
#======================================================================
#======================================================================
def gui_numerical():
Data_Type.set('Numerical')
CSVOUT.set('No')
EDFOUT.set('Yes')
jgn.set( jgn.get() + 1 )
ngui = jgn.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
GNumerical = Toplevel(root, borderwidth=10, relief=GROOVE)
GNumerical.title("Numerical Data")
GNumerical.grab_set()
ttk.Button(GNumerical, text="Select File", style='GE.TButton', command=infomat).grid(column=1, row=1, padx=5, pady=5)
ttk.Button(GNumerical, text="Plot", style='GE.TButton', command=plotmat).grid(column=1, row=2, padx=5, pady=5)
ttk.Button(GNumerical, text="Write EDF?", style='CB.TButton', command=writeout).grid(column=1, row=5, padx=5,pady=5)
ttk.Button(GNumerical, text="Close", style='CB.TButton', command=lambda:[jgn.set(0),GNumerical.grab_release(),GNumerical.destroy()]).grid(column=1, row=6, padx=5, pady=5)
return
#======================================================================
#======================================================================
# GUI for the writing of MetaData:
#======================================================================
#======================================================================
def gui_meta():
jmd.set( jmd.get() + 1 )
ngui = jmd.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
GMeta = Toplevel(root, borderwidth=10, relief=GROOVE)
GMeta.title("Write MetaData")
GMeta.grab_set()
ttk.Button(GMeta, text="Experimental", style='GE.TButton', command=gui_metaexp).grid(column=1, row=1, padx=5, pady=5)
ttk.Button(GMeta, text="Numerical" , style='GE.TButton', command=gui_metanum).grid(column=1, row=2, padx=5, pady=5)
ttk.Button(GMeta, text="Close", style='CB.TButton', command=lambda:[jmd.set(0),GMeta.grab_release(),GMeta.destroy()]).grid(column=1, row=3, padx=5, pady=5)
return
#======================================================================
# Stuff called by the GUIs:
#======================================================================
# GUI to input calibration parameters:
def gui_calib():
jcal.set( jcal.get() + 1 )
ngui = jcal.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
Gcalib = Toplevel(root, borderwidth=10, relief=GROOVE)
Gcalib.title("Calibration")
Gcalib.grab_set()
# Labels, column 1:
ttk.Label(Gcalib,text='Environment:' ).grid(column=1,row=1)
ttk.Label(Gcalib,text='Calibration Type:' ).grid(column=1,row=2)
ttk.Label(Gcalib,text='System Sensitivity:' ).grid(column=1,row=3)
ttk.Label(Gcalib,text='Transducer Sensitivity:').grid(column=1,row=4)
ttk.Label(Gcalib,text='Gain:' ).grid(column=1,row=5)
ttk.Label(Gcalib,text='ADC volts:' ).grid(column=1,row=6)
# Labels, column 3:
ttk.Label(Gcalib,text='dB re 1 V / Pa').grid(column=3,row=3)
ttk.Label(Gcalib,text='dB' ).grid(column=3,row=4)
ttk.Label(Gcalib,text='dB' ).grid(column=3,row=5)
ttk.Label(Gcalib,text='V 0-peak' ).grid(column=3,row=6)
# Comboboxes, column 2:
calibration = ttk.Combobox(Gcalib, width=30, textvariable=Envi)
calibration['values'] = ('Air','Water')
calibration.grid(column =2, row =1)
caltype = ttk.Combobox(Gcalib, width=30, textvariable=Ctype)
caltype['values'] = ('None', 'EE', 'RC', 'TS')
caltype.grid(column =2, row =2)
# Entries, column 2:
ttk.Entry(Gcalib,textvariable=SI ,width=30).grid(column=2,row=3)
ttk.Entry(Gcalib,textvariable=MH ,width=30).grid(column=2,row=4)
ttk.Entry(Gcalib,textvariable=GG ,width=30).grid(column=2,row=5)
ttk.Entry(Gcalib,textvariable=VADC,width=30).grid(column=2,row=6)
# Button, column 1:
ttk.Button(Gcalib, text="Close", style ='CB.TButton', command=lambda:[jcal.set(0),Gcalib.grab_release(),Gcalib.destroy()]).grid(column=2, row=7, padx=5, pady=5)
return
#======================================================================
# GUI to input analysis options:
def gui_analysis():
jan.set( jan.get() + 1 )
ngui = jan.get()
bao = jgea.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
Ganalysis = Toplevel(root, borderwidth=10, relief=GROOVE)
Ganalysis.title("Analysis")
Ganalysis.grab_set()
# Labels, column 1:
ttk.Label(Ganalysis,text='Analysis Type:' ).grid(column=1,row=1)
ttk.Label(Ganalysis,text='Window Type:' ).grid(column=1,row=2)
ttk.Label(Ganalysis,text='Plot Type:' ).grid(column=1,row=3)
ttk.Label(Ganalysis,text='Frequency Scale:' ).grid(column=1,row=4)
ttk.Label(Ganalysis,text='Window Overlap:' ).grid(column=1,row=5)
ttk.Label(Ganalysis,text='Window Length:' ).grid(column=1,row=6)
ttk.Label(Ganalysis,text='Low Freq. limit:' ).grid(column=1,row=7)
ttk.Label(Ganalysis,text='High Freq. limit:').grid(column=1,row=8)
ttk.Label(Ganalysis,text='Welch factor:' ).grid(column=1,row=9)
ttk.Label(Ganalysis,text='Channels:' ).grid(column=1,row=10)
ttk.Label(Ganalysis,text='Select channel:' ).grid(column=1,row=11)
# Labels, column 3:
ttk.Label(Ganalysis,text='%' ).grid(column=3,row=5)
ttk.Label(Ganalysis,text='s' ).grid(column=3,row=6)
ttk.Label(Ganalysis,text='Hz').grid(column=3,row=7)
ttk.Label(Ganalysis,text='Hz').grid(column=3,row=8)
# Comboboxes, column 2:
anatype = ttk.Combobox(Ganalysis, width=30, textvariable=Atype)
anatype['values'] = ('PSD','TOL','TOLf','Broadband','Waveform')
anatype.grid(column =2, row =1)
wintype = ttk.Combobox(Ganalysis, width=30, textvariable=Winname)
wintype['values'] = ('None', 'Hann', 'Hamming', 'Blackman')
wintype.grid(column =2, row =2)
plttype = ttk.Combobox(Ganalysis, width=30, textvariable=Plottype)
plttype['values'] = ('Time', 'Stats', 'Both')
plttype.grid(column =2, row =3)
fscale = ttk.Combobox(Ganalysis, width=30, textvariable=Linlog)
fscale['values'] = ('Logarithmic','Linear')
fscale.grid(column =2, row =4)
# Entries, column 2:
ttk.Entry(Ganalysis,textvariable=Wover ,width=30).grid(column=2,row=5)
ttk.Entry(Ganalysis,textvariable=Wlength,width=30).grid(column=2,row=6)
ttk.Entry(Ganalysis,textvariable=Lcut ,width=30).grid(column=2,row=7)
ttk.Entry(Ganalysis,textvariable=Hcut ,width=30).grid(column=2,row=8)
ttk.Entry(Ganalysis,textvariable=Welch ,width=30).grid(column=2,row=9)
ttk.Entry(Ganalysis,textvariable=nchann ,width=30,state='disabled').grid(column=2,row=10)
if ( bao == 1 ):
ttk.Entry(Ganalysis,textvariable=thechan,width=30,state='disabled').grid(column=2,row=11)
else:
ttk.Entry(Ganalysis,textvariable=thechan,width=30).grid(column=2,row=11)
# Button, column 1:
ttk.Button(Ganalysis, text="Close", style ='CB.TButton', command=lambda:[jan.set(0),Ganalysis.grab_release(),Ganalysis.destroy()]).grid(column=2, row=12, padx=5, pady=5)
return
#======================================================================
# GUI to write CVS/EDF:
def gui_writeout():
jwo.set( jwo.get() + 1 )
ngui = jwo.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
c = os.path.isfile('Aft.mat')
if ( c == True ):
Gwrite = Toplevel(root, borderwidth=10, relief=GROOVE)
Gwrite.title("Write CSV/EDF?")
Gwrite.grab_set()
ttk.Label(Gwrite, text='Select Output Type:', style='TE.TLabel').grid(column=1, row=1)
C1 = ttk.Checkbutton(Gwrite, text = "CSV", style='CB2.TCheckbutton', variable=CSVOUT, onvalue='Yes', offvalue='No').grid(column=1, row=2)
C2 = ttk.Checkbutton(Gwrite, text = "EDF", style='CB2.TCheckbutton', variable=EDFOUT, onvalue='Yes', offvalue='No').grid(column=1, row=3)
ttk.Button(Gwrite, text="Write", style ='CB.TButton', command=writeout).grid(column=1, row=4, padx=5, pady=5)
ttk.Button(Gwrite, text="Close", style ='CB.TButton', command=lambda:[jwo.set(0),Gwrite.grab_release(),Gwrite.destroy()]).grid(column=1, row=5, padx=5, pady=5)
else:
messagebox.showinfo("Oops...", 'Run Analysis first (except Waveform option)')
return
#======================================================================
# GUI to write CVS/EDF after batch processing:
def gui_writeoutb():
jwo.set( jwo.get() + 1 )
ngui = jwo.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
c = os.path.isfile('Aft1.mat')
if ( c == True ):
Gwrite = Toplevel(root, borderwidth=10, relief=GROOVE)
Gwrite.title("Write CSV/EDF?")
Gwrite.grab_set()
ttk.Label(Gwrite, text='Select Output Type:', style='TE.TLabel').grid(column=1, row=1)
C1 = ttk.Checkbutton(Gwrite, text = "CSV", style='CB2.TCheckbutton', variable=CSVOUT, onvalue='Yes', offvalue='No').grid(column=1, row=2)
C2 = ttk.Checkbutton(Gwrite, text = "EDF", style='CB2.TCheckbutton', variable=EDFOUT, onvalue='Yes', offvalue='No').grid(column=1, row=3)
ttk.Button(Gwrite, text="Write", style ='CB.TButton', command=writeoutb).grid(column=1, row=4, padx=5, pady=5)
ttk.Button(Gwrite, text="Close", style ='CB.TButton', command=lambda:[jwo.set(0),Gwrite.grab_release(),Gwrite.destroy()]).grid(column=1, row=5, padx=5, pady=5)
else:
messagebox.showinfo("Oops...", 'Run Analysis first (except Waveform option)')
return
#======================================================================
# GUI to create numerical metadata:
def gui_metanum():
Data_Type.set('Numerical')
jmdn.set( jmdn.get() + 1 )
ngui = jmdn.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
Gmetanum = Toplevel(root, borderwidth=10, relief=GROOVE)
Gmetanum.title("Numerical Metadata")
Gmetanum.grab_set()
ttk.Label(Gmetanum,text='Filename:' ).grid(column=1,row=1)
ttk.Entry(Gmetanum,textvariable=metfile, width=30).grid(column=2,row=1)
ttk.Label(Gmetanum,text='Format Version:' ).grid(column=1,row=2)
ttk.Entry(Gmetanum,textvariable=Format_Version,width=30).grid(column=2,row=2)
ttk.Label(Gmetanum,text='Author:' ).grid(column=1,row=3)
ttk.Entry(Gmetanum,textvariable=Author, width=30).grid(column=2,row=3)
ttk.Label(Gmetanum,text='Institution:' ).grid(column=1,row=4)
ttk.Entry(Gmetanum,textvariable=Institution, width=30).grid(column=2,row=4)
ttk.Label(Gmetanum,text='Country Code:' ).grid(column=1,row=5)
ttk.Entry(Gmetanum,textvariable=Country_Code, width=30).grid(column=2,row=5)
ttk.Label(Gmetanum,text='Contact:' ).grid(column=1,row=6)
ttk.Entry(Gmetanum,textvariable=Contact, width=30).grid(column=2,row=6)
ttk.Label(Gmetanum,text='Start Date (YYYYMMDD):' ).grid(column=1,row=7)
ttk.Entry(Gmetanum,textvariable=Start_Date, width=30).grid(column=2,row=7)
ttk.Label(Gmetanum,text='End Date (YYYYMMDD):' ).grid(column=1,row=8)
ttk.Entry(Gmetanum,textvariable=End_Date, width=30).grid(column=2,row=8)
ttk.Label(Gmetanum,text='Creation Date (YYYYMMDD):' ).grid(column=1,row=9)
ttk.Entry(Gmetanum,textvariable=Creation_Date, width=30).grid(column=2,row=9)
ttk.Label(Gmetanum,text='Purpose:' ).grid(column=1,row=10)
ttk.Entry(Gmetanum,textvariable=Purpose, width=30).grid(column=2,row=10)
ttk.Label(Gmetanum,text='Data UUID:' ).grid(column=1,row=11)
ttk.Entry(Gmetanum,textvariable=Data_Uuid, width=30).grid(column=2,row=11)
ttk.Label(Gmetanum,text='Data Type:' ).grid(column=3,row=2)
ttk.Label(Gmetanum,text='Numerical' ).grid(column=4,row=2)
ttk.Label(Gmetanum,text='Comments:' ).grid(column=3,row=3)
ttk.Entry(Gmetanum,textvariable=Comments, width=30).grid(column=4,row=3)
ttk.Label(Gmetanum,text='AIS Database:' ).grid(column=3,row=4)
ttk.Entry(Gmetanum,textvariable=AIS_DB, width=30).grid(column=4,row=4)
ttk.Label(Gmetanum,text='Source Levels:' ).grid(column=3,row=5)
ttk.Entry(Gmetanum,textvariable=Source_Levels, width=30).grid(column=4,row=5)
ttk.Label(Gmetanum,text='Bathymetry Database:' ).grid(column=3,row=6)
ttk.Entry(Gmetanum,textvariable=Bathy_DB, width=30).grid(column=4,row=6)
ttk.Label(Gmetanum,text='Temperature Database:' ).grid(column=3,row=7)
ttk.Entry(Gmetanum,textvariable=Temperature_DB,width=30).grid(column=4,row=7)
ttk.Label(Gmetanum,text='Salinity Database:' ).grid(column=3,row=8)
ttk.Entry(Gmetanum,textvariable=Salinity_DB, width=30).grid(column=4,row=8)
ttk.Label(Gmetanum,text='SSP Model:' ).grid(column=3,row=9)
ttk.Entry(Gmetanum,textvariable=SSP_Model, width=30).grid(column=4,row=9)
ttk.Label(Gmetanum,text='Propagation Model:' ).grid(column=3,row=10)
ttk.Entry(Gmetanum,textvariable=Propagation_Model,width=30).grid(column=4,row=10)
ttk.Label(Gmetanum,text='Data Calibration:' ).grid(column=3,row=11)
ttk.Entry(Gmetanum,textvariable=Data_Calibration, width=30).grid(column=4,row=11)
ttk.Label(Gmetanum,text='Documentation:' ,style='TE2.TLabel').grid(column=1,row=13)
ttk.Label(Gmetanum,text='Metadata_Format.pdf',style='TE2.TLabel').grid(column=2,row=13)
ttk.Button(Gmetanum, text="Write", style='CB.TButton', command=writenum).grid(column=4, row=12, padx=5, pady=5)
ttk.Button(Gmetanum, text="Close", style='CB.TButton', command=lambda:[jmdn.set(0),Gmetanum.grab_release(),Gmetanum.destroy()]).grid(column=4, row=13, padx=5, pady=5)
return
#======================================================================
# GUI to create experimental metadata:
def gui_metaexp():
Data_Type.set('Experimental')
jmde.set( jmde.get() + 1 )
ngui = jmde.get()
if ( ngui > 1 ):
messagebox.showinfo("Oops", 'Window already open.')
else:
Gmetaexp = Toplevel(root, borderwidth=10, relief=GROOVE)
Gmetaexp.title("Experimental Metadata")
Gmetaexp.grab_set()
Data_Type.set('Experimental')
ttk.Label(Gmetaexp,text='Filename:' ).grid(column=1,row=1)
ttk.Entry(Gmetaexp,textvariable=metfile, width=30).grid(column=2,row=1)
ttk.Label(Gmetaexp,text='Format Version:' ).grid(column=1,row=2)
ttk.Entry(Gmetaexp,textvariable=Format_Version,width=30).grid(column=2,row=2)
ttk.Label(Gmetaexp,text='Author:' ).grid(column=1,row=3)
ttk.Entry(Gmetaexp,textvariable=Author, width=30).grid(column=2,row=3)
ttk.Label(Gmetaexp,text='Institution:' ).grid(column=1,row=4)
ttk.Entry(Gmetaexp,textvariable=Institution, width=30).grid(column=2,row=4)
ttk.Label(Gmetaexp,text='Country Code:' ).grid(column=1,row=5)
ttk.Entry(Gmetaexp,textvariable=Country_Code, width=30).grid(column=2,row=5)
ttk.Label(Gmetaexp,text='Contact:' ).grid(column=1,row=6)
ttk.Entry(Gmetaexp,textvariable=Contact, width=30).grid(column=2,row=6)
ttk.Label(Gmetaexp,text='Start Date (YYYYMMDD):' ).grid(column=1,row=7)
ttk.Entry(Gmetaexp,textvariable=Start_Date, width=30).grid(column=2,row=7)
ttk.Label(Gmetaexp,text='End Date (YYYYMMDD):' ).grid(column=1,row=8)
ttk.Entry(Gmetaexp,textvariable=End_Date, width=30).grid(column=2,row=8)
ttk.Label(Gmetaexp,text='Creation Date (YYYYMMDD):' ).grid(column=1,row=9)
ttk.Entry(Gmetaexp,textvariable=Creation_Date, width=30).grid(column=2,row=9)
ttk.Label(Gmetaexp,text='Purpose:' ).grid(column=1,row=10)
ttk.Entry(Gmetaexp,textvariable=Purpose, width=30).grid(column=2,row=10)
ttk.Label(Gmetaexp,text='Data UUID:' ).grid(column=1,row=11)
ttk.Entry(Gmetaexp,textvariable=Data_Uuid, width=30).grid(column=2,row=11)
ttk.Label(Gmetaexp,text='Data Type:' ).grid(column=1,row=12)
ttk.Label(Gmetaexp,text='Experimental' ).grid(column=2,row=12)
ttk.Label(Gmetaexp,text='Comments:' ).grid(column=1,row=13)
ttk.Entry(Gmetaexp,textvariable=Comments, width=30).grid(column=2,row=13)
ttk.Label(Gmetaexp,text='Expsetup:' ).grid(column=1,row=14)
ttk.Entry(Gmetaexp,textvariable=Expsetup, width=30).grid(column=2,row=14)
ttk.Label(Gmetaexp,text='Recorder Manufacturer:' ).grid(column=1,row=15)
ttk.Entry(Gmetaexp,text=RecorderMa, width=30).grid(column=2,row=15)
ttk.Label(Gmetaexp,text='Recorder Serial Number:' ).grid(column=1,row=16)
ttk.Entry(Gmetaexp,textvariable=RecorderSN, width=30).grid(column=2,row=16)
ttk.Label(Gmetaexp,text='Recorder Model:' ).grid(column=1,row=17)
ttk.Entry(Gmetaexp,textvariable=RecorderMo, width=30).grid(column=2,row=17)
ttk.Label(Gmetaexp,text='Builtin Hydrophone:' ).grid(column=1,row=18)
ttk.Entry(Gmetaexp,textvariable=Builtin, width=30).grid(column=2,row=18)
ttk.Label(Gmetaexp,text='Hydrophone Manufacturer:' ).grid(column=1,row=19)
ttk.Entry(Gmetaexp,textvariable=HydroMa, width=30).grid(column=2,row=19)
ttk.Label(Gmetaexp,text='Hydrophone Sensitivity:' ).grid(column=1,row=20)
ttk.Entry(Gmetaexp,text=HydroS, width=30).grid(column=2,row=20)
ttk.Label(Gmetaexp,text='Hydrophone Serial Number:' ).grid(column=1,row=21)
ttk.Entry(Gmetaexp,textvariable=HydroSN, width=30).grid(column=2,row=21)
ttk.Label(Gmetaexp,text='Hydrophone Model:' ).grid(column=1,row=22)
ttk.Entry(Gmetaexp,textvariable=HydroMo, width=30).grid(column=2,row=22)
ttk.Label(Gmetaexp,text='Average Time (s):' ).grid(column=3,row=2)
ttk.Entry(Gmetaexp,textvariable=AVtime , width=30).grid(column=4,row=2)
ttk.Label(Gmetaexp,text='Calibration Datetime:' ).grid(column=3,row=3)
ttk.Entry(Gmetaexp,text=CalibD, width=30).grid(column=4,row=3)
ttk.Label(Gmetaexp,text='Calibration Factor:' ).grid(column=3,row=4)
ttk.Entry(Gmetaexp,textvariable=CalibF, width=30).grid(column=4,row=4)
ttk.Label(Gmetaexp,text='Calibration Procedure:' ).grid(column=3,row=5)
ttk.Entry(Gmetaexp,textvariable=CalibP, width=30).grid(column=4,row=5)
ttk.Label(Gmetaexp,text='Reference Frequencies:' ).grid(column=3,row=6)
ttk.Entry(Gmetaexp,textvariable=RefFreq, width=30).grid(column=4,row=6)
ttk.Label(Gmetaexp,text='Calibration Frequency Count:' ).grid(column=3,row=7)
ttk.Entry(Gmetaexp,textvariable=CalibCount, width=30).grid(column=4,row=7)
ttk.Label(Gmetaexp,text='Longitude:' ).grid(column=3,row=8)
ttk.Entry(Gmetaexp,textvariable=Longitude, width=30).grid(column=4,row=8)
ttk.Label(Gmetaexp,text='Latitude:' ).grid(column=3,row=9)
ttk.Entry(Gmetaexp,textvariable=Latitude, width=30).grid(column=4,row=9)
ttk.Label(Gmetaexp,text='Depth (m):' ).grid(column=3,row=10)
ttk.Entry(Gmetaexp,textvariable=Depth, width=30).grid(column=4,row=10)
ttk.Label(Gmetaexp,text='Frequency Count:' ).grid(column=3,row=11)
ttk.Entry(Gmetaexp,textvariable=FreqCount, width=30).grid(column=4,row=11)
ttk.Label(Gmetaexp,text='Frequency Band Definition:' ).grid(column=3,row=12)
ttk.Entry(Gmetaexp,textvariable=FreqBand, width=30).grid(column=4,row=12)
ttk.Label(Gmetaexp,text='Time Duty On:' ).grid(column=3,row=13)
ttk.Entry(Gmetaexp,textvariable=TimeDO, width=30).grid(column=4,row=14)
ttk.Label(Gmetaexp,text='Time Duty Off:' ).grid(column=3,row=14)
ttk.Entry(Gmetaexp,textvariable=TimeDF, width=30).grid(column=4,row=14)
ttk.Label(Gmetaexp,text='Hydrophone Count:' ).grid(column=3,row=15)
ttk.Entry(Gmetaexp,textvariable=HydroCount, width=30).grid(column=4,row=15)
ttk.Label(Gmetaexp,text='Percentile Count:' ).grid(column=3,row=16)
ttk.Entry(Gmetaexp,textvariable=PercCount, width=30).grid(column=4,row=16)
ttk.Label(Gmetaexp,text='Percentile List:' ).grid(column=3,row=17)
ttk.Entry(Gmetaexp,textvariable=PercList, width=30).grid(column=4,row=17)
ttk.Label(Gmetaexp,text='Documentation:' , style='TE2.TLabel').grid(column=3,row=20)
ttk.Label(Gmetaexp,text='Metadata_Format.pdf', style='TE2.TLabel').grid(column=4,row=20)
# Buttons:
ttk.Button(Gmetaexp, text="Write", style='CB.TButton', command=writeexp).grid(column=4, row=22, padx=5, pady=5)
ttk.Button(Gmetaexp, text="Close", style='CB.TButton', command=lambda:[jmde.set(0),Gmetaexp.grab_release(),Gmetaexp.destroy()]).grid(column=4, row=23, padx=5, pady=5)
return
#======================================================================
# Function to write the experimental metadata file:
def writeexp(*args):
dfile = metfile.get()
Data_Type.set('Experimental')
if ( dfile == 'Nothing selected...' ):
messagebox.showinfo("Oops", 'Specify a filename first...')
else:
metadatafile = open(dfile, "w") # Experimental metadata: 37 parameters
metadatafile.write(Format_Version.get()+'\n') # 1
metadatafile.write( Author.get()+'\n') # 2
metadatafile.write( Institution.get()+'\n') # 3
metadatafile.write( Country_Code.get()+'\n') # 4
metadatafile.write( Contact.get()+'\n') # 5
metadatafile.write( Start_Date.get()+'\n') # 6
metadatafile.write( End_Date.get()+'\n') # 7
metadatafile.write( Creation_Date.get()+'\n') # 8
metadatafile.write( Purpose.get()+'\n') # 9
metadatafile.write( Data_Uuid.get()+'\n') # 10
metadatafile.write( Data_Type.get()+'\n') # 11
metadatafile.write( Comments.get()+'\n') # 12
metadatafile.write( Expsetup.get()+'\n') # 13
metadatafile.write( RecorderMa.get()+'\n') # 14
metadatafile.write( RecorderSN.get()+'\n') # 15
metadatafile.write( RecorderMo.get()+'\n') # 16
metadatafile.write( Builtin.get()+'\n') # 17
metadatafile.write( HydroMa.get()+'\n') # 18
metadatafile.write( HydroS.get()+'\n') # 19
metadatafile.write( HydroSN.get()+'\n') # 20
metadatafile.write( HydroMo.get()+'\n') # 21
metadatafile.write( AVtime.get()+'\n') # 22
metadatafile.write( CalibD.get()+'\n') # 23
metadatafile.write( CalibF.get()+'\n') # 24
metadatafile.write( CalibP.get()+'\n') # 25
metadatafile.write( RefFreq.get()+'\n') # 26
metadatafile.write( CalibCount.get()+'\n') # 27
metadatafile.write( Longitude.get()+'\n') # 28
metadatafile.write( Latitude.get()+'\n') # 29
metadatafile.write( Depth.get()+'\n') # 30
metadatafile.write( FreqCount.get()+'\n') # 31
metadatafile.write( FreqBand.get()+'\n') # 32
metadatafile.write( TimeDO.get()+'\n') # 33
metadatafile.write( TimeDF.get()+'\n') # 34
metadatafile.write( HydroCount.get()+'\n') # 35
metadatafile.write( PercCount.get()+'\n') # 36
metadatafile.write( PercList.get()+'\n') # 37
metadatafile.close()
messagebox.showinfo("Done:", 'Metadata written to ' + dfile)
return
#======================================================================
# Function to write the numerical metadata file:
def writenum(*args):
dfile = metfile.get()
Data_Type.set('Numerical')
if ( dfile == 'Nothing selected...' ):
messagebox.showinfo("Oops", 'Specify a filename first...')
else:
metadatafile = open(dfile, "w") # Numerical metadata: 20 parameters
metadatafile.write(Format_Version.get()+'\n') # 1
metadatafile.write( Author.get()+'\n') # 2
metadatafile.write( Institution.get()+'\n') # 3
metadatafile.write( Country_Code.get()+'\n') # 4
metadatafile.write( Contact.get()+'\n') # 5
metadatafile.write( Start_Date.get()+'\n') # 6
metadatafile.write( End_Date.get()+'\n') # 7
metadatafile.write( Creation_Date.get()+'\n') # 8
metadatafile.write( Purpose.get()+'\n') # 9
metadatafile.write( Data_Uuid.get()+'\n') # 10
metadatafile.write( Data_Type.get()+'\n') # 11
metadatafile.write( Comments.get()+'\n') # 12
metadatafile.write( AIS_DB.get()+'\n') # 13
metadatafile.write( Source_Levels.get()+'\n') # 14
metadatafile.write( Bathy_DB.get()+'\n') # 15
metadatafile.write(Temperature_DB.get()+'\n') # 16
metadatafile.write( Salinity_DB.get()+'\n') # 17
metadatafile.write( SSP_Model.get()+'\n') # 18
metadatafile.write(Propagation_Model.get()+'\n') # 19
metadatafile.write( Data_Calibration.get()+'\n') # 20
metadatafile.close()
messagebox.showinfo("Done:", 'Metadata written to ' + dfile)
return
#======================================================================
#======================================================================
# FUNCTIONS
#======================================================================
#======================================================================
# Function to open a GUI depending on the option:
def whichgui():
thegui = gui2open.get()
if ( thegui == 'GED' ):
gui_experimental()
elif ( thegui == 'GND' ):
gui_numerical()
elif ( thegui == 'GMD' ):
gui_meta()
else:
messagebox.showerror("Oops", "Select an option first...")
return
#======================================================================
# Function to run the analysis:
def run_analysis():
ifile = sndfile.get()
nchannels = int( nchann.get() )
thechannel = int( thechan.get() )
if ( ifile == 'Nothing selected...' ):
messagebox.showerror("Error:", "Select a sound file first...")
elif ( Hcut.get() == ' ' ):
messagebox.showerror("Error:", "Specify a High Frequency...")
elif ( thechannel > nchannels ):
messagebox.showerror("Error:", "Selected channel does not exist...")
else:
atype = Atype.get()
ctype = Ctype.get()
plottype = Plottype.get()
envi = Envi.get()
winname = Winname.get()
Si = float( SI.get() )
Mh = float( MH.get() )
G = float( GG.get() )
vADC = float( VADC.get() )
r = float( Wover.get() )*0.01
wlength = float( Wlength.get() )
lcut = float( Lcut.get() )
hcut = float( Hcut.get() )
welch = float( Welch.get() )
S = Linlog.get()
thechannel = thechannel - 1 # Python starts at 0!!!!!
if ( S == 'Logarithmic' ):
linlog = 0
else:
linlog = 1
PG_Func(ifile,atype,plottype,envi,ctype,Si,Mh,G,vADC,r,wlength,winname,lcut,hcut,welch,linlog,thechannel)
return
#======================================================================
# Function to select the sound file:
def infosnd(*args):
sound_type = sndtype.get()
thefile = 'Nothing selected...'
if ( sound_type == '...' ):
messagebox.showinfo("Oops...", 'Select a file type first...')
elif ( sound_type == 'FLAC' ):
thefile = filedialog.askopenfilename(initialdir = "",title = "Select file", filetypes = (("FLAC files","*.flac"),("all files","*.*")))
else:
thefile = filedialog.askopenfilename(initialdir = "",title = "Select file", filetypes = (("WAV files","*.wav"),("all files","*.*")))
if ( sound_type != '...' ):
sndfile.set(thefile)
thesignal, Fs = sf.read(thefile,dtype=float64)
Hcut.set(Fs//2)
iaux = len(thesignal.shape)
if iaux == 1:
nchann.set(1)
else:
nchann.set(min(thesignal.shape))
samples = max( thesignal.shape )
if ( samples < Fs ):
sofs = samples/Fs
Wlength.set( sofs )
themessage = 'Window length should be smaller than ' + str(sofs) + ' s!!!!'
messagebox.showinfo("Warning:", themessage)
else:
messagebox.showinfo("Oops...", 'Select a file type first...')
return
#======================================================================
# Function to select the directory:
def infodir(*args):
thefile = filedialog.askdirectory(initialdir = "",title = "Select Directory")
sndfile.set(thefile)
thefiles = ''
j = 0
thedir = sndfile.get()
thetype = sndtype.get()
# YUP, I prefer file extensions this way:
if ( thetype == 'FLAC' ):
thetype = 'flac'
else:
thetype = 'wav'
x = os.listdir(thedir)
for i in x:
if i.endswith(thetype):
j = j + 1
thefiles = thefiles + ' ' + i
if ( j == 0 ):
messagebox.showinfo("Oops", 'No sound files found...')
elif ( j == 1 ):
messagebox.showinfo("Oops", 'Only one file found...')
else:
list_of_files = thefiles.split()
thesignal, Fs = sf.read(thedir+'/'+list_of_files[0],dtype=float64)
Hcut.set(Fs//2)
return
#======================================================================
# Function to select the mat file:
def infomat(*args):
thefile = filedialog.askopenfilename(initialdir = "",title = "Select file",filetypes = (("MAT files","*.mat"),("all files","*.*")))
matfile.set(thefile)
return
#======================================================================
# Function to run batch analysis in the directory:
def run_analysisb(*args):
thefiles = ''
j = 0
thedir = sndfile.get()
thetype = sndtype.get()
# YUP, I prefer file extensions this way:
if ( thetype == 'FLAC' ):
thetype = 'flac'
else:
thetype = 'wav'
x = os.listdir(thedir)
for i in x:
if i.endswith(thetype):
j = j + 1
thefiles = thefiles + ' ' + i
if ( j == 0 ):
messagebox.showinfo("Oops", 'No sound files found...')
elif ( j == 1 ):
messagebox.showinfo("Oops", 'Only one file found...')
else:
# CANCEL BATCH IF:
# THERE ARE SPACES IN THE FILENAMES
# SAMPLING FREQUENCIES ARE DIFFERENT
list_of_files = thefiles.split()
acheck = 0
for i in range(j):
thefile = list_of_files[i]
acheck = min( [acheck,str.find(thefile,thetype)] )
if ( acheck < 0 ):
messagebox.showinfo("Batch processing cancelled:", 'Filenames should not contain spaces...')
else:
sampling_frequency = zeros(j)
nchannels = zeros(j)
for i in range(j):
thesignal,sampling_frequency[i] = sf.read( thedir + '/' + list_of_files[i] )
nchannels[i] = len( thesignal.shape )
thesignal = []
cfreq = max( abs( diff( sampling_frequency ) ) )
cchan = max( abs( diff( nchannels ) ) ) # Not used, but let's keep it...
if ( cfreq != 0 ):
messagebox.showinfo("Batch processing cancelled:", 'Sampling rate should be the same for all files...')
else:
Fs = int( sampling_frequency[0] )
atype = Atype.get()
ctype = Ctype.get()
plottype = Plottype.get()
envi = Envi.get()
winname = Winname.get()
Si = float( SI.get() )
Mh = float( MH.get() )
G = float( GG.get() )
vADC = float( VADC.get() )
r = float( Wover.get() )*0.01
wlength = float( Wlength.get() )
lcut = float( Lcut.get() )
hcut = float( Hcut.get() )
welch = float( Welch.get() )
S = Linlog.get()
if ( S == 'Logarithmic' ):
linlog = 0
else:
linlog = 1
for i in range(j):
ifile = thedir + '/' + list_of_files[i]
outi = 'Aft' + str(i) + '.mat'
thechannel = 0 # Process only first channel in batch processing...
PG_Func(ifile,atype,plottype,envi,ctype,Si,Mh,G,vADC,r,wlength,winname,lcut,hcut,welch,linlog,thechannel)
os.rename('Aft.mat', outi)
return
#======================================================================
# Function to plot the mat file:
def plotmat(*args):
thefile = matfile.get()
if ( thefile != 'Nothing selected...' ):
matlab_data = loadmat(thefile,squeeze_me=True)
frequency = matlab_data['frequency' ] # 7
time = matlab_data['time' ] # 8
spl_values = matlab_data['spl_values'] # 9
percentile_list = matlab_data['percentile_list'] # 10
percentile_count = len( percentile_list )
cA = spl_values[0,:].size
time_count = spl_values[:,0].size
percentile_values = zeros((cA,percentile_count))
# Calculate the percentiles:
for i in range(percentile_count):
percentile_values[:,i] = percentile(spl_values,percentile_list[i],axis=0)
figure()
yscale('log')
pcolormesh(time,frequency,spl_values.transpose(),cmap='viridis',shading='auto')
xlim(time[0],time[-1])
ylim(frequency[0],frequency[-1])
xlabel('Time [s]',fontsize=16)
ylabel('Frequency [Hz]',fontsize=16)
title('SPL values [dB]')
colorbar()
figure()
for i in range(percentile_count):
thelabel = str( percentile_list[i] ) + '%'
plot(frequency,percentile_values[:,i],label=thelabel)
xlabel('Frequency [Hz]',fontsize=16)
title('Percentiles')
legend(loc='best')
show()
else:
messagebox.showerror("Error:", "Select a *.mat file first...")
return
#======================================================================
# Function to write the CSV and EDF files after batch processing
# (the CSV is written only for experimental data):
def writeoutb(*args):
thefiles = ''
j = 0
thedir = sndfile.get()
thetype = sndtype.get()
# YUP, I prefer file extensions this way:
if ( thetype == 'FLAC' ):
thetype = 'flac'
else:
thetype = 'wav'
x = os.listdir(thedir)
for i in x:
if i.endswith(thetype):
j = j + 1
thefiles = thefiles + ' ' + i
list_of_files = thefiles.split()
j = len( list_of_files )
for i in range(j):
ifile = thedir + '/' + list_of_files[i]
mfile = sndfile.set(ifile)
mati = 'Aft' + str(i) + '.mat'
os.rename(mati,'Aft.mat')
writeout()
#======================================================================
# Function to write the CSV and EDF files
# (the CSV is written only for experimental data):
def writeout(*args):
writecsv = CSVOUT.get()
writeedf = EDFOUT.get()
fileextension = sndtype.get()
mfile = sndfile.get()
if ( ( writecsv == 'No' ) and ( writeedf == 'No' ) ):
messagebox.showinfo("Done.", 'Nothing to be written')
if ( writecsv == 'Yes' ):
matlab_data = loadmat('Aft.mat',squeeze_me=True)
frequency = matlab_data['f']
time = matlab_data['t']
spl_values = matlab_data['A']
cA = frequency.size
rA = time.size
data = zeros((rA+1,cA+1))
data[1:,0] = time
data[0,1:] = frequency
data[1:,1:] = spl_values
if ( fileextension == 'FLAC' ):
csvfile = mfile[0:-4] + 'csv'
else:
csvfile = mfile[0:-3] + 'csv'
savetxt(csvfile, data, delimiter=',', fmt='%f')
csvmessage = 'Frequency, Time and SPL values written to ' + csvfile
messagebox.showinfo("Done.", csvmessage )
if ( writeedf == 'Yes' ):
seldata = Data_Type.get()
thefile = filedialog.askopenfilename(initialdir = "",title = "Select a Metadata File:",filetypes = (("Metadata files","*.met"),("all files","*.*")))
metfile.set(thefile)
messagebox.showinfo("Selected Metadata:", thefile)
# Check that the metadata file matches the Experimental/Numerical Case
dfile = metfile.get()
metadatafile = open(dfile, "r")
for i in range(10):
theline = metadatafile.readline()
data_type = metadatafile.readline()
data_type = data_type[0:-1].split()
metadatafile.close()
if ( data_type[0] != seldata ):
mismatchinfo = 'Starting case: ' + seldata + ', Metadata: ' + data_type[0]
messagebox.showinfo("Metadata mismatch...", mismatchinfo)
else:
if ( fileextension == 'flac' ):
hfile = mfile[0:-4] + 'h5'
else:
hfile = mfile[0:-3] + 'h5'
# Experimental Case:
if ( data_type[0] == 'Experimental' ):
metadatafile = open(dfile, "r") # Experimental metadata: 37 parameters
format_version= metadatafile.readline(); format_version = format_version[0:-1] # 1
author = metadatafile.readline(); author = author[ 0:-1] # 2
institution = metadatafile.readline(); institution = institution[ 0:-1] # 3
country_code = metadatafile.readline(); country_code = country_code[ 0:-1] # 4
contact = metadatafile.readline(); contact = contact[ 0:-1] # 5
start_date = int( metadatafile.readline() ) # 6
end_date = int( metadatafile.readline() ) # 7
date_of_creation = int( metadatafile.readline() ) # 8
purpose = metadatafile.readline(); purpose = purpose[ 0:-1] # 9
data_uuid = metadatafile.readline(); data_uuid = data_uuid[0:-1] # 10
data_type = metadatafile.readline(); data_type = data_type[0:-1] # 11
comments = metadatafile.readline(); comments = comments[ 0:-1] # 12
expsetup = metadatafile.readline(); expsetup = expsetup[ 0:-1] # 13
recorder_manufacturer = metadatafile.readline(); recorder_manufacturer = recorder_manufacturer[ 0:-1] # 14
recorder_serial_number = metadatafile.readline(); recorder_serial_number = recorder_serial_number[0:-1] # 15
recorder_model = metadatafile.readline(); recorder_model = recorder_model[ 0:-1] # 16
builtin_hydrophone = metadatafile.readline(); builtin_hydrophone = builtin_hydrophone[ 0:-1] # 17
hydrophone_manufacturer= metadatafile.readline(); hydrophone_manufacturer= hydrophone_manufacturer[0:-1]# 18
hydrophone_sensitivity = float( metadatafile.readline() ) # 19
hydrophone_serial_number = metadatafile.readline(); hydrophone_serial_number = hydrophone_serial_number[0:-1] # 20
hydrophone_model = metadatafile.readline(); hydrophone_model = hydrophone_model[0:-1] # 21
averaging_time = float( metadatafile.readline() ) # 22
calibration_datetime = int( metadatafile.readline() ) # 23
calibration_factor = float( metadatafile.readline() ) # 24
calibration_procedure = metadatafile.readline(); calibration_procedure = calibration_procedure[0:-1] # 25
reference_frequencies = int( metadatafile.readline() ) # 26
calibration_frequency_count = int( metadatafile.readline() ) # 27
slongitudes = metadatafile.readline().split() # 28
slatitudes = metadatafile.readline().split() # 29
sdepths = metadatafile.readline().split() # 30
frequency_count = int( metadatafile.readline() ) # 31
frequency_band_definition = metadatafile.readline(); frequency_band_definition = frequency_band_definition[0:-1] # 32
time_duty_on = metadatafile.readline(); time_duty_on = time_duty_on[ 0:-1] # 33
time_duty_off = metadatafile.readline(); time_duty_off = time_duty_off[0:-1] # 34
hydrophone_count = int( metadatafile.readline() ) # 35
percentile_count = int( metadatafile.readline() ) # 36
splist = metadatafile.readline().split() # 37
metadatafile.close()
# Convert the lists of strings to lists of floats:
depth = [float(xi) for xi in sdepths ]
latitude = [float(xi) for xi in slatitudes ]
longitude = [float(xi) for xi in slongitudes ]
percentile_list = [float(xi) for xi in splist]
percentile_count = len( percentile_list ) # Just in case... (yup, a list has length, not size)
# The following are reference values and they are written but not
# used when information is extracted from the h5 file:
total_number_of_grid_points = NaN
ais_database = 'AISHub - www.aishub.net'
bathymetry_database = 'GEBCO - www.gebco.net'
temperature_database = 'COPERNICUS - www.copernicus.eu'
salinity_database = 'COPERNICUS - www.copernicus.eu'
sound_speed_profile_model = 'Mackenzie-nine-term equation'
propagation_model = 'KRAKEN'
numeric_data_calibration = 'data uidn:xxxx-xxxx-xxxx-xxxx'
source_levels = [170.0, 120.0, 180.0]
matlab_data = loadmat('Aft.mat',squeeze_me=True)
frequency = matlab_data['f']
time = matlab_data['t']
spl_values = matlab_data['A']
cA = spl_values[0,:].size
time_count = spl_values[:,0].size
percentile_values = zeros((cA,percentile_count))
# Calculate the percentiles:
for i in range(percentile_count):
percentile_values[:,i] = percentile(spl_values,percentile_list[i],axis=0)
#======================================================================
# Numerical case (requires user's input about MAT file with data):
else:
mfile = matfile.get()
hfile = mfile[0:-3] + 'h5'
builtin_hydrophone = 'N/A'
calibration_procedure = 'N/A'
expsetup = 'N/A'
hydrophone_manufacturer= 'N/A'
hydrophone_model = 'N/A'
hydrophone_serial_number='N/A'
recorder_manufacturer = 'N/A'
recorder_model = 'N/A'
recorder_serial_number = 'N/A'
time_duty_on = 'N/A'
time_duty_off = 'N/A'
averaging_time = nan
calibration_datetime = nan
calibration_factor = nan
calibration_frequency_count = nan
reference_frequencies = nan
hydrophone_count = nan
hydrophone_sensitivity = nan
metadatafile = open(dfile, "r") # Numerical metadata: 20 parameters
format_version= metadatafile.readline(); format_version = format_version[0:-1] # 1
author = metadatafile.readline(); author = author[ 0:-1] # 2
institution = metadatafile.readline(); institution = institution[ 0:-1] # 3
country_code = metadatafile.readline(); country_code = country_code[ 0:-1] # 4
contact = metadatafile.readline(); contact = contact[ 0:-1] # 5
start_date = int( metadatafile.readline() ) # 6
end_date = int( metadatafile.readline() ) # 7
date_of_creation = int( metadatafile.readline() ) # 8
purpose = metadatafile.readline(); purpose = purpose[ 0:-1] # 9
data_uuid = metadatafile.readline(); data_uuid = data_uuid[0:-1] # 10
data_type = metadatafile.readline(); data_type = data_type[0:-1] # 11
comments = metadatafile.readline(); comments = comments[ 0:-1] # 12
ais_database = metadatafile.readline(); ais_database = ais_database[0:-1] # 13
ssource_levels = metadatafile.readline().split() # 14
bathymetry_database = metadatafile.readline(); bathymetry_database = bathymetry_database[ 0:-1] # 15
temperature_database= metadatafile.readline(); temperature_database= temperature_database[0:-1] # 16
salinity_database = metadatafile.readline(); salinity_database = salinity_database[ 0:-1] # 17
sound_speed_profile_model= metadatafile.readline(); sound_speed_profile_model = sound_speed_profile_model[0:-1] # 18
propagation_model = metadatafile.readline(); propagation_model = propagation_model[ 0:-1] # 19
numeric_data_calibration = metadatafile.readline(); numeric_data_calibration = numeric_data_calibration[ 0:-1] # 20
metadatafile.close()
# Convert the list of strings to a list of floats:
source_levels = [float(xi) for xi in ssource_levels]
# Load numerical data:
matlab_data = loadmat(mfile,squeeze_me=True)
total_number_of_grid_points = matlab_data['total_number_of_grid_points'] # 1
c = total_number_of_grid_points.size
if ( c == 0 ):
total_number_of_grid_points = nan
longitude = matlab_data['longitude'] # 2
latitude = matlab_data['latitude' ] # 3
depth = matlab_data['depth' ] # 4
frequency_band_definition = matlab_data['frequency_band_definition'] # 5
frequency_count = matlab_data['frequency_count' ] # 6
frequency = matlab_data['frequency' ] # 7
time = matlab_data['time' ] # 8
spl_values = matlab_data['spl_values' ] # 9
percentile_list = matlab_data['percentile_list'] # 10
percentile_count = len( percentile_list )
cA = spl_values[0,:].size
time_count = spl_values[:,0].size
percentile_values = zeros((cA,percentile_count))
# Calculate the percentiles:
for i in range(percentile_count):
percentile_values[:,i] = percentile(spl_values,percentile_list[i],axis=0)
#======================================================================
# Make a dictionary of data:
data = {"format_version":format_version, "author":author, "institution":institution,"country_code":country_code,
"contact":contact,"start_date":start_date,"end_date":end_date,"date_of_creation":date_of_creation,
"purpose":purpose,"data_uuid":data_uuid,"data_type":data_type,"comments":comments,"expsetup":expsetup,
"recorder_manufacturer":recorder_manufacturer,"recorder_serial_number":recorder_serial_number,
"recorder_model":recorder_model,"builtin_hydrophone":builtin_hydrophone,
"hydrophone_manufacturer":hydrophone_manufacturer,"hydrophone_sensitivity":hydrophone_sensitivity,
"hydrophone_serial_number":hydrophone_serial_number,"hydrophone_model":hydrophone_model,
"calibration_frequency_count":calibration_frequency_count,"calibration_datetime":calibration_datetime,
"calibration_factor":calibration_factor,"calibration_procedure":calibration_procedure,
"reference_frequencies":reference_frequencies,"ais_database":ais_database,
"source_levels":source_levels,
"bathymetry_database":bathymetry_database,"temperature_database":temperature_database,
"salinity_database":salinity_database,
"sound_speed_profile_model":sound_speed_profile_model,"propagation_model":propagation_model,
"numeric_data_calibration":numeric_data_calibration,
"hydrophone_count":hydrophone_count,
"total_number_of_grid_points":total_number_of_grid_points,
"longitude":longitude,"latitude":latitude,"depth":depth,
"frequency_count":frequency_count,"frequency_band_definition":frequency_band_definition,
"frequency":frequency,
"time_duty_on":time_duty_on,"time_duty_off":time_duty_off,"time_count":time_count,
"time":time,"averaging_time":averaging_time,
"spl_values":spl_values,
"percentile_list":percentile_list,"percentile_count":percentile_count,"percentile_values":percentile_values}
# Write the h5:
write_edf(hfile,data)
messagebox.showinfo("Done.", 'EDF file written.')
return
#======================================================================
# Function to end the GUI:
def byebye():
messagebox.showinfo("Bye bye...", 'Hasta la vista baby.')
root.destroy()
return
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#======================================================================
#======================================================================
# Ladies and Gentlemen, the GUI:
#======================================================================
#======================================================================
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root = Tk()
root.title("PAM2Py version 5.0")
# Styles:
style=ttk.Style()
style.map("TEntry",foreground=[("disabled", "black")])
fc = ttk.Style()
fc.configure('FC.TFrame', background='darkgreen')
bd = ttk.Style()
bd.configure('BD.TButton', font=('Helvetica', 18, 'bold'), width=20, background='white', foreground='black')
bq = ttk.Style()
bq.configure('BQ.TButton', font=('Helvetica', 18, 'bold'), width=20, background='white', foreground='black')
cb = ttk.Style()
cb.configure('CB.TButton', font=('Helvetica', 16, 'bold'), width=20, background='yellow', foreground='black')