forked from JoshuaPrzyborowski/PyTempCalc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pytempcalc.py
executable file
·802 lines (697 loc) · 55.4 KB
/
pytempcalc.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
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
'''
This program is free software; you can redistribute it and/or modify
it under the terms of the Revised BSD License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Revised BSD License for more details.
Copyright 2016-2019 Game Maker 2k - https://github.com/GameMaker2k
Copyright 2016-2019 Joshua Przyborowski - https://github.com/JoshuaPrzyborowski
$FileInfo: pytempcalc.py - Last Update: 2/9/2019 Ver. 0.4.0 RC 1 - Author: joshuatp $
'''
# http://www.nws.noaa.gov/om/winter/windchill.shtml
# http://www.wpc.ncep.noaa.gov/html/windchill.shtml
# http://www.wpc.ncep.noaa.gov/html/dewrh.shtml
# http://www.wpc.ncep.noaa.gov/html/heatindex.shtml
# http://maineharbors.com/weather/convert3.htm
import math
__program_name__ = "PyTempCalc"
__project__ = __program_name__
__project_url__ = "https://github.com/JoshuaPrzyborowski/PyTempCalc"
__version_info__ = (0, 4, 0, "RC 1", 1)
__version_date_info__ = (2019, 2, 9, "RC 1", 1)
__version_date__ = str(__version_date_info__[0])+"."+str(__version_date_info__[
1]).zfill(2)+"."+str(__version_date_info__[2]).zfill(2)
if(__version_info__[4] != None):
__version_date_plusrc__ = __version_date__ + \
"-"+str(__version_date_info__[4])
if(__version_info__[4] == None):
__version_date_plusrc__ = __version_date__
if(__version_info__[3] != None):
__version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(
__version_info__[2])+" "+str(__version_info__[3])
if(__version_info__[3] == None):
__version__ = str(
__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2])
def RoundToInt(IntNum):
return int(round(IntNum))
def ConvertTempUnits(Temperature, InTempUnit="Fahrenheit", OutTempUnit="Celsius"):
InTempUnit = InTempUnit.capitalize()
OutTempUnit = OutTempUnit.capitalize()
retval = {}
if(InTempUnit != "Fahrenheit" and InTempUnit != "Celsius"):
return False
if(OutTempUnit != "Fahrenheit" and OutTempUnit != "Celsius"):
return False
if(InTempUnit == "Fahrenheit" and OutTempUnit == "Celsius"):
# retvaltmp = float(5.0 / 9.0) * (float(Temperature) - 32.0);
retvaltmp = float(((float(Temperature) - 32) * 5) / 9)
retval.update({
'Fahrenheit': "{:0.2f}".format(float(Temperature)),
'Celsius': "{:0.2f}".format(float(retvaltmp)),
'Rankine': "{:0.2f}".format(float(Temperature) + float(273.15)),
'Kelvin': "{:0.2f}".format(float(retvaltmp) + float(273.15)),
'Delisle': "{:0.2f}".format(((float(Temperature) - 212) * 5) / 6),
'Newton': "{:0.2f}".format(((float(Temperature) - 32) * 11) / 60),
'Reaumur': "{:0.2f}".format(((float(Temperature) - 32) * 4) / 9),
'Romer': "{:0.2f}".format((((float(Temperature) - 32) * 7) / 24) + 7.5),
'FahrenheitFull': float(Temperature),
'CelsiusFull': float(retvaltmp),
'RankineFull': float(Temperature) + float(273.15),
'KelvinFull': float(retvaltmp) + float(273.15),
'DelisleFull': float(((float(Temperature) - 212) * 5) / 6),
'NewtonFull': float(((float(Temperature) - 32) * 11) / 60),
'ReaumurFull': float(((float(Temperature) - 32) * 4) / 9),
'RomerFull': float((((float(Temperature) - 32) * 7) / 24) + 7.5),
'FahrenheitRounded': RoundToInt(float(Temperature)),
'CelsiusRounded': RoundToInt(float(retvaltmp)),
'RankineRounded': RoundToInt(float(Temperature) + float(273.15)),
'KelvinRounded': RoundToInt(float(retvaltmp) + float(273.15)),
'DelisleRounded': RoundToInt(float(((float(Temperature) - 212) * 5) / 6)),
'NewtonRounded': RoundToInt(float(((float(Temperature) - 32) * 11) / 60)),
'ReaumurRounded': RoundToInt(float(((float(Temperature) - 32) * 4) / 9)),
'RomerRounded': RoundToInt(float((((float(Temperature) - 32) * 7) / 24) + 7.5))
})
elif(InTempUnit == "Celsius" and OutTempUnit == "Fahrenheit"):
# retvaltmp = float(5.0 * 9.0) / (float(Temperature) - 32.0);
retvaltmp = float(((float(Temperature) * 9) / 5) + 32)
retval.update({
'Fahrenheit': "{:0.2f}".format(float(retvaltmp)),
'Celsius': "{:0.2f}".format(float(Temperature)),
'Rankine': "{:0.2f}".format(float(retvaltmp) + float(273.15)),
'Kelvin': "{:0.2f}".format(float(Temperature) + float(273.15)),
'Delisle': "{:0.2f}".format(((float(Temperature) - 100) * 3) / 2),
'Newton': "{:0.2f}".format((float(Temperature) * 3) / 2),
'Reaumur': "{:0.2f}".format((float(Temperature) * 4) / 5),
'Romer': "{:0.2f}".format(float(((float(Temperature) * 21) / 40) + 7.5)),
'FahrenheitFull': float(retvaltmp),
'CelsiusFull': float(Temperature),
'RankineFull': float(retvaltmp) + float(273.15),
'KelvinFull': float(Temperature) + float(273.15),
'DelisleFull': float(((float(Temperature) - 100) * 3) / 2),
'NewtonFull': float((float(Temperature) * 3) / 2),
'ReaumurFull': float((float(Temperature) * 4) / 5),
'RomerFull': float(((float(Temperature) * 21) / 40) + 7.5),
'FahrenheitRounded': RoundToInt(float(retvaltmp)),
'CelsiusRounded': RoundToInt(float(Temperature)),
'RankineRounded': RoundToInt(float(retvaltmp) + float(273.15)),
'KelvinRounded': RoundToInt(float(Temperature) + float(273.15)),
'DelisleRounded': RoundToInt(float(((float(Temperature) - 100) * 3) / 2)),
'NewtonRounded': RoundToInt(float((float(Temperature) * 3) / 2)),
'ReaumurRounded': RoundToInt(float((float(Temperature) * 4) / 5)),
'RomerRounded': RoundToInt(float(((float(Temperature) * 21) / 40) + 7.5))
})
else:
return False
return retval
def ConvertTempUnitsFromFahrenheitToCelsius(Temperature):
return ConvertTempUnits(Temperature, "Fahrenheit", "Celsius")
def ConvertTempUnitsFromCelsiusToFahrenheit(Temperature):
return ConvertTempUnits(Temperature, "Celsius", "Fahrenheit")
def ConvertWindUnits(WindSpeed, InWindUnit="MPH", OutWindUnit="KMH"):
InWindUnit = InWindUnit.upper()
OutWindUnit = OutWindUnit.upper()
retval = {}
if(InWindUnit != "MPH" and InWindUnit != "KMH"):
return False
if(OutWindUnit != "MPH" and OutWindUnit != "KMH"):
return False
if(InWindUnit == "MPH" and OutWindUnit == "KMH"):
retvaltmp = float(float(WindSpeed) * 1.609344)
retval.update({
'MPH': "{:0.2f}".format(float(WindSpeed)),
'KMH': "{:0.2f}".format(float(retvaltmp)),
'NMPH': "{:0.2f}".format(float(float(WindSpeed) * 0.86897624)),
'MPHFull': float(WindSpeed),
'KMHFull': float(retvaltmp),
'NMPHFull': float(float(WindSpeed) * 0.86897624),
'MPHRounded': RoundToInt(float(WindSpeed)),
'KMHRounded': RoundToInt(float(retvaltmp)),
'NMPHRounded': RoundToInt(float(float(WindSpeed) * 0.86897624))
})
elif(InWindUnit == "KMH" and OutWindUnit == "MPH"):
retvaltmp = float(float(WindSpeed) / 1.609344)
retval.update({
'MPH': "{:0.2f}".format(float(retvaltmp)),
'KMH': "{:0.2f}".format(float(WindSpeed)),
'NMPH': "{:0.2f}".format(float(float(WindSpeed) * 0.5399568)),
'MPHFull': float(retvaltmp),
'KMHFull': float(WindSpeed),
'NMPHFull': float(float(WindSpeed) * 0.5399568),
'MPHRounded': RoundToInt(float(retvaltmp)),
'KMHRounded': RoundToInt(float(WindSpeed)),
'NMPHRounded': RoundToInt(float(float(WindSpeed) * 0.5399568))
})
else:
return False
return retval
def ConvertWindUnitsFromMPHToKMH(Temperature):
return ConvertWindUnits(WindSpeed, "MPH", "KMH")
def ConvertWindUnitsFromKMHToMPH(Temperature):
return ConvertWindUnits(WindSpeed, "KMH", "MPH")
def WindChill(Temperature, WindSpeed, TempUnit="Fahrenheit", WindUnit="MPH", NewWindChill=True):
TempUnit = TempUnit.capitalize()
WindUnit = WindUnit.upper()
windchillret = {}
if(TempUnit != "Fahrenheit" and TempUnit != "Celsius"):
return False
if(WindUnit != "MPH" and WindUnit != "KMH"):
return False
if(TempUnit == "Fahrenheit" and WindUnit == "MPH"):
if(NewWindChill):
windchill = float(35.74 + 0.6215 * float(Temperature) - 35.75 * math.pow(float(
WindSpeed), 0.16) + 0.4275 * float(Temperature) * math.pow(float(WindSpeed), 0.16))
else:
windchill = float(0.0817 * (3.71 * (math.sqrt(float(WindSpeed))) +
5.81 - 0.25 * float(WindSpeed)) * (float(Temperature) - 91.4) + 91.4)
windchillret.update({
'Fahrenheit': "{:0.2f}".format(float(windchill)),
'Celsius': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['CelsiusFull'])),
'Rankine': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RankineFull'])),
'Kelvin': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['KelvinFull'])),
'Delisle': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['DelisleFull'])),
'Newton': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['NewtonFull'])),
'Reaumur': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['ReaumurFull'])),
'Romer': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RomerFull'])),
'FahrenheitFull': float(windchill),
'CelsiusFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['CelsiusFull']),
'RankineFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RankineFull']),
'KelvinFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['KelvinFull']),
'DelisleFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['DelisleFull']),
'NewtonFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['NewtonFull']),
'ReaumurFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['ReaumurFull']),
'RomerFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RomerFull']),
'FahrenheitRounded': RoundToInt(float(windchill)),
'CelsiusRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['CelsiusFull']),
'RankineRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RankineFull']),
'KelvinRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['KelvinFull']),
'DelisleRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['DelisleFull']),
'NewtonRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['NewtonFull']),
'ReaumurRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['ReaumurFull']),
'RomerRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RomerFull'])
})
if(TempUnit == "Fahrenheit" and WindUnit == "KMH"):
WindSpeed = 0.621371 * float(WindSpeed)
if(NewWindChill):
windchill = float(35.74 + 0.6215 * float(Temperature) - 35.75 * math.pow(float(
WindSpeed), 0.16) + 0.4275 * float(Temperature) * math.pow(float(WindSpeed), 0.16))
else:
windchill = float(0.0817 * (3.71 * (math.sqrt(float(WindSpeed))) +
5.81 - 0.25 * float(WindSpeed)) * (float(Temperature) - 91.4) + 91.4)
windchillret.update({
'Fahrenheit': "{:0.2f}".format(float(windchill)),
'Celsius': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['CelsiusFull'])),
'Rankine': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RankineFull'])),
'Kelvin': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['KelvinFull'])),
'Delisle': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['DelisleFull'])),
'Newton': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['NewtonFull'])),
'Reaumur': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['ReaumurFull'])),
'Romer': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RomerFull'])),
'FahrenheitFull': float(windchill),
'CelsiusFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['CelsiusFull']),
'RankineFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RankineFull']),
'KelvinFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['KelvinFull']),
'DelisleFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['DelisleFull']),
'NewtonFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['NewtonFull']),
'ReaumurFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['ReaumurFull']),
'RomerFull': float(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RomerFull']),
'FahrenheitRounded': RoundToInt(float(windchill)),
'CelsiusRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['CelsiusFull']),
'RankineRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RankineFull']),
'KelvinRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['KelvinFull']),
'DelisleRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['DelisleFull']),
'NewtonRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['NewtonFull']),
'ReaumurRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['ReaumurFull']),
'RomerRounded': RoundToInt(ConvertTempUnits(float(windchill), "Fahrenheit", "Celsius")['RomerFull'])
})
if(TempUnit == "Celsius" and WindUnit == "KMH"):
if(NewWindChill):
windchill = float(13.12 + 0.6215 * float(Temperature) - 11.37 * math.pow(float(
WindSpeed), 0.16) + 0.3965 * float(Temperature) * math.pow(float(WindSpeed), 0.16))
else:
Temperature = ConvertTempUnits(float(Temperature), "Celsius", "Fahrenheit")[
'FahrenheitFull']
windchill = float(0.0817 * (3.71 * (math.sqrt(float(WindSpeed))) +
5.81 - 0.25 * float(WindSpeed)) * (float(Temperature) - 91.4) + 91.4)
Temperature = ConvertTempUnits(float(Temperature), "Fahrenheit", "Celsius")[
'CelsiusFull']
windchillret.update({
'Celsius': "{:0.2f}".format(float(windchill)),
'Fahrenheit': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['FahrenheitFull'])),
'Rankine': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RankineFull'])),
'Kelvin': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['KelvinFull'])),
'Delisle': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['DelisleFull'])),
'Newton': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['NewtonFull'])),
'Reaumur': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['ReaumurFull'])),
'Romer': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RomerFull'])),
'CelsiusFull': float(windchill),
'FahrenheitFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['FahrenheitFull']),
'RankineFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RankineFull']),
'KelvinFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['KelvinFull']),
'DelisleFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['DelisleFull']),
'NewtonFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['NewtonFull']),
'ReaumurFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['ReaumurFull']),
'RomerFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RomerFull']),
'CelsiusRounded': RoundToInt(float(windchill)),
'FahrenheitRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['FahrenheitFull']),
'RankineRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RankineFull']),
'KelvinRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['KelvinFull']),
'DelisleRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['DelisleFull']),
'NewtonRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['NewtonFull']),
'ReaumurRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['ReaumurFull']),
'RomerRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RomerFull'])
})
if(TempUnit == "Celsius" and WindUnit == "MPH"):
WindSpeed = 1.609344 * float(WindSpeed)
if(NewWindChill):
windchill = float(13.12 + 0.6215 * float(Temperature) - 11.37 * math.pow(float(
WindSpeed), 0.16) + 0.3965 * float(Temperature) * math.pow(float(WindSpeed), 0.16))
else:
Temperature = ConvertTempUnits(float(Temperature), "Celsius", "Fahrenheit")[
'FahrenheitFull']
windchill = float(0.0817 * (3.71 * (math.sqrt(float(WindSpeed))) +
5.81 - 0.25 * float(WindSpeed)) * (float(Temperature) - 91.4) + 91.4)
Temperature = ConvertTempUnits(float(Temperature), "Fahrenheit", "Celsius")[
'CelsiusFull']
windchillret.update({
'Celsius': "{:0.2f}".format(float(windchill)),
'Fahrenheit': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['FahrenheitFull'])),
'Rankine': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RankineFull'])),
'Kelvin': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['KelvinFull'])),
'Delisle': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['DelisleFull'])),
'Newton': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['NewtonFull'])),
'Reaumur': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['ReaumurFull'])),
'Romer': "{:0.2f}".format(float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RomerFull'])),
'CelsiusFull': float(windchill),
'FahrenheitFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['FahrenheitFull']),
'RankineFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RankineFull']),
'KelvinFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['KelvinFull']),
'DelisleFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['DelisleFull']),
'NewtonFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['NewtonFull']),
'ReaumurFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['ReaumurFull']),
'RomerFull': float(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RomerFull']),
'CelsiusRounded': RoundToInt(float(windchill)),
'FahrenheitRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['FahrenheitFull']),
'RankineRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RankineFull']),
'KelvinRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['KelvinFull']),
'DelisleRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['DelisleFull']),
'NewtonRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['NewtonFull']),
'ReaumurRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['ReaumurFull']),
'RomerRounded': RoundToInt(ConvertTempUnits(float(windchill), "Celsius", "Fahrenheit")['RomerFull'])
})
return windchillret
def WindChillFahrenheitMPH(Temperature, WindSpeed, NewWindChill=True):
return WindChill(Temperature, WindSpeed, "Fahrenheit", "MPH", NewWindChill)
def WindChillOldFahrenheitMPH(Temperature, WindSpeed):
return WindChillFahrenheitMPH(Temperature, WindSpeed, False)
def WindChillNewFahrenheitMPH(Temperature, WindSpeed):
return WindChillFahrenheitMPH(Temperature, WindSpeed, True)
def WindChillFahrenheitKMH(Temperature, WindSpeed, NewWindChill=True):
return WindChill(Temperature, WindSpeed, "Fahrenheit", "KMH", NewWindChill)
def WindChillOldFahrenheitKMH(Temperature, WindSpeed):
return WindChillFahrenheitKMH(Temperature, WindSpeed, False)
def WindChillNewFahrenheitKMH(Temperature, WindSpeed):
return WindChillFahrenheitKMH(Temperature, WindSpeed, True)
def WindChillCelsiusKMH(Temperature, WindSpeed, NewWindChill=True):
return WindChill(Temperature, WindSpeed, "Celsius", "KMH", NewWindChill)
def WindChillOldCelsiusKMH(Temperature, WindSpeed):
return WindChillCelsiusKMH(Temperature, WindSpeed, False)
def WindChillNewCelsiusKMH(Temperature, WindSpeed):
return WindChillCelsiusKMH(Temperature, WindSpeed, True)
def WindChillCelsiusMPH(Temperature, WindSpeed, NewWindChill=True):
return WindChill(Temperature, WindSpeed, "Celsius", "MPH", NewWindChill)
def WindChillOldCelsiusMPH(Temperature, WindSpeed):
return WindChillCelsiusMPH(Temperature, WindSpeed, False)
def WindChillNewCelsiusMPH(Temperature, WindSpeed):
return WindChillCelsiusMPH(Temperature, WindSpeed, True)
def WindChillGenXML(TempUnit="Fahrenheit", WindUnit="MPH", NewWindChill=True, OutputFile="-"):
TempUnit = TempUnit.capitalize()
WindUnit = WindUnit.upper()
mintemp = -45
maxtemp = 40
tempstart = 40
minwind = 5
maxwind = 60
windstart = 5
windchillout = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE noaawcc [\n<!ELEMENT noaawcc (wcc)*>\n<!ELEMENT wcc EMPTY>\n<!ATTLIST wcc windspeedmph CDATA #REQUIRED>\n<!ATTLIST wcc windspeedkhm CDATA #REQUIRED>\n<!ATTLIST wcc windspeedknots CDATA #REQUIRED>\n<!ATTLIST wcc temperaturef CDATA #IMPLIED>\n<!ATTLIST wcc temperaturec CDATA #IMPLIED>\n<!ATTLIST wcc temperaturer CDATA #IMPLIED>\n<!ATTLIST wcc temperaturek CDATA #IMPLIED>\n<!ATTLIST wcc temperatured CDATA #IMPLIED>\n<!ATTLIST wcc temperaturen CDATA #IMPLIED>\n<!ATTLIST wcc temperaturere CDATA #IMPLIED>\n<!ATTLIST wcc temperaturero CDATA #IMPLIED>\n<!ATTLIST wcc windchillf CDATA #IMPLIED>\n<!ATTLIST wcc windchillc CDATA #IMPLIED>\n<!ATTLIST wcc windchillr CDATA #IMPLIED>\n<!ATTLIST wcc windchillk CDATA #IMPLIED>\n<!ATTLIST wcc windchilld CDATA #IMPLIED>\n<!ATTLIST wcc windchilln CDATA #IMPLIED>\n<!ATTLIST wcc windchillre CDATA #IMPLIED>\n<!ATTLIST wcc windchillro CDATA #IMPLIED>\n<!ATTLIST wcc frostbitelevel CDATA #IMPLIED>\n<!ATTLIST wcc frostbitemin CDATA #IMPLIED>\n]>\n<noaawcc>\n"
while(windstart <= maxwind):
tempstart = 40
while(tempstart >= mintemp):
getwcval = WindChill(tempstart, windstart,
TempUnit, WindUnit, NewWindChill)
if(TempUnit == "Fahrenheit"):
gettuval = ConvertTempUnits(tempstart, "Fahrenheit", "Celsius")
if(TempUnit == "Celsius"):
gettuval = ConvertTempUnits(tempstart, "Celsius", "Fahrenheit")
if(WindUnit == "MPH"):
getwuval = ConvertWindUnits(tempstart, "MPH", "KMH")
if(WindUnit == "KMH"):
getwuval = ConvertWindUnits(tempstart, "KMH", "MPH")
if((windstart == 5 and tempstart <= 40 and tempstart >= -5) or
(windstart == 10 and tempstart <= 40 and tempstart >= 0) or
(windstart == 15 and tempstart <= 40 and tempstart >= 5) or
(windstart == 20 and tempstart <= 40 and tempstart >= 5) or
(windstart == 25 and tempstart <= 40 and tempstart >= 5) or
(windstart == 30 and tempstart <= 40 and tempstart >= 10) or
(windstart == 35 and tempstart <= 40 and tempstart >= 10) or
(windstart == 40 and tempstart <= 40 and tempstart >= 10) or
(windstart == 45 and tempstart <= 40 and tempstart >= 10) or
(windstart == 50 and tempstart <= 40 and tempstart >= 10) or
(windstart == 55 and tempstart <= 40 and tempstart >= 15) or
(windstart == 60 and tempstart <= 40 and tempstart >= 15)):
windchillout = windchillout + " <wcc windspeedmph=\""+str(getwuval['MPHRounded'])+"\" windspeedkhm=\""+str(getwuval['KMHRounded'])+"\" windspeedknots=\""+str(getwuval['NMPHRounded'])+"\" temperaturef=\""+str(gettuval['FahrenheitRounded'])+"\" temperaturec=\""+str(gettuval['CelsiusRounded'])+"\" temperaturer=\""+str(gettuval['RankineRounded'])+"\" temperaturek=\""+str(gettuval['KelvinRounded'])+"\" temperatured=\""+str(gettuval['DelisleRounded'])+"\" temperaturen=\""+str(gettuval['NewtonRounded'])+"\" temperaturere=\""+str(
gettuval['ReaumurRounded'])+"\" temperaturero=\""+str(gettuval['RomerRounded'])+"\" windchillf=\""+str(getwcval['FahrenheitRounded'])+"\" windchillc=\""+str(getwcval['CelsiusRounded'])+"\" windchillr=\""+str(getwcval['RankineRounded'])+"\" windchillk=\""+str(getwcval['KelvinRounded'])+"\" windchilld=\""+str(getwcval['DelisleRounded'])+"\" windchilln=\""+str(getwcval['NewtonRounded'])+"\" windchillre=\""+str(getwcval['ReaumurRounded'])+"\" windchillro=\""+str(getwcval['RomerRounded'])+"\" frostbitelevel=\"0\" frostbitemin=\"-1\" />\n"
if((windstart == 5 and tempstart <= -10 and tempstart >= -35) or
(windstart == 10 and tempstart <= -5 and tempstart >= -20) or
(windstart == 15 and tempstart <= 0 and tempstart >= -15) or
(windstart == 20 and tempstart <= 0 and tempstart >= -10) or
(windstart == 25 and tempstart <= 0 and tempstart >= -5) or
(windstart == 30 and tempstart <= 5 and tempstart >= -5) or
(windstart == 35 and tempstart <= 5 and tempstart >= 0) or
(windstart == 40 and tempstart <= 5 and tempstart >= 0) or
(windstart == 45 and tempstart <= 5 and tempstart >= 0) or
(windstart == 50 and tempstart <= 5 and tempstart >= 0) or
(windstart == 55 and tempstart <= 10 and tempstart >= 5) or
(windstart == 60 and tempstart <= 10 and tempstart >= 5)):
windchillout = windchillout + " <wcc windspeedmph=\""+str(getwuval['MPHRounded'])+"\" windspeedkhm=\""+str(getwuval['KMHRounded'])+"\" windspeedknots=\""+str(getwuval['NMPHRounded'])+"\" temperaturef=\""+str(gettuval['FahrenheitRounded'])+"\" temperaturec=\""+str(gettuval['CelsiusRounded'])+"\" temperaturer=\""+str(gettuval['RankineRounded'])+"\" temperaturek=\""+str(gettuval['KelvinRounded'])+"\" temperatured=\""+str(gettuval['DelisleRounded'])+"\" temperaturen=\""+str(gettuval['NewtonRounded'])+"\" temperaturere=\""+str(
gettuval['ReaumurRounded'])+"\" temperaturero=\""+str(gettuval['RomerRounded'])+"\" windchillf=\""+str(getwcval['FahrenheitRounded'])+"\" windchillc=\""+str(getwcval['CelsiusRounded'])+"\" windchillr=\""+str(getwcval['RankineRounded'])+"\" windchillk=\""+str(getwcval['KelvinRounded'])+"\" windchilld=\""+str(getwcval['DelisleRounded'])+"\" windchilln=\""+str(getwcval['NewtonRounded'])+"\" windchillre=\""+str(getwcval['ReaumurRounded'])+"\" windchillro=\""+str(getwcval['RomerRounded'])+"\" frostbitelevel=\"1\" frostbitemin=\"30\" />\n"
if((windstart == 5 and tempstart <= -40 and tempstart >= -45) or
(windstart == 10 and tempstart <= -25 and tempstart >= -45) or
(windstart == 15 and tempstart <= -20 and tempstart >= -35) or
(windstart == 20 and tempstart <= -15 and tempstart >= -30) or
(windstart == 25 and tempstart <= -10 and tempstart >= -25) or
(windstart == 30 and tempstart <= -10 and tempstart >= -20) or
(windstart == 35 and tempstart <= -5 and tempstart >= -15) or
(windstart == 40 and tempstart <= -5 and tempstart >= -15) or
(windstart == 45 and tempstart <= -5 and tempstart >= -10) or
(windstart == 50 and tempstart <= -5 and tempstart >= -10) or
(windstart == 55 and tempstart <= 0 and tempstart >= -10) or
(windstart == 60 and tempstart <= 0 and tempstart >= 0)):
windchillout = windchillout + " <wcc windspeedmph=\""+str(getwuval['MPHRounded'])+"\" windspeedkhm=\""+str(getwuval['KMHRounded'])+"\" windspeedknots=\""+str(getwuval['NMPHRounded'])+"\" temperaturef=\""+str(gettuval['FahrenheitRounded'])+"\" temperaturec=\""+str(gettuval['CelsiusRounded'])+"\" temperaturer=\""+str(gettuval['RankineRounded'])+"\" temperaturek=\""+str(gettuval['KelvinRounded'])+"\" temperatured=\""+str(gettuval['DelisleRounded'])+"\" temperaturen=\""+str(gettuval['NewtonRounded'])+"\" temperaturere=\""+str(
gettuval['ReaumurRounded'])+"\" temperaturero=\""+str(gettuval['RomerRounded'])+"\" windchillf=\""+str(getwcval['FahrenheitRounded'])+"\" windchillc=\""+str(getwcval['CelsiusRounded'])+"\" windchillr=\""+str(getwcval['RankineRounded'])+"\" windchillk=\""+str(getwcval['KelvinRounded'])+"\" windchilld=\""+str(getwcval['DelisleRounded'])+"\" windchilln=\""+str(getwcval['NewtonRounded'])+"\" windchillre=\""+str(getwcval['ReaumurRounded'])+"\" windchillro=\""+str(getwcval['RomerRounded'])+"\" frostbitelevel=\"2\" frostbitemin=\"10\" />\n"
if((windstart == 15 and tempstart <= -40 and tempstart >= -45) or
(windstart == 20 and tempstart <= -35 and tempstart >= -45) or
(windstart == 25 and tempstart <= -30 and tempstart >= -45) or
(windstart == 30 and tempstart <= -25 and tempstart >= -45) or
(windstart == 35 and tempstart <= -20 and tempstart >= -45) or
(windstart == 40 and tempstart <= -20 and tempstart >= -45) or
(windstart == 45 and tempstart <= -15 and tempstart >= -45) or
(windstart == 50 and tempstart <= -15 and tempstart >= -45) or
(windstart == 55 and tempstart <= -15 and tempstart >= -45) or
(windstart == 60 and tempstart <= -10 and tempstart >= -45)):
windchillout = windchillout + " <wcc windspeedmph=\""+str(getwuval['MPHRounded'])+"\" windspeedkhm=\""+str(getwuval['KMHRounded'])+"\" windspeedknots=\""+str(getwuval['NMPHRounded'])+"\" temperaturef=\""+str(gettuval['FahrenheitRounded'])+"\" temperaturec=\""+str(gettuval['CelsiusRounded'])+"\" temperaturer=\""+str(gettuval['RankineRounded'])+"\" temperaturek=\""+str(gettuval['KelvinRounded'])+"\" temperatured=\""+str(gettuval['DelisleRounded'])+"\" temperaturen=\""+str(gettuval['NewtonRounded'])+"\" temperaturere=\""+str(
gettuval['ReaumurRounded'])+"\" temperaturero=\""+str(gettuval['RomerRounded'])+"\" windchillf=\""+str(getwcval['FahrenheitRounded'])+"\" windchillc=\""+str(getwcval['CelsiusRounded'])+"\" windchillr=\""+str(getwcval['RankineRounded'])+"\" windchillk=\""+str(getwcval['KelvinRounded'])+"\" windchilld=\""+str(getwcval['DelisleRounded'])+"\" windchilln=\""+str(getwcval['NewtonRounded'])+"\" windchillre=\""+str(getwcval['ReaumurRounded'])+"\" windchillro=\""+str(getwcval['RomerRounded'])+"\" frostbitelevel=\"3\" frostbitemin=\"5\" />\n"
tempstart = tempstart - 5
windstart = windstart + 5
windchillout = windchillout + "</noaawcc>\n"
if(OutputFile != "-"):
wcof = open(OutputFile, 'w')
wcof.write(windchillout)
wcof.close()
return windchillout
def WindChillOldGenXML(TempUnit="Fahrenheit", WindUnit="MPH", OutputFile="-"):
return WindChillGenXML(TempUnit, WindUnit, False, OutputFile)
def WindChillNewGenXML(TempUnit="Fahrenheit", WindUnit="MPH", OutputFile="-"):
return WindChillGenXML(TempUnit, WindUnit, True, OutputFile)
def WindChillGenXMLFahrenheitMPH(NewWindChill=True, OutputFile="-"):
return WindChillGenXML("Fahrenheit", "MPH", NewWindChill, OutputFile)
def WindChillOldGenXMLFahrenheitMPH(OutputFile="-"):
return WindChillGenXMLFahrenheitMPH(False, OutputFile)
def WindChillNewGenXMLFahrenheitMPH(OutputFile="-"):
return WindChillGenXMLFahrenheitMPH(True, OutputFile)
def WindChillGenXMLFahrenheitKMH(NewWindChill=True, OutputFile="-"):
return WindChillGenXML("Fahrenheit", "KMH", NewWindChill, OutputFile)
def WindChillOldGenXMLFahrenheitKMH(OutputFile="-"):
return WindChillGenXMLFahrenheitKMH(False, OutputFile)
def WindChillNewGenXMLFahrenheitKMH(Temperature, WindSpeed, OutputFile="-"):
return WindChillGenXMLFahrenheitKMH(True, OutputFile)
def WindChillGenXMLCelsiusKMH(NewWindChill=True, OutputFile="-"):
return WindChillGenXML("Celsius", "KMH", NewWindChill, OutputFile)
def WindChillOldGenXMLCelsiusKMH(OutputFile="-"):
return WindChillGenXMLCelsiusKMH(False, OutputFile)
def WindChillNewGenXMLCelsiusKMH(OutputFile="-"):
return WindChillGenXMLCelsiusKMH(True, OutputFile)
def WindChillGenXMLCelsiusMPH(NewWindChill=True, OutputFile="-"):
return WindChillGenXML("Celsius", "MPH", NewWindChill, OutputFile)
def WindChillOldGenXMLCelsiusMPH(OutputFile="-"):
return WindChillGenXMLCelsiusMPH(False, OutputFile)
def WindChillNewGenXMLCelsiusMPH(OutputFile="-"):
return WindChillGenXMLCelsiusMPH(True, OutputFile)
def HeatIndexByDewPoint(Temperature, DewPointTemp, TempUnit="Fahrenheit"):
TempUnit = TempUnit.capitalize()
heatindexret = {}
if(TempUnit != "Fahrenheit" and TempUnit != "Celsius"):
return False
if(TempUnit == "Celsius"):
Temperature = ConvertTempUnits(float(Temperature), "Celsius", "Fahrenheit")[
'FahrenheitFull']
DewPointTemp = ConvertTempUnits(float(DewPointTemp), "Celsius", "Fahrenheit")[
'FahrenheitFull']
TempUnit = "Fahrenheit"
if(TempUnit == "Fahrenheit"):
tc2 = ConvertTempUnits(float(Temperature), "Fahrenheit", "Celsius")[
'CelsiusFull']
tdc2 = ConvertTempUnits(float(DewPointTemp), "Fahrenheit", "Celsius")[
'CelsiusFull']
vaporpressure = 6.11 * (math.pow(10, 7.5 * (tdc2 / (237.7 + tdc2))))
satvaporpressure = 6.11 * (math.pow(10, 7.5 * (tc2 / (237.7 + tc2))))
RHumidity2 = RoundToInt(100.0 * (vaporpressure / satvaporpressure))
hitemp = 61.0 + ((Temperature - 68.0) * 1.2) + (RHumidity2 * 0.094)
fptemp = float(Temperature)
hifinal = 0.5 * (fptemp + hitemp)
if(hifinal > 79.0):
hi = -42.379 + 2.04901523 * float(Temperature) + 10.14333127 * RHumidity2 - 0.22475541 * float(Temperature) * RHumidity2 - 6.83783 * (math.pow(10, -3)) * (math.pow(float(Temperature), 2)) - 5.481717 * (math.pow(10, -2)) * (math.pow(RHumidity2, 2)) + 1.22874 * (
math.pow(10, -3)) * (math.pow(float(Temperature), 2)) * RHumidity2 + 8.5282 * (math.pow(10, -4)) * float(Temperature) * (math.pow(RHumidity2, 2)) - 1.99 * (math.pow(10, -6)) * (math.pow(float(Temperature), 2)) * (math.pow(RHumidity2, 2))
if((RHumidity2 <= 13.0) and (Temperature >= 80.0) and (Temperature <= 112.0)):
adj1 = (13.0 - RHumidity2) / 4.0
adj2 = math.sqrt((17.0 - abs(Temperature - 95.0)) / 17.0)
adj = adj1 * adj2
hi = hi - adj
elif((RHumidity2 > 85.0) and (Temperature >= 80.0) and (Temperature <= 87.0)):
adj1 = (RHumidity2 - 85.0) / 10.0
adj2 = (87.0 - float(Temperature)) / 5.0
adj = adj1 * adj2
hi = hi + adj
else:
hi = hifinal
heatindexret.update({
'Fahrenheit': "{:0.2f}".format(float(hi)),
'Celsius': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['CelsiusFull'])),
'Rankine': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RankineFull'])),
'Kelvin': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['KelvinFull'])),
'Delisle': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['DelisleFull'])),
'Newton': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['NewtonFull'])),
'Reaumur': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['ReaumurFull'])),
'Romer': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RomerFull'])),
'FahrenheitFull': float(hi),
'CelsiusFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['CelsiusFull']),
'RankineFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RankineFull']),
'KelvinFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['KelvinFull']),
'DelisleFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['DelisleFull']),
'NewtonFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['NewtonFull']),
'ReaumurFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['ReaumurFull']),
'RomerFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RomerFull']),
'FahrenheitRounded': RoundToInt(float(hi)),
'CelsiusRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['CelsiusFull']),
'RankineRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RankineFull']),
'KelvinRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['KelvinFull']),
'DelisleRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['DelisleFull']),
'NewtonRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['NewtonFull']),
'ReaumurRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['ReaumurFull']),
'RomerRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RomerFull'])
})
return heatindexret
def HeatIndexByDewPointFahrenheit(Temperature, DewPointTemp):
return HeatIndexByDewPoint(Temperature, DewPointTemp, "Fahrenheit")
def HeatIndexByDewPointCelsius(Temperature, DewPointTemp):
return HeatIndexByDewPoint(Temperature, DewPointTemp, "Celsius")
def HeatIndexByRelativeHumidity(Temperature, Humidity, TempUnit="Fahrenheit"):
TempUnit = TempUnit.capitalize()
heatindexret = {}
if(TempUnit != "Fahrenheit" and TempUnit != "Celsius"):
return False
if(TempUnit == "Celsius"):
Temperature = ConvertTempUnits(float(Temperature), "Celsius", "Fahrenheit")[
'FahrenheitFull']
TempUnit = "Fahrenheit"
if(TempUnit == "Fahrenheit"):
hitemp = 61.0 + ((float(Temperature) - 68.0) * 1.2) + \
(float(Humidity) * 0.094)
fptemp = float(float(Temperature))
hifinal = 0.5 * (fptemp + hitemp)
if(hifinal > 79.0):
hi = -42.379 + 2.04901523 * float(Temperature) + 10.14333127 * float(Humidity) - 0.22475541 * float(Temperature) * float(Humidity) - 6.83783 * (math.pow(10, -3)) * (math.pow(float(Temperature), 2)) - 5.481717 * (math.pow(10, -2)) * (math.pow(float(Humidity), 2))+1.22874 * (
math.pow(10, -3)) * (math.pow(float(Temperature), 2)) * float(Humidity)+8.5282 * (math.pow(10, -4)) * float(Temperature) * (math.pow(float(Humidity), 2)) - 1.99 * (math.pow(10, -6)) * (math.pow(float(Temperature), 2)) * (math.pow(float(Humidity), 2))
if((float(Humidity) <= 13) and (float(Temperature) >= 80.0) and (float(Temperature) <= 112.0)):
adj1 = (13.0 - float(Humidity)) / 4.0
adj2 = math.sqrt(
(17.0 - abs(float(Temperature) - 95.0)) / 17.0)
adj = adj1 * adj2
hi = hi - adj
elif ((float(Humidity) > 85.0) and (float(Temperature) >= 80.0) and (float(Temperature) <= 87.0)):
adj1 = (float(Humidity) - 85.0) / 10.0
adj2 = (87.0 - float(Temperature)) / 5.0
adj = adj1 * adj2
hi = hi + adj
else:
hi = hifinal
heatindexret.update({
'Fahrenheit': "{:0.2f}".format(float(hi)),
'Celsius': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['CelsiusFull'])),
'Rankine': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RankineFull'])),
'Kelvin': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['KelvinFull'])),
'Delisle': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['DelisleFull'])),
'Newton': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['NewtonFull'])),
'Reaumur': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['ReaumurFull'])),
'Romer': "{:0.2f}".format(float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RomerFull'])),
'FahrenheitFull': float(hi),
'CelsiusFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['CelsiusFull']),
'RankineFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RankineFull']),
'KelvinFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['KelvinFull']),
'DelisleFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['DelisleFull']),
'NewtonFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['NewtonFull']),
'ReaumurFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['ReaumurFull']),
'RomerFull': float(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RomerFull']),
'FahrenheitRounded': RoundToInt(float(hi)),
'CelsiusRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['CelsiusFull']),
'RankineRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RankineFull']),
'KelvinRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['KelvinFull']),
'DelisleRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['DelisleFull']),
'NewtonRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['NewtonFull']),
'ReaumurRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['ReaumurFull']),
'RomerRounded': RoundToInt(ConvertTempUnits(float(hi), "Fahrenheit", "Celsius")['RomerFull'])
})
return heatindexret
def HeatIndexByRelativeHumidityFahrenheit(Temperature, Humidity):
return HeatIndexByRelativeHumidity(Temperature, Humidity, "Fahrenheit")
def HeatIndexByRelativeHumidityCelsius(Temperature, Humidity):
return HeatIndexByRelativeHumidity(Temperature, Humidity, "Celsius")
def HeatIndexByRelativeHumidityGenXML(TempUnit="Fahrenheit", OutputFile="-"):
TempUnit = TempUnit.capitalize()
mintemp = 80
maxtemp = 110
tempstart = 80
minhumid = 40
maxhumid = 100
humidstart = 40
humidityout = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE noaahic [\n<!ELEMENT noaahic (hic)*>\n<!ELEMENT hic EMPTY>\n<!ATTLIST hic temperaturef CDATA #IMPLIED>\n<!ATTLIST hic temperaturec CDATA #IMPLIED>\n<!ATTLIST hic temperaturer CDATA #IMPLIED>\n<!ATTLIST hic temperaturek CDATA #IMPLIED>\n<!ATTLIST hic temperatured CDATA #IMPLIED>\n<!ATTLIST hic temperaturen CDATA #IMPLIED>\n<!ATTLIST hic temperaturere CDATA #IMPLIED>\n<!ATTLIST hic temperaturero CDATA #IMPLIED>\n<!ATTLIST hic humidity CDATA #IMPLIED>\n<!ATTLIST hic humidityf CDATA #IMPLIED>\n<!ATTLIST hic humidityc CDATA #IMPLIED>\n<!ATTLIST hic humidityr CDATA #IMPLIED>\n<!ATTLIST hic humidityk CDATA #IMPLIED>\n<!ATTLIST hic humidityd CDATA #IMPLIED>\n<!ATTLIST hic humidityn CDATA #IMPLIED>\n<!ATTLIST hic humidityre CDATA #IMPLIED>\n<!ATTLIST hic humidityro CDATA #IMPLIED>\n<!ATTLIST hic heatlevelnum CDATA #IMPLIED>\n<!ATTLIST hic heatlevel CDATA #IMPLIED>\n]>\n<noaahic>\n"
while(humidstart <= maxhumid):
tempstart = 80
while(tempstart <= maxtemp):
getwcval = HeatIndexByRelativeHumidity(
tempstart, humidstart, TempUnit)
if(TempUnit == "Fahrenheit"):
gettuval = ConvertTempUnits(tempstart, "Fahrenheit", "Celsius")
if(TempUnit == "Celsius"):
gettuval = ConvertTempUnits(tempstart, "Celsius", "Fahrenheit")
if((humidstart == 40 and tempstart >= 80 and tempstart <= 88) or
(humidstart == 45 and tempstart >= 80 and tempstart <= 88) or
(humidstart == 50 and tempstart >= 80 and tempstart <= 86) or
(humidstart == 55 and tempstart >= 80 and tempstart <= 86) or
(humidstart == 60 and tempstart >= 80 and tempstart <= 84) or
(humidstart == 65 and tempstart >= 80 and tempstart <= 84) or
(humidstart == 70 and tempstart >= 80 and tempstart <= 82) or
(humidstart == 75 and tempstart >= 80 and tempstart <= 82) or
(humidstart == 80 and tempstart >= 80 and tempstart <= 82) or
(humidstart == 85 and tempstart >= 80 and tempstart <= 82) or
(humidstart == 90 and tempstart >= 80 and tempstart <= 80) or
(humidstart == 95 and tempstart >= 80 and tempstart <= 80) or
(humidstart == 100 and tempstart >= 80 and tempstart <= 80)):
humidityout = humidityout + " <hic temperaturef=\""+str(gettuval['FahrenheitRounded'])+"\" temperaturec=\""+str(gettuval['CelsiusRounded'])+"\" temperaturer=\""+str(gettuval['RankineRounded'])+"\" temperaturek=\""+str(gettuval['KelvinRounded'])+"\" temperatured=\""+str(gettuval['DelisleRounded'])+"\" temperaturen=\""+str(gettuval['NewtonRounded'])+"\" temperaturere=\""+str(gettuval['ReaumurRounded'])+"\" temperaturero=\""+str(gettuval['RomerRounded'])+"\" humidity=\""+str(
humidstart)+"\" humidityf=\""+str(getwcval['FahrenheitRounded'])+"\" humidityc=\""+str(getwcval['CelsiusRounded'])+"\" humidityr=\""+str(getwcval['RankineRounded'])+"\" humidityk=\""+str(getwcval['KelvinRounded'])+"\" humidityd=\""+str(getwcval['DelisleRounded'])+"\" humidityn=\""+str(getwcval['NewtonRounded'])+"\" humidityre=\""+str(getwcval['ReaumurRounded'])+"\" humidityro=\""+str(getwcval['RomerRounded'])+"\" heatlevelnum=\"0\" heatlevel=\"Caution\" />\n"
if((humidstart == 40 and tempstart >= 90 and tempstart <= 96) or
(humidstart == 45 and tempstart >= 90 and tempstart <= 94) or
(humidstart == 50 and tempstart >= 88 and tempstart <= 94) or
(humidstart == 55 and tempstart >= 88 and tempstart <= 92) or
(humidstart == 60 and tempstart >= 86 and tempstart <= 90) or
(humidstart == 65 and tempstart >= 86 and tempstart <= 90) or
(humidstart == 70 and tempstart >= 86 and tempstart <= 88) or
(humidstart == 75 and tempstart >= 84 and tempstart <= 86) or
(humidstart == 80 and tempstart >= 84 and tempstart <= 86) or
(humidstart == 85 and tempstart >= 84 and tempstart <= 86) or
(humidstart == 90 and tempstart >= 82 and tempstart <= 84) or
(humidstart == 95 and tempstart >= 82 and tempstart <= 84) or
(humidstart == 100 and tempstart >= 82 and tempstart <= 84)):
humidityout = humidityout + " <hic temperaturef=\""+str(gettuval['FahrenheitRounded'])+"\" temperaturec=\""+str(gettuval['CelsiusRounded'])+"\" temperaturer=\""+str(gettuval['RankineRounded'])+"\" temperaturek=\""+str(gettuval['KelvinRounded'])+"\" temperatured=\""+str(gettuval['DelisleRounded'])+"\" temperaturen=\""+str(gettuval['NewtonRounded'])+"\" temperaturere=\""+str(gettuval['ReaumurRounded'])+"\" temperaturero=\""+str(gettuval['RomerRounded'])+"\" humidity=\""+str(
humidstart)+"\" humidityf=\""+str(getwcval['FahrenheitRounded'])+"\" humidityc=\""+str(getwcval['CelsiusRounded'])+"\" humidityr=\""+str(getwcval['RankineRounded'])+"\" humidityk=\""+str(getwcval['KelvinRounded'])+"\" humidityd=\""+str(getwcval['DelisleRounded'])+"\" humidityn=\""+str(getwcval['NewtonRounded'])+"\" humidityre=\""+str(getwcval['ReaumurRounded'])+"\" humidityro=\""+str(getwcval['RomerRounded'])+"\" heatlevelnum=\"1\" heatlevel=\"Extreme Caution\" />\n"
if((humidstart == 40 and tempstart >= 98 and tempstart <= 106) or
(humidstart == 45 and tempstart >= 96 and tempstart <= 104) or
(humidstart == 50 and tempstart >= 96 and tempstart <= 102) or
(humidstart == 55 and tempstart >= 94 and tempstart <= 100) or
(humidstart == 60 and tempstart >= 92 and tempstart <= 98) or
(humidstart == 65 and tempstart >= 92 and tempstart <= 96) or
(humidstart == 70 and tempstart >= 90 and tempstart <= 94) or
(humidstart == 75 and tempstart >= 88 and tempstart <= 94) or
(humidstart == 80 and tempstart >= 88 and tempstart <= 92) or
(humidstart == 85 and tempstart >= 88 and tempstart <= 90) or
(humidstart == 90 and tempstart >= 86 and tempstart <= 90) or
(humidstart == 95 and tempstart >= 86 and tempstart <= 88) or
(humidstart == 100 and tempstart >= 86 and tempstart <= 88)):
humidityout = humidityout + " <hic temperaturef=\""+str(gettuval['FahrenheitRounded'])+"\" temperaturec=\""+str(gettuval['CelsiusRounded'])+"\" temperaturer=\""+str(gettuval['RankineRounded'])+"\" temperaturek=\""+str(gettuval['KelvinRounded'])+"\" temperatured=\""+str(gettuval['DelisleRounded'])+"\" temperaturen=\""+str(gettuval['NewtonRounded'])+"\" temperaturere=\""+str(gettuval['ReaumurRounded'])+"\" temperaturero=\""+str(gettuval['RomerRounded'])+"\" humidity=\""+str(
humidstart)+"\" humidityf=\""+str(getwcval['FahrenheitRounded'])+"\" humidityc=\""+str(getwcval['CelsiusRounded'])+"\" humidityr=\""+str(getwcval['RankineRounded'])+"\" humidityk=\""+str(getwcval['KelvinRounded'])+"\" humidityd=\""+str(getwcval['DelisleRounded'])+"\" humidityn=\""+str(getwcval['NewtonRounded'])+"\" humidityre=\""+str(getwcval['ReaumurRounded'])+"\" humidityro=\""+str(getwcval['RomerRounded'])+"\" heatlevelnum=\"2\" heatlevel=\"Danger\" />\n"
if((humidstart == 40 and tempstart >= 108 and tempstart <= 110) or
(humidstart == 45 and tempstart >= 106 and tempstart <= 108) or
(humidstart == 50 and tempstart >= 104 and tempstart <= 106) or
(humidstart == 55 and tempstart >= 102 and tempstart <= 104) or
(humidstart == 60 and tempstart >= 100 and tempstart <= 102) or
(humidstart == 65 and tempstart >= 98 and tempstart <= 100) or
(humidstart == 70 and tempstart >= 96 and tempstart <= 98) or
(humidstart == 75 and tempstart >= 96 and tempstart <= 96) or
(humidstart == 80 and tempstart >= 94 and tempstart <= 94) or
(humidstart == 85 and tempstart >= 92 and tempstart <= 94) or
(humidstart == 90 and tempstart >= 92 and tempstart <= 92) or
(humidstart == 95 and tempstart >= 90 and tempstart <= 90) or
(humidstart == 100 and tempstart >= 90 and tempstart <= 90)):
humidityout = humidityout + " <hic temperaturef=\""+str(gettuval['FahrenheitRounded'])+"\" temperaturec=\""+str(gettuval['CelsiusRounded'])+"\" temperaturer=\""+str(gettuval['RankineRounded'])+"\" temperaturek=\""+str(gettuval['KelvinRounded'])+"\" temperatured=\""+str(gettuval['DelisleRounded'])+"\" temperaturen=\""+str(gettuval['NewtonRounded'])+"\" temperaturere=\""+str(gettuval['ReaumurRounded'])+"\" temperaturero=\""+str(gettuval['RomerRounded'])+"\" humidity=\""+str(
humidstart)+"\" humidityf=\""+str(getwcval['FahrenheitRounded'])+"\" humidityc=\""+str(getwcval['CelsiusRounded'])+"\" humidityr=\""+str(getwcval['RankineRounded'])+"\" humidityk=\""+str(getwcval['KelvinRounded'])+"\" humidityd=\""+str(getwcval['DelisleRounded'])+"\" humidityn=\""+str(getwcval['NewtonRounded'])+"\" humidityre=\""+str(getwcval['ReaumurRounded'])+"\" humidityro=\""+str(getwcval['RomerRounded'])+"\" heatlevelnum=\"3\" heatlevel=\"Extreme Danger\" />\n"
tempstart = tempstart + 2
humidstart = humidstart + 5
humidityout = humidityout + "</noaahic>\n"
if(OutputFile != "-"):
wcof = open(OutputFile, 'w')
wcof.write(humidityout)
wcof.close()
return humidityout
def HeatIndexByRelativeHumidityGenXMLFahrenheitMPH(Temperature, WindSpeed):
return HeatIndexByRelativeHumidityGenXML("Fahrenheit", "MPH", OutputFile)
def HeatIndexByRelativeHumidityGenXMLFahrenheitKMH(Temperature, WindSpeed):
return HeatIndexByRelativeHumidityGenXML("Fahrenheit", "KMH", OutputFile)
def HeatIndexByRelativeHumidityGenXMLCelsiusKMH(Temperature, WindSpeed):
return HeatIndexByRelativeHumidityGenXML("Celsius", "KMH", OutputFile)
def HeatIndexByRelativeHumidityGenXMLCelsiusMPH(Temperature, WindSpeed):
return HeatIndexByRelativeHumidityGenXML("Celsius", "MPH", OutputFile)
def RelativeHumidity(Temperature, DewPointTemp, TempUnit="Fahrenheit"):
TempUnit = TempUnit.capitalize()
relativehumidityret = {}
if(TempUnit != "Fahrenheit" and TempUnit != "Celsius"):
return False
if(TempUnit == "Celsius"):
Temperature = ConvertTempUnits(float(Temperature), "Celsius", "Fahrenheit")[
'FahrenheitFull']
DewPointTemp = ConvertTempUnits(float(DewPointTemp), "Celsius", "Fahrenheit")[
'FahrenheitFull']
TempUnit = "Fahrenheit"
if(TempUnit == "Fahrenheit"):
a = float(Temperature)
b = float(DewPointTemp)
a_c = ConvertTempUnits(float(a), "Fahrenheit", "Celsius")[
'CelsiusFull']
b_c = ConvertTempUnits(float(b), "Fahrenheit", "Celsius")[
'CelsiusFull']
c = 6.11 * math.pow(10, ((7.5 * a_c / (237.7 + a_c))))
d = 6.11 * math.pow(10, ((7.5 * b_c / (237.7 + b_c))))
e = (d / c) * 100
f = (round(e * 100)) / 100
ffull = (e * 100) / 100
relativehumidityret.update({
'RelativeHumidity': "{:0.2f}".format(float(ffull)),
'RelativeHumidityRounded': RoundToInt(float(ffull)),
'RelativeHumidityFull': float(ffull)
})
return relativehumidityret
def RelativeHumidityFahrenheit(Temperature, DewPointTemp):
return RelativeHumidity(Temperature, DewPointTemp, "Fahrenheit")
def RelativeHumidityCelsius(Temperature, Humidity):
return RelativeHumidity(Temperature, DewPointTemp, "Celsius")