Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
MetricUtilsTest.c
Go to the documentation of this file.
1//
2// Copyright (C) 2011--2015 Reinhard Prix, Karl Wette
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#include <stdlib.h>
21#include <stdio.h>
22#include <math.h>
23
24#include <lal/MetricUtils.h>
25#include <lal/XLALError.h>
26#include <lal/UniversalDopplerMetric.h>
27#include <lal/LALInitBarycenter.h>
28
29#include <lal/GSLHelpers.h>
30
31int main( void )
32{
33
34 // Create a phase metric to use for testing
35 gsl_matrix *g_ij = NULL;
36 {
37
38 // Load ephemerides
39 char earthEphem[] = TEST_PKG_DATA_DIR "earth00-40-DE405.dat.gz";
40 char sunEphem[] = TEST_PKG_DATA_DIR "sun00-40-DE405.dat.gz";
41 EphemerisData *edat = XLALInitBarycenter( earthEphem, sunEphem );
43
44 // Initialise UniversalDopplerMetric parameter struct
45 LIGOTimeGPS startTime = { 912345678, 0 };
47 {
49 par.coordSys = coordSys;
50 }
51 par.detMotionType = DETMOTION_SPIN | DETMOTION_ORBIT;
53 {
54 LALStringVector *detNames = XLALCreateStringVector( "H1", "L1", NULL );
55 LALStringVector *sqrtSX = XLALCreateStringVector( "1.0", "1.0", NULL );
57 XLAL_CHECK_MAIN( XLALParseMultiNoiseFloor( &par.multiNoiseFloor, sqrtSX, par.multiIFO.length ) == XLAL_SUCCESS, XLAL_EFUNC );
58 XLALDestroyStringVector( detNames );
60 }
61 par.signalParams.Doppler.refTime = startTime;
62 par.signalParams.Doppler.fkdot[0] = 100;
63 par.projectCoord = -1;
64 par.approxPhase = 1;
65
66 // Compute phase metric
69 g_ij = metric->g_ij;
70 metric->g_ij = NULL;
71
72 // Cleanup
74 XLALSegListClear( &par.segmentList );
76 }
77
78 // Test XLALMetricEllipseBoundingBox()
79 fprintf( stderr, "\n=== Test XLALMetricEllipseBoundingBox() ===\n\n" );
80 {
81 gsl_vector *bbox = XLALMetricEllipseBoundingBox( g_ij, 0.3 );
82 XLAL_CHECK_MAIN( bbox != NULL, XLAL_EFUNC );
83 GPVEC( bbox, "%0.6g" );
84 const double bbox_0 = 0.148608;
85 XLAL_CHECK_MAIN( fabs( gsl_vector_get( bbox, 0 ) - bbox_0 ) <= 1e-5, XLAL_ETOL, "gsl_vector_get( bbox, 0 ) = %0.6g != %0.6g", gsl_vector_get( bbox, 0 ), bbox_0 );
86 GFVEC( bbox );
87 }
88
89 // Test XLALTransformMetric() and XLALInverseTransformMetric()
90 fprintf( stderr, "\n=== Test XLALTransformMetric() and XLALInverseTransformMetric() ===\n\n" );
91 {
92
93 // Allocate memory
94 gsl_matrix *GAMAT_MAIN( transform, g_ij->size1, g_ij->size2 );
95 gsl_matrix *GAMAT_MAIN( gpr_ij, g_ij->size1, g_ij->size2 );
96
97 // Create some transform
98 for ( size_t i = 0; i < transform->size1; ++i ) {
99 for ( size_t j = 0; j < transform->size2; ++j ) {
100 gsl_matrix_set( transform, i, j, ( j >= i ) ? pow( 2, j - i ) : 0.0 );
101 }
102 }
103
104 // Apply transform then inverse transfrom, should give back same metric
105 XLAL_CHECK_MAIN( XLALTransformMetric( &gpr_ij, transform, g_ij ) == XLAL_SUCCESS, XLAL_EFUNC );
106 XLAL_CHECK_MAIN( XLALInverseTransformMetric( &gpr_ij, transform, gpr_ij ) == XLAL_SUCCESS, XLAL_EFUNC );
107 const REAL8 d = XLALCompareMetrics( gpr_ij, g_ij ), d_max = 1e-10;
108 XLAL_CHECK_MAIN( d <= d_max, XLAL_ETOL, "XLALCompareMetric( gpr_ij, g_ij ) = %0.2g > %0.2g", d, d_max );
109
110 // Cleanup
111 GFMAT( transform, gpr_ij );
112 }
113
114 // Test XLALDiagNormalizeMetric()
115 fprintf( stderr, "\n=== Test XLALDiagNormalizeMetric() ===\n\n" );
116 {
117 gsl_matrix *transform = NULL, *gpr_ij = NULL;
118
119 // Diagonally normalize metric
120 XLAL_CHECK_MAIN( XLALDiagNormalizeMetric( &gpr_ij, &transform, g_ij ) == XLAL_SUCCESS, XLAL_EFUNC );
121 for ( size_t i = 0; i < gpr_ij->size1; ++i ) {
122 XLAL_CHECK_MAIN( fabs( gsl_matrix_get( gpr_ij, i, i ) - 1.0 ) <= 1e-5, XLAL_ETOL, "gsl_matrix_get( gpr_ij, %zu, %zu ) = %0.6g != 1.0", i, i, gsl_matrix_get( gpr_ij, i, i ) );
123 }
124
125 // Invert transform, should give back same metric
126 XLAL_CHECK_MAIN( XLALInverseTransformMetric( &gpr_ij, transform, gpr_ij ) == XLAL_SUCCESS, XLAL_EFUNC );
127 const REAL8 d = XLALCompareMetrics( gpr_ij, g_ij ), d_max = 1e-10;
128 XLAL_CHECK_MAIN( d <= d_max, XLAL_ETOL, "XLALCompareMetric( gpr_ij, g_ij ) = %0.2g > %0.2g", d, d_max );
129
130 // Cleanup
131 GFMAT( transform, gpr_ij );
132 }
133
134 // Cleanup
135 GFMAT( g_ij );
137
138 return EXIT_SUCCESS;
139
140}
int j
void LALCheckMemoryLeaks(void)
int main(void)
#define fprintf
double e
int XLALParseMultiLALDetector(MultiLALDetector *detInfo, const LALStringVector *detNames)
Parse string-vectors (typically input by user) of N detector-names for detectors ,...
int XLALParseMultiNoiseFloor(MultiNoiseFloor *multiNoiseFloor, const LALStringVector *sqrtSX, UINT4 numDetectors)
Parse string-vectors (typically input by user) of N detector noise-floors for detectors ,...
EphemerisData * XLALInitBarycenter(const CHAR *earthEphemerisFile, const CHAR *sunEphemerisFile)
XLAL interface to reading ephemeris files 'earth' and 'sun', and return ephemeris-data in old backwar...
void XLALDestroyEphemerisData(EphemerisData *edat)
Destructor for EphemerisData struct, NULL robust.
#define LAL_DAYSID_SI
double REAL8
#define XLAL_INIT_DECL(var,...)
REAL8 XLALCompareMetrics(const gsl_matrix *g1_ij, const gsl_matrix *g2_ij)
Flexible comparison function between two metrics and .
Definition: MetricUtils.c:52
int XLALInverseTransformMetric(gsl_matrix **p_gpr_ij, const gsl_matrix *transform, const gsl_matrix *g_ij)
Apply the inverse of a transform to a metric such that , or equivalently .
Definition: MetricUtils.c:341
int XLALDiagNormalizeMetric(gsl_matrix **p_gpr_ij, gsl_matrix **p_transform, const gsl_matrix *g_ij)
Diagonally-normalize a metric .
Definition: MetricUtils.c:391
int XLALTransformMetric(gsl_matrix **p_gpr_ij, const gsl_matrix *transform, const gsl_matrix *g_ij)
Apply a transform to a metric such that , or equivalently .
Definition: MetricUtils.c:286
gsl_vector * XLALMetricEllipseBoundingBox(const gsl_matrix *g_ij, const double max_mismatch)
Compute the extent of the bounding box of the mismatch ellipse of a metric .
Definition: MetricUtils.c:131
int XLALSegListClear(LALSegList *seglist)
int XLALSegListInitSimpleSegments(LALSegList *seglist, LIGOTimeGPS startTime, UINT4 Nseg, REAL8 Tseg)
void XLALDestroyStringVector(LALStringVector *vect)
LALStringVector * XLALCreateStringVector(const CHAR *str1,...)
void XLALDestroyDopplerPhaseMetric(DopplerPhaseMetric *metric)
Free a DopplerPhaseMetric structure.
DopplerPhaseMetric * XLALComputeDopplerPhaseMetric(const DopplerMetricParams *metricParams, const EphemerisData *edat)
Calculate an approximate "phase-metric" with the specified parameters.
@ DOPPLERCOORD_N3X_EQU
X component of unconstrained super-sky position in equatorial coordinates [Units: none].
@ DOPPLERCOORD_N3Z_EQU
Z component of unconstrained super-sky position in equatorial coordinates [Units: none].
@ DOPPLERCOORD_N3Y_EQU
Y component of unconstrained super-sky position in equatorial coordinates [Units: none].
@ DOPPLERCOORD_F1DOT
First spindown [Units: Hz/s].
@ DOPPLERCOORD_FREQ
Frequency [Units: Hz].
@ DETMOTION_SPIN
Full spin motion.
@ DETMOTION_ORBIT
Ephemeris-based orbital motion.
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
XLAL_ETOL
type describing a Doppler coordinate system: lists the number of dimensions and the symbolic names of...
meta-info specifying a Doppler-metric
Struct to hold the output of XLALComputeDopplerPhaseMetric(), including meta-info on the number of di...
This structure contains all information about the center-of-mass positions of the Earth and Sun,...