Ignore:
Timestamp:
Nov 5, 2011, 6:54:37 PM (13 years ago)
Author:
aslmd
Message:

PYTHON GRAPHICS: A REFERENCE VERSION FOR BOTH GCM AND MESOSCALE USE!

Merged recent changes by TN for better GCM handling + 1D/2D plots with AS mesoscale version [winds.py]

Now

  • there is a common function named planetoplot in planetoplot.py which supports both GCM and mesoscale plots

    this will be a common reference for future development

  • mesoscale users might want to use the script meso.py
  • GCM users might want to use the script gcm.py

Todo

  • a few capabilities that were in winds.py are broken in meso.py, this will be fixed soon. the 'old' reference script winds.py is still here anyway!
  • there is still a bug with 'ortho' projection with GCM fields. still searching...

Misc

  • A few modifications were done in myplot.py and mymath.py
  • Added a simple stupid little.py script illustrating very simple use of Python graphics
  • Added the script doing statistical analysis for dust devils
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MESOSCALE/LMD_MM_MARS/SRC/PYTHON/examples/scripts/find_devils.py

    r310 r349  
    2727   
    2828    ### LOAD NETCDF DATA
    29     filename = "psfc.nc"
     29    #filename = "/home/aymeric/Big_Data/psfc.nc"
    3030    nc = Dataset(filename)
    3131    psfc = nc.variables["PSFC"]
     
    3636    allsizesx = []
    3737    allsizesy = []
     38    depression = []
    3839    stride = 1 #5
    3940    for i in range(0,shape[0],stride):
     
    5253        fac = 3.5
    5354        #fac = 2.5
     55        fac = 3.
    5456        lim = ave - fac*std
    5557        where = np.where(psfc2d < lim)
    5658        ############### END CRITERION
     59
     60        depression = np.append(depression,np.ravel(psfc2d[where])-ave)
    5761   
    5862        lab = np.zeros(np.array(psfc2d).shape) ## points to be treated by the minimum_position routine
     
    115119    allsizesy.sort()
    116120   
    117     return allsizesx, allsizesy
     121    return allsizesx, allsizesy, depression
    118122
    119123#########################################################################
     
    125129import matplotlib.mlab as mlab
    126130import mymath as mym
     131import myplot as myp
     132
     133import plfit
     134import plplot
     135import randht
     136import plpva
    127137
    128138save = True
    129139save = False
     140pression = False
     141pression = True
    130142
    131143if save:
    132     allsizesx, allsizesy = getsize("psfc.nc")
     144    allsizesx, allsizesy, depression = getsize("/home/aymeric/Big_Data/psfc.nc")
    133145    ### sauvegarde texte pour inspection
    134146    mym.writeascii(allsizesx,'allsizex.txt')
    135147    mym.writeascii(allsizesy,'allsizey.txt')
     148    mym.writeascii(depression,'alldepression.txt')
    136149    ### sauvegarde binaire pour utilisation python
    137150    myfile = open('allsizex.bin', 'wb')
     
    141154    pickle.dump(allsizesy, myfile)
    142155    myfile.close()
     156    myfile = open('alldepression.bin', 'wb')
     157    pickle.dump(depression, myfile)
     158    myfile.close()
    143159
    144160### load files
     
    147163myfile = open('allsizey.bin', 'r')
    148164allsizesy = pickle.load(myfile)
    149 
    150 ### append sizes
    151 plothist = np.append(allsizesx,allsizesy)
     165myfile = open('alldepression.bin', 'r')
     166depression = pickle.load(myfile)
     167depression = np.array(abs(depression))#*1000.
     168
     169### sizes
     170#plothist = np.append(allsizesx,allsizesy)
    152171plothist = allsizesx
    153 #plothist = allsizesy
     172if pression: plothist = depression
    154173plothist.sort()
    155 
    156 ### make bins
     174print 'mean ', np.mean(plothist,dtype=np.float64) 
     175print 'std ', np.std(plothist,dtype=np.float64)
     176print 'max ', np.max(plothist)
     177print 'min ', np.min(plothist)
     178print 'len ', len(plothist)
     179
     180
     181### MAKE BINS
    157182nbins = 100
    158183zebins = [2.0]
     
    165190zebins = [2./np.sqrt(2.)]  ## ne pas tomber sur une dizaine ronde
    166191nbins = 200
    167 zebins = [0.2/np.sqrt(2.)]  ## ne pas tomber sur une dizaine ronde
     192
     193if pression: zebins = [0.3]
    168194
    169195for i in range(0,nbins):  zebins.append(zebins[i]*np.sqrt(2))
    170196zebins = 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
     198if not pression:
     199    zebins = zebins [ zebins > 15. ]
     200    zebins = zebins [ zebins < 1000. ]
     201else:
     202    zebins = zebins [ zebins < 10. ]
    175203print '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 calibrer
    179204
    180205#### HISTOGRAM
     206plt.figure(1)
    181207plt.hist(    plothist,\
    182208             log=True,\
    183209             bins=zebins,\
    184210#             cumulative=-1,\
     211             normed=True,\
    185212        )
    186213plt.xscale('log')
    187 plt.show()
    188 
     214if pression:    plt.xlabel('Pressure (Pa)')
     215else:           plt.xlabel('Diameter (m)')
     216plt.ylabel('Population (normalized)')
     217if pression: prefix="p"
     218else:        prefix=""
     219myp.makeplotres(prefix+"histogram",res=200,disp=False)
     220plt.close(1)
     221
     222### COMPARED HISTOGRAMS
     223### --- FIT WITH POWER LAW
     224if pression: [alpha, xmin, L] = plfit.plfit(plothist,'xmin',0.3)
     225else:        [alpha, xmin, L] = plfit.plfit(plothist,'limit',20.)
     226print 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)
     243plt.figure(2)
     244### --- POWER LAW (factor does not really matter)
     245power = (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
     247print 'mean ', np.mean(power,dtype=np.float64)
     248### --- EXPONENTIAL LAW
     249expo = randht.randht(10000,'exponential',1./(np.mean(power,dtype=np.float64)*1.00))
     250print 'mean ', np.mean(expo,dtype=np.float64)
     251### --- PLOT
     252plt.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        )
     259plt.legend()
     260plt.xscale('log')
     261if pression:    plt.xlabel('Pressure (Pa)')
     262else:           plt.xlabel('Diameter (m)')
     263plt.ylabel('Population (normalized)')
     264myp.makeplotres(prefix+"comparison",res=200,disp=False)
     265plt.close(2)
     266
     267########################
     268########################
     269zebins = [30.,42.,60.,84.,120.,170.,240.,340.]
     270plothist = []
     271plothist = np.append(plothist,30 *np.ones(306))
     272plothist = np.append(plothist,42 *np.ones(58) )
     273plothist = np.append(plothist,60 *np.ones(66) )
     274plothist = np.append(plothist,84 *np.ones(41) )
     275plothist = np.append(plothist,120*np.ones(19) )
     276plothist = np.append(plothist,170*np.ones(9)  )
     277plothist = np.append(plothist,240*np.ones(2)  )
     278plothist = 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
     290plt.figure(3)
     291[alpha, xmin, L] = plfit.plfit(plothist,'xmin',30)#50.)
     292print alpha,xmin
     293#a = plpva.plpva(plothist,30,'xmin',30)
     294h = plplot.plplot(plothist,xmin,alpha)
     295plt.loglog(h[0], h[1], 'k--',linewidth=2)
     296plt.hist(    plothist,\
     297             log=True,\
     298             bins=zebins,\
     299#             cumulative=-1,\
     300             normed=True,\
     301        )
     302plt.xscale('log')
     303plt.xlabel('Pressure (micro Pa)')
     304plt.ylabel('Population (normalized)')
     305myp.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.