-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.php
More file actions
686 lines (635 loc) · 16.2 KB
/
settings.php
File metadata and controls
686 lines (635 loc) · 16.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
<?php
/*
PRODSCRIPT SETTINGS FILE
This file serves two purposes:
First, some initial commands are run. These are mostly just setting variables.
Second, functions are defined that will be referenced by product scripts.
Be aware that this script will still be "executed" so vars that are defined early on_
were likely done there for a reason. In other words, moving things around may break stuff, so don't!
Gensini - 2014
*/
# Set the DISPLAY environmental variable, needed for _gf programs:
putenv("DISPLAY=:8");
# Display GEMPAK output?
$PrintOutput = true;
# This is the prodscript directory:
function ProdDir(){return "/home/scripts/models/prodscripts";}
# This is the base directory of where images will ultimately reside:
function BaseDir(){return "/home/apache/climate/data/forecast";}
function SubDir($Model,$RunTime,$Sector, $Date = null) {
if (($Model == "ECMWF") && ($Sector == "NAZM")) {
return "/".$Model."/".$RunTime."/NA";
} elseif ($Model == "CFS"){
if (!is_null($Date)) {
return "/".$Model."/".$Date."/".$Sector;
} else {
$Today = date("Ymd");
$FullRunTime = "$RunTime:00:00";
$TimeClass = new DateTime("$Today $FullRunTime");
if ($RunTime == 18) {
$TimeClass->modify('-1 day');
}
$CFSRunTime = $TimeClass->format("Ymd");
$CFSRunTime .= $RunTime;
return "/".$Model."/".$CFSRunTime."/".$Sector;
}
} else {
return "/".$Model."/".$RunTime."/".$Sector;
}
}
# Default image size:
$DefaultImageSize = "800;600";
# This is an array of sectors that should only plot "base" for mapfil:
$BigSectors = array("US", "NA", "WLD", "AO", "PO");
/*
FUNCTIONS USED FOR DEFINING VARIABLES
*/
# This function will return the image size to be used:
function SetImageSize($Sector,$DefaultSize){
if (($Sector == "ILS") || ($Sector == "ILB")) {
$ImageSize = "1024;768";
} elseif ($Sector == "NHEM") {
$ImageSize = "800;800";
} else {
$ImageSize = $DefaultSize;
}
return $ImageSize;
}
# This function will return an array with the sector coords and projection:
function SetSectorInfo($Sector){
$SectorFileName = "/home/scripts/reference/sectors.txt";
$FloaterSectorFileName = "/home/scripts/reference/floater.txt";
$WXCSectorFileName = "/home/apache/climate/wxchallenge/wxcs.dat";
if (($Sector == "WXCS") || ($Sector == "WXCB")) {
$WXCsectorFile = file($WXCSectorFileName);
if ($Sector == "WXCS") {
$Domain = trim($WXCsectorFile[8]);
} else {
$Domain = trim($WXCsectorFile[9]);
}
$Projection = "lcc";
} elseif ($Sector == "FLT") {
$Domain = trim(file_get_contents($FloaterSectorFileName));
$Projection = "lcc";
} else {
$SectorFile = file($SectorFileName);
foreach ($SectorFile as $line) {
if (substr(trim($line), 0, 1) == "#"){continue;} # hashtags denote comments, skip this line.
$line = trim(preg_replace("/[[:blank:]]+/"," ",$line));
list($abbr, $sTitle, $coords, $proj) = explode(" ", $line);
if ($Sector == $abbr) {
$Domain = $coords;
$Projection = $proj;
break;
}
}
}
$SectorInfo = array(
'Domain' => $Domain,
'Projection' => $Projection
);
return $SectorInfo;
}
# This function will return an array with the adjusted modname and appropriate grid name:
function SetModGridNames($Model) {
$GridFileName = "/home/scripts/reference/gridnames.txt";
$GridsFile = file($GridFileName);
foreach ($GridsFile as $line) {
$line = trim(preg_replace("/[[:blank:]]+/"," ",$line));
list($mod, $grid) = explode(" ", $line);
if ($Model == $mod) {
$ModName = $mod;
$GridName = $grid;
break;
}
}
if ($ModName == "GFSHD") {
$ModName = "GFS";
} elseif ($ModName == "GFSNA") {
$ModName = "GFS";
} elseif ($ModName == "NAM12") {
$ModName = "NAM";
} elseif ($ModName == "NAMAK") {
$ModName = "NAM";
}
$ModInfo = array(
'ModName' => $ModName,
'GridName' => $GridName
);
return $ModInfo;
}
function HRRRparmAdjust($type,$parm) {
if ($type == "GVCORD") {
switch ($parm) {
case 'NONE':
$HRRRparm = "ATMO";
break;
}
}
return $HRRRparm;
}
# This function will return stnplt, which is dynamic for some products:
function SetStationPlt($Product, $Sector) {
if (($Sector == "WXCS") || ($Sector == "WXCB")) {
switch ($Product) {
case 'cloud':
$stnplt = "24/1|24/15/4/2|wxcstations.tbl";
break;
case 'irsat':
$stnplt = "24/1|24/15/4/2|wxcstations.tbl";
break;
case 'cthk':
$stnplt = "10/1|10/15/4/2|wxcstations.tbl";
break;
case '30mbdewp':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'ltng':
$stnplt = "30/1|30/15/4/2|wxcstations.tbl";
break;
case 'uphly':
$stnplt = "30/1|30/15/4/2|wxcstations.tbl";
break;
case 'scp':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'mucape':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'gust':
$stnplt = "30/1|30/15/4/2|wxcstations.tbl";
break;
case 'mlcape':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'sbcape':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'prec':
$stnplt = "28/1|28/15/4/2|wxcstations.tbl";
break;
case 'cprec':
$stnplt = "28/1|28/15/4/2|wxcstations.tbl";
break;
case 'precacc':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'pwat':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'radar':
$stnplt = "30/1|30/15/4/2|wxcstations.tbl";
break;
case 'temp':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'thetae':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'wetblb':
$stnplt = "32/1|32/15/4/2|wxcstations.tbl";
break;
case 'rhum':
$stnplt = "17/1|17/15/4/2|wxcstations.tbl";
break;
default:
$stnplt = "";
break;
}
} elseif (($Sector == "FLT") || ($Sector == "CHI") || ($Sector == "ATL") || ($Sector == "DEN") || ($Sector == "OKC")) {
switch ($Product) {
case 'cape1000':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'ltng':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'snowmn12':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'uphly':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'gust':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'radar':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'snow1':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'snow12':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'snow4':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'snow8':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
case 'stp':
$stnplt = "32/.65|32/15/2/2|spcwatch.tbl";
break;
default:
$stnplt = "";
break;
}
} else {
$stnplt = "";
}
return $stnplt;
}
# This product will return stream, settings for streamlines, which is dynamic for some products:
function SetStream($Product, $ModName, $Sector = null) {
if ($Product == "30mbdewp") {
if ($ModName == "RAP") {
$stream = "0.3";
} elseif (($ModName == "NAM") && ($Sector == "AK")) {
$stream = "0.3";
} else {
$stream = "1";
}
} elseif ($Product == "rhum") {
if (($ModName == "RAP") && ($Sector == "US")) {
$stream = "0.4";
} elseif (($ModName == "NAM") && ($Sector == "AK")) {
$stream = "0.3";
} else {
$stream = "0.85";
}
} elseif ($Product == "mdiv") {
if (($ModName == "NAM") && ($Sector == "AK")) {
$stream = "0.2";
} else {
$stream = "1";
}
} elseif ($Product == "pvort") {
if (($ModName == "RAP") && ($Sector == "US")) {
$stream = "0.2";
} elseif (($ModName == "NAM") && ($Sector == "AK")) {
$stream = "0.2";
} elseif ($Sector == "NA") {
$stream = "0.4";
} elseif ($Sector == "WLD") {
$stream = "0.15";
} else {
$stream = "0.85";
}
}
return $stream;
}
# This product will return filter, which is dynamic for some products:
function SetFilter($ModName) {
switch ($ModName) {
case 'RAP':
$Filter = "0.8";
break;
default:
$Filter = "0.6";
break;
}
return $Filter;
}
#
function SetIJSkip($GridName, $Sector) {
$IJSkip = "";
if ($GridName == "GFSHD") {
switch ($Sector) {
case 'WLD':
$IJSkip = "";
break;
case 'NA':
$IJSkip = "0;335;680/0;190;350";
break;
case 'US':
$IJSkip = "0;435;610/0;215;300";
break;
case 'CGP':
$IJSkip = "0;485;570/0;245;285";
break;
case 'SGP':
$IJSkip = "0;490;560/0;225;270";
break;
case 'NE':
$IJSkip = "0;535;610/0;245;290";
break;
case 'SE':
$IJSkip = "0;520;585/0;225;265";
break;
case 'SW':
$IJSkip = "0;455;530/0;230;275";
break;
case 'CAN':
$IJSkip = "0;455;545/0;255;300";
break;
case 'AK':
$IJSkip = "0;330;505/0;275;330";
break;
case 'PO':
$IJSkip = "0;245;510/0;200;330";
break;
case 'AO':
$IJSkip = "/0;180;310";
break;
case 'NHEM':
$IJSkip = "/0;179;361";
break;
default:
$IJSkip = "";
break;
}
} elseif ($GridName == "HRRR") {
switch ($Sector) {
case 'CGPsf':
$IJSkip = "0;535;1375/0;415;1000";
break;
case 'MW':
$IJSkip = "0;890;1675/0;560;1130";
break;
case 'SL':
$IJSkip = "0;630;1405/0;630;1220";
break;
case 'NEsf':
$IJSkip = "0;1200;2145/0;520;1250";
break;
case 'SGP':
$IJSkip = "0;350;1490/0;90;910";
break;
case 'SE':
$IJSkip = "0;920;2100/0;1;820";
break;
case 'GC':
$IJSkip = "0;1010;1720/0;180;720";
break;
case 'CP':
$IJSkip = "0;400;1140/0;950;1377";
break;
case 'NW':
$IJSkip = "0;1;930/0;690;1377";
break;
case 'SW':
$IJSkip = "0;1;1000/0;200;1110";
break;
case 'CHI':
#$IJSkip = "0;1180;1420/0;770;930"; #For the old (original) CHI sector
$IJSkip = "0;1164;1435/0;745;940";
break;
case 'ATL':
$IJSkip = "0;1390;1540/0;460;570";
break;
case 'DEN':
$IJSkip = "0;700;855/0;730;840";
break;
case 'OKC':
$IJSkip = "0;830;1135/0;475;695";
break;
case 'ILS':
$IJSkip = "0;890;1675/0;560;1130";
break;
default:
$IJSkip = "yes";
break;
}
} elseif ($GridName == "RAP") {
switch ($Sector) {
case 'US':
$IJSkip = "";
break;
case 'CGP':
$IJSkip = "0;135;340/0;110;260";
break;
case 'SGP':
$IJSkip = "0;105;325/0;40;195";
break;
case 'NE':
$IJSkip = "0;265;451/0;120;285";
break;
case 'SE':
$IJSkip = "0;215;440/0;15;185";
break;
case 'SW':
$IJSkip = "0;1;230/0;60;235";
break;
case 'CAN':
$IJSkip = "0;35;285/0;165;337";
break;
default:
$IJSkip = "";
break;
}
} elseif ($GridName == "NAM12") {
switch ($Sector) {
case 'US':
$IJSkip = "";
break;
case 'CGP':
$IJSkip = "0;225;450/0;140;310";
break;
case 'SGP':
$IJSkip = "0;190;435/0;65;240";
break;
case 'NE':
$IJSkip = "0;365;614/0;150;345";
break;
case 'SE':
$IJSkip = "0;315;560/0;40;215";
break;
case 'SW':
$IJSkip = "0;75;330/0;90;280";
break;
case 'CAN':
$IJSkip = "0;110;390/0;205;410";
break;
default:
$IJSkip = "";
break;
}
} elseif ($GridName == "NAM") {
switch ($Sector) {
case 'US':
$IJSkip = "";
break;
case 'CGP':
$IJSkip = "0;65;135/0;45;100";
break;
case 'SGP':
$IJSkip = "0;55;130/0;20;75";
break;
case 'NE':
$IJSkip = "0;110;185/0;45;105";
break;
case 'SE':
$IJSkip = "0;95;170/0;10;75";
break;
case 'SW':
$IJSkip = "0;20;100/0;25;85";
break;
case 'CAN':
$IJSkip = "0;35;120/0;60;125";
break;
default:
$IJSkip = "";
break;
}
} elseif ($GridName == "NAM4KM") {
switch ($Sector) {
case 'CGP':
$IJSkip = "0;540;1080/0;350;740";
break;
case 'SGP':
$IJSkip = "0;460;1040/0;160;570";
break;
default:
$IJSkip = "";
break;
}
}
return $IJSkip;
}
# This function determines the LI grid name, because it is different in some models:
function SetCAPE($ModName) {
if ($ModName == "RAP") {
$CAPE = "CAPE@255:0%PDLY";
} else {
$CAPE = "CAPE@180:0%PDLY";
}
return $CAPE;
}
# This function determines the LI grid name, because it is different in some models:
function SetLI($ModName) {
if ($ModName == "GFS") {
$LI = "LIFT@0%NONE";
} else {
$LI = "LFT4@180:0%PDLY";
}
return $LI;
}
# This function determines the MSLP grid name, because it is different in some models:
function SetMSLP($ModName) {
switch ($ModName) {
case 'NAM':
$MSLP = "EMSL";
break;
case 'NAM4KM':
$MSLP = "sm9s(EMSL)";
break;
case 'RAP':
$MSLP = "quo(MSLMA,100)";
break;
default:
$MSLP = "PMSL";
break;
}
return $MSLP;
}
# This function determines the QPF grid name, because it is different in some models:
function SetQPF($ModName,$QPFhr) {
if ($ModName == "RAP") {
$QPF = "S".$QPFhr."M";
} else {
$QPF = "P".$QPFhr."M";
}
return $QPF;
}
/*
The next three functions deal with the date label that is in the upper right corner of each image.
The first function is essentially a list of models/runs that need a day subtracted,
The second function determines the valid time, dynamic based in part on current time,
And the second function creates a text file to be used to plot that string on the image.
*/
# This funciton is a list of model names and runtime pairs which need a day subtracted from the label.
# This need arises when a model of a runtime for one day, will have its images generated on the next day.
# A value of True will be returned if we do need to subtract a day, False if not (False is the default).
function RanNextDay_Check($ModName,$RunTime) {
$NeedSubtraction = FALSE;
switch ($ModName) {
case 'HRRR':
if ($RunTime == 23) {$NeedSubtraction = TRUE;}
break;
case 'SREF':
if ($RunTime == 21) {$NeedSubtraction = TRUE;}
break;
case 'CFS':
if ($RunTime == 18) {$NeedSubtraction = TRUE;}
break;
default:
// The passed model should never require a subtraction, move along.
break;
}
return $NeedSubtraction;
}
# This function will calculate the valid time based on the current and initialization times.
# There is a small chance of this being off if running data not from current day:
function GetValidTime($RunTime, $FHour) {
$Today = date("Y-m-d");
$FullRunTime = "$RunTime:00:00";
$TimeClass = new DateTime("$Today $FullRunTime");
$TimeClass->modify("$FHour hours");
return $TimeClass;
}
# This function will create a text file used in the labels of the model product:
function DateLabelFile($RunTime, $ModName, $FHour, $Level, $Product, $Sector, $TextDir, $Date = null){
# date will look like: date("H\Z D M d Y")
if (($ModName == "CFS") && (!is_null($Date))) {
$ValidTimeClass = DateTime::createFromFormat('YmdH', $Date);
$ValidTimeClass->modify("$FHour hours");
$Valid = $ValidTimeClass->format("H\Z D M d Y");
} else {
$ValidTimeClass = GetValidTime($RunTime, $FHour);
if (RanNextDay_Check($ModName,$RunTime)){ # See first function in this grouping for list of Model and Runtime pairs which will return true.
$ValidTimeClass->modify('-1 day');
}
$Valid = $ValidTimeClass->format("H\Z D M d Y");
}
// $ValidTimeClass = GetValidTime($RunTime, $FHour);
// if (($ModName == "CFS") && ($RunTime == 18)){
// $ValidTimeClass->modify('-1 day');
// }
// $Valid = $ValidTimeClass->format("H\Z D M d Y");
switch ($ModName) {
case 'SREF':
$spaces = " .";
break;
case 'HRRR':
$spaces = " .";
break;
case 'ECMWF':
$spaces = " .";
break;
case 'NAM4KM':
$spaces = " .";
break;
case 'ENSTHIN':
$spaces = " .";
break;
case 'GEFS':
$spaces = " .";
break;
default:
$spaces = " .";
break;
}
if ($Product == "ptype") {$spaces = "";}
$Text = $RunTime."Z $ModName $FHour hour - Valid $Valid$spaces";
$fname = "$TextDir/".$RunTime.$ModName.$Level.$Product.$Sector.$FHour.".txt";
file_put_contents($fname, $Text);
return $fname;
}
/*
This function will make the directory for the image if it does not already exist
*/
function EnsureDirExists($path) {
if (!file_exists($path)) {
mkdir($path, 0775, true);
}
}
/*
descriptor array, used for proc_open:
*/
$desc = array(
0 => array('pipe', 'r'), // 0 is STDIN for process
1 => array('pipe', 'w'), // 1 is STDOUT for process
2 => array('file', '/tmp/error-output.txt', 'a') // 2 is STDERR for process
);
?>