source: trunk/UTIL/PYTHON/powerlaw/previous_tests/plot_granulo.py @ 1242

Last change on this file since 1242 was 1053, checked in by aslmd, 11 years ago

UTIL PYTHON. tools to study dust devils in LES.

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#! /usr/bin/env python
2
3import numpy as np
4from scipy import ndimage
5import matplotlib.pyplot as plt
6
7from myplot import getfield
8from netCDF4 import Dataset
9from scipy import ndimage
10
11def disk_structure(n):
12    struct = np.zeros((2 * n + 1, 2 * n + 1))
13    x, y = np.indices((2 * n + 1, 2 * n + 1))
14    mask = (x - n)**2 + (y - n)**2 <= n**2
15    struct[mask] = 1
16    return struct.astype(np.bool)
17
18
19def granulometry(data, sizes=None):
20    s = max(data.shape)
21    if sizes == None:
22        sizes = range(1, s/2, 2)
23    granulo = [ndimage.binary_opening(data, \
24            structure=disk_structure(n)).sum() for n in sizes]
25    return granulo
26
27
28#np.random.seed(1)
29#n = 10
30#l = 256
31#im = np.zeros((l, l))
32#points = l*np.random.random((2, n**2))
33#im[(points[0]).astype(np.int), (points[1]).astype(np.int)] = 1
34#im = ndimage.gaussian_filter(im, sigma=l/(4.*n))
35#mask = im > im.mean()
36
37namefile = "/home/aymeric/Big_Data/psfc_f18.nc"
38nc  = Dataset(namefile)
39psfc_full=getfield(nc,'PSFC')
40
41#mask = psfc_full[250,100:200,100:200]
42mask = psfc_full[250,:,:]
43mask = ndimage.laplace(mask)
44#mask = mask > 0.3
45
46print mask.std()
47print mask.mean()
48
49lim = mask.std() * 12.
50
51ind1 = np.where(mask > lim)
52ind2 = np.where(mask < lim)
53mask[ind1] = 1
54mask[ind2] = 0
55
56print mask
57
58
59labeled_array, num_features = ndimage.label(mask)
60
61print num_features
62
63plt.pcolor(labeled_array)
64plt.show()
65exit()
66
67
68
69
70mask = mask < mask.mean() - 0.3
71
72#mask = mask > 0.3
73
74
75#plt.pcolor(mask)
76#plt.show()
77
78granulo = granulometry(mask, sizes=[2,5,20])
79
80print granulo
81
82plt.figure(figsize=(6, 2.2))
83
84plt.subplot(121)
85plt.imshow(mask, cmap=plt.cm.gray)
86opened = ndimage.binary_opening(mask, structure=disk_structure(10))
87opened_more = ndimage.binary_opening(mask, structure=disk_structure(14))
88plt.contour(opened, [0.5], colors='b', linewidths=2)
89plt.contour(opened_more, [0.5], colors='r', linewidths=2)
90plt.axis('off')
91plt.subplot(122)
92#plt.plot(np.arange(2, 19, 4), granulo, 'ok', ms=8)
93
94
95plt.subplots_adjust(wspace=0.02, hspace=0.15, top=0.95, bottom=0.15, left=0, right=0.95)
96plt.show()
Note: See TracBrowser for help on using the repository browser.