-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
3444 lines (2776 loc) · 169 KB
/
app.R
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
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(shiny)
library(shinyFiles)
library(shinyTime)
library(stringr)
library(leaflet)
library(lubridate)
library(readr)
#FNL and ERA5 Download Functions
#FNL Downloader
#Please create a rda.ucar.edu account and type the email and password below that you've registered.
email = ""
pass = ""
fnl_downloader = function(email, pass, path, from, to) {
email = email
pass = pass
setwd(path)
Sys.setenv(TZ="GMT")
data_i = from
data_f = to
dir.create(paste(path,"/fnl_",data_i,"_to_",data_f, sep = ""), showWarnings = F)
setwd(paste(path,"/fnl_",data_i,"_to_",data_f, sep = ""))
seq_dates = seq(as.POSIXct(data_i), as.POSIXct(data_f), by = "6 hour")
list_dates = format(seq_dates, "%Y%m%d_%H_00")
file_name = paste0("fnl_", list_dates, ".grib2") #as.list(paste(my_url, file_name, sep = ""))
if (data_i <= "2007-12-06" & data_f <= "2007-12-06") {
down_link = paste0("http://rda.ucar.edu/data/ds083.2/grib1/", format(seq_dates, "%Y"), "/", format(seq_dates, "%Y.%m"),"/fnl_", list_dates, ".grib1")
} else if (data_i >= "2007-12-06" & data_f >= "2007-12-06") {
down_link = paste0("http://rda.ucar.edu/data/ds083.2/grib2/", format(seq_dates, "%Y"), "/", format(seq_dates, "%Y.%m"),"/fnl_", list_dates, ".grib2")
}
system(paste0("wget -O Authentication.log --save-cookies auth.rda_ucar_edu --post-data 'email=", email, "&passwd=", pass, "&action=login' https://rda.ucar.edu/cgi-bin/login"))
for (i in 1:length(file_name)){
if (file.exists(file_name[i])) {
cat(paste0(file_name[i], " - already downloaded. \n"))
} else {
system(paste0("wget -N --load-cookies auth.rda_ucar_edu ", down_link[i]))
}
}
system(paste0("rm -rf Authentication.log auth.rda_ucar_edu"))
}
#ERA5 Downloader
#Please follow the instructions found at the link below before using it!
#https://cds.climate.copernicus.eu/api-how-to
era5_surf_downloader = function(path, from, to, area) {
# time sequence
data_i = from
data_f = to
setwd(path)
dir.create(paste(path,"/ERA5_",data_i,"_to_",data_f, sep = ""), showWarnings = F)
setwd(paste(path,"/ERA5_",data_i,"_to_",data_f, sep = ""))
list_dates = seq.Date(as.Date(data_i), as.Date(data_f), by = "day")
list_dates = format(list_dates, "%Y%m%d")
for (i in 1:length(list_dates)) {
if (file.exists(paste0("ERA5_sfc_", list_dates[i], ".grib"))) {
cat(paste0("ERA5_sfc_", list_dates[i], ".grib"), " - already downloaded. \n")
} else if (file.exists(paste0("ERA5_sfc_", list_dates[i], ".nc"))) {
cat(paste0("ERA5_sfc_", list_dates[i], ".nc"), " - already downloaded. \n")
} else {
txt = c("#!/usr/bin/env python",
"import cdsapi",
"",
"c = cdsapi.Client()",
"",
"c.retrieve(",
"'reanalysis-era5-single-levels',",
"{",
"'product_type':'reanalysis',",
"'format':'grib',",
"'variable':[",
"'10m_u_component_of_wind','10m_v_component_of_wind','2m_dewpoint_temperature',",
"'2m_temperature','land_sea_mask','mean_sea_level_pressure',",
"'sea_ice_cover','sea_surface_temperature','skin_temperature',",
"'snow_depth','soil_temperature_level_1','soil_temperature_level_2',",
"'soil_temperature_level_3','soil_temperature_level_4','surface_pressure',",
"'volumetric_soil_water_layer_1','volumetric_soil_water_layer_2','volumetric_soil_water_layer_3',",
"'volumetric_soil_water_layer_4'",
"],",
paste0("'day' : ['", ifelse(day(ymd(list_dates[i])) %in% 1:9, paste0(0,day(ymd(list_dates[i]))),day(ymd(list_dates[i]))),"'],"),
paste0("'month' : ['", ifelse(month(ymd(list_dates[i])) %in% 1:9, paste0(0,month(ymd(list_dates[i]))),month(ymd(list_dates[i]))),"'],"),
paste0("'year' : ['", year(ymd(list_dates[i])),"'],"),
"'time': [",
"'00:00', '01:00', '02:00',",
"'03:00', '04:00', '05:00',",
"'06:00', '07:00', '08:00',",
"'09:00', '10:00', '11:00',",
"'12:00', '13:00', '14:00',",
"'15:00', '16:00', '17:00',",
"'18:00', '19:00', '20:00',",
"'21:00', '22:00', '23:00',",
"],",
"'area': [",
paste0(area[1],",",area[2],",",area[3],",",area[4]),
"],",
"},",
paste0("'ERA5_sfc_", list_dates[i], ".grib')")
)
writeLines(txt, paste0("ECMWF_ERA5_sfc_", list_dates[i], ".py"))
cat(paste0("Downloading ECMWF ERA5 WRF sfc variables, day: ", list_dates[i]), "\n")
system(command = paste0("python ECMWF_ERA5_sfc_", list_dates[i], ".py"), ignore.stdout = F, ignore.stderr = F)
system(command = paste0("rm -rf ECMWF_ERA5_sfc_", list_dates[i], ".py"), ignore.stdout = F, ignore.stderr = F)
}
}
}
era5_pl_downloader = function(path, from, to, area) {
# time sequence
data_i = from
data_f = to
setwd(path)
dir.create(paste(path,"/ERA5_",data_i,"_to_",data_f, sep = ""), showWarnings = F)
setwd(paste(path,"/ERA5_",data_i,"_to_",data_f, sep = ""))
list_dates = seq.Date(as.Date(data_i), as.Date(data_f), by = "day")
list_dates = format(list_dates, "%Y%m%d")
for (i in 1:length(list_dates)) {
if (file.exists(paste0("ERA5_pl_", list_dates[i], ".grib"))) {
cat(paste0("ERA5_pl_", list_dates[i], ".grib"), " - already downloaded. \n")
} else if (file.exists(paste0("ERA5_pl_", list_dates[i], ".nc"))) {
cat(paste0("ERA5_pl_", list_dates[i], ".nc"), " - already downloaded. \n")
} else {
txt = c("#!/usr/bin/env python",
"import cdsapi",
"",
"c = cdsapi.Client()",
"",
"c.retrieve(",
"'reanalysis-era5-pressure-levels',",
"{",
"'product_type':'reanalysis',",
"'format':'grib',",
"'variable':[",
"'geopotential', 'relative_humidity', 'specific_humidity',",
"'temperature', 'u_component_of_wind', 'v_component_of_wind',",
"],",
"'pressure_level': [",
"'1', '2', '3',",
"'5', '7', '10',",
"'20', '30', '50',",
"'70', '100', '125',",
"'150', '175', '200',",
"'225', '250', '300',",
"'350', '400', '450',",
"'500', '550', '600',",
"'650', '700', '750',",
"'775', '800', '825',",
"'850', '875', '900',",
"'925', '950', '975',",
"'1000',",
"],",
paste0("'day' : ['", ifelse(day(ymd(list_dates[i])) %in% 1:9, paste0(0,day(ymd(list_dates[i]))),day(ymd(list_dates[i]))),"'],"),
paste0("'month' : ['", ifelse(month(ymd(list_dates[i])) %in% 1:9, paste0(0,month(ymd(list_dates[i]))),month(ymd(list_dates[i]))),"'],"),
paste0("'year' : ['", year(ymd(list_dates[i])),"'],"),
"'time': [",
"'00:00', '01:00', '02:00',",
"'03:00', '04:00', '05:00',",
"'06:00', '07:00', '08:00',",
"'09:00', '10:00', '11:00',",
"'12:00', '13:00', '14:00',",
"'15:00', '16:00', '17:00',",
"'18:00', '19:00', '20:00',",
"'21:00', '22:00', '23:00',",
"],",
"'area': [",
paste0(area[1],",",area[2],",",area[3],",",area[4]),
"],",
"},",
paste0("'ERA5_pl_", list_dates[i], ".grib')")
)
writeLines(txt, paste0("ECMWF_ERA5_pl_", list_dates[i], ".py"))
cat(paste0("Downloading ECMWF ERA5 WRF pl variables, day: ", list_dates[i]), "\n")
system(command = paste0("python ECMWF_ERA5_pl_", list_dates[i], ".py"), ignore.stdout = F, ignore.stderr = F)
system(command = paste0("rm -rf ECMWF_ERA5_pl_", list_dates[i], ".py"), ignore.stdout = F, ignore.stderr = F)
}
}
}
ui = navbarPage(inverse = TRUE, "WRF Model Initializer",
# First Tab - Intro
tabPanel("Summary About the App",
fluidPage(h1("WRF (Weather Research and Forecasting) Model Initializer"),
br(),
p(strong(em("This app provides to run WRF model on predefined domains."))),
br(),
p("The Weather Research and Forecasting (WRF) Model is a next-generation mesoscale numerical weather prediction system designed for both atmospheric research and operational forecasting applications."),
br(),
p("Even though this app can run the model from the data download to the WRF model initializing; it is strongly recommended to use/execute the final prepared bash script in Linux OS due to the background process problems of R Shiny platform!"),
br(),
p("This app has 5 different tabs;"),
br(),
p("Summary About the App: This tab!"),
p("1. Data: Download the data required for WPS (FNL and ERA5)"),
p("2. WPS: WRF Preprocessing configurations and initializing"),
p("3. WRF: WRF model configurations and initializing"),
p("4. Bash: Bash scripts that can be run in background!"),
br(),
p("Play with this interactive tool and find out!"),
br(),
br(),
br(),
br()
)
),
#Second Tab - Data Downloader!
tabPanel("Data",
fluidPage(titlePanel("Download the Initial Condition Data"),
p("In this section, the initial condition data that is required for initializing the WRF will be downloaded.
The worldwide known two datasets can be downloaded within this app."),
p(strong("1. FNL:"),"These NCEP FNL (Final) Operational Global Analysis data are on 1-degree
by 1-degree grids prepared operationally every six hours. For the detailed explanation,
click the",a("link", href = "https://rda.ucar.edu/datasets/ds083.2/#!description"),"."),
p(strong("2. ERA5:"),"ERA5 is the fifth generation ECMWF reanalysis for the global climate and weather for the past
4 to 7 decades. Data has been regridded on 0.25-degree by 0.25-degree grids. ERA5 provides hourly estimates
for a large number of atmospheric, ocean-wave and land-surface quantities. For the detailed
explanation, click the",a("link", href = "https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-pressure-levels?tab=overview"),"."),
fluidRow(column(12, align = "center",
wellPanel(style = "background: white",
p(strong("Choose the path for data that will be downloaded")),
shinyDirButton("datadir", "Data directory", "Choose the path for the data")))),
fluidRow(column(12, align = "center",
h4(strong("Choose the data and date range")),
fluidRow(column(6, align = "center",
wellPanel(style = "backgroud: white",
selectInput("datatype","Choose the data type",
choices = c("FNL","ERA5"),
selected = "FNL",
multiple = F))),
column(6, align = "center",
wellPanel(style = "background: white",
dateRangeInput("dateRange_data",
label = "Date range for downloading the data.",
start = Sys.Date() - 30, end = Sys.Date()-15)
)
)
)
)
),
fluidRow(column(12, align = "center",
h4("Choose the area (if the data is ERA5)"),
fluidRow(column(3,
wellPanel(style = "background: white",
numericInput("north",
label = "North (Latitude)",value = 45,
min = -90, max = 90)
)
),
column(3,
wellPanel(style = "background: white",
numericInput("west",
label = "West (Longitude)",value = 20,
min = -180, max = 180)
)
),
column(3,
wellPanel(style = "background: white",
numericInput("south",
label = "South (Latitude)",value = 33,
min = -90, max = 90)
)
),
column(3,
wellPanel(style = "background: white",
numericInput("east",
label = "East (Longitude)",value = 47,
min = -180, max = 180)
)
)
)
)
),
fluidRow(align = "center",
actionButton("areadef", "Show the area")
),
fluidRow(align = "center",
br(),
actionButton("download", "Download the data!")
)
),
mainPanel(
br(),
leafletOutput("mymap"),
textOutput("text_results"),
textOutput("text_area")
)
),
# Third Tab - WPS
tabPanel("WPS",
fluidPage(
fluidRow(column(6, align = "center",
h4(strong("Configuring WPS")),
fluidRow(column(12, align = "center",
h5("namelist.wps"),
fluidRow(column(6,
wellPanel(style = "background: white",
fileInput("wps_namelist", "Choose the predefined namelist.wps",
multiple = F)
)
),
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("Update parameters on app!")),
actionButton("update_wps","Update parameters"),
p("Update parameters on app based on uploaded namelist.wps!")))
))
),
fluidRow(column(12, align = "center",
wellPanel(style = "background: white",
p(strong("Choose the path for WPS directory")),
shinyDirButton("wpsdir", "WPS directory", "Choose the path for WPS")))
),
fluidRow(column(12, align = "center",
h5("Date & Time Manipulation"),
wellPanel(style = "background: white",
dateRangeInput("dateRange_WPS",
label = "Date range input for WPS (Year - Month - Day)",
start = Sys.Date() - 7, end = Sys.Date())),
fluidRow(column(6,
wellPanel(style = "background: white",
timeInput("time_start_wps",
"Select the time for the first date:",
value = strptime("00:00:00","%T")))
),
column(6,
wellPanel(style = "background: white",
timeInput("time_end_wps",
"Select the time for the first date:",
value = strptime("18:00:00","%T"))))))
),
fluidRow(column(12, align = "center",
h5("Other Configurations"),
fluidRow(column(6,
wellPanel(style = "background: white",
numericInput("max_dom", "Define max domain size",
value = 6,
min = 1,
max = 20))),
column(6,
wellPanel(style = "background: white",
sliderInput("timeres", "Choose time resolution (hours) of input",
value = 6,
min = 1,
max = 24,
step = 1))
)))
),
fluidRow(column(6, align = "center",
wellPanel(style = "backgroud: white",
selectInput("staticres", "Choose static data resolution",
choices = c("10m", "30s", "default"),
multiple = F,
selected = c("30s")))),
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("Choose the path for the data (If the data is not downloaded on previous step!)")),
shinyDirButton("datadir2", "Data directory", "Choose the path for the data")))
),
fluidRow(column(12, align = "center",
h5("Control Buttons!"),
column(4, align = "center",
wellPanel(style = "background: white",
p(strong("Check the possible errors!")),
actionButton("checkbutton_wps","Check errors!"),
p("Click the button to check the problems!"))),
column(8, align = "center",
wellPanel(style = "background: white",
p(strong("Observe the changes")),
actionButton("preprocess_WPS", "Make the changes!"),
radioButtons("save_wps",label = "Overwrite namelist.wps", choices = c("Yes","No"), selected = "Yes", inline = T),
p("Click the button to make the choices would be effective in namelist.wps! If No is selected, then you can download the configured namelist by using download button."))))
),
fluidRow(column(6, align = "center",
wellPanel(style = "background: white",
p(strong("1. Geogrid")),
actionButton("geogrid", "Execute Geogrid!"),
p("Click the button to execute the geogrid of WPS"))),
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("2. Ungrib")),
actionButton("ungrib","Execute Ungrib!"),
p("Click the button to execute ungrib of WPS")))
),
fluidRow(column(6, align = "center",
wellPanel(style = "background: white",
p(strong("Metgrid")),
actionButton("metgrid","Execute Metgrid!"),
p("Click the button to execute metgrid of WPS"))),
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("3 in 1")),
actionButton("AllWPS", "WPS Initializer!"),
p("Click the button to execute all WPS works")))
)),
column(6,
titlePanel("WPS Configuration & Initializing"),
p("In this section, you will;"),
p("1. Choose predefined namelist for WPS (namelist.wps)."),
p("2. Choose domain number for initializing."),
p("3. Choose the WPS directory."),
p("4. Select the date range that you want to initialize WRF."),
p("5. Select the times for the dates you've selected."),
p("6. Finally, you can run the WPS which includes three steps"),
br(),
br(),
fluidRow(align = "center",
downloadButton("download_wps", "Download")
),
br(),
mainPanel(
# p(strong(em("Selected WPS path is:"))),
# br(),
htmlOutput("update_warn_wps"),
htmlOutput("checktext_wps"),
# br(),
# p(strong(em("Configured WPS"), "Observe the changes")),
br(),
htmlOutput("geogrid_msg"),
br(),
htmlOutput("ungrib_msg"),
br(),
htmlOutput("metgrid_msg"),
br(),
uiOutput("text_namelist_wps")))
)
)),
# Fourth Tab - WRF
tabPanel("WRF",
fluidPage(
fluidRow(column(6, align = "center",
h4(strong("Configuring WRF")),
fluidRow(column(12, align = "center",
h5("namelist.input"),
fluidRow(column(6,
wellPanel(style = "background: white",
fileInput("wrf_namelist", "Choose the predefined namelist.input",
multiple = F)
)
),
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("Update parameters on app!")),
actionButton("update_wrf","Update parameters"),
p("Update parameters on app based on uploaded namelist.input!"))
)
))
),
fluidRow(column(12, align = "center",
wellPanel(style = "background: white",
p(strong("Choose the path for WRF directory")),
shinyDirButton("wrfdir", "WRF directory", "Choose the path for WRF")))
),
fluidRow(column(12, align = "center",
h5("Date & Time Manipulation"),
wellPanel(style = "background: white",
dateRangeInput("dateRange_WRF",
label = "Date range input for WRF (Year - Month - Day)",
start = Sys.Date() - 7, end = Sys.Date())),
fluidRow(column(6,
wellPanel(style = "background: white",
timeInput("time_start_wrf",
"Select the time for the first date:",
value = strptime("00:00:00","%T")))
),
column(6,
wellPanel(style = "background: white",
timeInput("time_end_wrf",
"Select the time for the first date:",
value = strptime("18:00:00","%T"))))))
),
fluidRow(column(12, align = "center",
h5("Other Configurations"),
fluidRow(column(6,
wellPanel(style = "background: white",
numericInput("max_dom_wrf", "Define max domain size",
value = 6,
min = 1,
max = 20))),
column(6,
wellPanel(style = "backgroud: white",
selectInput("hist_dom", "Choose the domains that the outputs are desired!",
choices = c("1","2","3","4","5","6","7","8"),
multiple = T,
selected = c("1","2")))
)))
),
fluidRow(column(6,align = "center",
wellPanel(style = "background: white",
numericInput("hist_int", "Choose history interval (in minutes) of WRF output.",
value = 60))
),
column(6,align = "center",
wellPanel(style = "backgroud: white",
numericInput("time_step", "Choose the time step of WRF model!",
value = 180,
min = 1))
)
),
fluidRow(column(12, align = "center",
h5("Control Buttons!"),
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("Check the possible errors!")),
actionButton("checkbutton_wrf","Check errors!"),
p("Click the button to check the problems!"))
),
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("Activate the configurations")),
actionButton("preprocess_WRF", "Make the changes!"),
radioButtons("save_wrf",label = "Overwrite namelist.input", choices = c("Yes","No"), selected = "Yes", inline = T),
p("Click the button to make the choices would be effective in namelist.input! If No is selected, then you can download the configured namelist by using download button."))
)
)
),
fluidRow(
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("MPI")),
radioButtons("mpisupport",label = "Is WRF installed with MPI Support?",choices = c("Yes","No"),selected = "Yes"),
p("Whether WRF model is built with MPI support or not."))),
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("CPU")),
sliderInput("cpu_n","CPU number",
value = 4,
min = 1,
max = 8,
step = 1),
p("Checks and automatically returns optimal CPU number!"))
)
),
fluidRow(column(6, align = "center",
wellPanel(style = "background: white",
p(strong("1. Real")),
actionButton("real", "Execute real.exe!"),
p("Click the button to execute the real.exe of WRF"))
),
column(6, align = "center",
wellPanel(style = "background: white",
p(strong("2. WRF")),
actionButton("wrf","Execute WRF!"),
p("Click the button to execute the WRF"))
)
),
fluidRow(column(12, align = "center",
wellPanel(style = "background: white",
p(strong("WRF Total")),
actionButton("AllWRF","Execute WRF with real!"),
p("Click the button to execute WRF with real")))
)),
column(6,
titlePanel("WRF Configuration & Initializing"),
p("In this section, you will;"),
p("1. Choose predefined namelist for WRF (namelist.input)."),
p("2. Choose domain number for initializing."),
p("3. Choose the WRF directory."),
p("4. Select the date range that you want to initialize WRF."),
p("5. Select the times for the dates you've selected."),
p("6. Finally, you can run the WRF which includes two steps"),
br(),
br(),
fluidRow(align = "center",
downloadButton("download_wrf", "Download")
),
br(),
mainPanel(
# p(strong(em("Selected WPS path is:"))),
# br(),
htmlOutput("update_warn_wrf"),
htmlOutput("checktext_wrf"),
br(),
htmlOutput("real_msg"),
br(),
htmlOutput("wrf_msg"),
br(),
uiOutput("text_namelist_wrf"),
# br(),
# p(strong(em("Configured WPS"), "Observe the changes")),
br()))
)
)),
# Fifth Tab - Bash
tabPanel("Bash Script",
sidebarLayout(
sidebarPanel(align = "center",
p(strong("Create the bash script!")),
p("This tab provides a bash script to run WRF model in Linux OS.
Since executing system commands on the background is not supported on R Shiny;
this bash script can be executed on background (nohup &, tmux, screen), Therefore;
this app can also be used for creating bash scripts instead of executing WRF model.",
align = "justify"),
p("Click the button to create the bash script in order to be able to run WRF model background."),
actionButton("bash_preparer", "Prepare the bash!"),
br(),
actionButton("bash_button","Bash script",align = "center"),
br(),
br(),
p("Should this bash include data downloading part?"),
radioButtons("datadownload",label = "Should data download be included?",inline = T, choices = c("Yes","No"), selected = "No"),
downloadButton("download_bash", "Download"),
br(),
br(),
p("This part is created for long WRF model runs with a speciefed sequence type in dates", align = "justify"),
p("For instance; if you would like to run a WRF model between 2020-01-01 00:00:00 and 2021-01-01 00:00:00; you should follow;", align = "justify"),
p("1. If you would like to download data; then, choose data type and data path in Data tab! Don't forget the push show area button if you've selected ERA5 data! (You don't need to specify date ranges in Data tab.)",align = "justify"),
p("2. Upload namelist.wps, update the related parameters, choose a path for WPS directory and definetely press make changes button in WPS tab. You can change any configuration you want before pressing Make changes button! (You don't need to specify the date ranges in WPS tab)",align = "justify"),
p("3. Upload namelist.input, update the related parameters, choose a path for WRF directory and definetely press make changes button in WRF tab. You can change any configurations you want beofre pressing Make changes button! (You don't need to specify the date range in WRF tab)",align = "justify"),
p("4. If you also want to download dataset please choose Yes in this tab",align = "justify"),
p("5. Please specify date and time ranges if you want to create a sequential bash scripts (ex. 2020-01-01, 2021-01-01)",align = "justify"),
p("6. Choose your sequence type (Day, Week or Month)",align = "justify"),
p("7. Choose your sequence numeric. For instance if you want to create a two-week time sequence, then Week and 2 should be chosen.",align = "justify"),
p("8. Choose a spin-up time specified in hours (if you do not want any spin-up then you can choose 0)",align = "justify"),
dateRangeInput("datebash",
label = "Date range",
start = Sys.Date() - 7, end = Sys.Date()),
timeInput("timebash1", "Start Time"),
timeInput("timebash2", "End Time"),
selectInput("sequence_bash","Choose your sequence",choices = c("Day","Week","Month"), selected = "Day"),
numericInput("seq_num_bash", "Choose your sequence number", min = 1, max = 31, value = 1),
br(),
numericInput("spinup_num","Choose a spin-up time in hours.", min = 0, max = 48, value = 3),
br(),
br(),
actionButton("checkbutton_bash2","Check errors!"),
br(),
actionButton("bash2_preparer", "Prepare the bash with sequence!"),
br(),
actionButton("bash2_button","Bash script with sequence",align = "center"),
br(),
br(),
downloadButton("download_bash2", "Download"),
),
mainPanel(
htmlOutput("checktext_bash"),
textOutput("bash_text",container = pre),
textOutput("bash_text2",container = pre)
)
))
)
server = function(input, output,session) {
volumes = getVolumes()
shinyDirChoose(input, "datadir", roots = volumes(), session = session)
dirpath_data = reactive({
req(input$datadir)
parseDirPath(volumes,input$datadir)
})
daterange_data = reactive({
req(input$dateRange_data)
date_range_data = as.character(input$dateRange_data)
date_range_data
})
datatype = reactive({
req(input$datatype)
datatype = as.character(input$datatype)
})
north = reactive({
req(input$north)
north = input$north
north
})
west = reactive({
req(input$west)
west = input$west
west
})
south = reactive({
req(input$south)
south = input$south
south
})
east = reactive({
req(input$east)
east = input$east
east
})
area = eventReactive(input$areadef, {
area = c(north(), west(), south(), east())
})
output$mymap <- renderLeaflet({
area = area()
leaflet() %>%
addTiles() %>%
addRectangles(
lng1=area[2], lat1=area[1],
lng2=area[4], lat2=area[3],
fillColor = "transparent")
})
observeEvent(input$download,{
datatype = datatype()
dirpath_data = dirpath_data()
daterange_data = daterange_data()
if (datatype == "FNL") {
fnl_downloader(email = email,
pass = pass,
path = dirpath_data,
from = daterange_data[1],
to = daterange_data[2])
} else {
area = area()
era5_surf_downloader(path = dirpath_data,
from = daterange_data[1],
to = daterange_data[2],
area = area)
era5_pl_downloader(path = dirpath_data,
from = daterange_data[1],
to = daterange_data[2],
area = area)
output$text_results = renderText({
list.files(path = path)
})
}
})
output$text_area = renderText({
area = area()
area
})
# WPS, Third Tab -----------------------------------------------------------
wps_predefined = reactive({
req(input$wps_namelist)
file = input$wps_namelist
ext = tools::file_ext(file$datapath)
wps_predefined = readLines(file$datapath)
wps_predefined
})
max_dom = reactive({
req(input$max_dom)
max_dom = input$max_dom
max_dom
})
daterange_wps = reactive({
req(input$dateRange_WPS)
daterange_wps = as.character(input$dateRange_WPS)
})
date_time_start_wps = reactive({
req(input$dateRange_WPS)
req(input$time_start_wps)
date_ranges_wps = daterange_wps()
time_1_wps = as.character(strftime(input$time_start_wps, "%T"))
date_time_start_wps = paste(as.character(date_ranges_wps[1]),time_1_wps, sep = "_")
date_time_start_wps
})
date_time_end_wps = reactive({
req(input$dateRange_WPS)
req(input$time_end_wps)
date_ranges_wps = daterange_wps()
time_2_wps = as.character(strftime(input$time_end_wps, "%T"))
date_time_end_wps = paste(as.character(date_ranges_wps[2]), time_2_wps, sep = "_")
date_time_end_wps
})
volumes = getVolumes()
shinyDirChoose(input, "wpsdir", roots = volumes(), session = session)
dirpath_wps = reactive({
req(input$wpsdir)
parseDirPath(volumes,input$wpsdir)
})
timeres = reactive({
req(input$timeres)
timeres = as.numeric(input$timeres)*3600
timeres
})
staticres = reactive({
req(input$staticres)
staticres = as.character(input$staticres)
staticres = rep(staticres, max_dom())
staticres = paste("'",paste(staticres,collapse = "','"),"'",sep = "")
staticres
})
volumes = getVolumes()
shinyDirChoose(input, "datadir2", roots = volumes(), session = session)
dirpath_data2 = reactive({
req(input$datadir2)
parseDirPath(volumes,input$datadir2)
})
observeEvent(input$update_wps, {
output$update_warn_wps = renderUI({
if(is.null(input$wps_namelist)) {
#Negative warn!
warn_wps = paste("<strong><span style=\"color:darkred\">Please upload the namelist.wps in order to be able to update the parameters!</span></strong>")
} else {
#Positive warn!
warn_wps = paste("<strong><span style=\"color:darkgreen\">Related parameters updated!</span></strong>")
}
HTML(paste(warn_wps, sep="<br/>"))
})
wps_predefined = wps_predefined()
#Update the namelist.wps based on the uploaded namelist.wps!
#Start date
Sys.setenv(TZ='GMT')
wps_s_i = str_detect(wps_predefined,"start_date")
s_i_1 = str_locate(wps_predefined[wps_s_i],"=")[1]
s_i_2 = str_locate(wps_predefined[wps_s_i],",")[1]
start_date_wps = ymd_hms(substr(wps_predefined[wps_s_i],(s_i_1+1), (s_i_2-1)))
#End date
wps_e_i = str_detect(wps_predefined,"end_date")
e_i_1 = str_locate(wps_predefined[wps_e_i],"=")[1]
e_i_2 = str_locate(wps_predefined[wps_e_i],",")[1]
end_date_wps = ymd_hms(substr(wps_predefined[wps_e_i],(e_i_1+1), (e_i_2-1)))
#Time
time_s_wps = strftime(start_date_wps, format="%T")
time_e_wps = strftime(end_date_wps, format="%T")
#Max dom
md_wps_i = str_detect(wps_predefined,"max_dom")
md_wps_i_1 = str_locate(wps_predefined[md_wps_i],"=")[1]
md_wps = parse_number(substr(wps_predefined[md_wps_i],md_wps_i_1,nchar(wps_predefined[md_wps_i])))
#Timeres
timeres_i = str_detect(wps_predefined,"interval_seconds")
timeres_i_1 = str_locate(wps_predefined[timeres_i],"=")[1]
timeres_u = parse_number(substr(wps_predefined[timeres_i],timeres_i_1,nchar(wps_predefined[timeres_i])))/3600
#Staticres
staticres_i = str_detect(wps_predefined,"geog_data_res")
staticres_i = which(staticres_i)[!str_detect(wps_predefined[staticres_i],"!")]
staticres_i_1 = str_locate(wps_predefined[staticres_i],"=")[1]
staticres_i_2 = str_locate(wps_predefined[staticres_i],",")[1]
staticres_u = substr(wps_predefined[staticres_i], (staticres_i_1+1), (staticres_i_2-1))
staticres_u = str_replace_all(staticres_u,pattern = " ", replacement = "")
staticres_u = str_replace_all(staticres_u,pattern = "'", replacement = "")
updateDateRangeInput(session, inputId = "dateRange_WPS", start = start_date_wps, end = end_date_wps)
updateTimeInput(session, "time_start_wps",value = strptime(time_s_wps,"%T"))
updateTimeInput(session, "time_end_wps",value = strptime(time_e_wps,"%T"))
updateNumericInput(session, "max_dom", value = md_wps)
updateSliderInput(session, "timeres", value = timeres_u)
updateSelectInput(session, "staticres", selected = staticres_u)
})
observeEvent(input$checkbutton_wps, {
output$checktext_wps = renderUI({
if (is.null(input$wps_namelist)) {
first_message_wps = paste("<strong><span style=\"color:darkred\">Please upload the namelist.wps!</span></strong>")
} else {
first_message_wps = paste("<strong><span style=\"color:darkgreen\">You have uploaded the namelist.wps.</span></strong>", sep = "")
}
date_time_start_wps = date_time_start_wps()
date_time_start_wps = ymd_hms(date_time_start_wps)
date_time_end_wps = date_time_end_wps()
date_time_end_wps = ymd_hms(date_time_end_wps)
timeres = timeres()
if (date_time_start_wps>=date_time_end_wps) {
second_message_wps = paste("<strong><span style=\"color:darkred\">Please choose a start date which is smaller than the end date.</span></strong>")
} else if(((as.numeric(date_time_end_wps)-as.numeric(date_time_start_wps)) %% timeres) == 0) {
second_message_wps = paste("<strong><span style=\"color:darkgreen\">",paste0("WPS will be executed between ",
date_time_start_wps(),
" and ",
date_time_end_wps(),"!"),
"</span></strong>", sep = "")
} else {
second_message_wps = paste("<strong><span style=\"color:darkred\">Please choose a valid date range that can be divisible by history interval (data time resolution) which is defined ",
timeres/3600,
" hours in WPS tab!</span></strong>", sep = "")
}
if (as.character(unlist(input$wpsdir)[1])==0) {
third_message_wps = paste("<strong><span style=\"color:darkred\">Please choose a path for WPS directory!</span></strong>")
} else {
third_message_wps = paste("<strong><span style=\"color:darkgreen\">",paste0("Path for the WPS is chosen as: ",
dirpath_wps()),
"</span></strong>", sep = "")
}