Changeset 349 for trunk/MESOSCALE/LMD_MM_MARS/SRC/PYTHON/examples
- Timestamp:
- Nov 5, 2011, 6:54:37 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MESOSCALE/LMD_MM_MARS/SRC/PYTHON/examples/scripts/find_devils.py
r310 r349 27 27 28 28 ### LOAD NETCDF DATA 29 filename = "psfc.nc"29 #filename = "/home/aymeric/Big_Data/psfc.nc" 30 30 nc = Dataset(filename) 31 31 psfc = nc.variables["PSFC"] … … 36 36 allsizesx = [] 37 37 allsizesy = [] 38 depression = [] 38 39 stride = 1 #5 39 40 for i in range(0,shape[0],stride): … … 52 53 fac = 3.5 53 54 #fac = 2.5 55 fac = 3. 54 56 lim = ave - fac*std 55 57 where = np.where(psfc2d < lim) 56 58 ############### END CRITERION 59 60 depression = np.append(depression,np.ravel(psfc2d[where])-ave) 57 61 58 62 lab = np.zeros(np.array(psfc2d).shape) ## points to be treated by the minimum_position routine … … 115 119 allsizesy.sort() 116 120 117 return allsizesx, allsizesy 121 return allsizesx, allsizesy, depression 118 122 119 123 ######################################################################### … … 125 129 import matplotlib.mlab as mlab 126 130 import mymath as mym 131 import myplot as myp 132 133 import plfit 134 import plplot 135 import randht 136 import plpva 127 137 128 138 save = True 129 139 save = False 140 pression = False 141 pression = True 130 142 131 143 if save: 132 allsizesx, allsizesy = getsize("psfc.nc")144 allsizesx, allsizesy, depression = getsize("/home/aymeric/Big_Data/psfc.nc") 133 145 ### sauvegarde texte pour inspection 134 146 mym.writeascii(allsizesx,'allsizex.txt') 135 147 mym.writeascii(allsizesy,'allsizey.txt') 148 mym.writeascii(depression,'alldepression.txt') 136 149 ### sauvegarde binaire pour utilisation python 137 150 myfile = open('allsizex.bin', 'wb') … … 141 154 pickle.dump(allsizesy, myfile) 142 155 myfile.close() 156 myfile = open('alldepression.bin', 'wb') 157 pickle.dump(depression, myfile) 158 myfile.close() 143 159 144 160 ### load files … … 147 163 myfile = open('allsizey.bin', 'r') 148 164 allsizesy = pickle.load(myfile) 149 150 ### append sizes 151 plothist = np.append(allsizesx,allsizesy) 165 myfile = open('alldepression.bin', 'r') 166 depression = pickle.load(myfile) 167 depression = np.array(abs(depression))#*1000. 168 169 ### sizes 170 #plothist = np.append(allsizesx,allsizesy) 152 171 plothist = allsizesx 153 #plothist = allsizesy 172 if pression: plothist = depression 154 173 plothist.sort() 155 156 ### make bins 174 print 'mean ', np.mean(plothist,dtype=np.float64) 175 print 'std ', np.std(plothist,dtype=np.float64) 176 print 'max ', np.max(plothist) 177 print 'min ', np.min(plothist) 178 print 'len ', len(plothist) 179 180 181 ### MAKE BINS 157 182 nbins = 100 158 183 zebins = [2.0] … … 165 190 zebins = [2./np.sqrt(2.)] ## ne pas tomber sur une dizaine ronde 166 191 nbins = 200 167 zebins = [0.2/np.sqrt(2.)] ## ne pas tomber sur une dizaine ronde 192 193 if pression: zebins = [0.3] 168 194 169 195 for i in range(0,nbins): zebins.append(zebins[i]*np.sqrt(2)) 170 196 zebins = np.array(zebins) 171 ### select reasonable bins for DD 172 zebins = zebins [ zebins > 10. ] 173 zebins = zebins [ zebins < 1000. ] 174 #print 'bins ',zebins 197 #### select reasonable bins for DD 198 if not pression: 199 zebins = zebins [ zebins > 15. ] 200 zebins = zebins [ zebins < 1000. ] 201 else: 202 zebins = zebins [ zebins < 10. ] 175 203 print 'corrected bins ',zebins 176 print 'max value ',mym.max(plothist),mym.max(allsizesx),mym.max(allsizesy)177 178 #plothist = [20.,30.,40.,50.,70.,100.,130.,190.,260.,370.,520.] ## pour calibrer179 204 180 205 #### HISTOGRAM 206 plt.figure(1) 181 207 plt.hist( plothist,\ 182 208 log=True,\ 183 209 bins=zebins,\ 184 210 # cumulative=-1,\ 211 normed=True,\ 185 212 ) 186 213 plt.xscale('log') 187 plt.show() 188 214 if pression: plt.xlabel('Pressure (Pa)') 215 else: plt.xlabel('Diameter (m)') 216 plt.ylabel('Population (normalized)') 217 if pression: prefix="p" 218 else: prefix="" 219 myp.makeplotres(prefix+"histogram",res=200,disp=False) 220 plt.close(1) 221 222 ### COMPARED HISTOGRAMS 223 ### --- FIT WITH POWER LAW 224 if pression: [alpha, xmin, L] = plfit.plfit(plothist,'xmin',0.3) 225 else: [alpha, xmin, L] = plfit.plfit(plothist,'limit',20.) 226 print alpha,xmin 227 228 #a = plpva.plpva(plothist,0.75,'xmin',0.75) 229 #print a 230 231 #### DEUXIEME ROUTINE 232 ####IL FAUT UTILISER LE DISCRET POUR LA TAILLE !!! 233 #if pression: myplfit = plfit.plfit(plothist,verbose=True,xmin=0.75) 234 #else: myplfit = plfit.plfit(plothist,verbose=True,xmin=20.) 235 #myplfit.plotppf() 236 #plt.show() 237 #exit() 238 239 240 #plt.figure(1) 241 #h = plplot.plplot(plothist,xmin,alpha) 242 #myp.makeplotres(prefix+"fit",res=200,disp=False) 243 plt.figure(2) 244 ### --- POWER LAW (factor does not really matter) 245 power = (xmin/2.2)*np.array(randht.randht(10000,'powerlaw',alpha)) 246 #power = (xmin/2.2)*np.array(randht.randht(10000,'cutoff',alpha,10.)) ##marche pas si trop grand 247 print 'mean ', np.mean(power,dtype=np.float64) 248 ### --- EXPONENTIAL LAW 249 expo = randht.randht(10000,'exponential',1./(np.mean(power,dtype=np.float64)*1.00)) 250 print 'mean ', np.mean(expo,dtype=np.float64) 251 ### --- PLOT 252 plt.hist( [plothist,power,expo],\ 253 label=['LES vortices','Power law '+'{:.1f}'.format(alpha),'Exponential law'],\ 254 log=True,\ 255 bins=zebins,\ 256 # cumulative=-1,\ 257 normed=True,\ 258 ) 259 plt.legend() 260 plt.xscale('log') 261 if pression: plt.xlabel('Pressure (Pa)') 262 else: plt.xlabel('Diameter (m)') 263 plt.ylabel('Population (normalized)') 264 myp.makeplotres(prefix+"comparison",res=200,disp=False) 265 plt.close(2) 266 267 ######################## 268 ######################## 269 zebins = [30.,42.,60.,84.,120.,170.,240.,340.] 270 plothist = [] 271 plothist = np.append(plothist,30 *np.ones(306)) 272 plothist = np.append(plothist,42 *np.ones(58) ) 273 plothist = np.append(plothist,60 *np.ones(66) ) 274 plothist = np.append(plothist,84 *np.ones(41) ) 275 plothist = np.append(plothist,120*np.ones(19) ) 276 plothist = np.append(plothist,170*np.ones(9) ) 277 plothist = np.append(plothist,240*np.ones(2) ) 278 plothist = np.append(plothist,340*np.ones(1) ) 279 280 #zebins = [50.,71.,100.,141.,200.,282.,400.] 281 #plothist = [] 282 #plothist = np.append(plothist,50. *np.ones(36)) 283 #plothist = np.append(plothist,71. *np.ones(18) ) 284 #plothist = np.append(plothist,100. *np.ones(12) ) 285 #plothist = np.append(plothist,141. *np.ones(6) ) 286 #plothist = np.append(plothist,200.*np.ones(4) ) 287 #plothist = np.append(plothist,282.*np.ones(1) ) 288 #plothist = np.append(plothist,400.*np.ones(2) ) 289 290 plt.figure(3) 291 [alpha, xmin, L] = plfit.plfit(plothist,'xmin',30)#50.) 292 print alpha,xmin 293 #a = plpva.plpva(plothist,30,'xmin',30) 294 h = plplot.plplot(plothist,xmin,alpha) 295 plt.loglog(h[0], h[1], 'k--',linewidth=2) 296 plt.hist( plothist,\ 297 log=True,\ 298 bins=zebins,\ 299 # cumulative=-1,\ 300 normed=True,\ 301 ) 302 plt.xscale('log') 303 plt.xlabel('Pressure (micro Pa)') 304 plt.ylabel('Population (normalized)') 305 myp.makeplotres("data",res=200,disp=False) 306 307 #plt.figure(4) 308 #[alpha, xmin, L] = plfit.plfit(plothist,'xmin',50.) #,'xmin',30.) 309 #print alpha,xmin 310 #h = plplot.plplot(plothist,xmin,alpha) 311 #myp.makeplotres("datafit",res=200,disp=False)
Note: See TracChangeset
for help on using the changeset viewer.