-
Notifications
You must be signed in to change notification settings - Fork 3
/
vectorify.pro
69 lines (64 loc) · 1.8 KB
/
vectorify.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
pro vectorify, cube, mask = mask $
, x = x, y = y, v = v, t = t, id = id $
, sz = sz, indvec = indvec
;+
; NAME:
; VECTORIFY
;
; PURPOSE:
;
; Takes a cube and (optionally) a mask and extracts a vector of
; position, data, and identifier values from the cube. Useful for
; grabbing a small subset of data from a largely empty data cube.
;
; CALLING SEQUENCE:
;
; vectorify, cube, mask = mask, x = x, y = y, v = v, t = t, id = id $
; , sz = sz
;
; INPUTS:
;
; CUBE : the three-dimensional data cube to vectorify.
;
; MASK : a mask identifying regions of interest within the data
; cube. If mask is set, regions with a value of zero in the mask will
; not be included in the output.
;
; KEYWORD PARAMETERS:
;
;
; OUTPUTS:
;
; X, Y, V : the x, y, and v coordinate, in pixels, of each output
; pixel.
;
; T : the data value of each output pixel.
;
; ID : the mask value (if supplied) for each output pixel.
;
; SZ : the size of the data cube. Necessary if you want to reconstruct
; the data cube using, e.g., cubify.
;
; INDVEC : the vector of indices corresponding to each X,Y,V,T pixel.
;
; MODIFICATION HISTORY:
;
; created on Dec 2, 2004.
;-
; GET THE SIZE OF THE CUBE
sz = size(cube)
; NOW PICK THE ELEMENTS TO VECTORIZE. NON-ZERO VALUES ONLY IF WE HAVE
; A MASK, OTHERWISE THE WHOLE DAMN THING.
if (n_elements(mask) gt 0) then $
indvec = where(mask gt 0) else $
indvec = lindgen(n_elements(cube))
; FIGURE OUT X, Y, V FROM THE INDEX FOR EACH ELEMENT IN THE VECTOR AND
; THEN RECORD THE INTENSITY (DATA VALUE), AND LABEL (MASK VALUE) FOR
; EACH ELEMENT
x = indvec mod sz[1]
y = (indvec mod (sz[1]*sz[2])) / sz[1]
v = indvec / (sz[1]*sz[2])
t = cube[indvec]
if (n_elements(mask) gt 0) then $
id = mask[indvec]
end ; OF VECTORIFY