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
GeneralMetricTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 David M. Whitbeck, 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 Jones, D. I., Owen, B. J.
22 * \file
23 * \ingroup PtoleMetric_h
24 *
25 * \brief Tests the various LAL metric functions, by outputting the metric at a
26 * point in parameter space, and also producing an array of ellipses of
27 * constant mismatch.
28 *
29 * ### Program <tt>GeneralMetricTest.c</tt> ###
30 *
31 *
32 * ### Usage ###
33 *
34 * \code
35 * GeneralMetricTest
36 * \endcode
37 *
38 * ### Description ###
39 *
40 * This program computes metric components using a metric function of the
41 * user's specification. The ordering of the components is \f$ (f_0,
42 * \alpha, \delta, f_1\ldots) \f$ for the unprojected metric, and \f$ (\alpha,
43 * \delta, f_1\ldots) \f$ for the metric with \f$ f_0 \f$ projected out.
44 *
45 * With no options, this program displays metric components for a single point
46 * in parameter space for the default parameter values.
47 *
48 * The <b>-c</b> option determines the point on the sky where the metric
49 * is evaluated. This option is hard-coded to use equatorial coordinates
50 * and the argument should be given in hh:mm:ss:dd:mm:ss format.
51 * (Default is the center of the globular cluster 47 Tuc).
52 *
53 * The <b>-f</b> option sets the maximum frequency (in Hz) to search. (The
54 * default is 1000.)
55 *
56 * The <b>-l</b> option determines the limits in right ascension and
57 * declination of the rectangular region over which the mismatch contours
58 * are computed. The argument should be given in degrees as
59 * %RA(min):%RA(max):dec(min):dec(max). (The default is the octant of the
60 * sky defined by \f$ 0 < \textrm{RA} < 90 \f$ and \f$ 0< \textrm{dec} < 85 \f$ ; this avoids the
61 * coordinate singularity at the poles.)
62 *
63 * The <b>-m</b> option sets the mismatch (default is \f$ 0.02 \f$ ).
64 *
65 * The <b>-n</b> option sets the number of spindown parameters (default 0).
66 *
67 * The <b>-p</b> option is provided for users who wish to view the
68 * power mismatch contours provided by the <b>-x</b> option (see below)
69 * but don't have xmgrace installed. All necessary data is simply
70 * written to a file ``nongrace.data''; it's probably best to look at the
71 * code to see the exact format. The user should then write a small
72 * script to convert the data into the format appropriate to their
73 * favorite graphics package.
74 *
75 * The <b>-t</b> option sets the duration of integration in seconds. (The
76 * default is \f$ 39600 \f$ seconds \f$ = 11 \f$ hours, which is chosen because it is of
77 * the right size for S2 analyses).
78 *
79 * The <b>-x</b> option produces a graph of the 2\% power mismatch
80 * contours on the sky. Dimensions of the ellipses have been exaggerated
81 * by a factor of \c MAGNIFY (specified within the code) for
82 * legibility. The purpose of the graph is to get a feel for how ellipses
83 * are varying across parameter space. Note that this option makes a
84 * system call to the \c xmgrace program, and will not work if that
85 * program is not installed on your system.
86 *
87 * ### Algorithm ###
88 *
89 *
90 * ### Uses ###
91 *
92 * \code
93 * lalDebugLevel
94 * LALCheckMemoryLeaks()
95 * LALCreateVector()
96 * LALDestroyVector()
97 * LALDCreateVector()
98 * LALDDestroyVector()
99 * LALProjectMetric()
100 * LALPtoleMetric()
101 * xmgrace
102 * \endcode
103 *
104 * ### Notes ###
105 *
106 * The code does not yet really work with more than one spindown parameter.
107 *
108 */
109
110
111/** \name Error Codes */ /** @{ */
112#define GENERALMETRICTESTC_EMEM 1
113#define GENERALMETRICTESTC_ESUB 2
114#define GENERALMETRICTESTC_ESYS 3
115#define GENERALMETRICTESTC_EMET 4
116
117#define GENERALMETRICTESTC_MSGEMEM "memory (de)allocation error"
118#define GENERALMETRICTESTC_MSGESUB "subroutine failed"
119#define GENERALMETRICTESTC_MSGESYS "system call failed"
120#define GENERALMETRICTESTC_MSGEMET "determinant of projected metric negative"
121
122/** @} */
123
124#include <math.h>
125#include <stdio.h>
126#include <stdlib.h>
127#include <string.h>
128#include <sys/types.h>
129#include <sys/stat.h>
130#include <lal/AVFactories.h>
131#include <lal/LALgetopt.h>
132#include <lal/LALMalloc.h>
133#include <lal/LALStdlib.h>
134#include <lal/PtoleMetric.h>
135#include <lal/LALBarycenter.h>
136#include <lal/LALInitBarycenter.h>
137
138/** \cond DONT_DOXYGEN */
139
140#define DEFAULT_DURATION 39600 /* seconds */
141#define SPOKES 30
142#define MAGNIFY 1.0 /* Magnification factor of ellipses */
143
144
145int main( int argc, char *argv[] )
146{
147 static LALStatus status; /* Status structure */
148 PtoleMetricIn in; /* PtoleMetric() input structure */
149 REAL8 mismatch; /* mismatch threshold of mesh */
150 REAL8Vector *metric; /* Parameter-space metric */
151 int j, k; /* Parameter-space indices */
152 int opt; /* Command-line option. */
153 BOOLEAN grace; /* Whether or not we use xmgrace */
154 BOOLEAN nongrace; /* Whether or not to output data to file*/
155 int ra, dec, i; /* Loop variables for xmgrace option */
156 FILE *pvc = NULL; /* Temporary file for xmgrace option */
157 FILE *fnongrace = NULL;/* File contaning ellipse coordinates */
158 REAL8 ra_point; /* RA at which metric is evaluated */
159 REAL8 dec_point; /* dec at which metric is evaluated */
160 float a, b, c, d, e, f; /* To input point in standard format */
161 int ra_min, ra_max; /* Min and max RA for ellipse plot */
162 int dec_min, dec_max; /* Min and max dec for ellipse plot */
163 float c_ellipse; /* Centers of ellipses */
164 float r_ellipse; /* Radii of ellipses */
165 REAL8 determinant; /* Determinant of projected metric */
166 REAL4 f0; /* carrier frequency */
167 UINT2 numSpindown; /* Number of spindowns */
168
169 /* Defaults that can be overwritten: */
170 in.epoch.gpsSeconds = 731265908;
171 in.epoch.gpsNanoSeconds = 0.0;
172 mismatch = 0.02;
173 nongrace = 0;
174 in.duration = DEFAULT_DURATION;
175 grace = 0;
176 ra_point = ( 24.1 / 60 ) * LAL_PI_180; /* 47 Tuc */
177 dec_point = -( 72 + 5. / 60 ) * LAL_PI_180;
178 ra_min = 0;
179 ra_max = 90;
180 dec_min = 0;
181 dec_max = 85;
182 f0 = 1000;
183 numSpindown = 0;
184
185 /* Parse options. */
186 while ( ( opt = LALgetopt( argc, argv, "a:b:c:d:ef:l:m:n:pt:s:x" ) ) != -1 ) {
187 switch ( opt ) {
188 case 'b':
189 in.epoch.gpsSeconds = atoi( LALoptarg );
190 break;
191 case 'c':
192 if ( sscanf( LALoptarg, "%f:%f:%f:%f:%f:%f", &a, &b, &c, &d, &e, &f ) != 6 ) {
193 fprintf( stderr, "coordinates should be hh:mm:ss:dd:mm:ss\n" );
194 }
195 ra_point = ( 15 * a + b / 4 + c / 240 ) * LAL_PI_180;
196 dec_point = ( d + e / 60 + f / 3600 ) * LAL_PI_180;
197 break;
198 case 'f':
199 f0 = atof( LALoptarg );
200 break;
201 case 'l':
202 if ( sscanf( LALoptarg, "%d:%d:%d:%d",
203 &ra_min, &ra_max, &dec_min, &dec_max ) != 4 ) {
204 fprintf( stderr, "coordinates should be ra_min, ra_max, dec_min, dec_max all in degrees" );
205 }
206 break;
207 case 'm':
208 mismatch = atof( LALoptarg );
209 break;
210 case 'n':
211 numSpindown = atoi( LALoptarg );
212 break;
213 case 'p':
214 nongrace = 1;
215 break;
216 case 's':
217 break;
218 case 'x':
219 grace = 1;
220 break;
221 }
222 }
223
224 /* Allocate storage. */
225 metric = NULL;
226 LALDCreateVector( &status, &metric, ( 3 + numSpindown ) * ( 4 + numSpindown ) / 2 );
227 if ( status.statusCode ) {
228 printf( "%s line %d: %s\n", __FILE__, __LINE__,
231 }
232
233 /* Position in parameter space (sky, frequency, spindowns) */
235 in.position.longitude = ra_point;
236 in.position.latitude = dec_point;
237 in.maxFreq = f0;
238 in.spindown = NULL;
239 if ( numSpindown > 0 ) {
240 LALCreateVector( &status, &( in.spindown ), numSpindown );
241 if ( status.statusCode ) {
242 printf( "%s line %d: %s\n", __FILE__, __LINE__,
245 }
246 for ( i = 0; i < numSpindown; i++ ) {
247 in.spindown->data[i] = 0;
248 }
249 }
250
251 /* Detector site */
253
254 /* Evaluate metric components. */
255 LALPtoleMetric( &status, metric, &in );
256 if ( status.statusCode ) {
257 printf( "%s line %d: %s\n", __FILE__, __LINE__,
260 }
261
262 /* Print metric. */
263 printf( "\nmetric (f0, alpha, delta, ...) at the requested point\n" );
264 for ( j = 0; j <= 2 + numSpindown; j++ ) {
265 for ( k = 0; k <= j; k++ ) {
266 printf( " %+.4e", metric->data[k + j * ( j + 1 ) / 2] );
267 }
268 printf( "\n" );
269 }
270
271 /* Print determinants. */
272 determinant = metric->data[5] * metric->data[2] - pow( metric->data[4], 2 );
273 printf( "\nSky-determinant %e\n", determinant );
274 if ( numSpindown == 1 ) {
275 determinant = metric->data[2] * metric->data[5] * metric->data[9]
276 - metric->data[2] * metric->data[8] * metric->data[8]
277 + metric->data[4] * metric->data[8] * metric->data[7]
278 - metric->data[4] * metric->data[4] * metric->data[9]
279 + metric->data[7] * metric->data[4] * metric->data[8]
280 - metric->data[7] * metric->data[7] * metric->data[5];
281 printf( "S&S determinant %e\n", determinant );
282 }
283
284 /* Project carrier frequency out of metric. */
286 if ( status.statusCode ) {
287 printf( "%s line %d: %s\n", __FILE__, __LINE__,
290 }
291
292 /* Print projected metric. */
293 printf( "\nf-projected metric (alpha, delta, ...) at the requested point\n" );
294 for ( j = 1; j <= 2 + numSpindown; j++ ) {
295 for ( k = 1; k <= j; k++ ) {
296 printf( " %+.4e", metric->data[k + j * ( j + 1 ) / 2] );
297 }
298 printf( "\n" );
299 }
300
301 /* Print determinants. */
302 determinant = metric->data[5] * metric->data[2] - pow( metric->data[4], 2 );
303 printf( "\nSky-determinant %e\n", determinant );
304 if ( numSpindown == 1 ) {
305 determinant = metric->data[2] * metric->data[5] * metric->data[9]
306 - metric->data[2] * metric->data[8] * metric->data[8]
307 + metric->data[4] * metric->data[8] * metric->data[7]
308 - metric->data[4] * metric->data[4] * metric->data[9]
309 + metric->data[7] * metric->data[4] * metric->data[8]
310 - metric->data[7] * metric->data[7] * metric->data[5];
311 printf( "S&S determinant %e\n", determinant );
312 }
313
314 /* Here is the code that uses xmgrace with the -x option, */
315 /* and outputs data to a file with the -t option. */
316 if ( grace || nongrace ) {
317
318 /* Take care of preliminaries. */
319 if ( grace ) {
320 pvc = popen( "xmgrace -pipe", "w" );
321 if ( !pvc ) {
322 printf( "%s line %d: %s\n", __FILE__, __LINE__,
325 }
326 fprintf( pvc, "@xaxis label \"Right ascension (degrees)\"\n" );
327 fprintf( pvc, "@yaxis label \"Declination (degrees)\"\n" );
328 }
329 if ( nongrace ) {
330 fnongrace = fopen( "nongrace.data", "w" );
331 if ( !fnongrace ) {
332 printf( "%s line %d: %s\n", __FILE__, __LINE__,
335 }
336 }
337
338 /* Step around the sky: a grid in ra and dec. */
339 j = 0;
340 for ( dec = dec_max; dec >= dec_min; dec -= 10 ) {
341 for ( ra = ra_min; ra <= ra_max; ra += 15 ) {
342 REAL8 gaa, gad, gdd, angle, smaj, smin;
343
344 /* Get the metric at this ra, dec. */
345 in.position.longitude = ra * LAL_PI_180;
346 in.position.latitude = dec * LAL_PI_180;
347
348 /* Evaluate metric: */
349 LALPtoleMetric( &status, metric, &in );
350 if ( status.statusCode ) {
351 printf( "%s line %d: %s\n", __FILE__, __LINE__,
354 }
355
356 /* Project metric: */
358 if ( status.statusCode ) {
359 printf( "%s line %d: %s\n", __FILE__, __LINE__,
362 }
363 determinant = metric->data[5] * metric->data[2] - pow( metric->data[4], 2.0 );
364 if ( determinant < 0.0 ) {
365 printf( "%s line %d: %s\n", __FILE__, __LINE__,
368 }
369
370
371
372 /* Rename \gamma_{\alpha\alpha}. */
373 gaa = metric->data[2];
374 /* Rename \gamma_{\alpha\delta}. */
375 gad = metric->data[4];
376 /* Rename \gamma_{\delta\delta}. */
377 gdd = metric->data[5];
378 /* Semiminor axis from larger eigenvalue of metric. */
379 smin = gaa + gdd + sqrt( pow( gaa - gdd, 2 ) + pow( 2 * gad, 2 ) );
380 smin = sqrt( 2 * mismatch / smin );
381 /* Semiminor axis from smaller eigenvalue of metric. */
382 smaj = gaa + gdd - sqrt( pow( gaa - gdd, 2 ) + pow( 2 * gad, 2 ) );
383 /*printf("ra = %d, dec = %d, temp = %g\n", ra, dec, smaj);*/
384 smaj = sqrt( 2 * mismatch / smaj );
385 /* Angle of semimajor axis with "horizontal" (equator). */
386 angle = atan2( gad, mismatch / smaj / smaj - gdd );
387 if ( angle <= -LAL_PI_2 ) {
388 angle += LAL_PI;
389 }
390 if ( angle > LAL_PI_2 ) {
391 angle -= LAL_PI;
392 }
393
394 if ( grace ) {
395 /* Print set header. */
396 fprintf( pvc, "@s%d color (0,0,0)\n", j );
397 fprintf( pvc, "@target G0.S%d\n@type xy\n", j++ );
398 /* Print center of patch. */
399 fprintf( pvc, "%16.8g %16.8g\n", ( float )ra, ( float )dec );
400 }
401 if ( nongrace )
402 /* Print center of patch. */
403 {
404 fprintf( fnongrace, "%16.8g %16.8g\n", ( float )ra, ( float )dec );
405 }
406 /* Loop around patch ellipse. */
407 for ( i = 0; i <= SPOKES; i++ ) {
408 c_ellipse = LAL_TWOPI * i / SPOKES;
409 r_ellipse = MAGNIFY * LAL_180_PI * smaj * smin /
410 sqrt( pow( smaj * sin( c_ellipse ), 2 ) + pow( smin * cos( c_ellipse ), 2 ) );
411 if ( grace )
412 fprintf( pvc, "%e %e\n", ra + r_ellipse * cos( angle - c_ellipse ),
413 dec + r_ellipse * sin( angle - c_ellipse ) );
414 if ( nongrace )
415 fprintf( fnongrace, "%e %e\n", ra + r_ellipse * cos( angle - c_ellipse ),
416 dec + r_ellipse * sin( angle - c_ellipse ) );
417
418 } /* for (a...) */
419
420 } /* for (ra...) */
421 } /* for (dec...) */
422 if ( grace ) {
423 pclose( pvc );
424 }
425 if ( nongrace ) {
426 fclose( fnongrace );
427 }
428 } /* if (grace || nongrace) */
429
430 printf( "\nCleaning up and leaving...\n" );
431
433 if ( status.statusCode ) {
434 printf( "%s line %d: %s\n", __FILE__, __LINE__,
437 }
438 if ( in.spindown ) {
439 LALDestroyVector( &status, &( in.spindown ) );
440 }
441
442 if ( status.statusCode ) {
443 printf( "%s line %d: %s\n", __FILE__, __LINE__,
446 }
448 return 0;
449} /* main() */
450
451/** \endcond */
LALDetectorIndexGEO600DIFF
#define SPOKES
Definition: DopplerScan.c:503
#define GENERALMETRICTESTC_MSGEMEM
#define GENERALMETRICTESTC_EMET
#define GENERALMETRICTESTC_MSGESUB
#define GENERALMETRICTESTC_MSGEMET
#define GENERALMETRICTESTC_EMEM
#define GENERALMETRICTESTC_ESUB
#define GENERALMETRICTESTC_MSGESYS
#define GENERALMETRICTESTC_ESYS
int j
int k
void LALCheckMemoryLeaks(void)
#define c
int LALgetopt(int argc, char *const *argv, const char *optstring)
char * LALoptarg
#define fprintf
double e
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
double REAL8
uint16_t UINT2
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 a
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