-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnooutputanalyse_cuterr.py
executable file
·95 lines (72 loc) · 2.21 KB
/
nooutputanalyse_cuterr.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
#!/usr/bin/env python
# -*- coding:Utf-8 -*-
import os
import sys
import scipy
import re
from pylab import *
import pylab
def string_to_tblnb(str):
# Match a number [-+]?([0-9]+\.?[0-9]*|\.[0-9]+)([eE][-+]?[0-9]+)?
# return [float(i) for i in re.findall(r'\d+(?:\.\d+)?',str)]
# print re.findall(r'([-+]?([0-9]+\.?[0-9]*|\.[0-9]+)([eE][-+]?[0-9]+)?)',str)
return [float(i[0]) for i in re.findall(r'([-+]?([0-9]+\.?[0-9]*|\.[0-9]+)([eE][-+]?[0-9]+)?)', str)]
if len(sys.argv) == 1:
print "zut", sys.argv
print "you must define a regular expression to check your files"
sys.exit(1)
regex_lect = sys.argv[1]
filenames = [i for i in os.listdir("./")
if (os.path.isfile("./"+i))
and re.match(regex_lect+"$", i)]
if len(filenames) == 0:
print "no match for your file"
sys.exit(1)
datas = []
altitude = array([])
defalt = False
skipped = 0
for i in filenames:
print i
fa = os.popen("grep -ri \"Electron impact ionization error\" "+i).read()
value = string_to_tblnb(fa)[0]
if(abs(value) > 5):
skipped += 1
print fa, " : SKIPPED"
continue
fi = os.popen("grep -ri nan "+i).read()
if(len(fi) > 0):
skipped += 1
continue
tmpdat = pylab.loadtxt("./"+i)
if(not defalt):
defalt = True
altitude = tmpdat[:, 0]
datas.append(tmpdat[:, 1:])
data = array(datas)
# print "bye"
fileintro = open("./"+filenames[0], 'r')
meslignes = []
for lines in fileintro:
if(re.match("^#", lines)):
meslignes.append(lines)
print data.shape
print altitude
(nbstat, nbalt, nbelem) = data.shape
sauvegarde = zeros((nbalt, nbelem*2+1)) # The number of elements corresponds to altitude+ elems+error
sauvegarde[:, 0] = altitude
for elem in range(nbelem):
value = zeros(nbalt)
error = zeros(nbalt)
for alt in range(nbalt):
tbl = data[:, alt, elem]
value[alt] = tbl.mean()
error[alt] = tbl.std()*2
print "position :", elem, 2*elem, 2*elem+1, "max :", nbelem*2
sauvegarde[:, 2*elem+1] = value
sauvegarde[:, 2*elem+2] = error
savetxt("montecarlo.dat", sauvegarde)
print "SKIPPED:", skipped
truc = file("montecarlo.dat", "a")
truc.writelines(meslignes)
truc.close()