Ignore:
Timestamp:
Sep 21, 2012, 3:03:27 PM (12 years ago)
Author:
acolaitis
Message:

PYTHON GRAPHICS

  • Added option --finddevil which finds the steepest pressure drop in the PSFC field of the file, and add a cross in it's position.

This new function is intended to provide lon and lat of a dust devil to planetoplot. This could be used to drive a slice plot at the corresponding location.

  • Removed dumpbdy for LES files (no relaxation zone)
  • Added --mark mode to tiled plot
  • Added routines in mymath to convert back and forth between greyscale Image objects and 2D arrays
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/myplot.py

    r783 r792  
    15411541    zt=(zteta+220.)*(zptot/p0)**(r_cp)
    15421542    return zt
     1543
     1544# Author : A.C.
     1545# Find the lon and lat index of the dust devil with the largest pressure gradient
     1546# Steps :
     1547# 1/ convert the chosen PSFC frame to an image of the PSFC anomaly with respect to the mean
     1548# 2/ apply the Sobel operator
     1549# (The Sobel operator performs a 2-D spatial gradient measurement on an image and so emphasizes regions of high spatial frequency that correspond to edges.)
     1550# 3/ find the maximum of the resulting field
     1551# 4/ find the points in a 5 pixel radius around the maximum for which the value of the Sobel transform is greater than half the maximum
     1552# 5/ define a slab of points encompassing the above selected points, including the potential points 'inside' them (if the above points are a hollow circle for example)
     1553# 6/ in this slab, find the point at which the surface pressure is minimum
     1554def find_devil(nc,indextime):
     1555    import numpy as np
     1556    from scipy import ndimage
     1557    from mymath import array2image,image2array
     1558
     1559    varinfile = nc.variables.keys()
     1560    if "PSFC" not in varinfile: errormess("You need PSFC in your file to find dust devils")
     1561    else: psfc_full=getfield(nc,'PSFC')
     1562    psfc,error=reducefield( psfc_full, d4=indextime)
     1563    psfcim=array2image(1000.*(psfc-psfc.mean()))
     1564    sx = ndimage.sobel(psfcim, axis=0, mode='constant') ; sy = ndimage.sobel(psfcim, axis=1, mode='constant')
     1565    sob = np.hypot(sx, sy)
     1566    zemax=np.max(sob)
     1567    goodvalues = sob[sob >= zemax/2]
     1568    ix = np.in1d(sob.ravel(), goodvalues).reshape(sob.shape)
     1569    idxs,idys=np.where(ix)
     1570    maxvalue = sob[sob == zemax]
     1571    ixmax = np.in1d(sob.ravel(), maxvalue[0]).reshape(sob.shape)
     1572    idxmax,idymax=np.where(ixmax)
     1573    valok=[]
     1574    for i in np.arange(len(idxs)):
     1575        a=np.sqrt((idxmax-idxs[i])**2 + (idymax-idys[i])**2)
     1576        if 0 < a <= 5.*np.sqrt(2.): valok.append(goodvalues[i])
     1577    ix = np.in1d(sob.ravel(), valok).reshape(sob.shape)
     1578    idxs,idys=np.where(ix)
     1579    hyperslab=psfc[np.min(idxs):np.max(idxs),np.min(idys):np.max(idys)]
     1580    idxsub,idysub=np.where(hyperslab==hyperslab.min())
     1581    idx=idxsub[0]+np.min(idxs) ; idy=idysub[0]+np.min(idys)
     1582    return np.int(idx),np.int(idy)
Note: See TracChangeset for help on using the changeset viewer.