File: WFPC2Image.tcl

package info (click to toggle)
ftools-fv 5.3%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,908 kB
  • ctags: 2,922
  • sloc: tcl: 48,319; ansic: 16,926; cpp: 169; makefile: 157; sh: 121; csh: 10; exp: 2
file content (327 lines) | stat: -rw-r--r-- 9,512 bytes parent folder | download | duplicates (6)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# First draft 06/27/96    Jianjun

# constrct a FitsImage object
# FitsImage FitsImageObjName FitsFileObjName currentHDU 

itcl::class WFPC2Image {
    inherit FitsImage
    constructor {args} {
	eval FitsImage::constructor $args
    } {
	#puts $args 
    }

# all these override/specialize their parents' (FitsImage and Table) methods

    private method _readInTable {} 
    private method _saveTableToAscii  {win_ asciiFileName_} 
    private method _powMakeImage {} 
}



itcl::body WFPC2Image::_readInTable { } {

    set _DC(height)   20
    set _DC(width)     [expr (int(log10($_numRows))+6)*$g_charPix]
    set _DC(headroom) 20
    set _DC(footroom) 40
    set _DC(vscrollsize) 15
    set _DC(hscrollsize) 15
    set _DC(rightspace) 6
    set _DC(interline)    0
    set _DC(tmar)         6
    set _DC(lmar)         8
    set _DC(tabspace)     0

# flag that the imageTable is being displayed
    set _isImageTable 1

    if { $_imgType == 0 } {
	set _cellSize 8
    } elseif {$_imgType == 1} {
	set _cellSize 8
    } elseif {$_imgType == 2} {
	set _cellSize 16
    } elseif {$_imgType == 3} {
	set _cellSize 16
    } elseif {$_imgType == 4} {
	set _cellSize 20
    } else {
	set _cellSize 8
    }

    set _listPreSelectedColNames {}
    set _dispCols $_numCols
    set _tableType Image

# use fits command setrowstate to initialize the rowState
# usage   setrowstate totalNumOfRos startRow endRow status 
# (0:normal, 1:selected, 2: deleted)
    setarray rowState 0 [expr $_numRows-1] 0
    setarray _colNotchedState 0 [expr $_dispCols-1] 0

    set _absXPos(0) [expr $_DC(lmar) + $_DC(width)/2]
    for {set i 0} {$i < $_dispCols} {incr i} {
        set _valueTDIM($i) 0
	set _columnName($i) [expr $i+1]
	set _columnType($i) " "
	set _columnUnit($i) " "
	lappend _listPreSelectedColNames [expr $i+1]
	set _cellWidth($i) $_cellSize 
	set _cellPixWidth($i) [expr $g_charPix*(1+$_cellWidth($i))]
	set _absXPos([expr $i+1]) [expr $_absXPos($i) + $_cellPixWidth($i) \
				      +$_DC(rightspace)] 
    }

}


itcl::body WFPC2Image::_powMakeImage {} {
    global powWCS powFitsHeader powFitsHeaderCnt powPlotParam
    global xCount yCount
    global powWCSName powWCSTranslation powWCSLabel powWCSList
    global useWCSInfo


    # get the pow widget 
    if { [winfo exist .pow.pow]!=1 } { 
	powInit .dummy
    }

    regsub -all { } [urlTail $fileName] _ cleanFileName
    set imgIndex  ${cleanFileName}_[expr $currentHDU-1]
    set imgHandle ${cleanFileName}_[expr $currentHDU-1]

    for {set i 1} {$i <=4} {incr i} {
	set ii $i
	set dataAddressForPOW [$fFile loadImageSlice $i [expr $i-1]] 
# the last param is for copying  data
	powCreateData ${imgHandle}_$ii $dataAddressForPOW $_imgType \
		       [expr $_numCols*$_numRows] 1
	# free the data array
	$fFile freeImage $dataAddressForPOW
    }
    # get the wcs info and pass them to pow
    # for WFPC images, the wcs info are stored in the second extension.
#    $fFile move +1
#    set crval1 [$fFile get table crval1]
#    set crval2 [$fFile get table crval2]
#    set crpix1 [$fFile get table crpix1]
#    set crpix2 [$fFile get table crpix2]
#    set cd1_1  [$fFile get table cd1_1 ]
#    set cd1_2  [$fFile get table cd1_2 ]
#    set cd2_1  [$fFile get table cd1_1 ]
#    set cd2_2  [$fFile get table cd1_2 ]
    

    set x_0 1
    set y_0 1
    set incrx 1
    set incry 1
    set x_label ""
    set y_label ""
    set x_unit "pixels"
    set y_unit "pixels"


    # Get the WCS info (if needed) and pass them to pow

    set powWCSLabel(xlabel,$imgIndex,DEFAULT) ""
    set powWCSLabel(ylabel,$imgIndex,DEFAULT) ""
    set powWCSLabel(xunit,$imgIndex,DEFAULT) ""
    set powWCSLabel(yunit,$imgIndex,DEFAULT) ""

    $fFile moveToHDU 1
    set powWCS($imgIndex) [$fFile getWcs]
    set powWCSName($imgIndex) 0
    set useWCSInfo($imgeIndex) $fvPref::ifWCSInfo

    if { $fvPref::ifWCSInfo } {
       set result [$fFile getHeader2String]
       set cntList($imgIndex) [$fFile getHeaderKeyWord [lindex $result 0] $imgIndex]
       set powFitsHeaderCnt($imgIndex) [lindex $cntList($imgIndex) 1]
       if { [lindex $cntList($imgIndex) 0] > 0 } {
          #set powFitsHeader($imgIndex) [$fFile assembleWcsHeader $imgIndex]
          set powFitsHeader($imgIndex) [lindex $result 0]
          set powWCSInfo($imgIndex,DEFAULT) $powWCS($imgIndex)
          set wcsinfo $powWCS($imgIndex) 
          set x_label [lindex [lindex $wcsinfo 3] 0]
          set y_label [lindex [lindex $wcsinfo 3] 1]
          if { $x_unit=="pixels" } {set x_unit NULL}
          if { $y_unit=="pixels" } {set y_unit NULL}
       } else {
          set powFitsHeader($imgIndex) [$fFile assembleWcsHeader $imgIndex NOWCS]
          set powWCS($imgIndex) [$fFile getWcs]
          set wcsinfo $powWCS($imgIndex) 
       }
    } else {
       set powWCS($imgIndex) [$fFile getWcs]
       set powFitsHeader($imgIndex) ""
       set powFitsHeaderCnt($imgIndex) 0
    }

    set powWCSList($imgIndex) {}
    set powWCSList(${imgIndex}scope) {}

    for {set i 1} {$i <=4} {incr i} {
# position the frames
#    2 1
#    3 4
	switch $i {
	    "1" {
		set x_0 [expr 1+$_numCols]
		set y_0 [expr 1+$_numRows]
		set incrx 1
		set incry 1
	    }
	    "2" {
		set x_0 1
		set y_0 [expr 1+$_numRows]
		set incrx 1
		set incry 1
	    }
	    "3" {
		set x_0 1
		set y_0 1
	    }
	    "4" {
		set x_0 [expr 1+$_numCols]
		set y_0 1 
		set incrx 1
		set incry 1

	    }
	}

	set ii $i
        set powWCSName(${imgHandle}_$ii) 0
        set powFitsHeader(${imgHandle}_$ii) $powFitsHeader($imgIndex)
        set powFitsHeaderCnt(${imgHandle}_$ii) $powFitsHeaderCnt($imgIndex)
        set powWCS(${imgHandle}_$ii) $powWCS($imgIndex)
        set powFitsHeader(${imgHandle}_${ii}scope) $powFitsHeader($imgIndex)
        set powFitsHeaderCnt(${imgHandle}_${ii}scope) $powFitsHeaderCnt($imgIndex)
        set powWCS(${imgHandle}_${ii}scope) $powWCS($imgIndex)

        set powPlotParam(graphType,${imgHandle}_$ii) \
                      [string tolower [lindex [$fFile getTableInfo hdutype] 0]]
        set powPlotParam(graphType,${imgHandle}_${ii}scope) \
                      $powPlotParam(graphType,${imgHandle}_$ii)
        set powPlotParam(zoomed,${imgHandle}_$ii) 0
        set powPlotParam(zoomed,${imgHandle}_${ii}scope) 0

        set xCount(${imgHandle}_$ii) 0
        set yCount(${imgHandle}_$ii) 0
        set xCount(${imgHandle}_${ii}scope) 0
        set yCount(${imgHandle}_${ii}scope) 0
        set powWCSName(${imgHandle}_$ii) 0
        set powWCSName(${imgHandle}_${ii}scope) 0
        set powWCSTranslation 0

	powCreateImage ${imgHandle}_$ii ${imgHandle}_$ii 0 0\
		       $_numCols $_numRows $x_0 \
		       $incrx $y_0 $incry $x_label $y_label counts

        if [info exists powWCSList(${imgHandle}_$ii)] {
           foreach name [lindex $powWCSList(${imgHandle}_$ii) 1] {
              $fFile assembleWcsLabel ${imgHandle}_$ii $name
           }
        } else {
           set powWCSList(${imgHandle}_$ii) {}
           lappend powWCSList(${imgHandle}_$ii) 1
           lappend powWCSList(${imgHandle}_$ii) {}
        }

        set powWCSList(${imgHandle}_${ii}scope) $powWCSList(${imgHandle}_${ii})

	set powRBmin(${imgHandle}_$ii) 0
	set powRBmax(${imgHandle}_$ii) 1000
    }

    # use one of the image list
    set powWCSList($imgIndex) $powWCSList(${imgHandle}_4)
    set powWCSList(${imgIndex}scope) $powWCSList(${imgHandle}_4)

    if [info exists powWCSList($imgIndex)] {
       foreach name [lindex $powWCSList($imgIndex) 1] {
          $fFile assembleWcsLabel $imgIndex $name
       }
    } else {
       set powWCSList($imgIndex) {}
       lappend powWCSList($imgIndex) 1
       lappend powWCSList($imgIndex) {}
    }

    set powWCSList(${imgHandle}) $powWCSList($imgIndex)
    set powWCSList(${imgHandle}scope) $powWCSList($imgIndex)

    set powWCSName(${imgHandle}) 0
    set powFitsHeader($imgHandle) $powFitsHeader($imgIndex)
    set powFitsHeaderCnt($imgHandle) $powFitsHeaderCnt($imgIndex)
    set powWCS($imgHandle) $powWCS($imgIndex)
    set powPlotParam(graphType,$imgHandle) [string tolower [lindex [$fFile getTableInfo hdutype] 0]]
    set powPlotParam(graphType,${imgHandle}scope) $powPlotParam(graphType,$imgHandle)
    set powPlotParam(zoomed,$imgHandle) 0
    set powPlotParam(zoomed,${imgHandle}scope) 0

    set xCount($imgHandle) 0
    set yCount($imgHandle) 0
    set xCount(${imgHandle}scope) 0
    set yCount(${imgHandle}scope) 0

    powCreateGraph $imgHandle NULL \
	[list ${imgHandle}_1  ${imgHandle}_2 ${imgHandle}_3 ${imgHandle}_4] \
		   $x_unit $y_unit \
		   $x_label $y_label \
		   [lindex $fvPref::graphDispSize 0] [lindex $fvPref::graphDispSize 1] 
}

itcl::body WFPC2Image::_saveTableToAscii  {win_ asciiFileName_} {

# setup the grouping 
  set tmpWidth  $_cellSize
  set tmpFirstCol(0) 1
  set groupCount  0  

  for {set  n 0} {$n < $_numCols-1} {incr n} {
      set tmpWidth [expr  $tmpWidth + $_cellSize]
      if { $tmpWidth > $_asciiColWidth} {
      incr groupCount 
      set tmpWidth  $_cellSize;
	  set tmpFirstCol($groupCount) [expr  $n+2]
    }
  }
  incr groupCount
  set tmpFirstCol($groupCount) [expr 1+$_numCols]

  $win_.f.fb configure -steps $groupCount
  for {set k 0} {$k< $groupCount} {incr k} {
      set nCols  [expr $tmpFirstCol([expr $k+1])-$tmpFirstCol($k)]
      $fFile saveImgToASCII $asciiFileName_ $k \
	  1 $_numRows $tmpFirstCol($k) $nCols $_cellSize
      if {[catch {$win_.f.fb step}] == 1} {
	  file delete $asciiFileName_
	  return
      }
  }
  destroy $win_

}