1 | #! /usr/bin/env python |
---|
2 | import matplotlib.pyplot as mpl |
---|
3 | import ppplot |
---|
4 | import numpy as np |
---|
5 | import scipy.optimize as sciopt |
---|
6 | |
---|
7 | ### SAVED |
---|
8 | #namefile = "/home/aymeric/Big_Data/LES_dd/sav/psfc_f18.ncm2_1.txt" ; drop = False ; typefit=1 |
---|
9 | #namefile = "/home/aymeric/Big_Data/LES_dd/sav/psfc_f18.ncm2_1.txt" ; drop = True ; typefit=2 |
---|
10 | #namefile = "/home/aymeric/Big_Data/LES_dd/sav/psfc_f18.ncm1_1.txt" ; drop = False ; typefit=1 |
---|
11 | #namefile = "/home/aymeric/Big_Data/LES_dd/sav/psfc_f18.ncm1_1.txt" ; drop = True ; typefit=1 |
---|
12 | #namefile = "/home/aymeric/Big_Data/LES_dd/sav/psfc.LMD_LES_MARS.160564.ncm2_1.txt" ; drop = False ; typefit=1 #bof. tous les 10 est mieux. |
---|
13 | # |
---|
14 | ########################################################### |
---|
15 | ##namefile = "/home/aymeric/Big_Data/LES_dd/psfc_f18.ncm1_1.txt" |
---|
16 | ##namefile = "/home/aymeric/Big_Data/LES_dd/psfc_f18.ncm2_1.txt" |
---|
17 | ##namefile = "/home/aymeric/Big_Data/LES_dd/psfc.LMD_LES_MARS.160564.ncm1_1.txt" |
---|
18 | ##namefile = "/home/aymeric/Big_Data/LES_dd/sav/psfc.LMD_LES_MARS.160564.ncm2_1.txt" |
---|
19 | #namefile = "/home/aymeric/Big_Data/LES_dd/press_ustm_exomars.nc1.txt" |
---|
20 | #namefile = "/home/aymeric/Big_Data/LES_dd/sav/press_ustm_exomars.ncm2_1.txt" |
---|
21 | ##namefile = "/home/aymeric/Big_Data/LES_dd/psfc_oldinsight100m.ncm1_1.txt" |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | case = "188324p" |
---|
27 | case = "191798" |
---|
28 | case = "160564p" |
---|
29 | case = "156487" |
---|
30 | case = "2007p" |
---|
31 | case = "13526p" |
---|
32 | case = "172097" |
---|
33 | namefile = "/planeto/aslmd/LESdata/"+case+".ncm1_1.txt" |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | drop = False ; typefit=1 |
---|
38 | #drop = True ; typefit=1 |
---|
39 | #drop = True ; typefit=2 |
---|
40 | ########################################################## |
---|
41 | ## define bins (we expect fit do not depend too much on this -- to be checked) |
---|
42 | nbins = 7 ; www = 3. |
---|
43 | #nbins = 10 ; www = 2.5 |
---|
44 | #nbins = 15 ; www = 2. |
---|
45 | ##nbins = 20 ; www = 1.75 |
---|
46 | ##nbins = 30 ; www = 1.5 |
---|
47 | ##nbins = 50 ; www = 1.2 |
---|
48 | ########################################################## |
---|
49 | limrest = 4. # restrict limit (multiple of dx) |
---|
50 | #limrest = 2. |
---|
51 | #limrest = 3. |
---|
52 | #limrest = 0. |
---|
53 | ########################################################## |
---|
54 | |
---|
55 | # -- functions for fitting |
---|
56 | # -- http://wiki.scipy.org/Cookbook/FittingData |
---|
57 | # power law |
---|
58 | def fitfunc(x,a,b): return a*(x**(-b)) |
---|
59 | # power law + constant |
---|
60 | def fitfunc3(x,a,b,c): return a*(x**(-b)) + c * (x**(-0.5)) |
---|
61 | # exponential law |
---|
62 | def fitfunc2(x,a,b): return a*np.exp(-b*x) |
---|
63 | |
---|
64 | # load data |
---|
65 | data = np.loadtxt(namefile,delimiter=";") |
---|
66 | t = data[:,0] ; s = data[:,1] ; d = data[:,2] |
---|
67 | i = data[:,3] ; j = data[:,4] # int? |
---|
68 | |
---|
69 | # a way to guess resolution |
---|
70 | dx = np.min(s)/2. ; print "resolution: ", dx |
---|
71 | |
---|
72 | # choose a variable |
---|
73 | if drop: var = d |
---|
74 | else: var = s |
---|
75 | |
---|
76 | # restrictions |
---|
77 | restrict = (s > 0) # initialization (True everywhere) |
---|
78 | restrict = restrict*(s >= limrest*dx) # remove lowest sizes (detection limit) |
---|
79 | #restrict = restrict*(np.abs(i-j) <= 6.*dx) # condition sur i,j (width,height) |
---|
80 | #restrict = restrict*(d > 0.9) # limit on drop for size (casse la power law? seulement si keep smaller devils) |
---|
81 | #restrict = restrict*(d > 0.5) |
---|
82 | var = var[restrict] |
---|
83 | |
---|
84 | ## define bins |
---|
85 | zebins = [np.min(var)] |
---|
86 | for i in range(0,nbins): zebins.append(zebins[i]*(www**0.5)) |
---|
87 | zebins = np.array(zebins) |
---|
88 | middle = 0.5*(zebins[1:] + zebins[:-1]) |
---|
89 | binwidth = zebins[1:] - zebins[:-1] |
---|
90 | |
---|
91 | # plot histogram |
---|
92 | yeah = mpl.hist(var,log=True,bins=zebins,normed=True,color='white') ; mpl.xscale('log') |
---|
93 | #yeah = mpl.hist(var,bins=zebins)#,normed=True) |
---|
94 | |
---|
95 | # print info |
---|
96 | print "min %5.2e // max %5.2e" % (np.min(var),np.max(var)) |
---|
97 | for iii in range(len(zebins)-1): |
---|
98 | print "%5.2e in [%5.0f %5.0f] %5.0f" % (yeah[0][iii],zebins[iii],zebins[iii+1],np.abs(zebins[iii+1]-zebins[iii])) |
---|
99 | |
---|
100 | # fitting function to superimpose |
---|
101 | if typefit == 1: xx = sciopt.curve_fit(fitfunc, middle, yeah[0]) |
---|
102 | elif typefit == 2: xx = sciopt.curve_fit(fitfunc2, middle, yeah[0]) |
---|
103 | elif typefit == 3: xx = sciopt.curve_fit(fitfunc3, middle, yeah[0]) |
---|
104 | print "exponent",xx[0][1] |
---|
105 | print "variance %",100.*xx[1][1][1]/xx[0][1] |
---|
106 | |
---|
107 | # plot obtained fit along with actual points |
---|
108 | if typefit == 1: func = fitfunc(middle,xx[0][0],xx[0][1]) |
---|
109 | elif typefit == 2: func = fitfunc2(middle,xx[0][0],xx[0][1]) |
---|
110 | elif typefit == 3: func = fitfunc3(middle,xx[0][0],xx[0][1],xx[0][2]) |
---|
111 | func[func<0]=np.nan |
---|
112 | ind = yeah[0]>0 |
---|
113 | mpl.plot(middle[ind],yeah[0][ind],'k.') |
---|
114 | mpl.plot(middle[ind],func[ind],'r-') |
---|
115 | mpl.plot(middle[ind],func[ind],'r.') |
---|
116 | |
---|
117 | # print fit vs. actual populations |
---|
118 | total = var.shape[0] |
---|
119 | fit = func*binwidth*total |
---|
120 | pop = yeah[0]*binwidth*total |
---|
121 | for iii in range(len(fit)): |
---|
122 | if fit[iii] > 0.99 or pop[iii] != 0: |
---|
123 | print "fit %5.0f actual %5.0f" % (fit[iii],pop[iii]) |
---|
124 | |
---|
125 | # plot settings |
---|
126 | ax = mpl.gca() ; ax.set_xbound(lower=np.min(zebins),upper=np.max(zebins)) |
---|
127 | if drop: mpl.xlabel("Pressure drop (Pa)") ; ax.set_xbound(lower=1.e-1,upper=10.) |
---|
128 | else: mpl.xlabel("Vortex size (m)") ; ax.set_xbound(lower=10.,upper=5000.) |
---|
129 | mpl.ylabel('Population density $n / N w_{bin}$') |
---|
130 | mpl.title("Statistics on "+str(total)+" detected vortices") |
---|
131 | |
---|
132 | # show plot and end |
---|
133 | mpl.show() |
---|
134 | exit() |
---|
135 | |
---|
136 | ################################################################################ |
---|
137 | ################################################################################ |
---|
138 | ################################################################################ |
---|
139 | |
---|
140 | ## UNCOMMENT |
---|
141 | ##import plfit,plpva,plplot |
---|
142 | |
---|
143 | #[alpha, xmin, L] = plfit.plfit(var,'xmin',0.3) |
---|
144 | [alpha, xmin, L] = plfit.plfit(var) |
---|
145 | print alpha,xmin |
---|
146 | |
---|
147 | #a = plpva.plpva(var,0.75,'xmin',0.75) |
---|
148 | #print a |
---|
149 | |
---|
150 | |
---|
151 | h = plplot.plplot(var,xmin,alpha) |
---|
152 | |
---|
153 | ppplot.save(mode="png") |
---|
154 | |
---|
155 | #mpl.loglog(h[0], h[1], 'k--',linewidth=2) |
---|
156 | |
---|
157 | #mpl.show() |
---|
158 | |
---|
159 | |
---|
160 | |
---|