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
WeaveSetup.c
Go to the documentation of this file.
1//
2// Copyright (C) 2016, 2017 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///
21/// \file
22/// \ingroup lalpulsar_bin_Weave
23///
24
25#include "Weave.h"
26#include "SetupData.h"
27
28#include <lal/LALInitBarycenter.h>
29#include <lal/LogPrintf.h>
30#include <lal/UserInput.h>
31
32int main( int argc, char *argv[] )
33{
34
35 // Set help information
36 lalUserVarHelpBrief = "create setup file for use with lalpulsar_Weave";
37
38 ////////// Parse user input //////////
39
40 // Initialise user input variables
41 struct uvar_type {
42 CHAR *segment_list, *sft_files, *detector_motion, *ephem_earth, *ephem_sun, *output_file;
44 LIGOTimeGPS ref_time;
45 LIGOTimeGPSRange first_segment;
46 REAL8 segment_gap;
47 UINT4 segment_count, spindowns;
48 } uvar_struct = {
49 .detector_motion = XLALStringDuplicate( "spin+orbit" ),
50 .ephem_earth = XLALStringDuplicate( "earth00-40-DE405.dat.gz" ),
51 .ephem_sun = XLALStringDuplicate( "sun00-40-DE405.dat.gz" ),
52 .segment_count = 1,
53 .spindowns = 1,
54 };
55 struct uvar_type *const uvar = &uvar_struct;
56
57 // Register user input variables:
58 //
59 // - General
60 //
62 output_file, STRING, 'o', REQUIRED,
63 "Output file while stores the segment list, parameter-space metrics, and other data required by lalpulsar_Weave, e.g. ephemerides. "
64 );
65 //
66 // - Segment list input/generation
67 //
68 lalUserVarHelpOptionSubsection = "Segment list input/generation";
70 segment_list, STRING, 'L', OPTIONAL,
71 "Loads the start and end times of each segment from this file. "
72 "Format is:\n"
73 " # comment\n <segment-start-time-GPS> <segment-end-time-GPS> [number-of-SFTs-in-segment]\n ..."
74 );
76 first_segment, EPOCHRange, 't', OPTIONAL,
77 "Generate segments; the range of the first segment is specified by this option. "
78 );
80 segment_count, UINT4, 'n', OPTIONAL,
81 "Generate this many segments by translating the first segment in time by its span, i.e. so that segments are contiguous and non-overlapping. "
82 "Must be at least 1. "
83 );
85 segment_gap, REAL8, 'g', DEVELOPER,
86 "When generating segments, increase the translation of the first segment by this amount (in seconds). "
87 "A positive value gives non-contiguous segments; a negative value gives overlapping segments. "
88 );
90 sft_files, STRING, 'I', NODEFAULT,
91 "Pattern matching the SFT files to be analysed; used to discard empty segments. Possibilities are:\n"
92 " - '<SFT file>;<SFT file>;...', where <SFT file> may contain wildcards\n - 'list:<file containing list of SFT files>'"
93 );
94 //
95 // - Parameter-space metric computation
96 //
97 lalUserVarHelpOptionSubsection = "Parameter-space metric computation";
99 ref_time, EPOCH, 'r', NODEFAULT,
100 "Reference time for the search, including the parameter-space metrics computed here, and the parameter space and output of lalpulsar_Weave. "
101 "If omitted, the mid-point between the start of the first segment and the end of the last segment is used. "
102 );
104 detectors, STRINGVector, 'd', REQUIRED,
105 "Comma-separated list of 2-character detector names (e.g. H1,L1,...) for which the parameter-space metrics are computed. "
106 "Note that the detector names are always sorted, since their order impacts the interpretation of some options to lalpulsar_Weave. "
107 );
109 detector_motion, STRING, 'm', DEVELOPER,
110 "Specify what detector motion to assume when computing the parameter-space metrics. "
111 "The only interesting options are:\n"
112 " - 'spin+orbit' use the full ephemeris of the Earth's orbit;\n"
113 " - 'spin+ptoleorbit': use a Ptolemaic approximation of the Earth's orbit."
114 );
116 ephem_earth, STRING, 'E', DEVELOPER,
117 "Earth ephemeris file, used to compute the parameter-space metrics and by lalpulsar_Weave. "
118 );
120 ephem_sun, STRING, 'S', DEVELOPER,
121 "Sun ephemeris file, used to compute the parameter-space metrics and by lalpulsar_Weave. "
122 );
124 spindowns, UINT4, 's', OPTIONAL,
125 "Maximum number of spindowns for which the parameter-space metrics are computed. "
126 "Must be at least 1. "
127 "This option limits the size of the spindown parameter space given to lalpulsar_Weave. "
128 );
129
130 // Parse user input
131 XLAL_CHECK_MAIN( xlalErrno == 0, XLAL_EFUNC, "A call to XLALRegisterUvarMember() failed" );
132 BOOLEAN should_exit = 0;
134 if ( should_exit ) {
135 return EXIT_FAILURE;
136 }
137
138 // Check user input:
139 //
140 // - General
141 //
142
143 //
144 // - Segment list input/generation
145 //
146 XLALUserVarCheck( &should_exit,
147 UVAR_SET2( segment_list, first_segment ) == 1,
148 "Exactly one of " UVAR_STR2OR( segment_list, first_segment ) " must be specified" );
149 XLALUserVarCheck( &should_exit,
150 !UVAR_ALLSET2( segment_list, segment_gap ),
151 "At most one of " UVAR_STR2AND( segment_list, segment_gap ) " may be specified" );
152 XLALUserVarCheck( &should_exit,
153 !UVAR_ALLSET2( segment_list, segment_count ),
154 "At most one of " UVAR_STR2AND( segment_list, segment_count ) " may be specified" );
155 XLALUserVarCheck( &should_exit,
156 uvar->segment_count > 0,
157 UVAR_STR( segment_count ) " must be strictly positive" );
158 //
159 // - Parameter-space metric computation
160 //
161 XLALUserVarCheck( &should_exit,
162 uvar->spindowns > 0,
163 UVAR_STR( spindowns ) " must be strictly positive" );
164
165 // Exit if required
166 if ( should_exit ) {
167 return EXIT_FAILURE;
168 }
169 LogPrintf( LOG_NORMAL, "Parsed user input successfully\n" );
170
171 ////////// Create setup data //////////
172
173 // Initialise setup data
174 WeaveSetupData XLAL_INIT_DECL( setup );
175
176 // Copy and sort list of detector names
177 setup.detectors = XLALCopyStringVector( uvar->detectors );
178 XLAL_CHECK_MAIN( setup.detectors != NULL, XLAL_EFUNC );
180
181 // Load ephemerides
182 LogPrintf( LOG_NORMAL, "Loading ephemerides from '%s' and '%s' ...\n", uvar->ephem_earth, uvar->ephem_sun );
183 setup.ephemerides = XLALInitBarycenter( uvar->ephem_earth, uvar->ephem_sun );
184 XLAL_CHECK_MAIN( setup.ephemerides != NULL, XLAL_EFUNC );
185
186 // Create segment list
187 if ( UVAR_SET( segment_list ) ) {
188
189 // Load segment list from file
190 LogPrintf( LOG_NORMAL, "Loading segment list from '%s' ...\n", uvar->segment_list );
191 setup.segments = XLALReadSegmentsFromFile( uvar->segment_list );
192 XLAL_CHECK_MAIN( setup.segments != NULL, XLAL_EFUNC );
193
194 } else {
195
196 // Generate segment list
197 LogPrintf( LOG_NORMAL, "Generating segment list; first segment = [%" LAL_GPS_FORMAT ", %" LAL_GPS_FORMAT "] GPS, segment gap = %g sec ...\n", LAL_GPS_PRINT( uvar->first_segment[0] ), LAL_GPS_PRINT( uvar->first_segment[1] ), uvar->segment_gap );
198 setup.segments = XLALSegListCreate();
199 XLAL_CHECK_MAIN( setup.segments != NULL, XLAL_EFUNC );
200
201 // Set first segment
202 LALSeg seg;
203 XLALSegSet( &seg, &uvar->first_segment[0], &uvar->first_segment[1], 0 );
204
205 // Increment to add to each successive segment
206 const REAL8 dt = XLALGPSDiff( &seg.end, &seg.start ) + uvar->segment_gap;
207
208 // Create segments
209 for ( UINT4 n = 0; n < uvar->segment_count; ++n ) {
210 XLAL_CHECK_MAIN( XLALSegListAppend( setup.segments, &seg ) == XLAL_SUCCESS, XLAL_EFUNC );
211 XLALGPSAdd( &seg.start, dt );
212 XLALGPSAdd( &seg.end, dt );
213 }
214
215 }
216
217 // Load SFT catalog to check for empty segments
218 if ( UVAR_SET( sft_files ) ) {
219
220 // Load SFT catalog from files given by 'sft_files'
221 LogPrintf( LOG_NORMAL, "Loading SFTs matching '%s' into catalog ...\n", uvar->sft_files );
222 SFTCatalog *sft_catalog = XLALSFTdataFind( uvar->sft_files, NULL );
223 XLAL_CHECK_MAIN( sft_catalog != NULL, XLAL_EFUNC );
224 XLAL_CHECK_MAIN( sft_catalog->length > 0, XLAL_EFUNC );
225 LogPrintf( LOG_NORMAL, "Loaded SFT catalog from SFTs matching '%s'\n", uvar->sft_files );
226
227 // Build new segment list without empty segments
228 LALSegList *nonempty_segments = XLALSegListCreate();
229 XLAL_CHECK_MAIN( nonempty_segments != NULL, XLAL_EFUNC );
230 for ( UINT4 n = 0; n < setup.segments->length; ++n ) {
231 const LALSeg *seg = &setup.segments->segs[n];
232 SFTCatalog XLAL_INIT_DECL( sft_catalog_seg );
233 XLAL_CHECK_MAIN( XLALSFTCatalogTimeslice( &sft_catalog_seg, sft_catalog, &seg->start, &seg->end ) == XLAL_SUCCESS, XLAL_EFUNC );
234 if ( sft_catalog_seg.length > 0 ) {
235 XLAL_CHECK_MAIN( XLALSegListAppend( nonempty_segments, seg ) == XLAL_SUCCESS, XLAL_EFUNC );
236 } else {
237 LogPrintf( LOG_NORMAL, "Discarding empty segment %u, range = [%" LAL_GPS_FORMAT ", %" LAL_GPS_FORMAT "] GPS\n", n, LAL_GPS_PRINT( seg->start ), LAL_GPS_PRINT( seg->end ) );
238 }
239 }
240 XLAL_CHECK_MAIN( nonempty_segments->length > 0, XLAL_EINVAL, "No SFTs found in any segments" );
241 XLALSegListFree( setup.segments );
242 setup.segments = nonempty_segments;
243
244 // Cleanup memory from SFT catalog
245 XLALDestroySFTCatalog( sft_catalog );
246
247 }
248
249 // Compute segment list range
250 LIGOTimeGPS segments_start, segments_end;
251 XLAL_CHECK_MAIN( XLALSegListRange( setup.segments, &segments_start, &segments_end ) == XLAL_SUCCESS, XLAL_EFUNC );
252 LogPrintf( LOG_NORMAL, "Segment list range = [%" LAL_GPS_FORMAT ", %" LAL_GPS_FORMAT "] GPS, segment count = %i\n", LAL_GPS_PRINT( segments_start ), LAL_GPS_PRINT( segments_end ), setup.segments->length );
253
254 // Set reference time
255 if ( UVAR_SET( ref_time ) ) {
256 setup.ref_time = uvar->ref_time;
257 } else {
258 setup.ref_time = segments_start;
259 XLALGPSAdd( &setup.ref_time, 0.5 * XLALGPSDiff( &segments_end, &segments_start ) );
260 }
261 LogPrintf( LOG_NORMAL, "Reference time = %" LAL_GPS_FORMAT " GPS\n", LAL_GPS_PRINT( setup.ref_time ) );
262
263 // Restrict ephemerides to range of segment list +/- 1 day
264 {
265 LIGOTimeGPS ephem_start = segments_start, ephem_end = segments_end;
266 XLALGPSAdd( &ephem_start, -LAL_DAYSID_SI );
267 XLALGPSAdd( &ephem_end, +LAL_DAYSID_SI );
268 XLAL_CHECK( XLALRestrictEphemerisData( setup.ephemerides, &ephem_start, &ephem_end ) == XLAL_SUCCESS, XLAL_EFUNC );
269 }
270
271 // Parse list of detectors
272 MultiLALDetector detector_info;
273 {
274 char *detectors_string = XLALConcatStringVector( uvar->detectors, "," );
275 XLAL_CHECK_MAIN( detectors_string != NULL, XLAL_EFUNC );
276 XLAL_CHECK_MAIN( XLALParseMultiLALDetector( &detector_info, uvar->detectors ) == XLAL_SUCCESS, XLAL_EINVAL, "Invalid value '%s' for " UVAR_STR( detectors ), detectors_string );
277 XLALFree( detectors_string );
278 }
279
280 // Parse detector motion string
281 const DetectorMotionType detector_motion = XLALParseDetectorMotionString( uvar->detector_motion );
282 XLAL_CHECK_MAIN( xlalErrno == 0, XLAL_EINVAL, "Invalid value '%s' for " UVAR_STR( detector_motion ), uvar->detector_motion );
283
284 // Compute reduced supersky metrics at fiducial frequency of 100Hz
285 // - Fiducial frequency is stored in coordinate transform data, so
286 // metrics can later be rescaled by search code
287 LogPrintf( LOG_NORMAL, "Computing reduced supersky metrics ...\n" );
288 const double fiducial_freq = 100.0;
289 setup.metrics = XLALComputeSuperskyMetrics( SUPERSKY_METRIC_TYPE, uvar->spindowns, &setup.ref_time, setup.segments, fiducial_freq, &detector_info, NULL, detector_motion, setup.ephemerides );
290 XLAL_CHECK_MAIN( setup.metrics != NULL, XLAL_EFUNC );
291 LogPrintf( LOG_NORMAL, "Finished computing reduced supersky metrics\n" );
292
293 ////////// Output setup data //////////
294
295 // Open output file
296 LogPrintf( LOG_NORMAL, "Opening output file '%s' for writing ...\n", uvar->output_file );
297 FITSFile *file = XLALFITSFileOpenWrite( uvar->output_file );
298 XLAL_CHECK_MAIN( file != NULL, XLAL_EFUNC );
301
302 // Write setup data
304
305 // Close output file
307 LogPrintf( LOG_NORMAL, "Closed output file '%s'\n", uvar->output_file );
308
309 ////////// Cleanup memory and exit //////////
310
311 // Cleanup memory from setup data
312 XLALWeaveSetupDataClear( &setup );
313
314 // Cleanup memory from user input
316
317 // Check for memory leaks
319
320 LogPrintf( LOG_NORMAL, "Finished successfully!\n" );
321
322 return EXIT_SUCCESS;
323
324}
325
326// Local Variables:
327// c-file-style: "linux"
328// c-basic-offset: 2
329// End:
FITSFile * XLALFITSFileOpenWrite(const CHAR UNUSED *file_name)
Definition: FITSFileIO.c:263
int XLALFITSFileWriteVCSInfo(FITSFile UNUSED *file, const LALVCSInfoList UNUSED vcs_list)
Definition: FITSFileIO.c:466
int XLALFITSFileWriteUVarCmdLine(FITSFile UNUSED *file)
Definition: FITSFileIO.c:508
void XLALFITSFileClose(FITSFile UNUSED *file)
Definition: FITSFileIO.c:245
void LALCheckMemoryLeaks(void)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
#define STRING(a)
void XLALWeaveSetupDataClear(WeaveSetupData *setup)
Free contents of setup data.
Definition: SetupData.c:40
int XLALWeaveSetupDataWrite(FITSFile *file, const WeaveSetupData *setup)
Write setup data to a FITS file.
Definition: SetupData.c:55
Module which handles the setup data.
int main(int argc, char *argv[])
Definition: WeaveSetup.c:32
#define LAL_GPS_FORMAT
#define LAL_GPS_PRINT(gps)
int XLALParseMultiLALDetector(MultiLALDetector *detInfo, const LALStringVector *detNames)
Parse string-vectors (typically input by user) of N detector-names for detectors ,...
struct tagFITSFile FITSFile
Representation of a FITS file.
Definition: FITSFileIO.h:54
EphemerisData * XLALInitBarycenter(const CHAR *earthEphemerisFile, const CHAR *sunEphemerisFile)
XLAL interface to reading ephemeris files 'earth' and 'sun', and return ephemeris-data in old backwar...
int XLALRestrictEphemerisData(EphemerisData *edat, const LIGOTimeGPS *startGPS, const LIGOTimeGPS *endGPS)
Restrict the EphemerisData 'edat' to the smallest number of entries required to cover the GPS time ra...
#define LAL_DAYSID_SI
unsigned char BOOLEAN
double REAL8
#define XLAL_INIT_DECL(var,...)
char CHAR
uint32_t UINT4
void XLALFree(void *p)
char char * XLALStringDuplicate(const char *s)
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
LOG_NORMAL
void XLALDestroySFTCatalog(SFTCatalog *catalog)
Free an 'SFT-catalogue'.
Definition: SFTcatalog.c:329
LALSegList * XLALReadSegmentsFromFile(const char *fname)
Function to read a segment list from given filename, returns a sorted LALSegList.
SFTCatalog * XLALSFTdataFind(const CHAR *file_pattern, const SFTConstraints *constraints)
Find the list of SFTs matching the file_pattern and satisfying the given constraints,...
Definition: SFTcatalog.c:71
int XLALSFTCatalogTimeslice(SFTCatalog *slice, const SFTCatalog *catalog, const LIGOTimeGPS *minStartGPS, const LIGOTimeGPS *maxStartGPS)
Set a SFT catalog 'slice' to a timeslice of a larger SFT catalog 'catalog', with entries restricted t...
Definition: SFTcatalog.c:624
LALSegList * XLALSegListCreate(void)
int XLALSegListFree(LALSegList *seglist)
int XLALSegListAppend(LALSegList *seglist, const LALSeg *seg)
int XLALSegSet(LALSeg *seg, const LIGOTimeGPS *start, const LIGOTimeGPS *end, const INT4 id)
int XLALSegListRange(const LALSegList *seglist, LIGOTimeGPS *start, LIGOTimeGPS *end)
int XLALSortStringVector(LALStringVector *strings)
char * XLALConcatStringVector(const LALStringVector *strings, const char *sep)
LALStringVector * XLALCopyStringVector(const LALStringVector *vect)
SuperskyMetrics * XLALComputeSuperskyMetrics(const SuperskyMetricType type, const size_t spindowns, const LIGOTimeGPS *ref_time, const LALSegList *segments, const double fiducial_freq, const MultiLALDetector *detectors, const MultiNoiseFloor *detector_weights, const DetectorMotionType detector_motion, const EphemerisData *ephemerides)
Compute the supersky metrics, which are returned in a SuperskyMetrics struct.
@ SUPERSKY_METRIC_TYPE
Metric for all-sky searches.
DetectorMotionType
Bitfield of different types of detector-motion to use in order to compute the Doppler-metric.
int XLALParseDetectorMotionString(const CHAR *detMotionString)
Parse a detector-motion type string into the corresponding enum-number,.
const char * lalUserVarHelpOptionSubsection
const char * lalUserVarHelpBrief
#define UVAR_STR2AND(n1, n2)
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
void XLALDestroyUserVars(void)
#define UVAR_ALLSET2(n1, n2)
#define XLALRegisterUvarMember(name, type, option, category,...)
#define UVAR_STR(n)
void XLALUserVarCheck(BOOLEAN *should_exit, const int assertion, const CHAR *fmt,...) _LAL_GCC_PRINTF_FORMAT_(3
#define UVAR_STR2OR(n1, n2)
#define UVAR_SET(n)
#define UVAR_SET2(n1, n2)
LIGOTimeGPS LIGOTimeGPSRange[2]
#define xlalErrno
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EINVAL
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
REAL8 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
output_file
n
LALDetector detectors[LAL_NUM_DETECTORS]
LIGOTimeGPS end
LIGOTimeGPS start
UINT4 length
array of detectors definitions 'LALDetector'
An "SFT-catalogue": a vector of SFTdescriptors, as returned by XLALSFTdataFind()
Definition: SFTfileIO.h:238
UINT4 length
number of SFTs in catalog
Definition: SFTfileIO.h:242
UserInput_t uvar_struct
Definition: sw_inj_frames.c:93