Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInference 4.1.9.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
DetectorFixedSkyCoords.c
Go to the documentation of this file.
1//
2// DetectorFixedSkyCoords.c
3//
4//
5// Created by John Veitch on 19/06/2014.
6//
7//
8
9#include <stdio.h>
10#include <math.h>
11#include <lal/LALInference.h>
12#include <lal/TimeDelay.h>
13#include <lal/LALDetectors.h>
14#include <lal/LALStatusMacros.h>
15#include <lal/SkyCoordinates.h>
16#include <lal/Date.h>
17
19 REAL8 t0, REAL8 alpha, REAL8 theta,
20 REAL8 *tg, REAL8 *ra, REAL8 *dec)
21{
22 if(det0==det1)
23 {
24 fprintf(stderr,"%s: Passed identical detectors as det0 and det1\n",__func__);
26 }
27 /* Calculate vector between detectors in earth frame */
28 REAL8 detvec[3];
29 UINT4 i,j;
30 for(i=0;i<3;i++) detvec[i]=det1->location[i]-det0->location[i];
31 REAL8 detnorm=0;
32 for(i=0;i<3;i++) detnorm+=detvec[i]*detvec[i];
33 for(i=0;i<3;i++) detvec[i]/=sqrt(detnorm);
34
35 REAL8 NORTH[3]={0,0,1};
36 REAL8 a[3];
37 /* Cross product of North vector with detector vector
38 will be the rotation axis for our matrix */
39 a[0]=detvec[1]*NORTH[2];
40 a[1]=-detvec[0]*NORTH[2];
41 a[2]=0.0;
42 REAL8 norm=sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
43 for (i=0;i<3;i++) a[i]/=norm;
44
45 /* Cartesian coordinates in detector-aligned frame */
46 REAL8 DETPOS[3];
47 DETPOS[0]=sin(alpha)*cos(theta);
48 DETPOS[1]=sin(alpha)*sin(theta);
49 DETPOS[2]=cos(alpha);
50
51 /* Rotation angle about a */
52 REAL8 rotang=-acos(detvec[2]*NORTH[2]);
53 REAL8 c=cos(rotang),s=sin(rotang);
54 /* Find rotation matrix to transform to Geographic coordinates */
55 REAL8 det2horiz[3][3]=
56 {
57 {c+a[0]*a[0]*(1.-c), a[1]*a[0]*(1.-c)-a[2]*s, a[0]*a[2]*(1.-c)+a[1]*s},
58 {a[1]*a[0]*(1.-c)+a[2]*s, c+a[1]*a[1]*(1.-c), a[1]*a[2]*(1.-c)-a[0]*s},
59 {a[0]*a[2]*(1.-c)-a[1]*s, a[1]*a[2]*(1.-c)+a[0]*s, c+a[2]*a[2]*(1.-c)}
60 };
61
62 /* Calculate cartesian coordinates in Geographic frame */
63 REAL8 GEO[3]={0,0,0};
64 for(i=0;i<3;i++) for(j=0;j<3;j++) GEO[i]+=det2horiz[i][j]*DETPOS[j];
65
66 REAL8 r=0;
67 for(i=0;i<3;i++) r+=GEO[i]*GEO[i];
68 r=sqrt(r);
69
70 /* Calculate Geographic coordinates */
71 REAL8 longitude=atan2(GEO[1],GEO[0]);
72 REAL8 latitude=asin(GEO[2]/r);
73 /* Calculate Equatorial coordinates */
74 SkyPosition horiz,equat;
75 horiz.longitude=longitude;
76 horiz.latitude=latitude;
78
80 memset(&status,0,sizeof(status));
81 LIGOTimeGPS gpstime;
82
83 XLALGPSSetREAL8(&gpstime,t0);
84 LALGeographicToEquatorial(&status,&equat,&horiz,&gpstime);
85 if(status.statusCode)
86 {
88 fprintf(stderr,"Error in coordinate conversion.\n");
89 exit(1);
90 }
91
92 *ra=equat.longitude;
93 *dec=equat.latitude;
94
95 /* Compute time at geocentre (strictly speaking we use the wrong gpstime for the earth orientation by a few ms) */
96 *tg=t0-XLALTimeDelayFromEarthCenter(det0->location, equat.longitude,equat.latitude,&gpstime);
97
98
99}
100
102 REAL8 tg, REAL8 ra, REAL8 dec,
103 REAL8 *t0, REAL8 *alpha, REAL8 *theta)
104{
105 if(det0==det1)
106 {
107 fprintf(stderr,"%s: Passed identical detectors as det0 and det1\n",__func__);
109 }
110 /* Calculate vector between detectors in earth frame */
111 REAL8 detvec[3];
112 UINT4 i,j;
113 for(i=0;i<3;i++) detvec[i]=det1->location[i]-det0->location[i];
114 REAL8 detnorm=0;
115 for(i=0;i<3;i++) detnorm+=detvec[i]*detvec[i];
116 for(i=0;i<3;i++) detvec[i]/=sqrt(detnorm);
117
118 REAL8 NORTH[3]={0,0,1};
119 REAL8 a[3];
120 /* Cross product of North vector with detector vector
121 will be the rotation axis for our matrix */
122 a[0]=detvec[1]*NORTH[2];
123 a[1]=-detvec[0]*NORTH[2];
124 a[2]=0.0;
125 REAL8 norm=sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
126 for (i=0;i<3;i++) a[i]/=norm;
127
128 /* Convert Equatorial (ra,dec) to geographic coordinates*/
129 SkyPosition horiz,equat;
130 equat.longitude=ra;
131 equat.latitude=dec;
133
135 memset(&status,0,sizeof(status));
136 LIGOTimeGPS gpstime;
137
138 XLALGPSSetREAL8(&gpstime,tg);
139 LALEquatorialToGeographic(&status,&horiz,&equat,&gpstime);
140 if(status.statusCode)
141 {
143 fprintf(stderr,"Error in coordinate conversion.\n");
144 exit(1);
145 }
146 REAL8 longitude=horiz.longitude;
147 REAL8 latitude=horiz.latitude;
148 /* Cartesian coordinates in Geographic frame */
149 REAL8 GEOPOS[3];
150 GEOPOS[0]=cos(latitude)*cos(longitude);
151 GEOPOS[1]=cos(latitude)*sin(longitude);
152 GEOPOS[2]=sin(latitude);
153
154 /* Rotation angle about a */
155 REAL8 rotang=-acos(detvec[2]*NORTH[2]);
156 REAL8 c=cos(rotang),s=sin(rotang);
157 /* Find rotation matrix to from Geographic coordinates (transpose of matrix in LALInferenceDetFrameToEquatorial) */
158 /*
159 {c+a[0]*a[0]*(1.-c), a[1]*a[0]*(1.-c)-a[2]*s, a[0]*a[2]*(1.-c)+a[1]*s},
160 {a[1]*a[0]*(1.-c)+a[2]*s, c+a[1]*a[1]*(1.-c), a[1]*a[2]*(1.-c)-a[0]*s},
161 {a[0]*a[2]*(1.-c)-a[1]*s, a[1]*a[2]*(1.-c)+a[0]*s, c+a[2]*a[2]*(1.-c)}
162 */
163 REAL8 horiz2det[3][3]=
164 {
165 {c+a[0]*a[0]*(1.-c), a[1]*a[0]*(1.-c)+a[2]*s, a[0]*a[2]*(1.-c)-a[1]*s},
166 {a[1]*a[0]*(1.-c)-a[2]*s, c+a[1]*a[1]*(1.-c), a[1]*a[2]*(1.-c)+a[0]*s},
167 {a[0]*a[2]*(1.-c)+a[1]*s, a[1]*a[2]*(1.-c)-a[0]*s, c+a[2]*a[2]*(1.-c)}
168 };
169
170 /* Calculate cartesian coordinates in detector frame */
171 REAL8 DETPOS[3]={0,0,0};
172 for(i=0;i<3;i++) for(j=0;j<3;j++) DETPOS[i]+=horiz2det[i][j]*GEOPOS[j];
173
174 REAL8 r=0;
175 for(i=0;i<3;i++) r+=DETPOS[i]*DETPOS[i];
176 r=sqrt(r);
177
178 /* Calculate detector coordinates */
179 *theta=atan2(DETPOS[1],DETPOS[0]);
180 *alpha=acos(DETPOS[2]/r);
181
182 /* Compute time at geocentre (strictly speaking we use the wrong gpstime for the earth orientation by a few ms) */
183 *t0=tg+XLALTimeDelayFromEarthCenter(det0->location, equat.longitude,equat.latitude,&gpstime);
184
185
186}
void REPORTSTATUS(LALStatus *status)
static REAL8 norm(const REAL8 x[3])
int j
#define fprintf
int s
double theta
double REAL8
uint32_t UINT4
void LALInferenceEquatorialToDetFrame(LALDetector *det0, LALDetector *det1, REAL8 tg, REAL8 ra, REAL8 dec, REAL8 *t0, REAL8 *alpha, REAL8 *theta)
void LALInferenceDetFrameToEquatorial(LALDetector *det0, LALDetector *det1, REAL8 t0, REAL8 alpha, REAL8 theta, REAL8 *tg, REAL8 *ra, REAL8 *dec)
Conversion routines between Equatorial (RA,DEC) and detector-based coordinate systems,...
static const INT4 r
static const INT4 a
COORDINATESYSTEM_GEOGRAPHIC
COORDINATESYSTEM_EQUATORIAL
void LALEquatorialToGeographic(LALStatus *stat, SkyPosition *output, SkyPosition *input, LIGOTimeGPS *gpsTime)
void LALGeographicToEquatorial(LALStatus *stat, SkyPosition *output, SkyPosition *input, LIGOTimeGPS *gpsTime)
REAL8 XLALTimeDelayFromEarthCenter(const double detector_earthfixed_xyz_metres[3], double source_right_ascension_radians, double source_declination_radians, const LIGOTimeGPS *gpstime)
#define XLAL_ERROR_VOID(...)
XLAL_EINVAL
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
c
double alpha
double t0
REAL8 location[3]
REAL8 longitude
REAL8 latitude
CoordinateSystem system