-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdecomp_select.pro
116 lines (95 loc) · 3.17 KB
/
decomp_select.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
pro decomp_select, cube, mask, all_neighbors = all_neighbors, $
minpix = minpix, $
x = x, y = y, v = v, t = t, index = index $
, decompose = decomp, assignment = asgn
;+
;
; NAME:
; DECOMP_SELECT
; PURPOSE:
; Select candidate clouds for decomposition into constituent GMCs.
;
; CALLING SEQUENCE:
; DECOMP_SELECT, cube, mask
;
; INPUTS:
; CUBE -- Original data cube
; MASK -- Binary mask of emission in the data set.
;
; KEYWORD PARAMETERS:
; ALL_NEIGHBORS -- Set this keyword to make pixels have 26 neighbors
; and not 6.
; MINPIX -- The minimum MEAN number of pixels per kernel in the
; decomposition. Defaults to zero, i.e. no minimum.
;
; OUTPUTS: Set keywords to variable names that will contain:
;
; X,Y,V,T -- The position and data value for each cloud
;
; ASSIGNMENT -- Integer assignment to of pixel to cloud N
;
; DECOMPOSE -- A binary flag for each pixel: 1 to decompose, 0 to
; not.
;
; KERNELS -- Indices of X,Y,V,T to indicate the coordinates of the
; local maxima
;
; INDEX -- The 1D index in the original array CUBE of the clouds in
; question.
;
; REQUIRES:
; ALLLOCMAX, MERGEFIND, DECIMATE_KERNELS
;
; MODIFICATION HISTORY:
;
; Mon Dec 6 12:53:15 2004, Erik Rosolowsky <eros@cosmic>
; Written.
;
;-
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; HANDLE INPUTS AND DEFAULTS
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; DEFAULT TO NO PIXEL MINIMUM
if n_elements(minpix) eq 0 then $
minpix = 0.0
; SET DEFAULT MINIMUM DYNAMIC RANGE TO BE A FACTOR OF TWO SIGMA
if n_elements(delta) eq 0 then $
delta = 2.0
; SIZE OF THE DATA CUBE
sz = size(cube)
; GET THE MEAN ABSOLUTE DEVIATION OF DATA IN THE CUBE
sigma = mad(cube)
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; LOCATE LOCAL MAXIMA
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; 1. LABEL SIMPLY CONNECTED REGIONS
regions = label_region(mask, all_neighbors = all_neighbors)
; 2. HISTOGRAM REGION-LABELS TO GET A COUNT OF ELEMENTS IN EACH CLOUD
h = histogram(regions, binsize = 1, omax = omax, $
omin = omin, reverse = ri)
; 3. TOTAL NUMBER OF PIXELS INCLUDED IN REGION LABELS
nelts = total(h[1:*])
; 4. AN ARRAY OF INDICES CORRESPONDING TO LABELLED PIXELS IN THE DATA
; CUBE
index = where(regions)
; 5. THE X, Y, V, T, AND ASSIGNMENT VALUES ASSOCIATED WITH EACH
; LABELLED PIXEL
coordinates = transpose(array_indices(cube, index))
x = coordinates[*, 0]
y = coordinates[*, 1]
v = coordinates[*, 2]
t = cube[index]
asgn = regions[index]
; 6. A BINARY FLAG INDICATING WHETHER THE CLOUD SHOULD BE DECOMPOSED
decomp = bytarr(n_elements(x))+1b
print, 'Identified ', omax, ' island(s).'
; 7. LOOP OVER ALL CLOUDS AND FLAG THEM TO BE EITHER DECOMPOSED OR NOT
; DEPENDING ON CLOUD SIZE AND CONTRAST BETWEEN PEAK AND SHARED
; CONTOURS
for k = 1, omax do begin
; GET THE PIXELS ASSOCIATED WITH CLOUD k
mindex = where(asgn eq k, count)
if count lt 2*minpix then decomp[mindex] = 0b
endfor
return
end