Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
PtoleMetricTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton, Ian Jones, Benjamin Owen
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/**
21 * \author Owen, B. J., Jones, D. I.
22 * \file
23 * \ingroup PtoleMetric_h
24 * \brief Tests the LALPtoleMetric() function.
25 *
26 * ### Program PtoleMetricTest ###
27 *
28 *
29 * ### Usage ###
30 *
31 * \code
32 * PtoleMetricTest
33 * \endcode
34 *
35 * ### Description ###
36 *
37 * This program computes metric components using LALPtoleMetric(). The
38 * ordering of the components is \f$ (f_0, \alpha, \delta, f_1, \ldots) \f$ for the
39 * unprojected metric, and \f$ (\alpha, \delta, f_1, \ldots) \f$ for the metric with
40 * \f$ f_0 \f$ projected out.
41 *
42 * With no options, this program displays metric components for a single point
43 * in parameter space for the default integration time (see the <tt>-t</tt>
44 * option).
45 *
46 * The <tt>-b</tt> option sets the beginning time of integration to the option
47 * argument. (Default is \f$ 0 \f$ seconds)
48 *
49 * The <tt>-e</tt> option causes the program to showcase error messages when
50 * given bad parameter values, etc.
51 *
52 * The <tt>-m</tt> option sets the mismatch (default is \f$ 0.02 \f$ ).
53 *
54 * The <tt>-p</tt> option is provided for users who wish to view the
55 * power mismatch contours provided by the <tt>-x</tt> option (see below)
56 * but don't have xmgrace installed. All necessary data is simply
57 * written to a file ``nongrace.data''; it's probably best to look at the
58 * code to see the exact format. The user should then write a small
59 * script to convert the data into the format appropriate to their
60 * favorite graphics package.
61 *
62 * The <tt>-t</tt> option sets the duration of integration in seconds. The default
63 * is \f$ 10^5 \f$ seconds, which is chosen because it is about one day but not an
64 * integer multiple of any astronomically important timescale.
65 *
66 * The <tt>-x</tt> option produces a graph of the 2\% power mismatch
67 * contours on the sky. Dimensions of the ellipses have been exaggerated
68 * by a factor of \c MAGNIFY (specified within the code) for
69 * legibility. The purpose of the graph is to get a feel for how ellipses
70 * are varying across parameter space. Note that this option makes a
71 * system call to the \c xmgrace program, and will not work if that
72 * program is not installed on your system.
73 *
74 * ### Algorithm ###
75 *
76 *
77 * ### Uses ###
78 *
79 * \code
80 * lalDebugLevel
81 * LALCheckMemoryLeaks()
82 * LALCreateVector()
83 * LALDestroyVector()
84 * LALDCreateVector()
85 * LALDDestroyVector()
86 * LALProjectMetric()
87 * LALPtoleMetric()
88 * xmgrace
89 * \endcode
90 *
91 * ### Notes ###
92 *
93 * The graph shows that the patches' overall area is independent of right
94 * ascension but that those near the equator rotate, which adds a new
95 * complication to the tiling.
96 *
97 */
98
99/** \name Error Codes */ /** @{ */
100#define PTOLEMETRICTESTC_EMEM 1
101#define PTOLEMETRICTESTC_ESUB 2
102#define PTOLEMETRICTESTC_ESYS 3
103
104#define PTOLEMETRICTESTC_MSGEMEM "memory (de)allocation error"
105#define PTOLEMETRICTESTC_MSGESUB "subroutine failed"
106#define PTOLEMETRICTESTC_MSGESYS "system call failed"
107/** @} */
108
109#include <math.h>
110#include <stdio.h>
111#include <stdlib.h>
112#include <string.h>
113#include <sys/types.h>
114#include <sys/stat.h>
115#include <lal/AVFactories.h>
116#include <lal/LALgetopt.h>
117#include <lal/LALMalloc.h>
118#include <lal/LALStdlib.h>
119#include <lal/PtoleMetric.h>
120
121/** \cond DONT_DOXYGEN */
122
123#define DEFAULT_DURATION 1e5 /* seconds */
124#define NUM_SPINDOWN 0 /* Number of spindown parameters */
125#define SPOKES 30
126#define MAGNIFY 1.0 /* Magnification factor of ellipses */
127
128
129int main( int argc, char *argv[] )
130{
131 static LALStatus status; /* Status structure */
132 PtoleMetricIn in; /* PtoleMetric() input structure */
133 REAL4 mismatch; /* mismatch threshold of mesh */
134 REAL4Vector *spindown = NULL; /* Spindown parameters */
135 REAL8Vector *metric = NULL; /* Parameter-space metric */
136 int j, k; /* Parameter-space indices */
137 int opt; /* Command-line option. */
138 BOOLEAN test = 0; /* Whether we showcase error messages */
139 BOOLEAN grace = 0; /* Whether or not we use xmgrace */
140 BOOLEAN nongrace = 0; /* Whether or not to output data to file*/
141 int ra, dec, i; /* Loop variables for xmgrace option */
142 FILE *pvc = NULL; /* Temporary file for xmgrace option */
143 FILE *fnongrace = NULL; /* File contaning ellipse coordinates */
144
145
146 /* Default values. */
147 in.duration = DEFAULT_DURATION;
148 in.epoch.gpsSeconds = 0.0;
149 in.epoch.gpsNanoSeconds = 0.0;
150 mismatch = 0.02;
151
152
153 /* Parse options. */
154 while ( ( opt = LALgetopt( argc, argv, "b:em:pt:x" ) ) != -1 ) {
155 switch ( opt ) {
156 case 'b':
157 in.epoch.gpsSeconds = atof( LALoptarg );
158 break;
159 case 'e':
160 test = 1;
161 break;
162 case 'm':
163 mismatch = atof( LALoptarg );
164 break;
165 case 'p':
166 nongrace = 1;
167 break;
168 case 't':
169 in.duration = atof( LALoptarg );
170 break;
171 case 'x':
172 grace = 1;
173 break;
174 }
175 }
176
177 if ( test ) {
178 printf( "\nTesting bad I/O structures...\n" );
179 LALPtoleMetric( &status, metric, NULL );
180 printf( "\nTesting bad sky position...\n" );
181 in.position.longitude = 1e10;
182 LALPtoleMetric( &status, metric, &in );
183 }
184 /* Good sky position: ra=19h13m, dec=+16deg, sound familiar? */
186 in.position.longitude = 288.25 * LAL_PI_180;
187 in.position.latitude = 16 * LAL_PI_180;
188
189 if ( test ) {
190 printf( "\nTesting bad spindown parameters...\n" );
191 LALPtoleMetric( &status, metric, &in );
192 }
193 /* Good spindown parameters: all zero (if we have any) */
194 if ( NUM_SPINDOWN > 0 ) {
195 LALCreateVector( &status, &spindown, NUM_SPINDOWN );
196 if ( status.statusCode ) {
197 printf( "%s line %d: %s\n", __FILE__, __LINE__,
200 }
201 for ( j = 0; ( UINT4 )j < spindown->length; j++ ) {
202 spindown->data[j] = 0;
203 }
204 in.spindown = spindown;
205 } else {
206 in.spindown = NULL;
207 }
208
209
210
211 if ( test ) {
212 REAL4 old_duration = in.duration;
213 printf( "\nTesting bad duration...\n" );
214 in.duration = -1;
215 LALPtoleMetric( &status, metric, &in );
216 in.duration = old_duration;
217 }
218
219 if ( test ) {
220 printf( "\nTesting bad maximum frequency...\n" );
221 in.maxFreq = 0;
222 LALPtoleMetric( &status, metric, &in );
223 }
224 /* Good maximum frequency */
225 in.maxFreq = 1e3;
226
227 /* JC: DISABLE THIS
228 if (test) {
229 printf("\nTesting bad detector site...\n");
230 in.site->frDetector.vertexLatitudeRadians = 100 * LAL_PI / 180;
231 LALPtoleMetric( &status, metric, &in );
232 }
233 */
234 /* Use GEO600 site. */
236
237 if ( test ) {
238 printf( "\nTesting bad output contents...\n" );
239 LALPtoleMetric( &status, metric, &in );
240 }
241 /* Allocate storage for output metric. */
242 LALDCreateVector( &status, &metric, ( 3 + NUM_SPINDOWN ) * ( 4 + NUM_SPINDOWN ) / 2 );
243 if ( status.statusCode ) {
244 printf( "%s line %d: %s\n", __FILE__, __LINE__, PTOLEMETRICTESTC_MSGEMEM );
246 }
247
248 /* Print results if no options. */
249 if ( argc == 1 ) {
250
251 printf( "\nValid results for duration %e seconds:\n", in.duration );
252 LALPtoleMetric( &status, metric, &in );
253 if ( status.statusCode ) {
254 printf( "%s line %d: %s\n", __FILE__, __LINE__,
257 }
258 for ( j = 0; j <= 2 + NUM_SPINDOWN; j++ ) {
259 for ( k = 0; k <= j; k++ ) {
260 printf( " %+.3e", metric->data[k + j * ( j + 1 ) / 2] );
261 }
262 printf( "\n" );
263 }
265 if ( status.statusCode ) {
266 printf( "%s line %d: %s\n", __FILE__, __LINE__,
269 }
270 printf( "With f0 projected out:\n" );
271 for ( j = 1; j <= 2 + NUM_SPINDOWN; j++ ) {
272 for ( k = 1; k <= j; k++ ) {
273 printf( " %+.3e", metric->data[k + j * ( j + 1 ) / 2] );
274 }
275 printf( "\n" );
276 }
277
278#if 0
279 printf( "\nValid results for duration 1e7 seconds:\n" );
280 in.duration = 1e7;
281 LALPtoleMetric( &status, metric, &in );
282 if ( status.statusCode ) {
283 printf( "%s line %d: %s\n", __FILE__, __LINE__,
286 }
287 for ( j = 0; j <= 2 + NUM_SPINDOWN; j++ ) {
288 for ( k = 0; k <= j; k++ ) {
289 printf( " %+.3e", metric->data[k + j * ( j + 1 ) / 2] );
290 }
291 printf( "\n" );
292 }
294 if ( status.statusCode ) {
295 printf( "%s line %d: %s\n", __FILE__, __LINE__,
298 }
299 printf( "With f0 projected out:\n" );
300 for ( j = 1; j <= 2 + NUM_SPINDOWN; j++ ) {
301 for ( k = 1; k <= j; k++ ) {
302 printf( " %+.3e", metric->data[k + j * ( j + 1 ) / 2] );
303 }
304 printf( "\n" );
305 }
306#endif
307 } /* if (argc...) */
308
309 /* Here is the code that uses xmgrace with the -x option, */
310 /* and outputs data to a file with the -t option. */
311 if ( grace || nongrace ) {
312
313 /* Take care of preliminaries. */
314 if ( grace ) {
315 pvc = popen( "xmgrace -pipe", "w" );
316 if ( !pvc ) {
317 printf( "%s line %d: %s\n", __FILE__, __LINE__,
320 }
321 fprintf( pvc, "@xaxis label \"Right ascension (degrees)\"\n" );
322 fprintf( pvc, "@yaxis label \"Declination (degrees)\"\n" );
323 }
324 if ( nongrace ) {
325 fnongrace = fopen( "nongrace.data", "w" );
326 if ( !fnongrace ) {
327 printf( "%s line %d: %s\n", __FILE__, __LINE__,
330 }
331 }
332
333 /* Step around the sky: a grid in ra and dec. */
334 j = 0;
335 for ( dec = 80; dec > 0; dec -= 10 ) {
336 for ( ra = 0; ra <= 90; ra += 15 ) {
337 float gaa, gad, gdd, angle, smaj, smin;
338
339 /* Get the metric at this ra, dec. */
340 in.position.longitude = ra * LAL_PI_180;
341 in.position.latitude = dec * LAL_PI_180;
342 LALPtoleMetric( &status, metric, &in );
343 if ( status.statusCode ) {
344 printf( "%s line %d: %s\n", __FILE__, __LINE__,
347 }
348
349 /* Project metric: */
351 if ( status.statusCode ) {
352 printf( "%s line %d: %s\n", __FILE__, __LINE__,
355 }
356
357 /* Rename \gamma_{\alpha\alpha}. */
358 gaa = metric->data[2];
359 /* Rename \gamma_{\alpha\delta}. */
360 gad = metric->data[4];
361 /* Rename \gamma_{\delta\delta}. */
362 gdd = metric->data[5];
363 /* Semiminor axis from larger eigenvalue of metric. */
364 smin = gaa + gdd + sqrt( pow( gaa - gdd, 2 ) + pow( 2 * gad, 2 ) );
365 smin = sqrt( 2 * mismatch / smin );
366 /* Semiminor axis from smaller eigenvalue of metric. */
367 smaj = gaa + gdd - sqrt( pow( gaa - gdd, 2 ) + pow( 2 * gad, 2 ) );
368 smaj = sqrt( 2 * mismatch / smaj );
369 /* Angle of semimajor axis with "horizontal" (equator). */
370 angle = atan2( gad, mismatch / smaj / smaj - gdd );
371 if ( angle <= -LAL_PI_2 ) {
372 angle += LAL_PI;
373 }
374 if ( angle > LAL_PI_2 ) {
375 angle -= LAL_PI;
376 }
377
378 if ( grace ) {
379 /* Print set header. */
380 fprintf( pvc, "@s%d color (0,0,0)\n", j );
381 fprintf( pvc, "@target G0.S%d\n@type xy\n", j++ );
382 /* Print center of patch. */
383 fprintf( pvc, "%16.8g %16.8g\n", ( float )ra, ( float )dec );
384 }
385 if ( nongrace )
386 /* Print center of patch. */
387 {
388 fprintf( fnongrace, "%16.8g %16.8g\n", ( float )ra, ( float )dec );
389 }
390 /* Loop around patch ellipse. */
391 for ( i = 0; i <= SPOKES; i++ ) {
392 float c, r;
393 c = LAL_TWOPI * i / SPOKES;
394 r = MAGNIFY * LAL_180_PI * smaj * smin / sqrt( pow( smaj * sin( c ), 2 )
395 + pow( smin * cos( c ), 2 ) );
396 if ( grace ) {
397 fprintf( pvc, "%e %e\n", ra + r * cos( angle - c ), dec + r * sin( angle - c ) );
398 }
399 if ( nongrace )
400 fprintf( fnongrace, "%e %e\n", ra + r * cos( angle - c ),
401 dec + r * sin( angle - c ) );
402
403 } /* for (a...) */
404
405 } /* for (ra...) */
406 } /* for (dec...) */
407 if ( grace ) {
408 pclose( pvc );
409 }
410 if ( nongrace ) {
411 fclose( fnongrace );
412 }
413 } /* if (grace || nongrace) */
414
415 printf( "\nCleaning up and leaving...\n" );
416 if ( spindown ) {
417 LALDestroyVector( &status, &spindown );
418 if ( status.statusCode ) {
419 printf( "%s line %d: %s\n", __FILE__, __LINE__,
422 }
423 }
425 if ( status.statusCode ) {
426 printf( "%s line %d: %s\n", __FILE__, __LINE__,
429 }
431 return 0;
432} /* main() */
433
434/** \endcond */
LALDetectorIndexGEO600DIFF
#define NUM_SPINDOWN
Definition: DopplerScan.c:504
#define SPOKES
Definition: DopplerScan.c:503
int j
int k
void LALCheckMemoryLeaks(void)
#define c
int LALgetopt(int argc, char *const *argv, const char *optstring)
char * LALoptarg
#define PTOLEMETRICTESTC_MSGESUB
#define PTOLEMETRICTESTC_ESYS
#define PTOLEMETRICTESTC_ESUB
#define PTOLEMETRICTESTC_MSGEMEM
#define PTOLEMETRICTESTC_MSGESYS
#define PTOLEMETRICTESTC_EMEM
#define fprintf
int main(int argc, char **argv)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
#define LAL_PI_2
#define LAL_180_PI
#define LAL_PI_180
#define LAL_PI
#define LAL_TWOPI
unsigned char BOOLEAN
uint32_t UINT4
float REAL4
void LALPtoleMetric(LALStatus *status, REAL8Vector *metric, PtoleMetricIn *input)
Computes metric components for a pulsar search in the `‘Ptolemaic’' approximation; both the Earth's s...
Definition: PtoleMetric.c:91
void LALProjectMetric(LALStatus *stat, REAL8Vector *metric, BOOLEAN errors)
Project out the zeroth dimension of a metric.
Definition: PtoleMetric.c:732
static const INT4 r
COORDINATESYSTEM_EQUATORIAL
void LALDestroyVector(LALStatus *, REAL4Vector **)
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALCreateVector(LALStatus *, REAL4Vector **, UINT4)
INT4 gpsNanoSeconds
This structure will likely be changed to match up better with those under StackMetric....
Definition: PtoleMetric.h:110
SkyPosition position
The equatorial coordinates at which the metric components are evaluated.
Definition: PtoleMetric.h:111
REAL4Vector * spindown
The (dimensionless) spindown parameters for which the metric components are evaluated.
Definition: PtoleMetric.h:112
REAL4 maxFreq
The maximum frequency to be searched, in Hz.
Definition: PtoleMetric.h:115
const LALDetector * site
The detector site, used only for its latitude and longitude.
Definition: PtoleMetric.h:116
REAL4 duration
Duration of integration, in seconds.
Definition: PtoleMetric.h:114
LIGOTimeGPS epoch
When the coherent integration begins.
Definition: PtoleMetric.h:113
REAL4 * data
REAL8 longitude
REAL8 latitude
CoordinateSystem system