-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript_1_Preprocessing.py
More file actions
1804 lines (1309 loc) · 71.3 KB
/
Copy pathScript_1_Preprocessing.py
File metadata and controls
1804 lines (1309 loc) · 71.3 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
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 14 15:16:11 2024
@author: Judith Tettenborn (j.a.f.tettenborn@uu.nl)
based on work of Daan Stroeken
Main script for (pre-)processing data.
- reads in data and does some preprocessing
- using scipy.signal.find_peaks CH4 enhancements are detected
- the timestamps, enhancements, etc. of the peaks found are saved into an excel
file (one file per (sub)-experiment with different excel sheets per instrument)
- overviewplots of the timeseries and peaks detected can pe created (optionally,
one per instrument)
- plots of each detected peak can be created for the following quality check step
(optional, up to several hundreds per instrument)
"""
# Modify Python Path Programmatically -> To include the directory containing the src folder
from pathlib import Path
import sys
# path_base = Path('C:/Users/.../CRE_CH4Quantification/') # insert the the project path here
path_base = Path('C:/Users/Judit/Documents/UNI/Utrecht/Hiwi/CRE_CH4Quantification/')
sys.path.append(str(path_base / 'src'))
# In Python, the "Python path" refers to the list of directories where Python looks for modules
# and packages when you try to import them in your scripts or interactive sessions. This path
# is stored in the sys.path list. When you execute an import statement in Python, it searches
# for the module or package you're trying to import in the directories listed in sys.path.
# If the directory containing the module or package is not included in sys.path, Python won't
# be able to find and import it.
import pandas as pd
import numpy as np
import time
import matplotlib.pyplot as plt
import tilemapbase
import matplotlib.colors as mcolors
from matplotlib import cm
from matplotlib.ticker import FuncFormatter
from preprocessing.read_in_data import *
from peak_analysis.find_analyze_peaks import *
from plotting.general_plots import *
from helper_functions.utils import *
from helper_functions.constants import (
dict_color_instr,
HEIGHT,
BG_QUANTILE,
DIST_G23,
WIDTH_G23,
DIST_G24,
WIDTH_G24,
DIST_LGR,
WIDTH_LGR,
DIST_LICOR,
WIDTH_LICOR,
DIST_G43,
WIDTH_G43,
DIST_AERIS,
WIDTH_AERIS,
DIST_MIRO,
WIDTH_MIRO,
DIST_AERO,
WIDTH_AERO
)
# path Controlled Release Experiment Utrecht
path_dataU1 = path_base / 'data' / 'raw' / 'Utrecht_I_2022'
path_dataU2 = path_base / 'data' / 'raw' / 'Utrecht_II_2024'
path_dataT = path_base / 'data' / 'raw' / 'Toronto_2021'
path_dataL1 = path_base / 'data' / 'raw' / 'London_I_2019'
path_dataL2 = path_base / 'data' / 'raw' / 'London_II_2024'
path_dataR = path_base / 'data' / 'raw' / 'Rotterdam_2022'
if not (path_base / 'results').is_dir(): # output: processed data
(path_base / 'results').mkdir(parents=True)
path_res = path_base / 'results'
if not (path_base / 'data' / 'processed').is_dir(): # output: processed data
(path_base / 'data' / 'processed').mkdir(parents=True)
path_processeddata = path_base / 'data' / 'processed'
overviewplot = True # Plot the find_peaks result
writexlsx = False # save peaks into excel file
indiv_peak_plots = False # plot individual peaks for QC? ATTENTION: when True this will create several hundreds of figures PER instrument
###############################################################################
#%% Utrecht I
###############################################################################
#%%% Load & Preprocess data
# create the folder if it they do not exist
if not (path_res / 'Figures' / 'Utrecht_I_2022').is_dir(): # output: figures
(path_res / 'Figures' / 'Utrecht_I_2022').mkdir(parents=True)
path_fig = path_res / 'Figures' / 'Utrecht_I_2022/'
morning_start = '2022-11-25 12:06:00'
morning_end = '2022-11-25 14:18:00'
U1_G2301_gps,U1_G4302_gps = read_and_preprocess_G23andG43_U1(path_dataU1, path_processeddata, writexlsx=writexlsx)
# Set the name attribute for each dataframe
U1_G2301_gps.name = 'G2301'
U1_G4302_gps.name = 'G4302'
#%%% Find peaks
if writexlsx:
writer = pd.ExcelWriter(path_processeddata / "U1_CH4peaks.xlsx", engine = 'xlsxwriter')
else:
writer = None
U1_G23_peaks = process_peak_data(U1_G2301_gps[morning_start:morning_end], 'G23', height=HEIGHT, distance=DIST_G23, width=WIDTH_G23,
overviewplot=overviewplot, savepath = path_fig / 'U1_overviewplot_G2301')
U1_G43_peaks = process_peak_data(U1_G4302_gps[morning_start:morning_end], 'G43', height=HEIGHT, distance=DIST_G43, width=WIDTH_G43,
overviewplot=overviewplot, savepath = path_fig / 'U1_overviewplot_G4302')
if writexlsx:
U1_G23_peaks.to_excel(writer, sheet_name='G2301')
U1_G43_peaks.to_excel(writer, sheet_name='G4302')
writer.book.close()
# figure peaks + timeseries
fig, ax1 = plt.subplots(figsize=(18,10))
ax2 = ax1.twinx()
ax1.plot(U1_G2301_gps.index,U1_G2301_gps['CH4_ele_G23'], alpha=1, label='G2301', linewidth=2, color=dict_color_instr['G2301'])
ax1.plot(U1_G4302_gps.index,U1_G4302_gps['CH4_ele_G43'], alpha=1, label='G4302', linewidth=2, color=dict_color_instr['Aeris'])
ax1.scatter(U1_G23_peaks.index,U1_G23_peaks['CH4_ele_G23'], alpha=1, label='Peaks G2301', color='red')
ax1.scatter(U1_G43_peaks.index,U1_G43_peaks['CH4_ele_G43'], alpha=1, label='Peaks G4302', color='red')
ax2.scatter(U1_G2301_gps.index,U1_G2301_gps['Speed [m/s]'], alpha=.2, label='Speed m/s', color='orange')
ax3 = ax1.twinx() # Create the third y-axis, sharing the same x-axis
ax3.spines["right"].set_position(("outward", 60)) # Offset the third y-axis to avoid overlap
ax3.plot(U1_G2301_gps.index,U1_G2301_gps['Latitude'], alpha=.8, label='Latitude', color='lightgrey')
ax3.set_ylim(52.085,52.12)
ax1.set_xlim(pd.to_datetime('2022-11-25 11:55:00'),pd.to_datetime('2022-11-25 14:25:00'))
plt.gca().xaxis.set_major_formatter(dates.DateFormatter('%H:%M:%S'))
ax1.legend()
plt.title('Utrecht I')
#%%% Peak Plots
# Define other necessary variables
coord_extent = [5.1633, 5.166, 52.0873, 52.0888]
release_loc1 = (5.1647191, 52.0874256)
release_loc2 = (5.164405555555556, 52.0885444)
column_names = {'G2301': 'CH4_ele_G23', 'G4302': 'CH4_ele_G43'}
if indiv_peak_plots:
# create the folder if it does not exist
if not (path_fig / 'U1_Peakplots').is_dir():
(path_fig / 'U1_Peakplots').mkdir(parents=True)
path_save = path_fig / 'U1_Peakplots'
# Remove rows with NaN values in column 'latitude'
gps = U1_G4302_gps.dropna(subset=['Latitude']).copy(deep=True)
# Call the function with necessary arguments
plot_indivpeaks_bevorQC(U1_G43_peaks, gps, path_save, coord_extent, release_loc1, release_loc2, indiv_peak_plots, column_names, U1_G2301_gps, U1_G4302_gps)
###############################################################################
#%% Utrecht II
###############################################################################
#%%% Load & Preprocess data
if not (path_res / 'Figures' / 'Utrecht_II_2024').is_dir(): # output: figures
(path_res / 'Figures' / 'Utrecht_II_2024').mkdir(parents=True)
path_fig = path_res / 'Figures' / 'Utrecht_II_2024/'
U2_G2301_gps,U2_aeris_gps = read_and_preprocess_U2(path_dataU2, path_processeddata,writexlsx=writexlsx)
# Set the name attribute for each dataframe
U2_G2301_gps.name = 'G2301'
U2_aeris_gps.name = 'Aeris'
#%%% Find peaks
if writexlsx:
writer = pd.ExcelWriter(path_processeddata /"U2_CH4peaks.xlsx", engine = 'xlsxwriter')
else:
writer = None
U2_G2301_peaks = process_peak_data(U2_G2301_gps, 'G23', height=HEIGHT, distance=DIST_G23, width=WIDTH_G23,
overviewplot=overviewplot, savepath = path_fig /'U2_overviewplot_G2301')
U2_aeris_peaks = process_peak_data(U2_aeris_gps, 'aeris', height=HEIGHT, distance=DIST_AERIS, width=WIDTH_AERIS,
overviewplot=overviewplot, savepath = path_fig /'U2_overviewplot_Aeris')
if writexlsx:
U2_G2301_peaks.to_excel(writer, sheet_name='G2301')
U2_aeris_peaks.to_excel(writer, sheet_name='Aeris')
writer.book.close()
#
fig, ax1 = plt.subplots(figsize=(18,10))
ax2 = ax1.twinx()
ax1.plot(U2_G2301_gps.index,U2_G2301_gps['CH4_ele_G23'], alpha=1, label='G2301', linewidth=2, color=dict_color_instr['G2301'])
ax1.plot(U2_aeris_gps.index,U2_aeris_gps['CH4_ele_aeris'], alpha=1, label='Aeris', linewidth=2, color=dict_color_instr['Aeris'])
ax1.scatter(U2_G2301_peaks.index,U2_G2301_peaks['CH4_ele_G23'], alpha=1, label='Peaks G2301', color='red')
ax1.scatter(U2_aeris_peaks.index,U2_aeris_peaks['CH4_ele_aeris'], alpha=1, label='Peaks Aeris', color='red')
ax2.scatter(U2_G2301_gps.index,U2_G2301_gps['Speed [m/s]'], alpha=.2, label='Speed m/s', color='orange')
ax3 = ax1.twinx() # Create the third y-axis, sharing the same x-axis
ax3.spines["right"].set_position(("outward", 60)) # Offset the third y-axis to avoid overlap
ax3.plot(U2_G2301_gps.index,U2_G2301_gps['Latitude'], alpha=.8, label='Latitude', color='lightgrey')
ax3.set_ylim(52.085,52.12)
plt.gca().xaxis.set_major_formatter(dates.DateFormatter('%H:%M:%S'))
ax1.legend()
plt.title('Utrecht II')
#%%% Peak Plots
# Define other necessary variables
coord_extent = [5.1633, 5.166, 52.0873, 52.0888]
release_loc1 = (5.164652777777778, 52.0874472)
release_loc1_2 = (5.16506388888889, 52.0875333)
release_loc2 = (5.164452777777778, 52.0885333)
column_names = {'G2301': 'CH4_ele_G23', 'Aeris': 'CH4_ele_aeris'}
# create the folder if it does not exist
if not (path_fig / 'U2_Peakplots').is_dir():
(path_fig / 'U2_Peakplots').mkdir(parents=True)
path_save = path_fig / 'U2_Peakplots/'
# Remove rows with NaN values in column 'latitude'
gps = U2_G2301_gps.dropna(subset=['Latitude']).copy(deep=True)
# Call the function with necessary arguments
plot_indivpeaks_bevorQC(U2_G2301_peaks, gps, path_save, coord_extent, release_loc1_2, release_loc2, indiv_peak_plots, column_names, U2_G2301_gps, U2_aeris_gps)
#%%% Tests
#%%%% Check CH4 data
# CH4 + speed ------------------------------------------------------------------
fig,ax = plt.subplots()
ax2 = ax.twinx()
ax2.plot(U2_G2301_gps.index,U2_G2301_gps['Speed [m/s]'],alpha=0.2,color='grey', label='Speed')
ax.plot(U2_G2301_gps.index,U2_G2301_gps['CH4_ele_G23'], label='G2301')
#ax.plot(U2_aeris_gps.index,U2_aeris_gps['CH4_ele_aeris'], label='Mira Ultra Aeris')
plt.xlabel('time')
ax.set_ylabel('CH4 elevation')
ax2.set_ylabel('Speed [m/s]')
plt.title('Utrecht II')
plt.legend()
# # CH4 + latitude ------------------------------------------------------------------
# fig,ax = plt.subplots()
# ax2 = ax.twinx()
# ax2.plot(U2_G2301_gps.index,U2_G2301_gps['Latitude'],alpha=0.2,color='grey', label='lat')
# ax.plot(U2_G2301_gps.index,U2_G2301_gps['CH4_ele_G23'], label='G2301')
# #ax.plot(U2_aeris_gps.index,U2_aeris_gps['CH4_ele_aeris'], label='Mira Ultra Aeris')
# ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S'))
# ax2.set_ylim(52.085,52.138)
# plt.xlabel('time')
# ax.set_ylabel('CH4 elevation')
# ax2.set_ylabel('Latitude')
# plt.title('Utrecht II - gps t5+60s')
# plt.legend()
#%%%% P 2Fig: Release rates per loc
# Loc 1 -----------------------------------------------------------------------
timestamps = {
'4 Lm a': pd.to_datetime('2024-06-11 10:48:00'),
'0 Lm a': pd.to_datetime('2024-06-11 11:22:00'),
'2.4 Lm': pd.to_datetime('2024-06-11 11:38:00'),
'10 Lm': pd.to_datetime('2024-06-11 11:48:00'),
'80 Lm': pd.to_datetime('2024-06-11 12:18:00'),
'20 Lm': pd.to_datetime('2024-06-11 12:32:00'),
'lunch': pd.to_datetime('2024-06-11 13:01:00'),
'100 Lm': pd.to_datetime('2024-06-11 14:05:00'),
'40 Lm': pd.to_datetime('2024-06-11 14:21:00'),
'0 Lm b': pd.to_datetime('2024-06-11 14:23:00'),
'15 Lm': pd.to_datetime('2024-06-11 14:28:00'),
'0 Lm c': pd.to_datetime('2024-06-11 15:23:00'),
'4 Lm b': pd.to_datetime('2024-06-11 16:19:00'),
'0.15 Lm': pd.to_datetime('2024-06-11 17:07:00'),
'1 Lm': pd.to_datetime('2024-06-11 17:44:00'),
'end': pd.to_datetime('2024-06-11 17:56:00')
}
# Define colors for each segment
colors = ['#ffcccc', '#8c8c8c', '#ccccff', '#ffffcc', '#ffccff', '#ccffff', '#8c8c8c', '#ffd6ff', '#ff9f1c' , '#8c8c8c', '#c8b6ff', '#8c8c8c', '#80ffdb', '#bbd0ff', '#e7c6ff' ]
# Create the plot
fig, ax = plt.subplots(figsize=(18,10))
ax2 = ax.twinx()
# Plot the data
ax2.plot(U2_G2301_gps.index, U2_G2301_gps['Speed [m/s]'], alpha=0.2, color='grey', label='Speed')
ax.plot(U2_G2301_gps.index, U2_G2301_gps['CH4_ele_G23'], label='G2301')
ax.plot(U2_aeris_gps.index, U2_aeris_gps['CH4_ele_aeris'], label='Mira Ultra Aeris')
# Set labels and title
plt.xlabel('Time')
ax.set_ylabel('CH4 Elevation')
ax2.set_ylabel('Speed [m/s]')
plt.title('release rates at Loc 1')
# Add background colors for segments
segments = list(timestamps.keys())
for i in range(len(segments) - 1):
start = timestamps[segments[i]]
print(start)
end = timestamps[segments[i + 1]]
color = colors[i % len(colors)]
ax.axvspan(start, end, color=color, alpha=0.3, label=segments[i])
# Create custom legend
handles, labels = ax.get_legend_handles_labels()
segment_handles = [plt.Line2D([0], [0], color=color, lw=4, alpha=0.3) for color in colors[:len(segments) - 1]]
segment_labels = segments[:-1]
plt.legend(handles, labels, loc='upper left', bbox_to_anchor=(1.1, 1))
# Show the plot
plt.tight_layout()
plt.show()
# fig.savefig(path_fig+f'U2_timeseries_rR_loc1.pdf',bbox_inches='tight')
# fig.savefig(path_fig+f'U2_timeseries_rR_loc1.png',bbox_inches='tight')
# Loc 2 -----------------------------------------------------------------------
timestamps = {
'2.4 Lm a' : pd.to_datetime('2024-06-11 10:50:00'),
'2.5 Lm' : pd.to_datetime('2024-06-11 11:10:00'),
'2.6 Lm' : pd.to_datetime('2024-06-11 11:29:00'),
'4 Lm' : pd.to_datetime('2024-06-11 11:31:00'),
'0.5 Lm' : pd.to_datetime('2024-06-11 12:09:00'),
'0.15 Lm' : pd.to_datetime('2024-06-11 12:37:00'),
'lunch' : pd.to_datetime('2024-06-11 13:01:00'),
'0.3 Lm' : pd.to_datetime('2024-06-11 14:02:00'),
'2 Lm' : pd.to_datetime('2024-06-11 14:40:00'),
'1 Lm' : pd.to_datetime('2024-06-11 15:13:00'),
'0 Lm' : pd.to_datetime('2024-06-11 15:52:00'),
'2.4 Lm b' : pd.to_datetime('2024-06-11 17:00:00'),
'60 Lm' : pd.to_datetime('2024-06-11 17:30:00'),
'20 Lm' : pd.to_datetime('2024-06-11 17:38:00'),
'80 Lm' : pd.to_datetime('2024-06-11 18:06:00'),
'end' : pd.to_datetime('2024-06-11 18:25:00')
}
# Define colors for each segment
colors = ['#ffcccc', '#f72585', '#ccccff', '#ffffcc', '#ffccff', '#ccffff', '#8c8c8c', '#ffd6ff', '#ff9f1c' , '#c8b6ff', '#8c8c8c', '#00a6fb','#bbd0ff', '#80ffdb', '#e7c6ff' ]
# Create the plot
fig, ax = plt.subplots(figsize=(18,10))
ax2 = ax.twinx()
# Plot the data
ax2.plot(U2_G2301_gps.index, U2_G2301_gps['Speed [m/s]'], alpha=0.2, color='grey', label='Speed')
ax.plot(U2_G2301_gps.index, U2_G2301_gps['CH4_ele_G23'], label='G2301')
ax.plot(U2_aeris_gps.index, U2_aeris_gps['CH4_ele_aeris'], label='Mira Ultra Aeris')
# Set labels and title
plt.xlabel('Time')
ax.set_ylabel('CH4 Elevation')
ax2.set_ylabel('Speed [m/s]')
plt.title('release rates at Loc 2')
# Add background colors for segments
segments = list(timestamps.keys())
for i in range(len(segments) - 1):
start = timestamps[segments[i]]
print(start)
end = timestamps[segments[i + 1]]
color = colors[i % len(colors)]
ax.axvspan(start, end, color=color, alpha=0.3, label=segments[i])
# Create custom legend
handles, labels = ax.get_legend_handles_labels()
segment_handles = [plt.Line2D([0], [0], color=color, lw=4, alpha=0.3) for color in colors[:len(segments) - 1]]
segment_labels = segments[:-1]
plt.legend(handles, labels, loc='upper left', bbox_to_anchor=(1.1, 1))
# Show the plot
plt.tight_layout()
plt.show()
# fig.savefig(path_fig+f'U2_timeseries_rR_loc2.pdf',bbox_inches='tight')
# fig.savefig(path_fig+f'U2_timeseries_rR_loc2.png',bbox_inches='tight')
#%%%% P 1Fig: Release rates per loc
timestamps1 = {
'4 Lm a': pd.to_datetime('2024-06-11 10:48:00'), #ffcccc
'0 Lm a': pd.to_datetime('2024-06-11 11:22:00'), #8c8c8c
'2.4 Lm': pd.to_datetime('2024-06-11 11:38:00'), #ccccff
'10 Lm': pd.to_datetime('2024-06-11 11:48:00'), #ffffcc
'80 Lm': pd.to_datetime('2024-06-11 12:18:00'), #ffccff
'20 Lm': pd.to_datetime('2024-06-11 12:32:00'), #ccffff
'lunch': pd.to_datetime('2024-06-11 13:01:00'), #8c8c8c
'100 Lm': pd.to_datetime('2024-06-11 14:05:00'), #ffd6ff
'40 Lm': pd.to_datetime('2024-06-11 14:21:00'), #ff9f1c
'0 Lm b': pd.to_datetime('2024-06-11 14:23:00'), #8c8c8c
'15 Lm': pd.to_datetime('2024-06-11 14:28:00'), #c8b6ff
'0 Lm c': pd.to_datetime('2024-06-11 15:23:00'), #8c8c8c
'4 Lm b': pd.to_datetime('2024-06-11 16:19:00'), #ffcccc
'0.15 Lm': pd.to_datetime('2024-06-11 17:07:00'),#bbd0ff
'1 Lm': pd.to_datetime('2024-06-11 17:44:00'), #e7c6ff
'end': pd.to_datetime('2024-06-11 17:56:00') #
}
timestamps2 = {
'2.4 Lm a' : pd.to_datetime('2024-06-11 10:50:00'), #ccccff
'2.5 Lm' : pd.to_datetime('2024-06-11 11:10:00'), #f72585
'2.6 Lm' : pd.to_datetime('2024-06-11 11:29:00'), #ffffcc
'4 Lm' : pd.to_datetime('2024-06-11 11:31:00'), #ffcccc
'0.5 Lm' : pd.to_datetime('2024-06-11 12:09:00'), #ffccff
'0.15 Lm' : pd.to_datetime('2024-06-11 12:37:00'), #bbd0ff
'lunch' : pd.to_datetime('2024-06-11 13:01:00'),#8c8c8c
'0.3 Lm' : pd.to_datetime('2024-06-11 14:02:00'), #ffccff
'2 Lm' : pd.to_datetime('2024-06-11 14:40:00'), #ffd6ff
'1 Lm' : pd.to_datetime('2024-06-11 15:13:00'), #e7c6ff
'0 Lm' : pd.to_datetime('2024-06-11 15:52:00'), #8c8c8c
'2.4 Lm b' : pd.to_datetime('2024-06-11 17:00:00'), #ccccff
'60 Lm' : pd.to_datetime('2024-06-11 17:30:00'), #ffbf69
'20 Lm' : pd.to_datetime('2024-06-11 17:38:00'), #ccffff
'80 Lm' : pd.to_datetime('2024-06-11 18:06:00'), #7400b8
'end' : pd.to_datetime('2024-06-11 18:25:00')
}
# Define colors for each segment
colors1 = ['#ffcccc', '#8c8c8c', '#ccccff', '#ffffcc', '#ffccff', '#ccffff', '#8c8c8c', '#ffd6ff', '#ff9f1c' , '#8c8c8c', '#c8b6ff', '#8c8c8c', '#ffcccc', '#bbd0ff', '#e7c6ff' ]
colors2 = ['#ccccff', '#f72585', '#ffffcc', '#ffcccc', '#ffccff', '#bbd0ff', '#8c8c8c', '#ffccff', '#ffd6ff' , '#e7c6ff', '#8c8c8c', '#ccccff','#ffbf69', '#ccffff', '#7400b8' ]
# PLOT =======================================================================
# Create the plot
fig, (ax1,ax2) = plt.subplots(2,1,figsize=(18,10))
ax11 = ax1.twinx()
ax22 = ax2.twinx()
# Loc 1 -----------------------------------------------------------------------
# Plot the data
ax11.plot(U2_G2301_gps.index, U2_G2301_gps['Speed [m/s]'], alpha=0.2, color='grey', label='Speed')
ax1.plot(U2_G2301_gps.index, U2_G2301_gps['CH4_ele_G23'], label='G2301')
ax1.plot(U2_aeris_gps.index, U2_aeris_gps['CH4_ele_aeris'], label='Mira Ultra Aeris')
# Set labels and title
ax1.set_xlabel('Time')
ax1.set_ylabel('CH4 Elevation')
ax11.set_ylabel('Speed [m/s]')
plt.title('release rates')
# Add background colors for segments
segments1 = list(timestamps1.keys())
for i in range(len(segments1) - 1):
start = timestamps1[segments1[i]]
print(start)
end = timestamps1[segments1[i + 1]]
color = colors1[i % len(colors1)]
ax1.axvspan(start, end, color=color, alpha=0.3, label=segments1[i])
# Create custom legend
handles1, labels1 = ax1.get_legend_handles_labels()
ax1.legend(handles1, labels1, loc='upper left', bbox_to_anchor=(1.1, 1))
# Loc 2 -----------------------------------------------------------------------
# Plot the data
ax22.plot(U2_G2301_gps.index, U2_G2301_gps['Speed [m/s]'], alpha=0.2, color='grey', label='Speed')
ax2.plot(U2_G2301_gps.index, U2_G2301_gps['CH4_ele_G23'], label='G2301')
ax2.plot(U2_aeris_gps.index, U2_aeris_gps['CH4_ele_aeris'], label='Mira Ultra Aeris')
# Set labels and title
ax2.set_xlabel('Time')
ax2.set_ylabel('CH4 Elevation')
ax22.set_ylabel('Speed [m/s]')
#plt.title('release rates at Loc 2')
# Add background colors for segments
segments2 = list(timestamps2.keys())
for i in range(len(segments2) - 1):
start = timestamps2[segments2[i]]
print(start)
end = timestamps2[segments2[i + 1]]
color = colors2[i % len(colors2)]
ax2.axvspan(start, end, color=color, alpha=0.3, label=segments2[i])
# Create custom legend
handles2, labels2 = ax2.get_legend_handles_labels()
# segment_handles = [plt.Line2D([0], [0], color=color, lw=4, alpha=0.3) for color in colors[:len(segments) - 1]]
# segment_labels = segments[:-1]
ax2.legend(handles2, labels2, loc='upper left', bbox_to_anchor=(1.1, 1))
# Show the plot
plt.tight_layout()
plt.show()
# fig.savefig(path_fig+f'U2_timeseries_rR_bothlocs.pdf',bbox_inches='tight')
# fig.savefig(path_fig+f'U2_timeseries_rR_bothlocs.png',bbox_inches='tight')
#%%%% Plots Check GPS
df_phone1_1 = gpx_to_df(path_dataU2 /'GPS/Phone1/20240611-1057_1200_Phone1_1.gpx')
df_phone1_2 = gpx_to_df(path_dataU2 /'GPS/Phone1/20240611-1201_1304_Phone1_2.gpx')
df_phone1_3 = gpx_to_df(path_dataU2 /'GPS/Phone1/20240611-1352_1426_Phone1_3.gpx')
df_phone1_4 = gpx_to_df(path_dataU2 /'GPS/Phone1/20240611-1426_1558_Phone1_4.gpx')
df_phone1_5 = gpx_to_df(path_dataU2 /'GPS/Phone1/20240611-1620_1816_Phone1_5.gpx')
gps_phone2 = gpx_to_df(path_dataU2 /'GPS/Phone2/20240611-1620_1844_Phone2_final.gpx')
df_phone1_1.index = df_phone1_1.index.tz_convert(None)
df_phone1_2.index = df_phone1_2.index.tz_convert(None)
df_phone1_3.index = df_phone1_3.index.tz_convert(None)
df_phone1_4.index = df_phone1_4.index.tz_convert(None)
df_phone1_5.index = df_phone1_5.index.tz_convert(None)
gps_phone2.index = gps_phone2.index.tz_convert(None)
# Time Periode 1 ----------------------
fig,ax = plt.subplots()
plt.plot(df_phone1_1.index,df_phone1_1['speed'], label='phone 1')
plt.xlabel('time')
plt.ylabel('latitude')
plt.title('Time Periode 1')
plt.legend()
# Time Periode 2 ----------------------
fig,ax = plt.subplots()
plt.scatter(df_phone1_2.index,df_phone1_2['latitude'], label='phone 1')
plt.xlabel('time')
plt.ylabel('latitude')
plt.title('Time Periode 2')
plt.legend()
# Time Periode 3 ----------------------
fig,ax = plt.subplots()
plt.plot(df_phone1_3.index,df_phone1_3['latitude'], label='phone 1')
plt.xlabel('time')
plt.ylabel('latitude')
plt.title('Time Periode 3')
plt.legend()
# Time Periode 4 ----------------------
fig,ax = plt.subplots()
plt.plot(df_phone1_4.index,df_phone1_4['latitude'], label='phone 1')
plt.xlabel('time')
plt.ylabel('latitude')
plt.title('Time Periode 4')
plt.legend()
# Time Periode 5 ----------------------
fig,ax = plt.subplots()
#plt.plot(df_phone1_5.index,df_phone1_5['latitude'], label='phone 1')
plt.scatter(gps_phone2.index,gps_phone2['latitude'], label='phone 2')
plt.xlabel('time')
plt.ylabel('latitude')
plt.title('Time Periode 5')
plt.legend()
fig,ax = plt.subplots()
plt.plot(df_phone1_5.index,df_phone1_5['longitude'], label='phone 1')
plt.plot(gps_phone2.index,gps_phone2['longitude'], label='phone 2')
plt.xlabel('time')
plt.ylabel('longitude')
plt.title('Time Periode 5')
plt.legend()
fig,ax = plt.subplots()
plt.plot(df_phone1_5.index,df_phone1_5['speed'], label='phone 1')
plt.plot(gps_phone2.index,gps_phone2['speed'], label='phone 2')
plt.xlabel('time')
plt.ylabel('speed [m/s]')
plt.title('Time Periode 5')
plt.legend()
#%%% Overview peak locations
U2_G2301_gps,U2_aeris_gps = read_and_preprocess_U2_no_shift(path_dataU2, path_processeddata,writexlsx=True)
# Set the name attribute for each dataframe
U2_G2301_gps.name = 'G2301'
U2_G2301_peaks = process_peak_data_new(U2_G2301_gps, 'G23', height=HEIGHT, distance=DIST_G23, width=WIDTH_G23,
overviewplot=overviewplot, savepath = path_fig /'U2_overviewplot_G2301')
#%%%% G2301
# Remove rows with NaN values in column 'latitude'
gps = U2_G2301_peaks.dropna(subset=['Latitude']).copy(deep=True)
# Plot location of all peaks in one plot
peak_loc_all = []
for index, row in U2_G2301_peaks.iterrows():
time = pd.to_datetime(index)#.round('1s')
#if time in gps.index:
lon = U2_G2301_gps.loc[time]['Longitude']
lat = U2_G2301_gps.loc[time]['Latitude']
coords = (lon,lat)
peak_loc = coords
peak_loc_all.append(peak_loc)
tilemapbase.start_logging()
tilemapbase.init(create=True)
t = tilemapbase.tiles.build_OSM()
extent = tilemapbase.Extent.from_lonlat(
5.1633, 5.166, 52.0873, 52.0888) #5.1633, 5.16587, 52.0873, 52.0888
extent = extent.to_aspect(1.0)
plotter = tilemapbase.Plotter(extent, t, width=600)
fig, ax1 = plt.subplots(figsize = (12,12))
#ax1.xaxis.set_visible(False)
#ax1.yaxis.set_visible(False)
plotter.plot(ax1, t)
# Loop over the list of tuples and unpack latitude and longitude values
for lat, lon in peak_loc_all:
x, y = tilemapbase.project(lat, lon)
#x,y = tilemapbase.project(peak_loc_all[i])
x1,y1 = tilemapbase.project(*release_loc1_2)
x2,y2 = tilemapbase.project(*release_loc2)
ax1.scatter(x,y, marker = "x", color = 'red' ,s = 30, alpha=0.7)
ax1.scatter(x1,y1, marker = "x", color = 'black' ,s = 30)
ax1.scatter(x2,y2, marker = "x", color = 'black' ,s = 30)
#plt.savefig(path_fig/"U2_Peakplots/Overview_Peak_Locations_G4.jpg")
#%%%% t4 shift
# t_1 = '2024-06-11 10:57:00':'2024-06-11 12:01:00'
# t_2 = '2024-06-11 12:01:00':'2024-06-11 13:04:00'
# t_3 = '2024-06-11 13:52:00':'2024-06-11 14:26:00'
# t_4 = '2024-06-11 14:31:00':'2024-06-11 15:58:00' 1431-1558
# t_5 = '2024-06-11 16:20:00':'2024-06-11 18:44:00'
# t4_1 1431-1440 = '2024-06-11 14:31:00':'2024-06-11 14:40:00' #before 14:31 car standing, loc1 15slpm-loc2 0_3slpm
# t4_2 1440-1513 = '2024-06-11 14:40:00':'2024-06-11 15:13:00' # loc1 15slpm-loc2 2_2slpm
# t4_3 1513-1523 = '2024-06-11 15:13:00':'2024-06-11 15:23:00 # loc1 15slpm-loc2 1slpm
# t4_4 1523-1552 '2024-06-11 15:23:00':'2024-06-11 15:52:00'
# copy dfs
U2_G2301_peaks_test = U2_G2301_peaks['2024-06-11 14:31:00':'2024-06-11 15:58:00'].copy()
U2_G2301_peaks_test.index = pd.to_datetime(U2_G2301_peaks_test.index)
U2_G2301_gps_test = U2_G2301_gps.copy()
# shift gps -> optimal 22 = 66 s
shift = 0 #22
U2_G2301_gps_test['Longitude_shift'] = np.roll(U2_G2301_gps_test.Longitude, shift)
U2_G2301_gps_test['Latitude_shift'] = np.roll(U2_G2301_gps_test.Latitude, shift)
title_descr=f't4 1431-1558 - shift gps by {shift*3} s'
# Prepare your data
peak_loc_all = []
for index, row in U2_G2301_peaks_test.iterrows(): #['2024-06-11 16:20:00':'2024-06-11 18:44:00']
time = pd.to_datetime(index)
lon = U2_G2301_gps_test.loc[time]['Longitude_shift']
lat = U2_G2301_gps_test.loc[time]['Latitude_shift']
ch4_value = row['CH4_ele_G23']
peak_loc_all.append((time, lon, lat, ch4_value))
# Convert times to Unix timestamps
times = [x[0].timestamp() for x in peak_loc_all]
norm = mcolors.Normalize(vmin=min(times), vmax=max(times))
cmap = cm.get_cmap('rainbow')
# Create a colormap
colors = [cmap(norm(time)) for time in times]
# Normalize CH4_ele_G23 values for marker sizes
ch4_values = [x[3] for x in peak_loc_all]
size_norm = mcolors.Normalize(vmin=min(ch4_values), vmax=max(ch4_values))
sizes = [size_norm(ch4) * 800 for ch4 in ch4_values] # Scale size for better visibility
# Initialize tilemapbase
tilemapbase.start_logging()
tilemapbase.init(create=True)
t = tilemapbase.tiles.build_OSM()
extent = tilemapbase.Extent.from_lonlat(5.1633, 5.166, 52.0873, 52.0888).to_aspect(1.0)
plotter = tilemapbase.Plotter(extent, t, width=600)
fig, ax1 = plt.subplots(figsize=(12, 12))
plotter.plot(ax1, t)
# Plot the points with the colormap
for (time, lat, lon, ch4_value), color, size in zip(peak_loc_all, colors, sizes):
x, y = tilemapbase.project(lat, lon)
ax1.scatter(x, y, marker="o", color=color,s=size, alpha=0.7, edgecolor='black')
# Add release locations
x1, y1 = tilemapbase.project(*release_loc1_2)
x2, y2 = tilemapbase.project(*release_loc2)
x3,y3 = tilemapbase.project(*release_loc1)
ax1.scatter(x1, y1, marker="x", color='black', s=100)
ax1.scatter(x2, y2, marker="x", color='black', s=100)
ax1.scatter(x3,y3, marker = "x", color = 'black' ,s = 100)
# Create ScalarMappable for colorbar
sm = cm.ScalarMappable(cmap=cmap, norm=norm)
sm.set_array([]) # Only needed for matplotlib < 3.1
# Add the colorbar with custom formatter
cbar = plt.colorbar(sm, ax=ax1)
# Set the formatter for colorbar
cbar.ax.yaxis.set_major_formatter(FuncFormatter(time_ticks))
cbar.set_label('Time (HH:MM)')
plt.title(f'Utrecht II - {title_descr} - G2301',fontsize=18)
plt.savefig(path_fig/ f'Test_GPS_shift/Overview_peaklocations_{title_descr}.pdf',bbox_inches='tight')
# plt.savefig(path_fig/ f'Test Peak Loc/Shift GPS/Overview_peaklocations_{title_descr}.svg',bbox_inches='tight')
#%%%% t3 shift
# t_1 = '2024-06-11 10:57:00':'2024-06-11 12:01:00'
# t_2 = '2024-06-11 12:01:00':'2024-06-11 13:04:00'
# t_3 = '2024-06-11 13:52:00':'2024-06-11 14:26:00'
# t_4 = '2024-06-11 14:31:00':'2024-06-11 15:58:00' 1431-1558
# t_5 = '2024-06-11 16:20:00':'2024-06-11 18:44:00'
# t3 1402-1423
# t3_1 1402-1421 = '2024-06-11 14:02:00':'2024-06-11 14:21:00' # loc1 100slpm-loc2 0_3slpm
# t3_2 1421-1423 = '2024-06-11 14:21:00':'2024-06-11 14:23:00' # loc1 40slpm-loc2 0_3slpm
# copy dfs
U2_G2301_peaks_test = U2_G2301_peaks['2024-06-11 14:02:00':'2024-06-11 14:23:00'].copy()
U2_G2301_peaks_test.index = pd.to_datetime(U2_G2301_peaks_test.index)
U2_G2301_gps_test = U2_G2301_gps.copy()
# shift gps -> optimal: 39
shift = 39
#U2_G2301_peaks_test.index = U2_G2301_peaks_test.index + pd.Timedelta(seconds=shift)
#U2_G2301_gps_test.index = U2_G2301_gps_test.index + pd.Timedelta(seconds=shift)
U2_G2301_gps_test['Longitude_shift'] = np.roll(U2_G2301_gps_test.Longitude, shift)
U2_G2301_gps_test['Latitude_shift'] = np.roll(U2_G2301_gps_test.Latitude, shift)
title_descr=f't3 1402-1423 - shift gps by {shift*3} s'
# Prepare your data
peak_loc_all = []
for index, row in U2_G2301_peaks_test.iterrows(): #['2024-06-11 16:20:00':'2024-06-11 18:44:00']
time = pd.to_datetime(index)
lon = U2_G2301_gps_test.loc[time]['Longitude_shift']
lat = U2_G2301_gps_test.loc[time]['Latitude_shift']
ch4_value = row['CH4_ele_G23']
peak_loc_all.append((time, lon, lat, ch4_value))
# Convert times to Unix timestamps
times = [x[0].timestamp() for x in peak_loc_all]
norm = mcolors.Normalize(vmin=min(times), vmax=max(times))
cmap = cm.get_cmap('rainbow')
# Create a colormap
colors = [cmap(norm(time)) for time in times]
# Normalize CH4_ele_G23 values for marker sizes
ch4_values = [x[3] for x in peak_loc_all]
size_norm = mcolors.Normalize(vmin=min(ch4_values), vmax=max(ch4_values))
sizes = [size_norm(ch4) * 800 for ch4 in ch4_values] # Scale size for better visibility
# Initialize tilemapbase
tilemapbase.start_logging()
tilemapbase.init(create=True)
t = tilemapbase.tiles.build_OSM()
extent = tilemapbase.Extent.from_lonlat(5.1633, 5.166, 52.0873, 52.0888).to_aspect(1.0)
plotter = tilemapbase.Plotter(extent, t, width=600)
fig, ax1 = plt.subplots(figsize=(12, 12))
plotter.plot(ax1, t)
# Plot the points with the colormap
for (time, lat, lon, ch4_value), color, size in zip(peak_loc_all, colors, sizes):
x, y = tilemapbase.project(lat, lon)
ax1.scatter(x, y, marker="o", color=color,s=size, alpha=0.7, edgecolor='black')
# Add release locations
x1, y1 = tilemapbase.project(*release_loc1_2)
x2, y2 = tilemapbase.project(*release_loc2)
x3,y3 = tilemapbase.project(*release_loc1)
ax1.scatter(x1, y1, marker="x", color='black', s=100)
ax1.scatter(x2, y2, marker="x", color='black', s=100)
ax1.scatter(x3,y3, marker = "x", color = 'black' ,s = 100)
# Create ScalarMappable for colorbar
sm = cm.ScalarMappable(cmap=cmap, norm=norm)
sm.set_array([]) # Only needed for matplotlib < 3.1
# Add the colorbar with custom formatter
cbar = plt.colorbar(sm, ax=ax1)
# Set the formatter for colorbar
cbar.ax.yaxis.set_major_formatter(FuncFormatter(time_ticks))
cbar.set_label('Time (HH:MM)')
plt.title(f'Utrecht II - {title_descr} - G2301',fontsize=18)
plt.savefig(path_fig/ f'Test_GPS_shift/Overview_peaklocations_{title_descr}.pdf',bbox_inches='tight')
# plt.savefig(path_fig/ f'Test Peak Loc/Shift GPS/Overview_peaklocations_{title_descr}.svg',bbox_inches='tight')
#%%%% t2 shift
# t1 = '2024-06-11 10:57:00':'2024-06-11 12:01:00'
# t2 1201-1304
# t2 = '2024-06-11 12:01:00':'2024-06-11 13:04:00'
# t3 = '2024-06-11 13:52:00':'2024-06-11 14:26:00'
# t4 = '2024-06-11 14:31:00':'2024-06-11 15:58:00' 1431-1558
# t5 = '2024-06-11 16:20:00':'2024-06-11 18:44:00'
# t2_1 1200-1209 = '2024-06-11 12:00:00':'2024-06-11 12:09:00' # loc1 10slpm-loc2 4slpm
# t2_2 1209-1218 = '2024-06-11 12:09:00':'2024-06-11 12:18:00' # loc1 10slpm-loc2 0_5slpm
# t2_3 1218-1232 = '2024-06-11 12:18:00':'2024-06-11 12:32:00' # loc1 80slpm-loc2 0_5slpm
# t2_4 1232-1250 = '2024-06-11 12:32:00':'2024-06-11 12:50:00' # loc1 20slpm-loc2 0_5and0_15slpm
# copy dfs
U2_G2301_peaks_test = U2_G2301_peaks['2024-06-11 12:09:00':'2024-06-11 12:50:00'].copy()
U2_G2301_peaks_test.index = pd.to_datetime(U2_G2301_peaks_test.index)
U2_G2301_gps_test = U2_G2301_gps.copy()
# shift gps
shift = 20
#U2_G2301_peaks_test.index = U2_G2301_peaks_test.index + pd.Timedelta(seconds=shift)
#U2_G2301_gps_test.index = U2_G2301_gps_test.index + pd.Timedelta(seconds=shift)
U2_G2301_gps_test['Longitude_shift'] = np.roll(U2_G2301_gps_test.Longitude, shift)
U2_G2301_gps_test['Latitude_shift'] = np.roll(U2_G2301_gps_test.Latitude, shift)
title_descr=f't2 1209-1250 - shift gps by {shift*3} s'
# Prepare your data
peak_loc_all = []
for index, row in U2_G2301_peaks_test.iterrows(): #['2024-06-11 16:20:00':'2024-06-11 18:44:00']
time = pd.to_datetime(index)
lon = U2_G2301_gps_test.loc[time]['Longitude_shift']
lat = U2_G2301_gps_test.loc[time]['Latitude_shift']
ch4_value = row['CH4_ele_G23']
peak_loc_all.append((time, lon, lat, ch4_value))
# Convert times to Unix timestamps
times = [x[0].timestamp() for x in peak_loc_all]
norm = mcolors.Normalize(vmin=min(times), vmax=max(times))
cmap = cm.get_cmap('rainbow')
# Create a colormap
colors = [cmap(norm(time)) for time in times]
# Normalize CH4_ele_G23 values for marker sizes
ch4_values = [x[3] for x in peak_loc_all]
size_norm = mcolors.Normalize(vmin=min(ch4_values), vmax=max(ch4_values))
sizes = [size_norm(ch4) * 800 for ch4 in ch4_values] # Scale size for better visibility
# Initialize tilemapbase
tilemapbase.start_logging()
tilemapbase.init(create=True)
t = tilemapbase.tiles.build_OSM()
extent = tilemapbase.Extent.from_lonlat(5.1633, 5.166, 52.0873, 52.0888).to_aspect(1.0)
plotter = tilemapbase.Plotter(extent, t, width=600)
fig, ax1 = plt.subplots(figsize=(12, 12))
plotter.plot(ax1, t)
# Plot the points with the colormap
for (time, lat, lon, ch4_value), color, size in zip(peak_loc_all, colors, sizes):
x, y = tilemapbase.project(lat, lon)
ax1.scatter(x, y, marker="o", color=color,s=size, alpha=0.7, edgecolor='black')
# Add release locations
x1, y1 = tilemapbase.project(*release_loc1_2)
x2, y2 = tilemapbase.project(*release_loc2)
x3,y3 = tilemapbase.project(*release_loc1)
ax1.scatter(x1, y1, marker="x", color='black', s=100)
ax1.scatter(x2, y2, marker="x", color='black', s=100)
ax1.scatter(x3,y3, marker = "x", color = 'black' ,s = 100)
# Create ScalarMappable for colorbar
sm = cm.ScalarMappable(cmap=cmap, norm=norm)
sm.set_array([]) # Only needed for matplotlib < 3.1
# Add the colorbar with custom formatter
cbar = plt.colorbar(sm, ax=ax1)
# Set the formatter for colorbar
cbar.ax.yaxis.set_major_formatter(FuncFormatter(time_ticks))
cbar.set_label('Time (HH:MM)')
plt.title(f'Utrecht II - {title_descr} - G2301',fontsize=18)
plt.savefig(path_fig/ f'Test_GPS_shift/Overview_peaklocations_{title_descr}.pdf',bbox_inches='tight')
# plt.savefig(path_fig/ f'Test Peak Loc/Shift GPS/Overview_peaklocations_{title_descr}.svg',bbox_inches='tight')
#%%%% t1 shift
# t1 1059-1201
# t1 = '2024-06-11 10:57:00':'2024-06-11 12:01:00'
# t2 = '2024-06-11 12:01:00':'2024-06-11 13:04:00'
# t3 = '2024-06-11 13:52:00':'2024-06-11 14:26:00'
# t4 = '2024-06-11 14:31:00':'2024-06-11 15:58:00' 1431-1558
# t5 = '2024-06-11 16:20:00':'2024-06-11 18:44:00'
# t1_1 1058-1122 = '2024-06-11 10:58:00':'2024-06-11 11:22:00' #loc1 4slpm-loc2 2_5slpm
# t1_2 1122-1130 = '2024-06-11 11:22:00':'2024-06-11 11:30:00' # only loc2 2_5slpm
# t1_3 1131-1138 = '2024-06-11 11:31:00':'2024-06-11 11:38:00' # only loc2 4slpm
# t1_4 1138-1148 = '2024-06-11 11:38:00':'2024-06-11 11:48:00' # loc1 4slpm-loc2 4slpm
# t1_5 1148-1200 = '2024-06-11 11:48:00':'2024-06-11 12:00:00' # loc1 10slpm-loc2 4slpm
# copy dfs
U2_G2301_peaks_test = U2_G2301_peaks['2024-06-11 11:22:00':'2024-06-11 11:30:00'].copy()
U2_G2301_peaks_test.index = pd.to_datetime(U2_G2301_peaks_test.index)
U2_G2301_gps_test = U2_G2301_gps.copy()
# shift gps
shift = 20 # change shift here
U2_G2301_gps_test['Longitude_shift'] = np.roll(U2_G2301_gps_test.Longitude, shift)
U2_G2301_gps_test['Latitude_shift'] = np.roll(U2_G2301_gps_test.Latitude, shift)
title_descr=f't1_2 1122-1130 - shift gps by {shift*3} s' # change description to match timeperiode you inserted
# Prepare your data
peak_loc_all = []
for index, row in U2_G2301_peaks_test.iterrows(): #['2024-06-11 16:20:00':'2024-06-11 18:44:00']
time = pd.to_datetime(index)
lon = U2_G2301_gps_test.loc[time]['Longitude_shift']
lat = U2_G2301_gps_test.loc[time]['Latitude_shift']
ch4_value = row['CH4_ele_G23']
peak_loc_all.append((time, lon, lat, ch4_value))
# Convert times to Unix timestamps
times = [x[0].timestamp() for x in peak_loc_all]
norm = mcolors.Normalize(vmin=min(times), vmax=max(times))
cmap = cm.get_cmap('rainbow')
# Create a colormap
colors = [cmap(norm(time)) for time in times]
# Normalize CH4_ele_G23 values for marker sizes
ch4_values = [x[3] for x in peak_loc_all]
size_norm = mcolors.Normalize(vmin=min(ch4_values), vmax=max(ch4_values))
sizes = [size_norm(ch4) * 800 for ch4 in ch4_values] # Scale size for better visibility
# Initialize tilemapbase
tilemapbase.start_logging()
tilemapbase.init(create=True)