-
Notifications
You must be signed in to change notification settings - Fork 3
/
LAF.py
1466 lines (1357 loc) · 58.1 KB
/
LAF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
import datetime
import math
import time
from psychropy import *
import urllib
import pandas as pd
import numpy as np
import MesoPy as Meso
from PyQt5 import QtWebChannel
from PyQt5.QtWidgets import *
#
from GUI_about import *
from GUI_custom_page import *
from GUI_latlonpage import *
from GUI_mainPage import *
from GUI_Networks import *
from GUI_tmy3 import *
from GUI_mw_api_gui import *
from GUI_ack import *
from GUI_license import *
#
from Locations import *
from mw_stations_list import *
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Global Variables
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global lat, long, DS, City, State, Country, elev, wmosn, comm1, tz, refy, lat_mw, long_mw, lat_tmy3, long_tmy3
lat = '0'
long = '0'
DS = '-Not Set-'
City = '-Not Set-'
State = '-Not Set-'
Country = 'USA'
elev = '0'
wmosn = '0'
comm1 = '-'
tz = '0'
lat_mw = 40.767367
long_mw = -111.848007
lat_tmy3 = 40.767367
long_tmy3 = -111.848007
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Text2Vector
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def t2v(text):
line = []
i = 0
while i < len(text):
if text[i].isdigit():
numb = 0
while text[i].isdigit():
numb = numb * 10 + int(text[i])
i = i + 1
if i > len(text) - 1:
break
line.append(numb)
else:
i = i + 1
return line
#
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Read TMY3 file
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def read_tmy3(tmy3_name):
if len(tmy3_name) is 0:
nothing = 1
else:
############################
# Read TMY3 header
############################
f = open(tmy3_name)
global header
header = []
for i in range(0, 8):
line = f.readline()
header.append(line)
f.close()
f2 = open(tmy3_name, 'rt')
first_line = next(csv.reader(f2))
for i in range(0, 4):
next(csv.reader(f2))
comm_line = next(csv.reader(f2))
f2.close()
#
global lat, long, DS, City, State, Country, elev, wmosn, comm1, tz, refy
lat = first_line[6]
long = first_line[7]
DS = 'LAF'
City = first_line[1]
State = first_line[2]
Country = first_line[3]
elev = first_line[9]
wmosn = first_line[5]
comm1 = comm_line[1]
tz = first_line[8]
############################
# Read TMY3 data
############################
data = read_datafile(tmy3_name, 8)
global Y, M, D, HH, MM, Tdb, Tdew, RH, Patm, ExHorRad, ExDirNormRad, HorIR, GHRad, DNRad, DHRad, GHIll, DNIll, DHIll
global HorIR, GHRad, GHIll, DNIll, DHIll, ZenLum, Wdir, Wspeed, TotSkyCover, OpSkyCover, Visib, CeilH, PrecWater
global AerOptDepth, SnowDepth, DSLS, Albedo, LiqPrecDepth, LiqPrecQuant, PresWeathObs, PresWeathCodes
Y = data[:, 0]
M = data[:, 1]
D = data[:, 2]
HH = data[:, 3]
MM = data[:, 4]
Tdb = data[:, 6]
Tdew = data[:, 7]
RH = data[:, 8]
Patm = data[:, 9]
ExHorRad = data[:, 10]
ExDirNormRad = data[:, 11]
HorIR = data[:, 12]
GHRad = data[:, 13]
DNRad = data[:, 14]
DHRad = data[:, 15]
GHIll = data[:, 16]
DNIll = data[:, 17]
DHIll = data[:, 18]
ZenLum = data[:, 19]
Wdir = data[:, 20]
Wspeed = data[:, 21]
TotSkyCover = data[:, 22]
OpSkyCover = data[:, 23]
Visib = data[:, 24]
CeilH = data[:, 25]
PresWeathObs = data[:, 26]
PresWeathCodes = data[:, 27]
PrecWater = data[:, 28]
AerOptDepth = data[:, 29]
SnowDepth = data[:, 30]
DSLS = data[:, 31]
Albedo = data[:, 32]
LiqPrecDepth = data[:, 33]
LiqPrecQuant = data[:, 34]
############################
# Date/Time vector
############################
global DateTime
DateTime = []
for i in range(0, 8760):
dt = str(int(Y[i])) + '/' + str(int(M[i])) + '/' + str(int(D[i])) + ' - ' + str(int(HH[i])) + ':' + str(int(MM[i])) + ':00'
DateTime.append(dt)
############################
return 0
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Read CSV file
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def read_csv(csv_name, var):
global Tdb, Tdew, RH, Patm, Wdir, Wspeed
############################
# CSV file reading
############################
# Cases:
# 0) Tdb + Tdew + RH = 0
# 1) Tdb + Tdew = RH
# 2) Tdb + RH = Tdew
# 3) Tdew + RH = Tdb
# 4) Tdb ---RHtmy3--> Tdew
# 5) RH ---Tdbtmy3--> Tdew
# 6) Tdew ---Tdbtmy3--> RH
#
df = pd.read_csv(csv_name)
dimen = df.shape
n_columns = dimen[1]
columns = []
for i in range(0, n_columns):
col = df.iloc[:, i]
columns.append(col)
data2 = columns
if len(var) > n_columns:
flag_columns = 33
# ONLY 1 VARIABLE CUSTOMIZED
elif len(var) == 1:
flag_columns = 0
for i in range(0, 8760):
if var[0] == 1:
Patm[i] = data2[0][i]
elif var[0] == 2:
RH[i] = data2[0][i]
Tdew[i] = psych(Patm[i], 'Tdb', Tdb[i], 'RH', RH[i] / 100, 'DP', 'SI')
elif var[0] == 3:
Tdew[i] = data2[0][i]
RH[i] = (psych(Patm[i], 'Tdb', Tdb[i], 'DP', Tdew[i], 'RH', 'SI')) * 100
elif var[0] == 4:
Tdb[i] = data2[0][i]
Tdew[i] = psych(Patm[i], 'Tdb', Tdb[i], 'RH', RH[i] / 100, 'DP', 'SI')
elif var[0] == 5:
Wspeed[i] = data2[0][i]
elif var[0] == 6:
Wdir[i] = data2[0][i]
#MORE THAN 1 VARIABLE:
else:
flag_columns = 0
for j in range(0, 8760):
if 4 in var:
if 2 in var:
if 3 in var:
# DO NOT USE ANY PSYCHROMETRIC RELATIONSHIP, NOT NECESSARY
for i in range(0, len(var)):
if var[i] == 1:
Patm[j] = data2[i][j]
elif var[i] == 2:
RH[j] = data2[i][j]
elif var[i] == 3:
Tdew[j] = data2[i][j]
elif var[i] == 4:
Tdb[j] = data2[i][j]
elif var[i] == 5:
Wspeed[j] = data2[i][j]
elif var[i] == 6:
Wdir[j] = data2[i][j]
else:
for i in range(0, len(var)):
if var[i] == 1:
Patm[j] = data2[i][j]
elif var[i] == 2:
RH[j] = data2[i][j]
elif var[i] == 4:
Tdb[j] = data2[i][j]
elif var[i] == 5:
Wspeed[j] = data2[i][j]
elif var[i] == 6:
Wdir[j] = data2[i][j]
Tdew[j] = psych(Patm[j], 'Tdb', Tdb[j], 'RH', RH[j] / 100, 'DP', 'SI')
elif 3 in var:
for i in range(0, len(var)):
if var[i] == 1:
Patm[j] = data2[i][j]
elif var[i] == 4:
Tdb[j] = data2[i][j]
elif var[i] == 5:
Wspeed[j] = data2[i][j]
elif var[i] == 6:
Wdir[j] = data2[i][j]
RH[j] = (psych(Patm[j], 'Tdb', Tdb[j], 'DP', Tdew[j], 'RH', 'SI')) * 100
else:
for i in range(0, len(var)):
if var[i] == 1:
Patm[j] = data2[i][j]
elif var[i] == 2:
RH[j] = data2[i][j]
elif var[i] == 4:
Tdb[j] = data2[i][j]
elif var[i] == 5:
Wspeed[j] = data2[i][j]
elif var[i] == 6:
Wdir[j] = data2[i][j]
Tdew[j] = psych(Patm[j], 'Tdb', Tdb[j], 'RH', RH[j] / 100, 'DP', 'SI')
elif 2 in var:
if 3 in var:
for i in range(0, len(var)):
if var[i] == 1:
Patm[j] = data2[i][j]
elif var[i] == 2:
RH[j] = data2[i][j]
elif var[i] == 3:
Tdew[j] = data2[i][j]
elif var[i] == 5:
Wspeed[j] = data2[i][j]
elif var[i] == 6:
Wdir[j] = data2[i][j]
Tdb[j] = psych(Patm[j], 'DP', Tdew[j], 'RH', RH[j] / 100, 'DP', 'SI')
else:
for i in range(0, len(var)):
if var[i] == 1:
Patm[j] = data2[i][j]
elif var[i] == 2:
RH[j] = data2[i][j]
elif var[i] == 4:
Tdb[j] = data2[i][j]
elif var[i] == 5:
Wspeed[j] = data2[i][j]
elif var[i] == 6:
Wdir[j] = data2[i][j]
Tdew[j] = psych(Patm[j], 'Tdb', Tdb[j], 'RH', RH[j] / 100, 'DP', 'SI')
elif 3 in var:
for i in range(0, len(var)):
if var[i] == 1:
Patm[j] = data2[i][j]
# elif var[i] == 2:
# RH = data2[:, i]
elif var[i] == 3:
Tdew[j] = data2[i][j]
elif var[i] == 4:
Tdb[j] = data2[i][j]
elif var[i] == 5:
Wspeed[j] = data2[i][j]
elif var[i] == 6:
Wdir[j] = data2[i][j]
RH[j] = (psych(Patm[j], 'Tdb', Tdb[j], 'DP', Tdew[j], 'RH', 'SI')) * 100
else:
for i in range(0, len(var)):
if var[i] == 1:
Patm[j] = data2[i][j]
elif var[i] == 5:
Wspeed[j] = data2[i][j]
elif var[i] == 6:
Wdir[j] = data2[i][j]
return flag_columns
#
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Write new EPW file
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def write_epw(save_path):
OPFILE = save_path + '.epw'
ofile = open(OPFILE, "w", newline='')
line1 = 'LOCATION,' + City + ',' + State + ',' + Country + ',customized weather file,' + str(wmosn) + ',' +\
str(lat) + ',' + str(long) + ',' + str(tz) + ',' + str(elev) + '\n'
ofile.write(line1)
ofile.write(header[1])
ofile.write(header[2])
ofile.write(header[3])
ofile.write(header[4])
ofile.write('COMMENTS 1, ' + str(comm1) + '\n')
# ofile.write(header[6])
ofile.write('COMMENTS 2, TMY3 data downloaded Climate.Onebuilding.Org - Data merged with the Localized AMY File Creator (LA'+'F)\n')
ofile.write('DATA PERIODS,1,1,Data,Sunday, 1/1,12/31\n')
#
writer = csv.writer(ofile, delimiter=',')
#
for i in range(0, 8760):
row = [int(Y[i]), int(M[i]), int(D[i]), int(HH[i]), int(MM[i]), DS,
Tdb[i], Tdew[i], RH[i], Patm[i], ExHorRad[i], ExDirNormRad[i], HorIR[i],
GHRad[i], DNRad[i], DHRad[i], GHIll[i], DNIll[i], DHIll[i], ZenLum[i],
Wdir[i], Wspeed[i], TotSkyCover[i], OpSkyCover[i], Visib[i], CeilH[i],
PresWeathObs[i], PresWeathCodes[i], PrecWater[i], AerOptDepth[i], SnowDepth[i],
DSLS[i], Albedo[i], LiqPrecDepth[i], LiqPrecQuant[i]]
writer.writerow(row)
ofile.close()
return 0
#
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Read TMY3 file 2
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def tmy3_reader_select(tmy3_name, csv_name, var, save_path):
OPFILE = save_path
############################
# Read TMY3 header
############################
f = open(tmy3_name)
header = []
for i in range(0, 8):
line = f.readline()
header.append(line)
f.close()
############################
# Read TMY3 data
############################
data = read_datafile(tmy3_name, 8)
# #
global Y, M, D, HH, MM, Tdb, Tdew, RH, Patm, ExHorRad, ExDirNormRad, HorIR, GHRad, DNRad, DHRad, GHIll, DNIll, DHIll
global HorIR, GHRad, GHIll, DNIll, DHIll, ZenLum, Wdir, Wspeed, TotSkyCover, OpSkyCover, Visib, CeilH, PrecWater
global AerOptDepth, SnowDepth, DSLS, Albedo, LiqPrecDepth, LiqPrecQuant
Y = data[:, 0]
M = data[:, 1]
D = data[:, 2]
HH = data[:, 3]
MM = data[:, 4]
Tdb = data[:, 6]
Tdew = data[:, 7]
RH = data[:, 8]
Patm = data[:, 9]
ExHorRad = data[:, 10]
ExDirNormRad = data[:, 11]
HorIR = data[:, 12]
GHRad = data[:, 13]
DNRad = data[:, 14]
DHRad = data[:, 15]
GHIll = data[:, 16]
DNIll = data[:, 17]
DHIll = data[:, 18]
ZenLum = data[:, 19]
Wdir = data[:, 20]
Wspeed = data[:, 21]
TotSkyCover = data[:, 22]
OpSkyCover = data[:, 23]
Visib = data[:, 24]
CeilH = data[:, 25]
PresWeathObs = data[:, 26]
PresWeathCodes = data[:, 27]
PrecWater = data[:, 28]
AerOptDepth = data[:, 29]
SnowDepth = data[:, 30]
DSLS = data[:, 31]
Albedo = data[:, 32]
LiqPrecDepth = data[:, 33]
LiqPrecQuant = data[:, 34]
############################
# CSV file reading
############################
data2 = read_datafile(csv_name, 1)
#
flag = 0
for i in range(0, len(var)-1):
if var == 1:
Patm = data2[:, i]
elif var[i] == 2:
RH = data2[:, i]
elif var[i] == 3:
Tdew = data2[:, i]
elif var[i] == 4:
Tdb = data2[:, i]
elif var[i] == 5:
Wspeed = data2[:, i]
elif var[i] == 6:
Wdir = data2[:, i]
############################
# Date/Time vector
############################
global DateTime
DateTime = []
for i in range(0, 8760):
dt = str(int(Y[i])) + '/' + str(int(M[i])) + '/' + str(int(D[i])) + ' - ' + str(int(HH[i])) + ':' + str(int(MM[i])) + ':00'
DateTime.append(dt)
############################
ofile = open(OPFILE, "w")
line1 = 'LOCATION,' + City + ',' + State + ',' + Country + ',customized weather file,' + str(wmosn) + ',' +\
str(lat) + ',' + str(long) + ',' + str(tz) + ',' + str(elev) + '\n'
ofile.write(line1)
ofile.write(header[1])
ofile.write(header[2])
ofile.write(header[3])
ofile.write(header[4])
ofile.write('COMMENTS 1,' + str(comm1) + '\n')
ofile.write(header[6])
ofile.write('DATA PERIODS,1,1,Data,Sunday, 1/ 1,12/31\n')
#
writer = csv.writer(ofile, delimiter=',')
#
for i in range(0, 8760):
row = [int(Y[i]), int(M[i]), int(D[i]), int(HH[i]), int(MM[i]), DS, Tdb[i], Tdew[i], RH[i], Patm[i],
ExHorRad[i],
ExDirNormRad[i], HorIR[i], GHRad[i], DNRad[i], DHRad[i], GHIll[i], DNIll[i], DHIll[i], HorIR[i],
GHRad[i],
GHIll[i], DNIll[i], DHIll[i], ZenLum[i], Wdir[i], Wspeed[i], TotSkyCover[i], OpSkyCover[i],
Visib[i],
CeilH[i],
PrecWater[i], AerOptDepth[i], SnowDepth[i], DSLS[i], Albedo[i], LiqPrecDepth[i], LiqPrecQuant[i]]
writer.writerow(row)
ofile.close()
return 0
#
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Read file
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def read_datafile(file_name, skiplines):
data = numpy.genfromtxt(file_name, delimiter=',', skip_header=skiplines)
return data
#
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Main Page
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
class MainPage(QMainWindow):
def __init__(self):
super().__init__()
self.mainpage = Ui_mainpage() # The name of my top level object is MainWindow
self.mainpage.setupUi(self)
self.mainpage.custom_button.clicked.connect(self.open_custom)
self.mainpage.mesowest.clicked.connect(self.open_mesowest)
self.mainpage.About_label.mousePressEvent = self.open_about
self.mainpage.tmy3_button.clicked.connect(self.open_tmy3)
def open_custom(self):
self.custom = CustomEPW()
self.custom.show()
def open_tmy3(self):
try:
urllib.request.urlopen('http://google.com')
self.tmy3page = tmy3_page()
self.tmy3page.show()
except:
QMessageBox.warning(self, 'No Internet connection',
"Check your Internet connection!\nI need to access the web to show you the TMY3 locations.")
def open_mesowest(self):
try:
urllib.request.urlopen('http://google.com')
self.mw = MW_Download()
self.mw.show()
except:
QMessageBox.warning(self, 'No Internet connection',
"Check your Internet connection!\nI need to access the web to show you the MesoWest locations.")
def open_about(self, event):
self.about_page = About()
self.about_page.show()
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# TMY3 - MAP
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def _downloadRequested(item): # QWebEngineDownloadItem
# self.license_page.textBrowser.setOpenExternalLinks(True)
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
#
global pathsave_custom
pathsave_custom = QFileDialog.getSaveFileName(None, "Select destination folder and file name", "", "Zip file (*.zip)",
options=options)[0]
print('downloading to', item.path())
item.setPath(pathsave_custom + '.zip')
print('downloading to', item.path())
print(item)
print(type(item))
item.accept()
save_path = item.path()
class tmy3_page(QMainWindow):
def __init__(self):
super().__init__()
self.map_tmy3 = Ui_tmy3page()
self.map_tmy3.setupUi(self)
self.map_tmy3.html_code.loadFinished.connect(self.onLoad)
self.map_tmy3.html_code.setHtml('''
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=yes" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?key=AIzaSyCi_p9RIzuQ6my0jEklidpxDrAXuNX_JTQ">
</script>
<script type="text/javascript">
var map;
function initialize() {
var latlng = new google.maps.LatLng(40.767367, -111.848007);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
}
function addMarker(lat, lon, city, url) {
var newmarker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
map: map,
title: city
});
newmarker['infowindow'] = new google.maps.InfoWindow({
content: url
});
google.maps.event.addListener(newmarker, 'click', function() {
this['infowindow'].open(map, this);
});
}
</script>
</head>
<body onload="initialize();">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
''')
self.map_tmy3.html_code.page().profile().downloadRequested.connect(_downloadRequested)
def onLoad(self):
QtCore.QTimer.singleShot(1000, self.save_fun)
def save_fun(self):
state = locations_col(1)
cities = locations_col(2)
type = locations_col(3)
latitudes = locations_col(4)
longitudes = locations_col(5)
links = locations_col(6)
names = []
address = []
for i in range(0, len(state)):
names.append(cities[i] + ", " + state[i])
print(links[i])
address.append('<div id="content">' +
'<div id="siteNotice">' +
'</div>' +
'<h1 id="firstHeading" class="firstHeading">' + names[i] + '</h1>' +
'<div id="bodyContent">' +
'<p> Type: ' + type[i] + '</p>' +
'<p> Latitude: ' + str(latitudes[i]) + '</p>' +
'<p> Longitude: ' + str(longitudes[i]) + '</p>' +
'<p><a href="' + links[i] + '">' +
'Download</a> ' +
'.</p>' +
'</div>' +
'</div>')
argument = "addMarker(" + str(latitudes[i]) + "," + str(longitudes[i]) + ",'" + names[i] + "','" + \
address[i] + "')"
self.map_tmy3.html_code.page().runJavaScript(argument)
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# MesoWest
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
class MW_Download(QMainWindow):
def __init__(self):
super().__init__()
global year_start
year_start = 2015
self.latitude_marker = 40.767367
self.longitude_marker = -111.848007
self.radius = 5
self.mwapi = Ui_mw_page() # The name of my top level object is MainWindow
self.mwapi.setupUi(self)
channel = QtWebChannel.QWebChannel(self.mwapi.html_code.page())
self.mwapi.html_code.page().setWebChannel(channel)
channel.registerObject("jshelper", self)
self.mwapi.html_code.setHtml('''
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=yes"/>
<script src="qrc:///qtwebchannel/qwebchannel.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=AIzaSyCi_p9RIzuQ6my0jEklidpxDrAXuNX_JTQ"></script>
<!--<script type="text/javascript" src="useless.js"></script>-->
<script type="text/javascript">
var jshelper;
new QWebChannel(qt.webChannelTransport, function (channel) {
jshelper = channel.objects.jshelper;
});
function geocodePosition(pos) {
geocoder.geocode({
latLng: pos
}, function (responses) {
if (responses && responses.length > 0) {
updateMarkerAddress(responses[0].formatted_address);
} else {
updateMarkerAddress('Cannot determine address at this location.');
}
});
}
function updateMarkerStatus(str) {
document.getElementById('markerStatus').innerHTML = str;
}
function updateMarkerPosition(latLng) {
document.getElementById('info').innerHTML = [
latLng.lat(),
latLng.lng()
].join(', ');
}
function updateMarkerAddress(str) {
document.getElementById('address').innerHTML = str;
}
var geocoder = new google.maps.Geocoder();
var map;
var goldStar = {
path: 'M 125,5 155,90 245,90 175,145 200,230 125,180 50,230 75,145 5,90 95,90 z',
fillColor: 'yellow',
fillOpacity: 0.8,
scale: 0.1,
strokeColor: 'gold',
strokeWeight: 1
};
function addMarker(lat, lon, city, url) {
var newmarker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
icon: goldStar,
map: map,
title: city
});
newmarker['infowindow'] = new google.maps.InfoWindow({
content: url
});
google.maps.event.addListener(newmarker, 'click', function () {
this['infowindow'].open(map, this);
});
}
function initialize(lat_init, long_init) {
var latLng = new google.maps.LatLng(lat_init, long_init);
// function initialize() {
// var latLng = new google.maps.LatLng(40.767367, -111.848007);
// create as a global variable
map = new google.maps.Map(document.getElementById('mapCanvas'), {
zoom: 11,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: latLng,
title: 'Point A',
map: map,
draggable: true
});
// Update current position info.
updateMarkerPosition(latLng);
geocodePosition(latLng);
// Add dragging event listeners.
google.maps.event.addListener(marker, 'dragstart', function () {
updateMarkerAddress('Dragging...');
});
google.maps.event.addListener(marker, 'drag', function () {
updateMarkerStatus('Dragging...');
updateMarkerPosition(marker.getPosition());
jshelper.markerMoved(marker.position.lat(), marker.position.lng());
});
google.maps.event.addListener(marker, 'dragend', function () {
updateMarkerStatus('Drag ended');
geocodePosition(marker.getPosition());
});
// return latLng
}
// Onload handler to fire off the app.
// google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<style>
#mapCanvas {
width: 102%;
height: 102%;
float: left;
/*margin-left: -7px;*/
/*margin-right: -10px;*/
/*margin-top: -7px;*/
/*margin-bottom: -10px;*/
}
/*#infoPanel {*/
/*float: left;*/
/*margin-left: 20px;*/
/*}*/
/*#infoPanel div {*/
/*margin-bottom: 10px;*/
/*}*/
</style>
<span style="font-size: small; color: black; font-family: verdana; "></span>
<div id="mapCanvas"></div>
<div id="infoPanel">
<span style="font-size: small; color: black; font-family: verdana; "></span>
<!-- <b>Marker status:</b> -->
<div id="markerStatus"><i>Click and drag the marker.</i></div>
<!--<span style="font-size: small; color: black; font-family: verdana; "></span>-->
<!--<b>Current position:</b>-->
<div id="info"></div>
<!--<b>Closest matching address:</b>-->
<!--<div id="address"></div>-->
</div>
</body>
</html>
''')
self.mwapi.rad_scan.valueChanged[str].connect(self.rad_fun)
self.mwapi.html_code.loadFinished.connect(self.onLoad)
self.mwapi.update_map.clicked.connect(self.add_stars)
self.mwapi.html_code.page().profile().downloadRequested.connect(_downloadRequested)
self.mwapi.year_mw.valueChanged[str].connect(self.y_start)
self.mwapi.year_mw_2.valueChanged[str].connect(self.y_end)
self.mwapi.download_button.clicked.connect(self.download_mw)
self.mwapi.networks.clicked.connect(self.nw_info)
@QtCore.pyqtSlot(float, float)
def markerMoved(self, lat_marker, lng_marker):
global latitude_marker, longitude_marker
self.latitude_marker = lat_marker
self.longitude_marker = lng_marker
self.mwapi.le_lat.setText(str(self.latitude_marker))
self.mwapi.le_long.setText(str(self.longitude_marker))
print(self.latitude_marker)
print(self.longitude_marker)
def rad_fun(self, text):
global rad_mw
self.radius = float(text)
rad_mw = self.radius
print(rad_mw)
if rad_mw > 10:
Area_rad_mw = math.pi * rad_mw ** 2
message_rad = 'Be aware you are scanning an area of ' + str(
float("{0:.2f}".format(Area_rad_mw))) + ' squared miles, you may want to reduce the radius'
QMessageBox.warning(None, 'Large Radius', message_rad)
def nw_info(self):
self.nw_class = NW()
self.nw_class.show()
def onLoad(self):
QtCore.QTimer.singleShot(1000, self.add_stars)
def add_stars(self):
print(self.latitude_marker, self.latitude_marker)
argument_init = "initialize('" + str(self.latitude_marker) + "','" + str(self.longitude_marker) + "')"
self.mwapi.html_code.page().runJavaScript(argument_init)
date1 = year_start * 100000000 + 1 * 1000000 + 1 * 10000
date2 = year_start * 100000000 + 1 * 1000000 + 2 * 10000 + 100
names = []
address = []
[lat_station, long_station, name_st, distance, network, POR, SensVars] = show_mw_stats(self.latitude_marker, self.longitude_marker, self.radius, str(date1), str(date2))
if not long_station:
nothing = 1
else:
for i in range(0, len(long_station)):
address.append('<div id="content">' +
'<div id="siteNotice">' +
'</div>' +
'<h1 id="firstHeading" class="firstHeading">' + name_st[i] + '</h1>' +
'<div id="bodyContent">' +
'<p> Latitude: ' + str(lat_station[i]) + '</p>' +
'<p> Longitude: ' + str(long_station[i]) + '</p>' +
'<p> Distance from marker: ' + str(distance[i]) + ' miles</p>' +
'<p> Network ID: ' + str(network[i]) + '</p>' +
'<p> Period of Record -> ' + str(POR[i]) + '</p>' +
'<p> Sensor Variables: ' + str(SensVars[i]) + '</p>' +
'</div>' +
'</div>')
argument = "addMarker(" + str(lat_station[i]) + "," + str(long_station[i]) + ",'" + name_st[i] + "','" + \
address[i] + "')"
self.mwapi.html_code.page().runJavaScript(argument)
def y_start(self, text):
global year_start
year_start = int(text)
def y_end(self, text):
global year_end
year_end = int(text)
def path_fun(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
#
global path_mw
path_mw = QFileDialog.getSaveFileName(self, "Select destination folder and file name", "", "CSV files (*.csv)", options=options)[0]
def Date(self):
now = datetime.datetime.now()
ThisYear = int(now.year)
if 'year_start' in globals():
nothing = 1
else:
global year_start
year_start = 2015
if 'year_end' in globals():
nothing = 1
else:
global year_end
year_end = 2015
Delta = ThisYear - int(year_end)
if Delta > 0:
if year_start > year_end:
QMessageBox.warning(self, 'Wrong Year', "Wait, we can't go back in time yet!\n Correct the years to simulate")
else:
self.flag_date = 3
else:
QMessageBox.warning(self, 'Wrong Year', "Wait, we can't forecast the future yet!\n Chose another year")
def check_fun(self, inp):
if inp == "Atmospheric pressure [Pa]":
return 1
elif inp == "Relative humidity [%]":
return 2
elif inp == "Dewpoint Temperature [°C]":
return 3
elif inp == "Dry Bulb Temperature [°C]":
return 4
elif inp == "Wind speed [m/s]":
return 5
elif inp == "Wind Direction [Deg]":
return 6
else:
return 99
def variable_list(self):
# If checkbox is checked, append number of the chosen variable in the option to the variables_mw
variables_mw = []
list_nw = []
check_nw = 0
if self.mwapi.checkBox1.isChecked():
variables_mw.append(self.check_fun(self.mwapi.option1.currentText()))
netw1 = t2v(self.mwapi.lineEdit_1.text())
list_nw.append(netw1)
if not netw1:
check_nw = 1
if self.mwapi.checkBox2.isChecked():
variables_mw.append(self.check_fun(self.mwapi.option2.currentText()))
netw2 = t2v(self.mwapi.lineEdit_2.text())
list_nw.append(netw2)
if not netw2:
check_nw = 1
if self.mwapi.checkBox3.isChecked():
variables_mw.append(self.check_fun(self.mwapi.option3.currentText()))
netw3 = t2v(self.mwapi.lineEdit_3.text())
list_nw.append(netw3)
if not netw3:
check_nw = 1
if self.mwapi.checkBox4.isChecked():
variables_mw.append(self.check_fun(self.mwapi.option4.currentText()))
netw4 = t2v(self.mwapi.lineEdit_4.text())
list_nw.append(netw4)
if not netw4:
check_nw = 1
if self.mwapi.checkBox5.isChecked():
variables_mw.append(self.check_fun(self.mwapi.option5.currentText()))
netw5 = t2v(self.mwapi.lineEdit_5.text())
list_nw.append(netw5)
if not netw5:
check_nw = 1
if self.mwapi.checkBox6.isChecked():
variables_mw.append(self.check_fun(self.mwapi.option6.currentText()))
netw6 = t2v(self.mwapi.lineEdit_6.text())
list_nw.append(netw6)
if not netw6:
check_nw = 1
return variables_mw, list_nw, check_nw
def download_mw(self):
t = time.time()
#
[variables_mw, list_nw, check_nw] = self.variable_list()
#
self.flag_date = 0
self.Date()
if 99 in variables_mw:
QMessageBox.warning(self, 'No Variable Selected', "One or more columns have been selected but no variable has been chosen")
else:
if self.flag_date == 3:
if 'rad_mw' not in globals():
global rad_mw
rad_mw = 5
global variable_flag, nw
variable_names = []
# get variables_mw and for each number get corresponding variable name
for i in range(0, len(variables_mw)):
if variables_mw[i] == 1:
variable_flag = 'pressure'
elif variables_mw[i] == 2:
variable_flag = 'relative_humidity'
elif variables_mw[i] == 3:
variable_flag = 'dew_point_temperature'
elif variables_mw[i] == 4:
variable_flag = 'air_temp'
elif variables_mw[i] == 5:
variable_flag = 'wind_speed'
elif variables_mw[i] == 6:
variable_flag = 'wind_direction'
variable_names.append(variable_flag)
variable_names = np.unique(variable_names)
# obtimezone
token = 'ca01203d0c9746cd998ee8d0007fdf07'
m = Meso(token=token)
YearlyVariable_final = MesoWest_fun2(self.latitude_marker, self.longitude_marker,