- Timestamp:
- 10/23/12 19:45:55 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapgrid.py
r2679 r2680 7 7 from logging import asaplog 8 8 9 class asapgrid: 9 class asapgrid_base(object): 10 def __init__( self ): 11 self.outfile = None 12 self.ifno = None 13 self.gridder = None 14 self.infile = None 15 self.scantab = None 16 17 def setData( self, infile ): 18 raise NotImplementedError('setData is not implemented') 19 20 def setIF( self, ifno ): 21 """ 22 Set IFNO to be processed. Currently, asapgrid allows to process 23 only one IFNO for one gridding run even if the data contains 24 multiple IFs. If you didn't specify IFNO, default value, which 25 is IFNO in the first spectrum, will be processed. 26 27 ifno -- IFNO to be processed. 28 """ 29 self.ifno = ifno 30 self.gridder._setif( self.ifno ) 31 32 def setPolList( self, pollist ): 33 """ 34 Set list of polarization components you want to process. 35 If not specified, all POLNOs will be processed. 36 37 pollist -- list of POLNOs. 38 """ 39 self.gridder._setpollist( pollist ) 40 41 def setScanList( self, scanlist ): 42 """ 43 Set list of scans you want to process. If not specified, all 44 scans will be processed. 45 46 scanlist -- list of SCANNOs. 47 """ 48 self.gridder._setscanlist( scanlist ) 49 50 def defineImage( self, nx=-1, ny=-1, cellx='', celly='', center='' ): 51 """ 52 Define spatial grid. 53 54 First two parameters, nx and ny, define number of pixels of 55 the grid. If which of those is not specified, it will be set 56 to the same value as the other. If none of them are specified, 57 it will be determined from map extent and cell size. 58 59 Next two parameters, cellx and celly, define size of pixel. 60 You should set those parameters as string, which is constructed 61 numerical value and unit, e.g. '0.5arcmin', or numerical value. 62 If those values are specified as numerical value, their units 63 will be assumed to 'arcsec'. If which of those is not specified, 64 it will be set to the same value as the other. If none of them 65 are specified, it will be determined from map extent and number 66 of pixels, or set to '1arcmin' if neither nx nor ny is set. 67 68 The last parameter, center, define the central coordinate of 69 the grid. You should specify its value as a string, like, 70 71 'J2000 05h08m50s -16d23m30s' 72 73 or 74 75 'J2000 05:08:50 -16.23.30' 76 77 You can omit equinox when you specify center coordinate. In that 78 case, J2000 is assumed. If center is not specified, it will be 79 determined from the observed positions of input data. 80 81 nx -- number of pixels along x (R.A.) direction. 82 ny -- number of pixels along y (Dec.) direction. 83 cellx -- size of pixel in x (R.A.) direction. 84 celly -- size of pixel in y (Dec.) direction. 85 center -- central position of the grid. 86 """ 87 if not isinstance( cellx, str ): 88 cellx = '%sarcsec'%(cellx) 89 if not isinstance( celly, str ): 90 celly = '%sarcsec'%(celly) 91 self.gridder._defineimage( nx, ny, cellx, celly, center ) 92 93 def setFunc( self, func='box', convsupport=-1, truncate="-1", gwidth="-1", jwidth="-1" ): 94 """ 95 Set convolution function. Possible options are 'box' (Box-car, 96 default), 'sf' (prolate spheroidal), 'gauss' (Gaussian), and 97 'gjinc' (Gaussian * Jinc). 98 Width of convolution function can be set using several parameters. 99 For 'box' and 'sf', we have one parameter, convsupport, that 100 specifies a cut-off radius of the convlolution function. By default 101 (-1), convsupport is automatically set depending on each convolution 102 function. Default values for convsupport are: 103 104 'box': 1 pixel 105 'sf': 3 pixels 106 107 For 'gauss', we have two parameters for convolution function, 108 truncate and gwidth. The truncate is similar to convsupport 109 except that truncate allows to specify its value as float or 110 string consisting of numeric and unit (e.g. '10arcsec' or 111 '3pixel'). Available units are angular units ('arcsec', 'arcmin', 112 'deg', etc.) and 'pixel'. Default unit is 'pixel' so that if 113 you specify numerical value or string without unit to gwidth, 114 the value will be interpreted as 'pixel'. gwidth is an HWHM of 115 gaussian. It also allows string value. Interpretation of the 116 value for gwidth is same as truncate. Default value for 'gauss' 117 is 118 119 gwidth: '-1' ---> sqrt(log(2.0)) pixel 120 truncate: '-1' ---> 3*gwidth pixel 121 122 For 'gjinc', there is an additional parameter jwidth that 123 specifies a width of the jinc function whose functional form is 124 125 jinc(x) = J_1(pi*x/jwidth) / (pi*x/jwidth) 126 127 Default values for 'gjinc' is 128 129 gwidth: '-1' ---> 2.52*sqrt(log(2.0)) pixel 130 jwidth: '-1' ---> 1.55 131 truncate: '-1' ---> automatically truncate at first null 132 133 Default values for gwidth and jwidth are taken from Mangum et al. 134 (2007). 135 136 func -- Function type ('box', 'sf', 'gauss', 'gjinc'). 137 convsupport -- Width of convolution function. Default (-1) is 138 to choose pre-defined value for each convolution 139 function. Effective only for 'box' and 'sf'. 140 truncate -- Truncation radius of the convolution function. 141 Acceptable value is an integer or a float in units of 142 pixel, or a string consisting of numeric plus unit. 143 Default unit for the string is 'pixel'. Default (-1) 144 is to choose pre-defined value for each convolution 145 function. Effective only for 'gauss' and 'gjinc'. 146 gwidth -- The HWHM of the gaussian. Acceptable value is an integer 147 or a float in units of pixel, or a string consisting of 148 numeric plus unit. Default unit for the string is 'pixel'. 149 Default (-1) is to choose pre-defined value for each 150 convolution function. Effective only for 'gauss' and 151 'gjinc'. 152 jwidth -- The width of the jinc function. Acceptable value is an 153 integer or a float in units of pixel, or a string 154 consisting of numeric plus unit. Default unit for the 155 string is 'pixel'. Default (-1) is to choose pre-defined 156 value for each convolution function. Effective only for 157 'gjinc'. 158 """ 159 self.gridder._setfunc(func, 160 convsupport=convsupport, 161 truncate=truncate, 162 gwidth=gwidth, 163 jwidth=jwidth) 164 165 def setWeight( self, weightType='uniform' ): 166 """ 167 Set weight type. Possible options are 'uniform' (default), 168 'tint' (weight by integration time), 'tsys' (weight by 169 Tsys: 1/Tsys**2), and 'tintsys' (weight by integration time 170 as well as Tsys: tint/Tsys**2). 171 172 weightType -- weight type ('uniform', 'tint', 'tsys', 'tintsys') 173 """ 174 self.gridder._setweight( weightType ) 175 176 def enableClip( self ): 177 """ 178 Enable min/max clipping. 179 180 By default, min/max clipping is disabled so that you should 181 call this method before actual gridding if you want to do 182 clipping. 183 """ 184 self.gridder._enableclip() 185 186 def disableClip( self ): 187 """ 188 Disable min/max clipping. 189 """ 190 self.gridder._disableclip() 191 192 def grid( self ): 193 """ 194 Actual gridding which will be done based on several user inputs. 195 """ 196 self.gridder._grid() 197 198 def plotFunc(self, clear=True): 199 """ 200 Support function to see the shape of current grid function. 201 202 clear -- clear panel if True. Default is True. 203 """ 204 pl.figure(11) 205 if clear: 206 pl.clf() 207 f = self.gridder._getfunc() 208 convsampling = 100 209 a = numpy.arange(0,len(f)/convsampling,1./convsampling,dtype=float) 210 pl.plot(a,f,'.-') 211 pl.xlabel('pixel') 212 pl.ylabel('convFunc') 213 214 def save( self, outfile='' ): 215 raise NotImplementedError('save is not implemented') 216 217 def plot( self, plotchan=-1, plotpol=-1, plotobs=False, plotgrid=False ): 218 raise NotImplementedError('plot is not implemented') 219 220 def getResult( self ): 221 raise NotImplementedError('getResult is not implemented') 222 223 class asapgrid(asapgrid_base): 10 224 """ 11 225 The asapgrid class is defined to convolve data onto regular … … 44 258 to grid more than one data at once. 45 259 """ 46 self.outfile = None 47 self.ifno = None 260 super(asapgrid,self).__init__() 48 261 self.gridder = stgrid() 49 self.setData( infile ) 262 self.infile=infile 263 self.setData(infile) 50 264 51 265 def setData( self, infile ): … … 61 275 self.gridder._setfiles( infile ) 62 276 self.infile = infile 63 64 def setIF( self, ifno ):65 """66 Set IFNO to be processed. Currently, asapgrid allows to process67 only one IFNO for one gridding run even if the data contains68 multiple IFs. If you didn't specify IFNO, default value, which69 is IFNO in the first spectrum, will be processed.70 71 ifno -- IFNO to be processed.72 """73 self.ifno = ifno74 self.gridder._setif( self.ifno )75 76 def setPolList( self, pollist ):77 """78 Set list of polarization components you want to process.79 If not specified, all POLNOs will be processed.80 81 pollist -- list of POLNOs.82 """83 self.gridder._setpollist( pollist )84 85 def setScanList( self, scanlist ):86 """87 Set list of scans you want to process. If not specified, all88 scans will be processed.89 90 scanlist -- list of SCANNOs.91 """92 self.gridder._setscanlist( scanlist )93 94 def defineImage( self, nx=-1, ny=-1, cellx='', celly='', center='' ):95 """96 Define spatial grid.97 98 First two parameters, nx and ny, define number of pixels of99 the grid. If which of those is not specified, it will be set100 to the same value as the other. If none of them are specified,101 it will be determined from map extent and cell size.102 103 Next two parameters, cellx and celly, define size of pixel.104 You should set those parameters as string, which is constructed105 numerical value and unit, e.g. '0.5arcmin', or numerical value.106 If those values are specified as numerical value, their units107 will be assumed to 'arcsec'. If which of those is not specified,108 it will be set to the same value as the other. If none of them109 are specified, it will be determined from map extent and number110 of pixels, or set to '1arcmin' if neither nx nor ny is set.111 112 The last parameter, center, define the central coordinate of113 the grid. You should specify its value as a string, like,114 115 'J2000 05h08m50s -16d23m30s'116 117 or118 119 'J2000 05:08:50 -16.23.30'120 121 You can omit equinox when you specify center coordinate. In that122 case, J2000 is assumed. If center is not specified, it will be123 determined from the observed positions of input data.124 125 nx -- number of pixels along x (R.A.) direction.126 ny -- number of pixels along y (Dec.) direction.127 cellx -- size of pixel in x (R.A.) direction.128 celly -- size of pixel in y (Dec.) direction.129 center -- central position of the grid.130 """131 if not isinstance( cellx, str ):132 cellx = '%sarcsec'%(cellx)133 if not isinstance( celly, str ):134 celly = '%sarcsec'%(celly)135 self.gridder._defineimage( nx, ny, cellx, celly, center )136 137 def setFunc( self, func='box', convsupport=-1, truncate="-1", gwidth="-1", jwidth="-1" ):138 """139 Set convolution function. Possible options are 'box' (Box-car,140 default), 'sf' (prolate spheroidal), 'gauss' (Gaussian), and141 'gjinc' (Gaussian * Jinc).142 Width of convolution function can be set using several parameters.143 For 'box' and 'sf', we have one parameter, convsupport, that144 specifies a cut-off radius of the convlolution function. By default145 (-1), convsupport is automatically set depending on each convolution146 function. Default values for convsupport are:147 148 'box': 1 pixel149 'sf': 3 pixels150 151 For 'gauss', we have two parameters for convolution function,152 truncate and gwidth. The truncate is similar to convsupport153 except that truncate allows to specify its value as float or154 string consisting of numeric and unit (e.g. '10arcsec' or155 '3pixel'). Available units are angular units ('arcsec', 'arcmin',156 'deg', etc.) and 'pixel'. Default unit is 'pixel' so that if157 you specify numerical value or string without unit to gwidth,158 the value will be interpreted as 'pixel'. gwidth is an HWHM of159 gaussian. It also allows string value. Interpretation of the160 value for gwidth is same as truncate. Default value for 'gauss'161 is162 163 gwidth: '-1' ---> sqrt(log(2.0)) pixel164 truncate: '-1' ---> 3*gwidth pixel165 166 For 'gjinc', there is an additional parameter jwidth that167 specifies a width of the jinc function whose functional form is168 169 jinc(x) = J_1(pi*x/jwidth) / (pi*x/jwidth)170 171 Default values for 'gjinc' is172 173 gwidth: '-1' ---> 2.52*sqrt(log(2.0)) pixel174 jwidth: '-1' ---> 1.55175 truncate: '-1' ---> automatically truncate at first null176 177 Default values for gwidth and jwidth are taken from Mangum et al.178 (2007).179 180 func -- Function type ('box', 'sf', 'gauss', 'gjinc').181 convsupport -- Width of convolution function. Default (-1) is182 to choose pre-defined value for each convolution183 function. Effective only for 'box' and 'sf'.184 truncate -- Truncation radius of the convolution function.185 Acceptable value is an integer or a float in units of186 pixel, or a string consisting of numeric plus unit.187 Default unit for the string is 'pixel'. Default (-1)188 is to choose pre-defined value for each convolution189 function. Effective only for 'gauss' and 'gjinc'.190 gwidth -- The HWHM of the gaussian. Acceptable value is an integer191 or a float in units of pixel, or a string consisting of192 numeric plus unit. Default unit for the string is 'pixel'.193 Default (-1) is to choose pre-defined value for each194 convolution function. Effective only for 'gauss' and195 'gjinc'.196 jwidth -- The width of the jinc function. Acceptable value is an197 integer or a float in units of pixel, or a string198 consisting of numeric plus unit. Default unit for the199 string is 'pixel'. Default (-1) is to choose pre-defined200 value for each convolution function. Effective only for201 'gjinc'.202 """203 self.gridder._setfunc(func,204 convsupport=convsupport,205 truncate=truncate,206 gwidth=gwidth,207 jwidth=jwidth)208 209 def setWeight( self, weightType='uniform' ):210 """211 Set weight type. Possible options are 'uniform' (default),212 'tint' (weight by integration time), 'tsys' (weight by213 Tsys: 1/Tsys**2), and 'tintsys' (weight by integration time214 as well as Tsys: tint/Tsys**2).215 216 weightType -- weight type ('uniform', 'tint', 'tsys', 'tintsys')217 """218 self.gridder._setweight( weightType )219 220 def enableClip( self ):221 """222 Enable min/max clipping.223 224 By default, min/max clipping is disabled so that you should225 call this method before actual gridding if you want to do226 clipping.227 """228 self.gridder._enableclip()229 230 def disableClip( self ):231 """232 Disable min/max clipping.233 """234 self.gridder._disableclip()235 236 def grid( self ):237 """238 Actual gridding which will be done based on several user inputs.239 """240 self.gridder._grid()241 277 242 278 def save( self, outfile='' ): … … 277 313 asaplog.push('plot: elapsed time %s sec'%(t1-t0)) 278 314 asaplog.post('DEBUG','asapgrid.plot') 279 280 def plotFunc(self, clear=True):281 """282 Support function to see the shape of current grid function.283 284 clear -- clear panel if True. Default is True.285 """286 pl.figure(11)287 if clear:288 pl.clf()289 f = self.gridder._getfunc()290 convsampling = 100291 a = numpy.arange(0,len(f)/convsampling,1./convsampling,dtype=float)292 pl.plot(a,f,'.-')293 pl.xlabel('pixel')294 pl.ylabel('convFunc')295 315 296 class asapgrid2 :316 class asapgrid2(asapgrid_base): 297 317 """ 298 318 The asapgrid class is defined to convolve data onto regular … … 330 350 to grid more than one data at once. 331 351 """ 332 self.outfile = None 333 self.ifno = None 352 super(asapgrid2,self).__init__() 334 353 self.gridder = stgrid2() 354 self.scantab = scantab 335 355 self.setData( scantab ) 336 356 … … 348 368 self.scantab = scantab 349 369 350 def setIF( self, ifno ):351 """352 Set IFNO to be processed. Currently, asapgrid allows to process353 only one IFNO for one gridding run even if the data contains354 multiple IFs. If you didn't specify IFNO, default value, which355 is IFNO in the first spectrum, will be processed.356 357 ifno -- IFNO to be processed.358 """359 self.ifno = ifno360 self.gridder._setif( self.ifno )361 362 def setPolList( self, pollist ):363 """364 Set list of polarization components you want to process.365 If not specified, all POLNOs will be processed.366 367 pollist -- list of POLNOs.368 """369 self.gridder._setpollist( pollist )370 371 def setScanList( self, scanlist ):372 """373 Set list of scans you want to process. If not specified, all374 scans will be processed.375 376 scanlist -- list of SCANNOs.377 """378 self.gridder._setscanlist( scanlist )379 380 def defineImage( self, nx=-1, ny=-1, cellx='', celly='', center='' ):381 """382 Define spatial grid.383 384 First two parameters, nx and ny, define number of pixels of385 the grid. If which of those is not specified, it will be set386 to the same value as the other. If none of them are specified,387 it will be determined from map extent and cell size.388 389 Next two parameters, cellx and celly, define size of pixel.390 You should set those parameters as string, which is constructed391 numerical value and unit, e.g. '0.5arcmin', or numerical value.392 If those values are specified as numerical value, their units393 will be assumed to 'arcsec'. If which of those is not specified,394 it will be set to the same value as the other. If none of them395 are specified, it will be determined from map extent and number396 of pixels, or set to '1arcmin' if neither nx nor ny is set.397 398 The last parameter, center, define the central coordinate of399 the grid. You should specify its value as a string, like,400 401 'J2000 05h08m50s -16d23m30s'402 403 or404 405 'J2000 05:08:50 -16.23.30'406 407 You can omit equinox when you specify center coordinate. In that408 case, J2000 is assumed. If center is not specified, it will be409 determined from the observed positions of input data.410 411 nx -- number of pixels along x (R.A.) direction.412 ny -- number of pixels along y (Dec.) direction.413 cellx -- size of pixel in x (R.A.) direction.414 celly -- size of pixel in y (Dec.) direction.415 center -- central position of the grid.416 """417 if not isinstance( cellx, str ):418 cellx = '%sarcsec'%(cellx)419 if not isinstance( celly, str ):420 celly = '%sarcsec'%(celly)421 self.gridder._defineimage( nx, ny, cellx, celly, center )422 423 def setFunc( self, func='box', width=-1 ):424 """425 Set convolution function. Possible options are 'box' (Box-car,426 default), 'sf' (prolate spheroidal), and 'gauss' (Gaussian).427 Width of convolution function can be set using width parameter.428 By default (-1), width is automatically set depending on each429 convolution function. Default values for width are:430 431 'box': 1 pixel432 'sf': 3 pixels433 'gauss': 1 pixel (width is used as HWHM)434 435 func -- Function type ('box', 'sf', 'gauss').436 width -- Width of convolution function. Default (-1) is to437 choose pre-defined value for each convolution function.438 """439 fname = func.upper()440 if fname == 'GAUSS' or fname == 'GJINC':441 gw = str(gwidth)442 jw = str(jwidth)443 w = str(width)444 if w[0] == '-': w = ''445 #self.gridder._setfunc(fname, -1, w, gw, jw)446 self.gridder._setfunc(fname,convsupport=-1,gwidth=gw,jwidth=jw,truncate=w)447 else:448 self.gridder._setfunc( func, convsupport=width )449 450 def setWeight( self, weightType='uniform' ):451 """452 Set weight type. Possible options are 'uniform' (default),453 'tint' (weight by integration time), 'tsys' (weight by454 Tsys: 1/Tsys**2), and 'tintsys' (weight by integration time455 as well as Tsys: tint/Tsys**2).456 457 weightType -- weight type ('uniform', 'tint', 'tsys', 'tintsys')458 """459 self.gridder._setweight( weightType )460 461 def enableClip( self ):462 """463 Enable min/max clipping.464 465 By default, min/max clipping is disabled so that you should466 call this method before actual gridding if you want to do467 clipping.468 """469 self.gridder._enableclip()470 471 def disableClip( self ):472 """473 Disable min/max clipping.474 """475 self.gridder._disableclip()476 477 def grid( self ):478 """479 Actual gridding which will be done based on several user inputs.480 """481 self.gridder._grid()482 483 370 def getResult( self ): 484 371 """ … … 486 373 """ 487 374 tp = 0 if rcParams['scantable.storage']=='memory' else 1 488 return scantable( self.gridder._get( tp ), average=False ) 489 490 def plotFunc(self, clear=True): 491 """ 492 Support function to see the shape of current grid function. 493 494 clear -- clear panel if True. Default is True. 495 """ 496 pl.figure(11) 497 if clear: 498 pl.clf() 499 f = self.gridder._getfunc() 500 convsampling = 100 501 a = numpy.arange(0,len(f)/convsampling,1./convsampling,dtype=float) 502 pl.plot(a,f,'.-') 503 pl.xlabel('pixel') 504 pl.ylabel('convFunc') 375 return scantable( self.gridder._get( tp ), average=False ) 505 376 506 377 class _SDGridPlotter:
Note:
See TracChangeset
for help on using the changeset viewer.