-
Notifications
You must be signed in to change notification settings - Fork 0
/
AiresInfoFunctions.py
1999 lines (1800 loc) · 67.3 KB
/
AiresInfoFunctions.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
#if you are having encoding errors, specially in lyon, be sure to force the environment to utf8
#setenv LANGUAGE en_US.UTF-8 ;setenv LC_ALL en_US.UTF-8 ;setenv LANG en_US.UTF-8setenv LC_TYPE en_US.UTF-8
#
#this functions will accept GRAND and AIRES outmode, to give the results in each convention
#it will output the primary zen,azim,energy,primarytype, taken from the .inp file present at input_file_path) (assumed only one .inp file per dir)
#TO DO: treat correctly the different possible primary types, including RASPASS Multi primary
#TO DO: treat correctly the case where a distribution of primary types or energies or angles is put in the input
#TO DO: Check consistency of the output (energy within a range, angles within a range, etc)
#TO DO: have the .sry reader regenerate the summary using AiresSry, if the file is not foun
#6/2019 Matias Tueros, first attempt at python based on original script by Anne Zilles.
#10/2019 Migrated them to make it the official library
#12/2019 Set up on git
#03/2020 Corona Virus
import sys
from sys import argv
import os
import glob
import logging
#this function reads he Aires .sry file and tries to extract information from the simulation parameters
#using the .sry file is preferred to using the .inp files because:
#Output is standarized: you dont know what you can find in an .inp file (leading spaces, commented lines, repeated keywords, etc)
#Output is what really happened, not what the user whished it would happen when he did his crappy .inp file.
#lets break the ReadAiresSry into smaller modules. It has the disadventage of opening, scanning and closing the file each time
#but it adds modularity, and closes the files when it does not use it any more.
#If at some point we need speed, then we could input datafile, and make a wraper for opening the file
AiresPath="/home/tomas/aires/bin"
#AiresPath=os.environ["AIRESBINDIR"]
#AiresPath="/home/mjtueros/AiresRepository/Dropbox/AiresBzr/Aires.19-04-04-ZHAireS-development/zhadl/bin"
def GetZenithAngleFromSry(sry_file,outmode="GRAND"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Primary zenith angle:' in line:
line = line.lstrip()
stripedline=line.split(' ',-1)
zen=float(stripedline[len(stripedline)-2])
if outmode == 'GRAND':
zen = 180-zen #conversion to GRAND convention i.e. pointing towards antenna/propagtion direction
#logging.debug('Found Zenith ' + str(zen))
return zen
try:
zen
except NameError:
zen = 0 #If no zenith angle was included in the input file, AIRES defaults to 0
if outmode == 'GRAND':
zen = 180-0 #that translates to 180 in GRAND
logging.info("Zenith Angle not found in sry file, defaulting to:" + str(zen))
return zen
except:
logging.error("GetZenithAngleFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetAzimuthAngleFromSry(sry_file,outmode="GRAND"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Primary azimuth angle:' in line:
line = line.lstrip()
stripedline=line.split(' ',-1)
azim = float(stripedline[len(stripedline)-2])
if outmode == 'GRAND':
azim=azim+180 #conversion to GRAND convention i.e. pointing towards antenna/propagtion direction
if azim>=360:
azim= azim-360
#logging.debug('Found Azimuth ' + str(azim))
return azim
try:
azim
except NameError:
azim = 0 #If no azimuth angle was included in the input file, AIRES defaults to 0
if outmode == 'GRAND':
azim = 0+180 # that translates to 18
logging.info("Azimuth Angle not found in sry file, defaulting to:" + str(azim))
return azim
except:
logging.error("GetAzimuthAngleFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetEnergyFromSry(sry_file,outmode="GRAND"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Primary energy:' in line:
line = line.lstrip()
stripedline=line.split(' ',-1)
try: #this is to detect if it is the first time we find the string, so that we ignore the following
energy
except NameError:
energy = float(stripedline[len(stripedline)-2])
unit= str(stripedline[len(stripedline)-1])
if unit == "eV\n":
energy = energy *1e-9
if unit == "KeV\n":
energy = energy *1e-6
if unit == "MeV\n":
energy = energy *1e-3
if unit == "GeV\n":
energy = energy
if unit == "TeV\n":
energy = energy *1e3
if unit == "PeV\n":
energy = energy *1e6
if unit == "EeV\n":
energy = energy *1e9
if outmode == 'GRAND': #AIRES mode outputs in GeV, GRAND in EeV
energy = energy * 1e-9
#logging.debug('Found Energy ' + str(energy)) #debug level 1
return energy
try:
energy
except NameError:
logging.error('warning energy not found, Aires has no default value, cannot continue')
exit()
except:
logging.error("GetEnergyFromSry:file not found or invalid:"+sry_file)
raise
return -1
#output is in meters
def GetCorePositionFromInp(inp_file,outmode="N/A"):
try:
datafile=open(inp_file,'r')
with open(inp_file, "r") as datafile:
for line in datafile:
if '#Core Position:' in line:
line = line.lstrip()
stripedline=line.split(':',-1)
stripedline=stripedline[1]
stripedline=stripedline.split(' ',-1)
x=float(stripedline[1])
y=float(stripedline[2])
z=float(stripedline[3])
coreposition=(x,y,z)
return coreposition
try:
coreposition
except NameError:
logging.error('warning core position not found, defaulting to (0,0,0)')
return (0.0,0.0,0.0)
except:
logging.error("GetCorePositionFromInp:file not found or invalid:"+inp_file)
raise
return -1
def GetThinningRelativeEnergyFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Thinning energy:' in line:
line = line.lstrip()
stripedline=line.split('Thinning energy:',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
Thinning=stripedline[0]
Relative=stripedline[1]
if(Relative!="Relative\n"):
logging.error('warning , we only support Relative thinning for now, sorry!. This is easy to implement if you need it!')
return -1
return Thinning
try:
Thinning
except NameError:
logging.error('warning Thinning energy not found, Aires has no default value, cannot continue')
exit()
except:
logging.error("GetThinningRelativeEnergyFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetGammaEnergyCutFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Cut energy for gammas:' in line:
line = line.lstrip()
stripedline=line.split('Cut energy for gammas:',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
energy=stripedline[0]
unit=stripedline[1]
if unit == "eV\n":
energy = energy *1e-6
if unit == "KeV\n":
energy = energy *1e-3
if unit == "MeV\n":
energy = energy
if unit == "GeV\n":
energy = energy *1e3
if unit == "TeV\n":
energy = energy *1e6
if unit == "PeV\n":
energy = energy *1e9
if unit == "EeV\n":
energy = energy *1e12
return energy
try:
energy
except NameError:
logging.error('warning GammaCutEnergy not found, defaulting to 80keV')
return 80+1e-3
except:
logging.error("GetGammaEnergyCutFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetElectronEnergyCutFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Cut energy for e+ e-:' in line:
line = line.lstrip()
stripedline=line.split('Cut energy for e+ e-:',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
energy=stripedline[0]
unit=stripedline[1]
if unit == "eV\n":
energy = energy *1e-6
if unit == "KeV\n":
energy = energy *1e-3
if unit == "MeV\n":
energy = energy
if unit == "GeV\n":
energy = energy *1e3
if unit == "TeV\n":
energy = energy *1e6
if unit == "PeV\n":
energy = energy *1e9
if unit == "EeV\n":
energy = energy *1e12
return energy
try:
energy
except NameError:
logging.error('warning ElectronCutEnergy not found, defaulting to 80keV')
return 80+1e-3
except:
logging.error("GetElectronEnergyCutFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetMuonEnergyCutFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Cut energy for mu+ mu-:' in line:
line = line.lstrip()
stripedline=line.split('Cut energy for mu+ mu-:',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
energy=stripedline[0]
unit=stripedline[1]
if unit == "eV\n":
energy = energy *1e-6
if unit == "KeV\n":
energy = energy *1e-3
if unit == "MeV\n":
energy = energy
if unit == "GeV\n":
energy = energy *1e3
if unit == "TeV\n":
energy = energy *1e6
if unit == "PeV\n":
energy = energy *1e9
if unit == "EeV\n":
energy = energy *1e12
return energy
try:
energy
except NameError:
logging.error('warning MuonCutEnergy not found, defaulting to 10MeV')
return 10
except:
logging.error("GetMuonEnergyCutFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetMesonEnergyCutFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Cut energy for mesons:' in line:
line = line.lstrip()
stripedline=line.split('Cut energy for mesons:',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
energy=stripedline[0]
unit=stripedline[1]
if unit == "eV\n":
energy = energy *1e-6
if unit == "KeV\n":
energy = energy *1e-3
if unit == "MeV\n":
energy = energy
if unit == "GeV\n":
energy = energy *1e3
if unit == "TeV\n":
energy = energy *1e6
if unit == "PeV\n":
energy = energy *1e9
if unit == "EeV\n":
energy = energy *1e12
return energy
try:
energy
except NameError:
logging.error('warning MesonCutEnergy not found, defaulting to 60MeV')
return 60
except:
logging.error("GetMesonEnergyCutFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetNucleonEnergyCutFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Cut energy for nucleons:' in line:
line = line.lstrip()
stripedline=line.split('Cut energy for nucleons:',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
energy=stripedline[0]
unit=stripedline[1]
if unit == "eV\n":
energy = energy *1e-6
if unit == "KeV\n":
energy = energy *1e-3
if unit == "MeV\n":
energy = energy
if unit == "GeV\n":
energy = energy *1e3
if unit == "TeV\n":
energy = energy *1e6
if unit == "PeV\n":
energy = energy *1e9
if unit == "EeV\n":
energy = energy *1e12
return energy
try:
energy
except NameError:
logging.error('warning NucleonCutEnergy not found, defaulting to 60MeV')
return 60
except:
logging.error("GetNucleonEnergyCutFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetPrimaryFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Primary particle:' in line:
line = line.lstrip()
stripedline=line.split(' ',-1)
if(len(stripedline)==3):
primarytype = str(stripedline[len(stripedline)-1])
elif(len(stripedline)==5):
primarytype = str(stripedline[len(stripedline)-3])
elif(len(stripedline)==6):
primarytype = str(stripedline[len(stripedline)-4])
elif(len(stripedline)==7):
primarytype = str(stripedline[len(stripedline)-5])
else:
primarytype = "unknown"
primarytype=primarytype.replace('\n','')
#logging.debug('Found Primary ' + primarytype) #debug level 1
if(outmode=="GRAND"):
#convert to GRAND coding. PDG?
if primarytype=="Proton":
primarytype=2212
if primarytype=="Neutron":
primarytype=2112
if primarytype=="Pi0":
primarytype=111
if primarytype=="Pi+":
primarytype=211
if primarytype=="Pi-":
primarytype=-211
return primarytype
try:
primarytype
except NameError:
logging.error('warning primary not found, Aires has no default value, cannot continue')
exit()
except:
logging.error("GetPrimaryFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetSlantXmaxFromSry(sry_file,outmode="N/A"): #To do. Handle when Xmax is not found, becouse the fit didnt converge
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Sl. depth of max. (g/cm2)' in line:
line = line.lstrip()
stripedline=line.split(' ',-1)
xmax = float(stripedline[len(stripedline)-1])
#logging.debug('Found Xmax ' + str(xmax)) #debug level 1
return xmax
try:
xmax
except NameError:
logging.info('warning xmax not found')
xmax=-1
return xmax
except:
logging.error("GetSlantXmaxFromSry:file not found or invalid:"+sry_file)
raise
return -1
#
#Charged pcles. at maximum
def GetNmaxFromSry(sry_file,outmode="N/A"): #To do. Handle when Xmax is not found, becouse the fit didnt converge
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Charged pcles. at maximum' in line:
line = line.lstrip()
stripedline=line.split(' ',-1)
nmax = float(stripedline[len(stripedline)-1])
#logging.debug('Found Nmax ' + str(nmax)) #debug level 1
return nmax
try:
xmax
except NameError:
logging.info('warning nmax not found')
xmax=-1
return xmax
except:
logging.error("GetNmaxFromSry:file not found or invalid:"+sry_file)
raise
return -1
# Altitude Distance x y z
# Location of max.(Km): 3.612 3.66 0.00 0.57 3.61
def GetKmXmaxFromSry(sry_file,outmode="N/A"): #To do. Handle when Xmax is not found, becouse the fit didnt converge, or becouse this is not ZHAireS, or its latest version
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if ('Location of max.(Km)' in line) or ('Pos. Max.' in line) :
line = line.lstrip()
stripedline=line.split()
kmxmax = float(stripedline[len(stripedline)-5])
distance = float(stripedline[len(stripedline)-4])
x = float(stripedline[len(stripedline)-3])
y = float(stripedline[len(stripedline)-2])
z = float(stripedline[len(stripedline)-1])
logging.debug("Found Xmax altitude " + str(kmxmax) + " distance " + str(distance) + " x:" + str(x) + " y:"+ str(y) + " z:" + str(z) ) #debug level 1
return kmxmax,distance,x,y,z
try:
kmxmax
except NameError:
logging.info('warning distance to xmax not found')
return -1,-1,-1,-1,-1
except:
logging.error("GetKmXmaxFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetExpectedKmXmaxFromSry(sry_file,outmode="N/A"): #To do. Handle when Xmax is not found, becouse the fit didnt converge, or becouse this is not ZHAireS, or its latest version
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Exp Distance To Xmax' in line:
line = line.lstrip()
stripedline=line.split()
kmxmax = float(stripedline[len(stripedline)-2])
logging.debug("Found Expected Xmax distance " + str(kmxmax) ) #debug level 1
return kmxmax
try:
kmxmax
except NameError:
logging.info('warning expected distance to xmax not found')
return -1
except:
logging.error("GetExpectedKmXmaxFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetTaskNameFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Task Name:' in line:
line = line.lstrip()
stripedline=line.split(' ',-1)
taskname=stripedline[len(stripedline)-1]
taskname=taskname.replace('\n','')
#logging.debug("Found taskname " + taskname)
if '...' in taskname:
base=os.path.basename(sry_file)
taskname=os.path.splitext(base)[0]
logging.debug("taskname contained ... (too long), using filename instead")
print("taskname:"+taskname)
return taskname
try:
taskname
except NameError:
logging.error('warning taskname not found, Aires has no default value, cannot continue')
exit()
except:
logging.error("GetTaskNameFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetRandomSeedFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Seed of random generator:' in line:
line = line.lstrip()
stripedline=line.split(' ',-1)
randomseed=stripedline[len(stripedline)-1]
randomseed=randomseed.replace('\n','')
return randomseed
try:
randomseed
except NameError:
logging.error('warning randomseed not found, Aires has no default value, cannot continue')
exit()
except:
logging.error("GetRandomSeedFromSry:file not found or invalid:"+sry_file)
raise
return -1
#output is in meters
def GetGroundAltitudeFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Ground altitude:' in line:
line = line.lstrip()
stripedline=line.split(':',-1)
stripedline=stripedline[1]
stripedline=stripedline.split(' ',-1)
groundalt=float(stripedline[1])
unit=stripedline[2]
if unit == "km":
groundalt=groundalt*1000.0
if unit == "cm":
groundalt=groundalt/100.0
return groundalt
try:
groundalt
except NameError:
logging.error('warning groundalt not found, defaulting to sea level')
return 0
except:
logging.error("GetGroundAltitudeFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetTimeBinFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Time Domain Bin Size:' in line:
line = line.lstrip()
stripedline=line.split('Time Domain Bin Size:',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
timebin=float(stripedline[0])
unit=stripedline[1]
if unit != "sec\n":
logging.error('warning, time bin must be in seconds on the summary file, other units not supported yet')
return -1
return timebin*1e9
try:
timebin
except NameError:
logging.error('warning timebin not found')
return 0
except:
logging.error("GetTimeBinFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetTimeWindowMinFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Antenna Time Window Min:' in line:
line = line.lstrip()
stripedline=line.split('Antenna Time Window Min:',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
timemin=float(stripedline[0])
unit=stripedline[1]
if unit != "sec\n":
logging.error('warning, time window must be in seconds on the summary file, other units not supported yet')
return -1
return timemin*1e9
try:
timemin
except NameError:
logging.error('warning timewindow min not found')
return 0
except:
logging.error("GetTimeWindowMinFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetTimeWindowMaxFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Antenna Time Window Max:' in line:
line = line.lstrip()
stripedline=line.split('Antenna Time Window Max:',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
timemax=float(stripedline[0])
unit=stripedline[1]
if unit != "sec\n":
logging.error('warning, time window must be in seconds on the summary file, other units not supported yet')
return -1
return timemax*1e9
try:
timemax
except NameError:
logging.error('warning timewindow max not found')
return 0
except:
logging.error("GetTimeWindowMaxFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetWeightFactorFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Max. stat. weight factor:' in line:
line = line.lstrip()
stripedline=line.split(':',-1)
stripedline=stripedline[1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
wf=float(stripedline[0])
return wf
try:
wf
except NameError:
logging.error('warning weight factor not found, default is 12')
return 12
except:
logging.error("GetWeightFactorFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetMagneticFieldFromSry(sry_file,outmode="N/A"):
fieldintensity=float(0.0)
fieldinclination=float(0.0)
fielddeclination=float(0.0)
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Geomagnetic field:' in line:
line = line.lstrip()
if 'Off'in line:
fieldintensity=0.0
fieldinclination=0.0
fielddeclination=0.0
else:
stripedline=line.split('Intensity:',-1)
intensityline=stripedline[1]
intensityline=intensityline.lstrip()
stripedline=intensityline.split(' ',-1)
fieldintensity=float(stripedline[0])
if 'I:' in line:
line = line.lstrip()
stripedline=line.split('I:',-1)
inclinationline=stripedline[1]
inclinationline=inclinationline.lstrip()
stripedline=inclinationline.split(' ',-1)
fieldinclination=float(stripedline[0])
stripedline=line.split('D:',-1)
declinationline=stripedline[1]
declinationline=declinationline.lstrip()
stripedline=declinationline.split(' ',-1)
fielddeclination=float(stripedline[0])
try:
fieldintensity
return fieldintensity,fieldinclination,fielddeclination
except NameError:
logging.error('warning MagneticField not found, defaulting to sea level')
return 0,0,0
except:
logging.error("GetMagneticFieldFromSry:file not found or invalid:"+sry_file)
raise
return -1,-1,-1
def GetTotalCPUTimeFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Total CPU time' in line:
line = line.lstrip()
stripedline=line.split(':',-1)
CPUtime=stripedline[len(stripedline)-1]
#logging.debug("Found taskname " + taskname)
CPUtime=CPUtime.replace('\n','')
stripedline=CPUtime.split(' ',-1)
time=0.0
if(len(stripedline)>1):
if(stripedline[-1]=="sec"):
time=time+float(stripedline[-2])
if(stripedline[-1]=="min"):
time=time+60.0*int(stripedline[-2])
if(stripedline[-1]=="hr"):
time=time+60.0*60.0*int(stripedline[-2])
if(len(stripedline)>3):
if(stripedline[-3]=="sec"):
time=time+float(stripedline[-4])
if(stripedline[-3]=="min"):
time=time+60.0*int(stripedline[-4])
if(stripedline[-3]=="hr"):
time=time+60.0*60.0*int(stripedline[-4])
if(len(stripedline)>5):
if(stripedline[-5]=="sec"):
time=time + float(stripedline[-6])
if(stripedline[-5]=="min"):
time=time + 60.0*int(stripedline[-6])
if(stripedline[-5]=="hr"):
time=time + 60.0*60.0*int(stripedline[-6])
CPUtime=time
return CPUtime
try:
CPUtime
except NameError:
logging.error('warning Total CPU time not found')
return -1
except:
logging.error("GetTotalCPUTimeFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetHadronicModelFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Hadronic Mean Free Paths' in line:
line = line.lstrip()
stripedline=line.split(':',-1)
HadronicModel=stripedline[len(stripedline)-1]
#logging.debug("Found taskname " + taskname)
return HadronicModel
try:
HadronicModel
except NameError:
logging.error('warning Hadronic Model not found')
return -1
except:
logging.error("GetHadronicModelFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetRandomSeedFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Seed of random generator:' in line:
line = line.lstrip()
stripedline=line.split(':',-1)
RandomSeed=stripedline[len(stripedline)-1]
#logging.debug("Found taskname " + taskname)
return RandomSeed
try:
#RandomSeedl
pass
except NameError:
logging.error('warning RandomSeed not found')
return -1
except:
logging.error("GetRandomSeedFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetAiresVersionFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'This is AIRES version' in line:
line = line.lstrip()
stripedline=line.split('This is AIRES version',-1)
stripedline=stripedline[-1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
AiresVersion=stripedline[0]
#ogging.debug("Found Version " + AiresVersion)
return AiresVersion
try:
AiresVersion
except NameError:
logging.error('warning Aires Version not found')
return -1
except:
logging.error("GetAiresVersionFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetZHAireSVersionFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'With ZHAireS version' in line:
line = line.lstrip()
stripedline=line.split('With ZHAireS version',-1)
stripedline=stripedline[-1]
stripedline=stripedline.lstrip()
stripedline=stripedline.split(' ',-1)
ZHAiresVersion=stripedline[0]
#ogging.debug("Found Version " + AiresVersion)
return ZHAiresVersion
try:
ZHAiresVersion
except NameError:
logging.error('warning ZHAireS Version not found')
return -1
except:
logging.error("GetZHAireSVersionFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetAtmosphericModelFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Atmospheric model' in line:
line = line.lstrip()
stripedline=line.split(':',-1)
AtmosphericModel=stripedline[len(stripedline)-1]
#logging.debug("Found taskname " + taskname)
return AtmosphericModel
try:
AtmosphericModel
except NameError:
logging.error('warning Atmospheric Model not found')
return -1
except:
logging.error("GetAtmosphericModelFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetRefractionIndexModelFromSry(sry_file,outmode="N/A"): #for aires 19.04.06
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Glasgow-Dale refraction index model' in line:
IndexModel="Glasgow-Dale"
return IndexModel
if 'Exponential refraction index model' in line:
IndexModel="Exponential"
return IndexModel
if 'Constant refraction index model':
IndexModel="Constant"
return IndexModel
try:
IndexModel
except NameError:
logging.error('warning Refraction Index Model not found')
return -1
except:
logging.error("GetRefractionIndexModelFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetSiteFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Site:' in line:
line = line.lstrip()
stripedline=line.split(':',-1)
Site=stripedline[len(stripedline)-1]
#logging.debug("Found taskname " + taskname)
return Site
try:
Site
except NameError:
logging.error('warning Site not found')
return -1
except:
logging.error("GetSiteFromSry:file not found or invalid:"+sry_file)
raise
return -1
def GetLatLongFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if '(Lat:' in line:
line = line.lstrip()
stripedline=line.split(':',-1)
Lat= stripedline[1]
Lat= Lat.lstrip()
Lat= Lat.split(" ",-1)
Lat= Lat[0]
Long=stripedline[2]
Long= Long.lstrip()
Long= Long.split(" ",-1)
Long= Long[0]
return Lat,Long
try:
Lat
Long
except NameError:
logging.error('warning Latitude or Longitude not found')
return -1,-1
except:
logging.error("GetLatLongFromSry:file not found or invalid:"+sry_file)
raise
return -1,-1
def GetDateFromSry(sry_file,outmode="N/A"):
try:
datafile=open(sry_file,'r')
with open(sry_file, "r") as datafile:
for line in datafile:
if 'Date:' in line:
line = line.lstrip()
stripedline=line.split(':',-1)