-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_zones.pro
137 lines (92 loc) · 4.23 KB
/
search_zones.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
function search_zones,imagecube,ringsize,n_ang
print, '--[ SEARCH_ZONES ]-- STARTING'
;Get the dimensions of a single frame
x = (size(imagecube))(1)
y = (size(imagecube))(2)
x = double(x)
y = double(y)
;Make sure array is square
if x ne y then begin
if x lt y then y = x else x = y ;Use a square of the smaller dimension
endif
imagecube[where(finite(imagecube) eq 0)] = 0.00 ; Can't have NaN
;How many frames do we have?
nimages = (size(imagecube))(3)
;Check that ringsize is valid
if ringsize gt x/2. then begin
print, 'Ring Size larger than image, using max ring size instead'
ringsize = round(x/2.) ; Use max ring size (in integer pixels)
if x/2. - ringsize lt 0. then ringsize = ringsize - 1. ; Be sure to round down
endif
;How many rings?
nrings = round(.5*x/ringsize) ; Use greatest number of rings possible
if x/ringsize - nrings lt 0. then nrings = nrings - 1. ; round down
;Make sure we have integer number of angular segments
if 360. mod n_ang ne 0. then begin
print, '360 not divisible by angle size, using 10 angle segments instead'
n_ang = 10.
endif
;Total number of data points?
ndatapoints = x*x ; Data array for a single image is a square
;Define our final data arrays
structure = {ringseg:fltarr(nimages,nrings,n_ang,ndatapoints), mask_index:fltarr(nrings,n_ang,ndatapoints)}
structure.ringseg[ * ] = !values.f_nan
structure.mask_index[ * ] = !values.f_nan
;========================================================
; We will first define two general masks, one for radial
; distance and one for angular value (in radians)
;=========================================================
distmask = imagecube[*,*,0] ; use the first image in cube to create mask
N = x ; Define the size of N x N output array
dist_circle, distmask, N, [x/2., y/2.] ; create distance mask
writefits, 'distmask.fits', distmask
print, '--[ SEARCH_ZONES ]-- DISTANCE MASK COMPLETE'
anglemask = imagecube[*,*,0] ; use the first image in cube to create mask
;Define Mask by Pixel
for xx=0, x-1 do begin
for yy=0, y-1 do begin
;Define angle on just the axes
if yy eq y/2. and xx ge x/2. then anglemask[xx,yy] = 0.
if xx eq x/2. and yy ge y/2. then anglemask[xx,yy] = !pi/2.
if yy eq y/2. and xx le x/2. then anglemask[xx,yy] = !pi
if xx eq x/2. and yy le y/2. then anglemask[xx,yy] = 3.*!pi/2.
;Define angles where atan is defined (4 cases because atan is not unique)
if xx gt x/2. and yy gt y/2. then anglemask[xx,yy] = atan((yy-y/2.)/(xx-x/2.))
if xx lt x/2. and yy gt y/2. then anglemask[xx,yy] = atan((x/2.-xx)/(yy-y/2.))+!pi/2.
if xx lt x/2. and yy lt y/2. then anglemask[xx,yy] = atan((y/2.-yy)/(x/2.-xx))+!pi
if xx gt x/2. and yy lt y/2. then anglemask[xx,yy] = atan((xx-x/2.)/(y/2.-yy))+3.*!pi/2.
endfor
endfor
writefits, 'anglemask.fits',anglemask
print, '--[ SEARCH_ZONES ]-- ANGLE MASK COMPLETE'
;========================================================
; Next we will loop over images, rings, and angles in
; order to store data in ringseg array
;=========================================================
;Loop over image
for ii=0, nimages-1 do begin
;Break frame into rings
for jj=0, nrings-1 do begin
ringmask = imagecube[*,*,ii] ; Get Frame
r_inner = jj*ringsize
r_outer = (jj+1)*ringsize
ringmask[where(distmask ge r_outer or distmask lt r_inner)] = !values.f_nan
;Break rings into angular segments
for kk=0,n_ang-1 do begin
segmask = ringmask ; start with ringmask
minang = kk*360./n_ang
minang = !pi/180.*minang ; Convert to radians
maxang = (kk+1)*360./n_ang
maxang = !pi/180.*maxang ; Convert to radians
segmask[where(anglemask ge maxang or anglemask lt minang)] = !values.f_nan
if ii eq 0 then begin
structure.mask_index[jj,kk,*]=segmask ; find mask index for first image
endif
segmask = segmask[where(finite(segmask) eq 1)] ; Use only finite values and convert to 1-D array
structure.ringseg[ii, jj, kk, 0:n_elements(segmask)-1] = segmask ; add current seg to final array
endfor ; Loop over images
endfor ; Loop over rings
endfor ; Loop over angular segments
print, '--[ SEARCH_ZONES ]-- COMPLETE'
return, structure ; Send back final data array
end