00001 /* 00002 * Copyright (C) 2005 Badri Krishnan, Alicia Sintes 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with with program; see the file COPYING. If not, write to the 00016 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00017 * MA 02111-1307 USA 00018 */ 00019 00020 /** 00021 * \author Alicia Sintes, Badri Krishnan 00022 * \ingroup pulsarHough 00023 * \file DriveHough.c 00024 * \brief Routines for creating the Hough skypatch 00025 */ 00026 00027 /*----------------------------------------------------------------------- 00028 * 00029 * File Name: PatchGrid.c 00030 * 00031 * Authors: Sintes, A.M., Krishnan, B. 00032 * 00033 * Revision: $Id: PatchGrid.c,v 1.10 2007/11/16 17:58:56 llucia Exp $ 00034 * 00035 * History: Created by Sintes May 14, 2001 00036 * Modified by Badri Krishnan Feb 2003 00037 * Modified by Sintes May 2003 00038 * 00039 *----------------------------------------------------------------------- 00040 * 00041 * NAME 00042 * PatchGrid.c 00043 * 00044 * SYNOPSIS 00045 * 00046 * DESCRIPTION 00047 * 00048 * DIAGNOSTICS 00049 * 00050 *----------------------------------------------------------------------- 00051 */ 00052 00053 /************************************ <lalVerbatim file="PatchGridCV"> 00054 Author: Sintes, A. M., Krishnan, B. 00055 $Id: PatchGrid.c,v 1.10 2007/11/16 17:58:56 llucia Exp $ 00056 ************************************* </lalVerbatim> */ 00057 00058 00059 /* <lalLaTeX> 00060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00061 \subsection{Module \texttt{PatchGrid.c}} 00062 \label{ss:PatchGrid.c} 00063 Function for tiling the sky-patch (on the projected plane). 00064 00065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00066 \subsubsection*{Prototypes} 00067 \vspace{0.1in} 00068 \input{PatchGridD} 00069 \index{\verb&LALHOUGHComputeSizePar()&} 00070 \index{\verb&LALHOUGHComputeNDSizePar()&} 00071 \index{\verb&LALHOUGHFillPatchGrid()&} 00072 %\index{\verb&LALHOUGHPatchGrid()&} 00073 00074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00075 \subsubsection*{Description} 00076 00077 This is a {\sc provisional}final now ? routine for tiling a sky-pacth 00078 on the projected plane. 00079 00080 Patch size specified by user 00081 00082 ==doc needs to be updated == 00083 00084 The reason to call it {\sc provisional} is because 00085 the size of the patch depends on the grid used in the 00086 demodulation stage. Neighbour sky-patches should not be separated 00087 nor overlapping too much. 00088 Here for setting the patch size, we consider only $v_{epicycle}$, 00089 the frequency \verb@f0@ and \verb@deltaF@ so that the \lq longitudinal' size 00090 of the patch is given by \verb@side == deltaF/f0 * c/v_epi@. 00091 By taking \verb@f0@ to be the maximun frequency considered in that step, 00092 the patch-size is valid for a whole frequency range.\\ 00093 00094 00095 Given input parameters, the function \verb&LALHOUGHPatchGrid()& provides 00096 patch information. 00097 00098 The input \verb@*in1@ is a structure of type \verb@HOUGHResolutionPar@ 00099 containing 00100 some resolution parameters such as: 00101 \texttt{in1->f0} a frequency, \texttt{in1->deltaF} the frequency resolution, and 00102 \texttt{in1->minWidthRatio} the ratio between the minimum annulus width 00103 for this search and the minimun annulus width for 1 year integration time. 00104 This value should be in the interval [1.0, 25.0]. 00105 00106 The output structure \verb@*out@ of type \verb@HOUGHPatchGrid@ 00107 stores patch grid information. The fields are: 00108 \begin{description} 00109 \item[\texttt{out->f0 }] The frequency to construct grid 00110 \item[\texttt{out->deltaF }] The frequency resolution: \texttt{df=1/TCOH} 00111 \item[\texttt{out->minWidthRatio }] Same as \texttt{in1->minWidthRatio} 00112 \item[\texttt{out->deltaX }] Space discretization in the x-direction 00113 \verb@=deltaF * minWidthRatio/(f0 * VTOT * PIXELFACTORX)@. 00114 \item[\texttt{out->xMin }] Minimum x value allowed, given as the center of the first pixel. 00115 \item[\texttt{out->xMax }] Maximun x value allowed, given as the center of the last pixel. 00116 \item[\texttt{out->xSide }] Real number of pixels in the x direction (in the 00117 projected plane). It should be smaller or equal to \texttt{xSideMax} 00118 (\verb@xSide = VTOT * PIXELFACTORX / (VEPI * minWidthRatio)@ ). 00119 \item[\texttt{out->xSideMax }] Length of \texttt{xCoor}. 00120 \item[\texttt{out->xCoor }] Coordinates of the pixel centers in the 00121 x-direction. 00122 \item[\texttt{out->deltaY }] Space resolution in the y-direction 00123 \verb@=deltaF * minWidthRatio/(f0 * VTOT * PIXELFACTORY)@. 00124 \item[\texttt{out->yMin }] Minimum y value allowed, given as the center of the first pixel. 00125 \item[\texttt{out->yMax }] Maximun y value allowed, given as the center of the last pixel. 00126 \item[\texttt{out->ySide }] Real number of pixels in the y-direction. It should 00127 be smaller or equal to \texttt{ySideMax} 00128 (\verb@ySide = VTOT * PIXELFACTORY / (VEPI * minWidthRatio)@ ). 00129 \item[\texttt{out->ySideMax }] Length of \texttt{yCoor}. 00130 \item[\texttt{out->yCoor }] Coordinates of the pixel centers in the 00131 y-direction. 00132 \end{description} 00133 00134 00135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00136 \subsubsection*{Uses} 00137 %%\begin{verbatim} 00138 %%LALZDestroyVector() 00139 %%\end{verbatim} 00140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00141 \subsubsection*{Notes} 00142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00143 \vfill{\footnotesize\input{PatchGridCV}} 00144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00145 </lalLaTeX> */ 00146 00147 00148 #include <lal/LUT.h> 00149 00150 00151 00152 NRCSID (PATCHGRIDC, "$Id: PatchGrid.c,v 1.10 2007/11/16 17:58:56 llucia Exp $"); 00153 00154 00155 /* 00156 * The functions that make up the guts of this module 00157 */ 00158 00159 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ 00160 /* ******************************* <lalVerbatim file="PatchGridD"> */ 00161 void LALHOUGHComputeSizePar (LALStatus *status, /* demodulated case */ 00162 HOUGHSizePar *out, 00163 HOUGHResolutionPar *in1 00164 ) 00165 { /* ********************************************* </lalVerbatim> */ 00166 00167 00168 INT8 f0Bin; /* corresponding freq. bin */ 00169 REAL8 deltaF; /* frequency resolution df=1/TCOH*/ 00170 REAL8 pixelFactor; /* number of pixel that fit in the thinnest annulus*/ 00171 REAL8 pixErr; /* for validity of LUT as PIXERR */ 00172 REAL8 linErr; /* as LINERR circle ->line */ 00173 REAL8 vTotC; /* estimate value of v-total/C as VTOT */ 00174 00175 REAL8 deltaX; /* pixel size in the projected plane */ 00176 REAL8 deltaY; 00177 UINT2 xSide; /* number of pixels in the x direction (projected plane)*/ 00178 UINT2 ySide; /* number of pixels in the y direction */ 00179 UINT2 maxSide; /* number of pixels in the y direction */ 00180 00181 UINT2 maxNBins; /* maximum number of bins affecting the patch. For 00182 memory allocation */ 00183 REAL8 patchSizeX; /* size of sky patch projected */ 00184 REAL8 patchSizeY; /* size of sky patch prijected */ 00185 REAL8 patchSkySizeX; /* Size of sky patch in radians */ 00186 REAL8 patchSkySizeY; 00187 00188 /* --------------------------------------------- */ 00189 INITSTATUS (status, "LALHOUGHComputeSizePar", PATCHGRIDC); 00190 ATTATCHSTATUSPTR (status); 00191 00192 /* Make sure the arguments are not NULL: */ 00193 ASSERT (out, status, LUTH_ENULL, LUTH_MSGENULL); 00194 ASSERT (in1 , status, LUTH_ENULL, LUTH_MSGENULL); 00195 00196 patchSkySizeX = in1->patchSkySizeX; 00197 patchSkySizeY = in1->patchSkySizeY; 00198 00199 /* Make sure the user chose a sky patch smaller that pi of the sky */ 00200 ASSERT (patchSkySizeX > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00201 ASSERT (patchSkySizeX <= LAL_PI,status, LUTH_EVAL, LUTH_MSGEVAL); 00202 ASSERT (patchSkySizeY > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00203 ASSERT (patchSkySizeY <= LAL_PI,status, LUTH_EVAL, LUTH_MSGEVAL); 00204 00205 pixelFactor = in1->pixelFactor; 00206 pixErr = in1->pixErr; 00207 linErr = in1->linErr; 00208 00209 /* Make sure the parameters make sense */ 00210 ASSERT (pixelFactor > 0, status, LUTH_EVAL, LUTH_MSGEVAL); 00211 ASSERT (pixErr < 1.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00212 ASSERT (linErr < 1.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00213 ASSERT (pixErr > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00214 ASSERT (linErr > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00215 00216 f0Bin = in1->f0Bin; 00217 deltaF = in1->deltaF; 00218 vTotC = in1->vTotC; 00219 00220 ASSERT (f0Bin > 0, status, LUTH_EVAL, LUTH_MSGEVAL); 00221 ASSERT (deltaF > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00222 ASSERT (vTotC > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00223 ASSERT (vTotC < 0.001, status, LUTH_EVAL, LUTH_MSGEVAL); 00224 00225 /* ************ THIS IS FOR THE DEMODULATED CASE ONLY *********** */ 00226 out->deltaF = deltaF; 00227 out->f0Bin = f0Bin; 00228 00229 deltaX = deltaY = 1.0/(vTotC *pixelFactor * f0Bin); 00230 out->deltaX = deltaX; 00231 out->deltaY = deltaY; 00232 00233 patchSizeX = 4.0 * tan(0.25*patchSkySizeX); 00234 patchSizeY = 4.0 * tan(0.25*patchSkySizeY); 00235 xSide = out->xSide = ceil( patchSizeX/deltaX ); 00236 ySide = out->ySide = ceil( patchSizeY/deltaY ); 00237 maxSide = MAX( xSide , ySide ); 00238 00239 /* the max number of bins that can fit in the diagonal and a bit more 00240 1.41->1.5 */ 00241 maxNBins = out->maxNBins = ceil( (1.5* maxSide)/pixelFactor); 00242 00243 /* maximum number of borders affecting the patch +1. Each Bin has up to 4 00244 borders, but they are common (they share 2 with the next bin). Depending on 00245 the orientation could be equal to maxNBins. In other cases twice maxNBins. 00246 Here we are very conservative*/ 00247 00248 out->maxNBorders = 1 + 2*maxNBins; 00249 00250 /* LUT validity */ 00251 /* From equation: nFreqValid = pixErr/(pixelFactor* vTotC * 0.5 * maxSide * deltaX); 00252 or the same is */ 00253 out->nFreqValid = (pixErr * 2 * f0Bin)/(pixelFactor * maxNBins); 00254 00255 /* max. angle (rad.) from the pole to consider a circle as a line in the projected plane */ 00256 /* epsilon ~ 2/radius circle; radius ~h*h/(2b), epsilon = 4b/(h*h) */ 00257 00258 out->epsilon=8.0* linErr/(maxSide*deltaX*maxSide) ; 00259 00260 /* ------------------------------------------- */ 00261 00262 00263 DETATCHSTATUSPTR (status); 00264 00265 /* normal exit */ 00266 RETURN (status); 00267 } 00268 00269 00270 00271 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ 00272 /* ******************************* <lalVerbatim file="PatchGridD"> */ 00273 void LALHOUGHComputeNDSizePar (LALStatus *status, /* non-demod. case */ 00274 HOUGHSizePar *out, 00275 HOUGHResolutionPar *in1 00276 ) 00277 { /* ********************************************* </lalVerbatim> */ 00278 00279 INT8 f0Bin; /* corresponding freq. bin */ 00280 REAL8 deltaF; /* frequency resolution df=1/TCOH*/ 00281 REAL8 pixelFactor; /* number of pixel that fit in the thinnest annulus*/ 00282 REAL8 pixErr; /* for validity of LUT as PIXERR */ 00283 REAL8 linErr; /* as LINERR circle ->line */ 00284 REAL8 vTotC; /* estimate value of v-total/C as VTOT */ 00285 00286 REAL8 deltaX; /* pixel size in the projected plane */ 00287 REAL8 deltaY; 00288 UINT2 xSide; /* number of pixels in the x direction (projected plane)*/ 00289 UINT2 ySide; /* number of pixels in the y direction */ 00290 UINT2 maxDopplerBin; 00291 UINT2 maxSide; /* number of pixels in the y direction */ 00292 00293 UINT2 maxNBins1,maxNBins2; 00294 UINT2 maxNBins; /* maximum number of bins affecting the patch. For 00295 memory allocation */ 00296 REAL8 patchSizeX; /* size of sky patch projected */ 00297 REAL8 patchSizeY; /* size of sky patch prijected */ 00298 REAL8 patchSkySizeX; /* Size of sky patch in radians */ 00299 REAL8 patchSkySizeY; 00300 00301 /* --------------------------------------------- */ 00302 INITSTATUS (status, "LALHOUGHComputeNDSizePar", PATCHGRIDC); 00303 ATTATCHSTATUSPTR (status); 00304 00305 /* Make sure the arguments are not NULL: */ 00306 ASSERT (out, status, LUTH_ENULL, LUTH_MSGENULL); 00307 ASSERT (in1 , status, LUTH_ENULL, LUTH_MSGENULL); 00308 00309 patchSkySizeX = in1->patchSkySizeX; 00310 patchSkySizeY = in1->patchSkySizeY; 00311 00312 /* Make sure the user chose a sky patch smaller that pi of the sky */ 00313 ASSERT (patchSkySizeX > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00314 ASSERT (patchSkySizeX <= LAL_PI,status, LUTH_EVAL, LUTH_MSGEVAL); 00315 ASSERT (patchSkySizeY > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00316 ASSERT (patchSkySizeY <= LAL_PI,status, LUTH_EVAL, LUTH_MSGEVAL); 00317 00318 pixelFactor = in1->pixelFactor; 00319 pixErr = in1->pixErr; 00320 linErr = in1->linErr; 00321 00322 /* Make sure the parameters make sense */ 00323 ASSERT (pixErr < 1.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00324 ASSERT (linErr < 1.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00325 ASSERT (pixErr > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00326 ASSERT (linErr > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00327 00328 f0Bin = in1->f0Bin; 00329 deltaF = in1->deltaF; 00330 vTotC = in1->vTotC; 00331 00332 ASSERT (f0Bin > 0, status, LUTH_EVAL, LUTH_MSGEVAL); 00333 ASSERT (deltaF > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00334 ASSERT (vTotC > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00335 ASSERT (vTotC < 0.001, status, LUTH_EVAL, LUTH_MSGEVAL); 00336 00337 /* ************ THIS IS FOR THE *NON* DEMODULATED CASE ONLY *********** */ 00338 out->deltaF = deltaF; 00339 out->f0Bin = f0Bin; 00340 00341 deltaX = deltaY = 1.0/(vTotC *pixelFactor * f0Bin); 00342 out->deltaX = deltaX; 00343 out->deltaY = deltaY; 00344 00345 patchSizeX = 4.0 * tan(0.25*patchSkySizeX); 00346 patchSizeY = 4.0 * tan(0.25*patchSkySizeY); 00347 xSide = out->xSide = ceil( patchSizeX/deltaX ); 00348 ySide = out->ySide = ceil( patchSizeY/deltaY ); 00349 maxSide = MAX( xSide , ySide ); 00350 00351 /* the max number of bins that can fit in the full sky */ 00352 maxDopplerBin = floor( f0Bin * vTotC +0.5); 00353 maxNBins1 = 1+ 2* maxDopplerBin; 00354 00355 /* estimate of the max number of bins that can fit in the patch 00356 (over-estimated) as the max number of bins that can fit in the diagonal 00357 and a bit more 1.41->1.5 */ 00358 maxNBins2 = ceil( (1.5* maxSide)/pixelFactor); 00359 00360 maxNBins = out->maxNBins = MIN( maxNBins1 , maxNBins2 ); 00361 00362 /* maximum number of borders affecting the patch +1. Each Bin has up to 4 00363 borders, but they are common (they share 2 with the next bin). Depending on 00364 the orientation could be equal to maxNBins. In other cases twice maxNBins. 00365 Here we are very conservative*/ 00366 00367 out->maxNBorders = 1 + 2*maxNBins; 00368 00369 /* LUT validity */ 00370 if(maxDopplerBin < 2){ 00371 /* the answer is infinity more or less */ 00372 out->nFreqValid = f0Bin; 00373 } 00374 else { 00375 REAL8 num, den; 00376 num = maxDopplerBin *maxDopplerBin; 00377 den = (maxDopplerBin -1)*(maxDopplerBin -1); 00378 out->nFreqValid =pixErr/(pixelFactor*vTotC)*sqrt(num/den -1.0); 00379 } 00380 00381 /* max. angle (rad.) from the pole to consider a circle as a line in the projected plane */ 00382 /* epsilon ~ 2/radius circle; radius ~h*h/(2b), epsilon = 4b/(h*h) */ 00383 00384 out->epsilon=8.0* linErr/(maxSide*deltaX*maxSide) ; 00385 00386 /* ------------------------------------------- */ 00387 00388 00389 DETATCHSTATUSPTR (status); 00390 00391 /* normal exit */ 00392 RETURN (status); 00393 } 00394 00395 00396 00397 00398 00399 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ 00400 /* *********************************<lalVerbatim file="PatchGridD"> */ 00401 void LALHOUGHFillPatchGrid (LALStatus *status, 00402 HOUGHPatchGrid *out, /* */ 00403 HOUGHSizePar *in1) 00404 { /* ***********************************************</lalVerbatim> */ 00405 00406 REAL8 deltaX; 00407 REAL8 deltaY; 00408 UINT2 xSide; /* number of pixels in the x direction (projected plane)*/ 00409 UINT2 ySide; /* number of pixels in the y direction */ 00410 00411 INT4 i; 00412 REAL8 xMin, xMax, x1; 00413 REAL8 yMin, yMax, myy1; 00414 REAL8 *xCoord; 00415 REAL8 *yCoord; 00416 /* --------------------------------------------- */ 00417 00418 INITSTATUS (status, "LALHOUGHFillPatchGrid", PATCHGRIDC); 00419 ATTATCHSTATUSPTR (status); 00420 00421 /* Make sure the arguments are not NULL: */ 00422 ASSERT (out, status, LUTH_ENULL, LUTH_MSGENULL); 00423 ASSERT (in1, status, LUTH_ENULL, LUTH_MSGENULL); 00424 ASSERT (out->xCoor, status, LUTH_ENULL, LUTH_MSGENULL); 00425 ASSERT (out->yCoor, status, LUTH_ENULL, LUTH_MSGENULL); 00426 00427 xCoord = out->xCoor; 00428 yCoord = out->yCoor; 00429 00430 xSide = out->xSide; 00431 ySide = out->ySide; 00432 00433 /* Make sure there are physical pixels in that patch */ 00434 ASSERT (xSide, status, LUTH_EVAL, LUTH_MSGEVAL); 00435 ASSERT (ySide, status, LUTH_EVAL, LUTH_MSGEVAL); 00436 00437 deltaX = out->deltaX = in1->deltaX; 00438 deltaY = out->deltaY = in1->deltaY; 00439 00440 /* Make sure pixel sizes are positive definite */ 00441 ASSERT (deltaX > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00442 ASSERT (deltaY > 0.0, status, LUTH_EVAL, LUTH_MSGEVAL); 00443 00444 out->f0 = in1->f0Bin * in1->deltaF; 00445 out->deltaF = in1->deltaF; 00446 00447 /* ------------------------------------------- */ 00448 /* Calculation of the patch limits with respect to the centers of the 00449 last pixels. Note xSide and ySide are integers */ 00450 xMax = out->xMax = deltaX*0.5*(xSide-1); 00451 yMax = out->yMax = deltaY*0.5*(ySide-1); 00452 00453 xMin = out->xMin = -xMax; 00454 yMin = out->yMin = -yMax; 00455 00456 /* ------------------------------------------- */ 00457 00458 /* Coordiantes of the pixel centers, in the projected plane */ 00459 x1=xMin; 00460 for (i=0;i<xSide;++i){ 00461 xCoord[i] = x1; 00462 x1+= deltaX; 00463 } 00464 00465 myy1=yMin; 00466 for (i=0;i<ySide;++i){ 00467 yCoord[i] = myy1; 00468 myy1+= deltaY; 00469 } 00470 00471 /* ------------------------------------------- */ 00472 00473 DETATCHSTATUSPTR (status); 00474 00475 /* normal exit */ 00476 RETURN (status); 00477 } 00478 00479 00480 00481 00482 00483 00484 00485 00486
1.5.2