-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscisat.py
2424 lines (2097 loc) · 96.3 KB
/
scisat.py
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
#
# Micro-application to visualize SCISAT data.
#
# Three main charts:
# 1. Gas concentration in parts per volume (ppv) visualized on a world map
# 2. Gas concentration in parts per volume (ppv) over the selected altitude
# 3. Evolution of the gas concentration in parts per volume (ppv) over the years
#
# @source https://github.com/asc-csa/Scisat-App
# @author Emiline Filion - Canadian Space Agency
#
# Modification History:
#
#
import dash
import cartopy.feature as cf
import configparser
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import plotly.express as px
import pandas as pd
import datetime as dt
from dash.dependencies import Input, Output, State
import flask
from io import StringIO
from flask_babel import _ ,Babel
from flask import session, redirect, url_for, make_response
import urllib.parse
import dash_table as dst
from dash_table.Format import Format, Scheme
from scipy.io import netcdf #### <--- This is the library to import data
import numpy as np
from os import path
import os.path
class CustomDash(dash.Dash):
analytics_code = ''
analytics_footer = ''
lang = ''
header = ''
footer = ''
meta_html = ''
app_header = ''
app_footer = ''
def set_analytics(self, code):
self.analytics_code = code
def set_analytics_footer(self, code):
self.analytics_footer = code
def set_lang(self, lang):
self.lang = lang
def set_header(self, header):
self.header = header
def set_footer(self, footer):
self.footer = footer
def set_meta_tags(self, meta_html):
self.meta_html = meta_html
def set_app_header(self, header):
self.app_header = header
def set_app_footer(self, footer):
self.app_footer = footer
def interpolate_index(self, **kwargs):
# Inspect the arguments by printing them
return '''
<!DOCTYPE html>
<html lang='{lang}'>
<head>
{metas}
{meta}
{analytics}
{favicon}
<title>
{title}
</title>
<style id='dash_components_css'></style>
{css}
</head>
<body id='wb-cont'>
{header}
<main property="mainContentOfPage" typeof="WebPageElement" class="container">
{app_header}
{app_entry}
{app_footer}
</main>
<div class="global-footer">
<footer id="wb-info">
{footer}
{config}
{scripts}
{renderer}
{analytics_footer}
</footer>
</div>
</body>
</html>
'''.format(
app_entry=kwargs['app_entry'],
config=kwargs['config'],
scripts=kwargs['scripts'],
renderer=kwargs['renderer'],
metas = kwargs['metas'],
favicon = kwargs['favicon'],
css = kwargs['css'],
title = kwargs['title'],
analytics = self.analytics_code,
analytics_footer = self.analytics_footer,
meta = self.meta_html,
lang = self.lang,
header = self.header,
footer = self.footer,
app_header = self.app_header,
app_footer = self.app_footer
)
#==========================================================================================
# load data and transform as needed
external_stylesheets = [
'https://canada.ca/etc/designs/canada/wet-boew/css/wet-boew.min.css',
'https://canada.ca/etc/designs/canada/wet-boew/css/theme.min.css',
'https://use.fontawesome.com/releases/v5.8.1/css/all.css'
] # Link to external CSS
external_scripts = [
'//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js',
'https://canada.ca/etc/designs/canada/wet-boew/js/wet-boew.min.js',
'https://canada.ca/etc/designs/canada/wet-boew/js/theme.min.js',
'assets/scripts.js'
]
DATA_VERSION = 'ACEFTS_L2_v5p2'
# Loads the config file
def get_config_dict():
config = configparser.RawConfigParser()
#config.read('config.cfg')
config.read('/home/ckanportal/App-Launcher/config.cfg')
DATA_VERSION = config['SCISAT']['DATA_VERSION']
print("SCISAT Data version: " + DATA_VERSION)
if not hasattr(get_config_dict, 'config_dict'):
get_config_dict.config_dict = dict(config.items('TOKENS'))
return get_config_dict.config_dict
def generate_meta_tag(name, content):
return "<meta name=\"" + name + "\" content=\"" + content + "\">"
def generate_meta_tag_with_title(name, content, title):
return "<meta name=\"" + name + "\" title=\"" + title + "\" content=\"" + content + "\">"
# Runs the application based on what executed this file.
if __name__ == '__main__':
from header_footer import gc_header_en, gc_footer_en, gc_header_fr, gc_footer_fr, app_title_en, app_title_fr, app_footer_en, app_footer_fr
from config import Config
#print ('DEBUG: SCISAT Main Block used')
if(path.exists(os.path.dirname(os.path.abspath(__file__)) + r"/analytics.py")):
from .analytics import analytics_code, analytics_footer
else:
analytics_code = '<h1>Did not load things</h1>'
analytics_footer = '<h1>Did not load things footer</h1>'
app_config = Config()
path_data=app_config.DATA_PATH
prefixe= app_config.APP_PREFIX
tokens = get_config_dict()
app = CustomDash(
__name__,
meta_tags=[{"name": "viewport", "content": "width=device-width"}],
external_stylesheets=external_stylesheets,
external_scripts=external_scripts,
# analytics = analytics_code
)
else :
from .header_footer import gc_header_en, gc_footer_en, gc_header_fr, gc_footer_fr, app_title_en, app_title_fr, app_footer_en, app_footer_fr
from .config import Config
#print ('DEBUG: SCISAT Alternate Block used')
if(path.exists(os.path.dirname(os.path.abspath(__file__)) + r"/analytics.py")):
from .analytics import analytics_code, analytics_footer
else:
analytics_code = ''
analytics_footer = ''
app_config = Config()
path_data=app_config.DATA_PATH
prefixe= app_config.APP_PREFIX
tokens = get_config_dict()
app = CustomDash(
__name__,
requests_pathname_prefix=prefixe,
meta_tags=[{"name": "viewport", "content": "width=device-width"}],
external_stylesheets=external_stylesheets,
external_scripts=external_scripts,
# analytics = analytics_code
)
meta_html = ''
if app_config.DEFAULT_LANGUAGE == 'en':
app.set_header(gc_header_en)
app.set_footer(gc_footer_en)
meta_html += generate_meta_tag(
'description',
'Explore the composition of the Earth’s atmosphere with data from the SCISAT satellite! SCISAT has been monitoring the atmospheric concentrations of ozone and 70 other gases since 2003.'
)
meta_html += generate_meta_tag('keywords', '')
meta_html += generate_meta_tag('dcterms.title', 'SCISAT : data exploration application for atmospheric composition')
meta_html += generate_meta_tag_with_title('dcterms.language', 'eng', 'ISO639-2')
meta_html += generate_meta_tag('dcterms.creator', 'Canadian Space Agency')
meta_html += generate_meta_tag('dcterms.accessRights', '2')
meta_html += generate_meta_tag('dcterms.service', 'CSA-ASC')
app.title="SCISAT : data exploration application for atmospheric composition"
app.set_app_header(app_title_en)
app.set_app_footer(app_footer_en)
else:
app.set_header(gc_header_fr)
app.set_footer(gc_footer_fr)
meta_html += generate_meta_tag(
'description',
"Explorez la composition de l’atmosphère terrestre avec les données du satellite SCISAT! SCISAT surveille les concentrations atmosphériques d'ozone et de 70 gaz supplémentaires depuis 2003."
)
meta_html += generate_meta_tag('keywords', '')
meta_html += generate_meta_tag('dcterms.title', 'SCISAT : application d’exploration des données de composition atmosphérique ')
meta_html += generate_meta_tag_with_title('dcterms.language', 'fra', 'ISO639-2')
meta_html += generate_meta_tag('dcterms.creator', 'Agence spatiale canadienne')
meta_html += generate_meta_tag('dcterms.accessRights', '2')
meta_html += generate_meta_tag('dcterms.service', 'CSA-ASC')
app.title="SCISAT : application d’exploration des données de composition atmosphérique"
app.set_app_header(app_title_fr)
app.set_app_footer(app_footer_fr)
app.set_meta_tags(meta_html)
app.set_analytics(analytics_code)
app.set_analytics_footer(analytics_footer)
app.set_lang(app_config.DEFAULT_LANGUAGE)
server = app.server
server.config['SECRET_KEY'] = tokens['secret_key'] # Setting up secret key to access flask session
babel = Babel(server) # Hook flask-babel to the app
# Loads data file based on values provided into a pandas dataframe.
def data_reader(file,path_to_files,start_date=0,end_date=0,lat_min=-90,lat_max=90,lon_min=-180,lon_max=180,alt_range=[0,150]) :
"""
Parameters
----------
file : String
Name of data file.
path_to_files : String
Path to the data files.
start_date : Datetime, optional
First day in the date range selected by user. The default is the first day of data available.
end_date : Datetime, optional
Last day in the date range selected by user. The default is the last day of data available.
lat_min : float, optional
Minimum latitude selected by user. The default is -90.
lat_max : float, optional
Maximum latitude selected by user. The default is 90.
lon_min : float, optional
Minimum longitude selected by user. The default is -180.
lon_max : float, optional
Maximum longitude selected by user. The default is 180.
alt_range : List
Range of alitutudes selected. Default is [0,150]
Returns
-------
df : DATAFRAME
Dataframe of all the gaz concentrations with columns :
Altitudes (from 0.5 to 149.5), Mean on altitude (Alt_Mean), date,
Latitude (lat) and Longitude (long)
"""
if data_reader.page_df.size != 0:
return data_reader.page_df
#print('\nDEBUG: entering data_reader()')
#start_time1 = time.time()
print("SCISAT Data version: " + DATA_VERSION)
print('data_reader() -> file: ' + file)
#print('data_reader() -> datareader path: ' + path_to_files)
if type(file)==list:
file=file[0]
gaz = file.strip().split('.')[0].strip().split('_')[3:]
if len(gaz)>1:
gaz = gaz[0]+'_'+gaz[1]
else:
gaz=gaz[0]
name=path_to_files+'/'+file
nc = netcdf.netcdf_file(name,'r')
#print('DEBUG: data_reader() - Time spent so far (#1): ' + str(time.time() - start_time1))
#Trier / définir rapido les données et les variables
fillvalue1 = -999.
months=np.copy(nc.variables['month'][:])
years = np.copy(nc.variables['year'][:])
days = np.copy(nc.variables['day'][:])
lat = np.copy(nc.variables['latitude'][:])
long =np.copy( nc.variables['longitude'][:])
alt = np.copy(nc.variables['altitude'][:])
#valeurs de concentration [ppv]
data = np.copy(nc.variables[gaz][:])
#Remplacer les données vides
data[data == fillvalue1] = np.nan
#Choisir les données dans l'intervalle de l'altitude
data = data[:,alt_range[0]:alt_range[1]]
df = pd.DataFrame(data,columns=alt[alt_range[0]:alt_range[1]])
#print('DEBUG: Number of elements in the dataframe: ' + str(df.size))
#print('DEBUG: data_reader() - Time spent so far (#2): ' + str(time.time() - start_time1))
#Trie données abérrantes
# TODO: This part takes a long time. We should optmize it. numpy.nan is too slow
#slow
df[df>1e-5]=np.nan
#slow
std=df.std()
mn=df.mean()
maxV = mn+3*std
minV = mn-3*std
# slow
df[df>maxV]=np.nan
#slow
df[df<minV]=np.nan
#print('DEBUG: data_reader() - Time spent so far (#3): ' + str(time.time() - start_time1))
#Colonne de dates
date=[]
nbDays = len(days)
#print('DEBUG: Number of days to loop: ' + str(nbDays))
date = np.array([dt.datetime(int(years[i]), int(months[i]), int(days[i])) for i in range (nbDays)])
#print('DEBUG: data_reader() - Time spent so far (#4): ' + str(time.time() - start_time1))
data_meanAlt = np.nanmean(df,1)
df['Alt_Mean'] = data_meanAlt
df['date'] = date
df['lat'] = lat
df['long'] = long
if start_date!=0 and end_date!=0 :
df=df[np.where(df['date']>start_date,True,False)]
df=df[np.where(df['date']<end_date,True,False)]
#filters the data based on min/max longitude/latitude
df=df[np.where(df['lat']>lat_min,True,False)]
df=df[np.where(df['lat']<lat_max,True,False)]
df=df[np.where(df['long']>lon_min,True,False)]
df=df[np.where(df['long']<lon_max,True,False)]
#print('DEBUG: end of data_reader() - TOTAL Time spent: ' + str(time.time() - start_time1) + '\n\n')
data_reader.page_df = df
return df
data_reader.page_df = pd.DataFrame()
# Returns a binned dataframe with the provided steps.
def databin(df, step):
"""
Create data bins of specified steps in terms of longitude and latitude.
Parameters
----------
start_date : Datetime
First day in the date range selected by user. The default is the first day of data available.
end_date : Datetime
Last day in the date range selected by user. The default is the last day of data available.
lat_min : float
Minimum value of the latitude stored as a float.
lat_max : float
Maximum value of the latitude stored as a float.
lon_min : float
Minimum value of the longitude stored as a float.
lon_max : float
Maximum value of the longitude stored as a float.
gaz_list : list
Gas name strings stored in a list (e.g. ['Ozone'])
alt_range : List
Range of altitudes
step : float
Size of bins in terms of lat/long degrees
Returns
-------
Dataframe
A dataframe contained the binned data provided in steps of specified degrees.
"""
# We create a binning map
#print('\n\nDEBUG: entering databin()')
#start_time1 = time.time()
to_bin = lambda x: np.round(x / step) * step
#print('DEBUG: databin() - Time spent so far (#1): ' + str(time.time() - start_time1))
# We map the current data into the bins
# TODO: This part takes a long time, but it looks like we already use the optimized way
df["lat"] = df['lat'].map(to_bin)
df["long"] = df['long'].map(to_bin)
# We return a mean value of all overlapping data to ensure there are no overlaps
#print('DEBUG: end of databin() - TOTAL Time spent: ' + str(time.time() - start_time1) + '\n\n')
return df.groupby(["lat", "long"]).mean().reset_index()
# Dropdown options
#======================================================================================
# Controls for webapp
gaz_name_options = [
{'label': _('Acetone'), 'value': DATA_VERSION + '_C3H6O.nc'},
{'label': _('Acetonitrite'), 'value': DATA_VERSION + '_CH3CN.nc'},
{'label': _('Acetylene'), 'value': DATA_VERSION + '_C2H2.nc'},
{'label': _('Carbon dioxide'), 'value': DATA_VERSION + '_CO2.nc'},
{'label': _('Carbon dioxide 627'), 'value': DATA_VERSION + '_CO2_627.nc'},
{'label': _('Carbon dioxide 628'), 'value': DATA_VERSION + '_CO2_628.nc'},
{'label': _('Carbon dioxide 636'), 'value': DATA_VERSION + '_CO2_636.nc'},
{'label': _('Carbon dioxide 637'), 'value': DATA_VERSION + '_CO2_637.nc'},
{'label': _('Carbon dioxide 638'), 'value': DATA_VERSION + '_CO2_638.nc'}, #9
{'label': _('Carbon monoxide'), 'value': DATA_VERSION + '_CO.nc'},
{'label': _('Carbon monoxide 27'), 'value': DATA_VERSION + '_CO_27.nc'},
{'label': _('Carbon monoxide 28'), 'value': DATA_VERSION + '_CO_28.nc'},
{'label': _('Carbon monoxide 36'), 'value': DATA_VERSION + '_CO_36.nc'},
{'label': _('Carbon monoxide 38'), 'value': DATA_VERSION + '_CO_38.nc'}, #14
{'label': _('Carbon tetrachloride'), 'value': DATA_VERSION + '_CCl4.nc'},
{'label': _('Carbon tetrafluoride'), 'value': DATA_VERSION + '_CF4.nc'},
{'label': _('Carbonyl chlorofluoride'), 'value': DATA_VERSION + '_COClF.nc'},
{'label': _('Carbonyl fluoride'), 'value': DATA_VERSION + '_COF2.nc'},
{'label': _('Carbonyl sulfide'), 'value': DATA_VERSION + '_OCS.nc'},
{'label': _('Carbonyl sulfide 623'), 'value': DATA_VERSION + '_OCS_623.nc'},
{'label': _('Carbonyl sulfide 624'), 'value': DATA_VERSION + '_OCS_624.nc'},
{'label': _('Carbonyl sulfide 632'), 'value': DATA_VERSION + '_OCS_632.nc'},
{'label': _('Chlorine monoxide'), 'value': DATA_VERSION + '_ClO.nc'},
{'label': _('Chlorine nitrate'), 'value': DATA_VERSION + '_ClONO2.nc'},
{'label': _('Chloromethane'), 'value': DATA_VERSION + '_CH3Cl.nc'}, #25
{'label': _('Dichlorodifluoromethane'), 'value': DATA_VERSION + '_CCl2F2.nc'},
{'label': _('Difluorochloromethane'), 'value': DATA_VERSION + '_CHF2Cl.nc'},
{'label': _('Dinitrogen pentaoxide'), 'value': DATA_VERSION + '_N2O5.nc'}, #28
{'label': _('Ethane'), 'value': DATA_VERSION + '_C2H6.nc'},
{'label': _('Formaldehyde'), 'value': DATA_VERSION + '_H2CO.nc'},
{'label': _('Formic acid'), 'value': DATA_VERSION + '_HCOOH.nc'}, #31
{'label': _('GLC'), 'value': DATA_VERSION + '_GLC.nc'},
{'label': _('Hydrochlorofluorocarbon 141b'), 'value': DATA_VERSION + '_HCFC141b.nc'},
{'label': _('Hydrochlorofluorocarbon 142b'), 'value': DATA_VERSION + '_HCFC142b.nc'},
{'label': _('Hydrochloric acid'), 'value': DATA_VERSION + '_HCl.nc'},
{'label': _('Hydrofluorocarbon 134a'), 'value': DATA_VERSION + '_HFC134a.nc'},
{'label': _('Hydrogen cyanide'), 'value': DATA_VERSION + '_HCN.nc'},
{'label': _('Hydrogen fluoride'), 'value': DATA_VERSION + '_HF.nc'},
{'label': _('Hydrogen peroxide'), 'value': DATA_VERSION + '_H2O2.nc'}, #39
{'label': _('Methane'), 'value': DATA_VERSION + '_CH4.nc'},
{'label': _('Methane 212'), 'value': DATA_VERSION + '_CH4_212.nc'},
{'label': _('Methane 311'), 'value': DATA_VERSION + '_CH4_311.nc'},
{'label': _('Methanol'), 'value': DATA_VERSION + '_CH3OH.nc'}, #43
{'label': _('Nitric acid'), 'value': DATA_VERSION + '_HNO3.nc'},
{'label': _('Nitric acid 156'), 'value': DATA_VERSION + '_HNO3_156.nc'},
{'label': _('Nitrogen'), 'value': DATA_VERSION + '_N2.nc'},
{'label': _('Nitrogen dioxide'), 'value': DATA_VERSION + '_NO2.nc'},
{'label': _('Nitrogen dioxide 656'), 'value': DATA_VERSION + '_NO2_656.nc'},
{'label': _('Nitrous monoxide 447'), 'value': DATA_VERSION + '_NO.nc'},
{'label': _('Nitrous oxide'), 'value': DATA_VERSION + '_N2O.nc'},
{'label': _('Nitrous oxide 447'), 'value': DATA_VERSION + '_N2O_447.nc'},
{'label': _('Nitrous oxide 448'), 'value': DATA_VERSION + '_N2O_448.nc'},
{'label': _('Nitrous oxide 456'), 'value': DATA_VERSION + '_N2O_456.nc'},
{'label': _('Nitrous oxide 546'), 'value': DATA_VERSION + '_N2O_546.nc'}, #54
{'label': _('Oxygen'), 'value': DATA_VERSION + '_O2.nc'},
{'label': _('Ozone'), 'value': DATA_VERSION + '_O3.nc'},
{'label': _('Ozone 667'), 'value': DATA_VERSION + '_O3_667.nc'},
{'label': _('Ozone 668'), 'value': DATA_VERSION + '_O3_668.nc'},
{'label': _('Ozone 676'), 'value': DATA_VERSION + '_O3_676.nc'},
{'label': _('Ozone 686'), 'value': DATA_VERSION + '_O3_686.nc'}, #60
{'label': _('Peroxynitric acid'), 'value': DATA_VERSION + '_HO2NO2.nc'},
{'label': _('Phosgene'), 'value': DATA_VERSION + '_COCl2.nc'},
{'label': _('Phosphorus'), 'value': DATA_VERSION + '_P.nc'},
{'label': _('Polyacrylonitrile'), 'value': DATA_VERSION + '_PAN.nc'}, #64
{'label': _('Sulfur dioxide'), 'value': DATA_VERSION + '_SO2.nc'},
{'label': _('Sulfur hexafluoride'), 'value': DATA_VERSION + '_SF6.nc'}, #66
{'label': _('Trichlorofluoromethane'), 'value': DATA_VERSION + '_CCl3F.nc'},
{'label': _('Trichlorotrifluoroethane'), 'value': DATA_VERSION + '_CFC113.nc'},
{'label': _('Trifluoromethane'), 'value': DATA_VERSION + '_CHF3.nc'}, #69
{'label': _('Water'), 'value': DATA_VERSION + '_H2O.nc'},
{'label': _('Water 162'), 'value': DATA_VERSION + '_H2O_162.nc'},
{'label': _('Water 171'), 'value': DATA_VERSION + '_H2O_171.nc'},
{'label': _('Water 181'), 'value': DATA_VERSION + '_H2O_181.nc'},
{'label': _('Water 182'), 'value': DATA_VERSION + '_H2O_182.nc'}, #74
# {'label': _('Temperature'), 'value': 'ACEFTS_L2_v5p0_T.nc'} #!!! Est ce qu'on la met?
]
#======================================================================================
# Create global chart template
mapbox_access_token = tokens['scisat_mapbox_token']
layout = dict(
autosize=True,
automargin=True,
margin=dict(l=30, r=30, b=20, t=40),
hovermode="closest",
plot_bgcolor="#F9F9F9",
paper_bgcolor="#F9F9F9",
legend=dict(font=dict(size=10), orientation="h"),
title="Gas concentration overview",
mapbox=dict(
style="light",
# center=dict(lon=-78.05, lat=42.54),
zoom=2,
),
transition={'duration': 500},
)
# Builds the layout for the header
def build_header():
return html.Div(
[
html.Div([], className="one column"),
html.Div(
[
html.H1(
"",
style={"margin-bottom": "10px", "margin-left": "15%"},
id="page-title"),
],
className="six columns",
id="title",
),
html.Div(
[
html.Img(
src=app.get_asset_url("csa-logo.png"),
id="csa-image",
style={
"height": "60px",
"width": "auto",
"margin": "25px",
},
alt="CSA Logo"
)
],
className="one column",
),
html.Div(
[
html.A(
html.Span("", id="learn-more-button"),
href="https://www.asc-csa.gc.ca/eng/satellites/scisat/about.asp",
id='learn-more-link',
className="btn btn-primary"
),
html.A(
html.Span('FR', id='language-button'),
href='/scisat/language/fr',
id='language-link',
className="btn btn-primary"
),
],
className="four columns",
id="button-div",
style={"display": "flex", "justify-content": "space-around"}
),
],
id="header",
className="row flex-display",
style={"margin-bottom": "25px"},
)
# Builds the layout and components for the inputs to filter the data
def build_filtering():
return html.Div([
html.Div(
[
html.Div(
[
html.H2(id="filtering_text"),
html.P(id="data-ratio"),
html.P(id='placeholder')
],
id="info-container",
className="mini_container three columns",
style={"text-align": "center"},
),
html.Div(
[
html.Div(
[
dcc.Markdown(id="description-1"),
dcc.Markdown(id="description-2"),
dcc.Markdown(id="description-3"),
dcc.Markdown(id="description-4"),
html.P(
html.A(
id="github-link",
href = "https://github.com/asc-csa",
title = "ASC-CSA Github"
)
)
],
id="description_div",
),
],
id="description-container",
className="container-display mini_container nine columns",
),
],
className="row flex-display twelve columns"
),
html.Div(
[
html.H3(
id="select-data"
),
],
style={"margin-top": "10px", "margin-left": "auto", "margin-right": "auto", "text-align": "center"},
className="twelve columns"
),
html.Div(
html.Form(
[
html.Section(
[
html.H2(
id='error_header'
),
html.Ul(
id='form_errors'
)
],
id='filter_errors',
hidden=True,
className='alert alert-danger'
),
html.Div(
[
html.Div(
[
html.Div(
className='label label-danger',
id="gas_alert",
hidden=True
)
],
className="error"
),
html.Div(
[
html.Label(
id="gas_selection",
htmlFor='gaz_list_dropdown',
className="control_label",
),
dcc.Dropdown(
id="gaz_list",
options= gaz_name_options,
placeholder=_('Select a gas'),
multi=False,
value=DATA_VERSION + '_O3.nc',
className="dcc_control",
label = 'Label test'
),
# html.Span(children=html.P(),className="wb-inv")
],
role='listbox',
**{'aria-label': 'Gas Dropdown'}
)
],
style={"textAlign":"left"}
),
html.Div(
[
html.Div(
className="error"
),
# dbc.Alert(
# color="secondary",
# id="pos_alert",
# is_open=False,
# fade=False,
# style={"margin-top":"0.5em"},
# className='dash-alert dash-alert-danger'
# )
]
),
html.Div([
html.Div( #Latitude picker
[
html.Label(
id="latitude-text",
className="control_label",
style={"textAlign":"left"}
),
html.Div(
className='label label-danger',
id="lat_alert",
hidden=True
),
html.Div([
html.Label(
id = "lat_min-text",
htmlFor = "lat_min",
hidden = True
),
dcc.Input(
id="lat_min",
type='number',
value=-90.0,
placeholder="Min Latitude",
min=-90.0,
max=90.0,
step=5,
debounce=True
),
html.Label(
id = "lat_max-text",
htmlFor = "lat_max",
hidden = True
),
dcc.Input(
id="lat_max",
type='number',
value=90.0,
placeholder="Max Latitude",
min=-90.0,
max=90.0,
step=5,
debounce=True
)
]),
html.Div(children=html.P(id="lat_selection"),className="wb-inv")
],
className="col-md-4",
),
html.Div( #longitude picker
[
html.Label(
id="longitude-text",
className="control_label",
style ={"textAlign":"left"}
),
html.Div(
className='label label-danger',
id="lon_alert",
hidden=True
),
html.Div([
html.Label(
htmlFor="lon_min",
id= "lon_min-text",
hidden = True
),
dcc.Input(
id="lon_min",
type='number',
value=-180.0,
placeholder="Min Longitude",
min=-180.0,
max=180.0,
step=5,
debounce=True
),
html.Label(
htmlFor="lon_max",
id= "lon_max-text",
hidden = True
),
dcc.Input(
id="lon_max",
type='number',
value=180.0,
placeholder="Max Longitude",
min=-180.0,
max=180.0,
step=5,
debounce=True
),
]),
html.Div(children=html.P(id="lon_selection"),className="wb-inv")
],
className="col-md-4",
style={"textAlign":"left"}
),
html.Div(
[ #Year selection + download button
html.Div([
html.Div(id="date_alert", hidden=True, style={"margin-top":"0.5em"}, className='label label-danger'),
]),
html.Label(
id="yearslider-text",
className="control_label"
),
html.Div(
[
dcc.DatePickerRange(
id='date_picker_range',
start_date=dt.datetime(2004, 2, 1),
end_date=dt.datetime(2020, 5, 5),
min_date_allowed=dt.datetime(2004, 2, 1),
max_date_allowed=dt.date.today(),
start_date_placeholder_text=_('Select start date'),
end_date_placeholder_text=_('Select end date'),
display_format="Y-MM-DD",
start_date_aria_label = _('Start Date'),
end_date_aria_label = _('End Date'),
),
html.Div(id='output-container-date-picker-range'),
html.Div(children=html.P(id="date_selection"),className="wb-inv")
]
),
],
className="col-md-12 col-lg-4",
),
],
className='row align-items-start ',
style={"textAlign":"left"}
),
html.Hr(),
html.Div([ #Choix altitude
html.Label(id="altitude-text"),
dcc.RangeSlider(
id='alt_range',
marks = {i: "{}".format(i) for i in np.append(np.arange(0.5,149.5,10),149.5)},
min=0,
max=150,
step=1,
value=[0, 150] ,
# tooltip = { 'always_visible': True }
),
html.Div(id='output-container-alt-picker-range'),
],style={"margin-top":"75px"}),
html.Div(
[
html.Div(
[
html.Div(
[
html.Div(
html.Span(
id='generate-button',
n_clicks=0,
style={
'padding': '0px 10px',
'display': 'inline-block',
'padding' : '6px 22px'
},
className="btn btn-primary",
role = 'button',
tabIndex=0
),
style={
"text-align": "center"
},
id='generate',
),
html.Div(
children=html.P(
id="generate_selection"
),
className="wb-inv"
)
],
style={'text-align': 'center'}
)
],
className="one-half column",
style={"textAlign":"right"}
),
html.Div(
[ #Download button
html.Div(
[
html.A(
html.Span(
id='download-button-1',
n_clicks=0,
style={'padding': '0px 10px'}
),
id='download-link-1',
# download='rawdata.csv',
href="",
target="_blank",
className="btn btn-primary"
),
html.Div(
children=html.P(id="download_selection"),
className="wb-inv"
)
]
),
],
id="cross-filter-options",
className="one-half column"
)
],
style={"margin-top":"30px"}
)
],
),
className="pretty_container twelve column wb-frmvld",
style={"justify-content": "space-evenly"}
)
])
def detail_table(id, id2):
#next button pagnation, for some reason the pages are 0 indexed but the dispalyed page isn't
@app.callback(
[
Output( id, 'page_current'),
Output( id+'-btn-1-a', 'data-value'),
Output( id+'-btn-2-a', 'data-value'),
Output( id+'-btn-3-a', 'data-value'),
Output( id+'-btn-1-a', "children"),
Output( id+'-btn-2-a', "children"),
Output( id+'-btn-3-a', "children"),
Output( id+'-btn-1-a', "aria-label"),
Output( id+'-btn-2-a', "aria-label"),
Output( id+'-btn-3-a', "aria-label"),
Output( id+'-btn-1-a', "aria-current"),
Output( id+'-btn-2-a', "aria-current"),
Output( id+'-btn-3-a', "aria-current"),
Output( id+'-btn-1', "className"),
Output( id+'-btn-2', "className"),
Output( id+'-btn-prev-a', 'children'),
Output( id+'-btn-next-a', 'children'),
Output( id+'-btn-prev-a', "aria-label"),
Output( id+'-btn-next-a', "aria-label"),
Output( id+'-navigation', "aria-label"),
],
[
Input( id+'-btn-prev', 'n_clicks'),
Input( id+'-btn-1', 'n_clicks'),
Input( id+'-btn-2', 'n_clicks'),
Input( id+'-btn-3', 'n_clicks'),
Input( id+'-btn-next', 'n_clicks')
],
[