LALPulsar 7.1.1.1-eeff03c
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 *metric_type_str, *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 .metric_type_str = XLALStringDuplicate( "all-sky" ),
50 .detector_motion = XLALStringDuplicate( "spin+orbit" ),
51 .ephem_earth = XLALStringDuplicate( "earth00-40-DE405.dat.gz" ),
52 .ephem_sun = XLALStringDuplicate( "sun00-40-DE405.dat.gz" ),
53 .segment_count = 1,
54 .spindowns = 1,
55 };
56 struct uvar_type *const uvar = &uvar_struct;
57
58 // Register user input variables:
59 //
60 // - General
61 //
63 output_file, STRING, 'o', REQUIRED,
64 "Output file while stores the segment list, parameter-space metrics, and other data required by lalpulsar_Weave, e.g. ephemerides. "
65 );
66 //
67 // - Segment list input/generation
68 //
69 lalUserVarHelpOptionSubsection = "Segment list input/generation";
71 segment_list, STRING, 'L', OPTIONAL,
72 "Loads the start and end times of each segment from this file. "
73 "Format is:\n"
74 " # comment\n <segment-start-time-GPS> <segment-end-time-GPS> [number-of-SFTs-in-segment]\n ..."
75 );
77 first_segment, EPOCHRange, 't', OPTIONAL,
78 "Generate segments; the range of the first segment is specified by this option. "
79 );
81 segment_count, UINT4, 'n', OPTIONAL,
82 "Generate this many segments by translating the first segment in time by its span, i.e. so that segments are contiguous and non-overlapping. "
83 "Must be at least 1. "
84 );
86 segment_gap, REAL8, 'g', DEVELOPER,
87 "When generating segments, increase the translation of the first segment by this amount (in seconds). "
88 "A positive value gives non-contiguous segments; a negative value gives overlapping segments. "
89 );
91 sft_files, STRING, 'I', NODEFAULT,
92 "Pattern matching the SFT files to be analysed; used to discard empty segments. Possibilities are:\n"
93 " - '<SFT file>;<SFT file>;...', where <SFT file> may contain wildcards\n - 'list:<file containing list of SFT files>'"
94 );
95 //
96 // - Parameter-space metric computation
97 //
98 lalUserVarHelpOptionSubsection = "Parameter-space metric computation";
100 metric_type_str, STRING, 'T', OPTIONAL,
101 "The type of metrics to be computed (all-sky/directed search)."
102 );
104 ref_time, EPOCH, 'r', NODEFAULT,
105 "Reference time for the search, including the parameter-space metrics computed here, and the parameter space and output of lalpulsar_Weave. "
106 "If omitted, the mid-point between the start of the first segment and the end of the last segment is used. "
107 );
109 detectors, STRINGVector, 'd', REQUIRED,
110 "Comma-separated list of 2-character detector names (e.g. H1,L1,...) for which the parameter-space metrics are computed. "
111 "Note that the detector names are always sorted, since their order impacts the interpretation of some options to lalpulsar_Weave. "
112 );
114 detector_motion, STRING, 'm', DEVELOPER,
115 "Specify what detector motion to assume when computing the parameter-space metrics. "
116 "The only interesting options are:\n"
117 " - 'spin+orbit' use the full ephemeris of the Earth's orbit;\n"
118 " - 'spin+ptoleorbit': use a Ptolemaic approximation of the Earth's orbit."
119 );
121 ephem_earth, STRING, 'E', DEVELOPER,
122 "Earth ephemeris file, used to compute the parameter-space metrics and by lalpulsar_Weave. "
123 );
125 ephem_sun, STRING, 'S', DEVELOPER,
126 "Sun ephemeris file, used to compute the parameter-space metrics and by lalpulsar_Weave. "
127 );
129 spindowns, UINT4, 's', OPTIONAL,
130 "Maximum number of spindowns for which the parameter-space metrics are computed. "
131 "Must be at least 1. "
132 "This option limits the size of the spindown parameter space given to lalpulsar_Weave. "
133 );
134
135 // Parse user input
136 XLAL_CHECK_MAIN( xlalErrno == 0, XLAL_EFUNC, "A call to XLALRegisterUvarMember() failed" );
137 BOOLEAN should_exit = 0;
139 if ( should_exit ) {
140 return EXIT_FAILURE;
141 }
142
143 // Check user input:
144 //
145 // - General
146 //
147
148 //
149 // - Segment list input/generation
150 //
151 XLALUserVarCheck( &should_exit,
152 UVAR_SET2( segment_list, first_segment ) == 1,
153 "Exactly one of " UVAR_STR2OR( segment_list, first_segment ) " must be specified" );
154 XLALUserVarCheck( &should_exit,
155 !UVAR_ALLSET2( segment_list, segment_gap ),
156 "At most one of " UVAR_STR2AND( segment_list, segment_gap ) " may be specified" );
157 XLALUserVarCheck( &should_exit,
158 !UVAR_ALLSET2( segment_list, segment_count ),
159 "At most one of " UVAR_STR2AND( segment_list, segment_count ) " may be specified" );
160 XLALUserVarCheck( &should_exit,
161 uvar->segment_count > 0,
162 UVAR_STR( segment_count ) " must be strictly positive" );
163 //
164 // - Parameter-space metric computation
165 //
166 XLALUserVarCheck( &should_exit,
167 uvar->spindowns > 0,
168 UVAR_STR( spindowns ) " must be strictly positive" );
169 XLALUserVarCheck( &should_exit,
170 strcmp( uvar->metric_type_str, "all-sky" ) || strcmp( uvar->metric_type_str, "directed" ),
171 UVAR_STR( metric_type_str ) " must be 'all-sky' or 'directed'" );
172
173 // Exit if required
174 if ( should_exit ) {
175 return EXIT_FAILURE;
176 }
177 LogPrintf( LOG_NORMAL, "Parsed user input successfully\n" );
178
179 ////////// Create setup data //////////
180
181 // Initialise setup data
182 WeaveSetupData XLAL_INIT_DECL( setup );
183
184 // Copy metric type
185 setup.metric_type = XLALStringDuplicate( uvar->metric_type_str );
186 XLAL_CHECK_MAIN( setup.metric_type != NULL, XLAL_ENOMEM );
187
188 // Copy and sort list of detector names
189 setup.detectors = XLALCopyStringVector( uvar->detectors );
190 XLAL_CHECK_MAIN( setup.detectors != NULL, XLAL_EFUNC );
192
193 // Load ephemerides
194 LogPrintf( LOG_NORMAL, "Loading ephemerides from '%s' and '%s' ...\n", uvar->ephem_earth, uvar->ephem_sun );
195 setup.ephemerides = XLALInitBarycenter( uvar->ephem_earth, uvar->ephem_sun );
196 XLAL_CHECK_MAIN( setup.ephemerides != NULL, XLAL_EFUNC );
197
198 // Create segment list
199 if ( UVAR_SET( segment_list ) ) {
200
201 // Load segment list from file
202 LogPrintf( LOG_NORMAL, "Loading segment list from '%s' ...\n", uvar->segment_list );
203 setup.segments = XLALReadSegmentsFromFile( uvar->segment_list );
204 XLAL_CHECK_MAIN( setup.segments != NULL, XLAL_EFUNC );
205
206 } else {
207
208 // Generate segment list
209 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 );
210 setup.segments = XLALSegListCreate();
211 XLAL_CHECK_MAIN( setup.segments != NULL, XLAL_EFUNC );
212
213 // Set first segment
214 LALSeg seg;
215 XLALSegSet( &seg, &uvar->first_segment[0], &uvar->first_segment[1], 0 );
216
217 // Increment to add to each successive segment
218 const REAL8 dt = XLALGPSDiff( &seg.end, &seg.start ) + uvar->segment_gap;
219
220 // Create segments
221 for ( UINT4 n = 0; n < uvar->segment_count; ++n ) {
222 XLAL_CHECK_MAIN( XLALSegListAppend( setup.segments, &seg ) == XLAL_SUCCESS, XLAL_EFUNC );
223 XLALGPSAdd( &seg.start, dt );
224 XLALGPSAdd( &seg.end, dt );
225 }
226
227 }
228
229 // Load SFT catalog to check for empty segments
230 if ( UVAR_SET( sft_files ) ) {
231
232 // Load SFT catalog from files given by 'sft_files'
233 LogPrintf( LOG_NORMAL, "Loading SFTs matching '%s' into catalog ...\n", uvar->sft_files );
234 SFTCatalog *sft_catalog = XLALSFTdataFind( uvar->sft_files, NULL );
235 XLAL_CHECK_MAIN( sft_catalog != NULL, XLAL_EFUNC );
236 XLAL_CHECK_MAIN( sft_catalog->length > 0, XLAL_EFUNC );
237 LogPrintf( LOG_NORMAL, "Loaded SFT catalog from SFTs matching '%s'\n", uvar->sft_files );
238
239 // Build new segment list without empty segments
240 LALSegList *nonempty_segments = XLALSegListCreate();
241 XLAL_CHECK_MAIN( nonempty_segments != NULL, XLAL_EFUNC );
242 for ( UINT4 n = 0; n < setup.segments->length; ++n ) {
243 const LALSeg *seg = &setup.segments->segs[n];
244 SFTCatalog XLAL_INIT_DECL( sft_catalog_seg );
245 XLAL_CHECK_MAIN( XLALSFTCatalogTimeslice( &sft_catalog_seg, sft_catalog, &seg->start, &seg->end ) == XLAL_SUCCESS, XLAL_EFUNC );
246 if ( sft_catalog_seg.length > 0 ) {
247 XLAL_CHECK_MAIN( XLALSegListAppend( nonempty_segments, seg ) == XLAL_SUCCESS, XLAL_EFUNC );
248 } else {
249 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 ) );
250 }
251 }
252 XLAL_CHECK_MAIN( nonempty_segments->length > 0, XLAL_EINVAL, "No SFTs found in any segments" );
253 XLALSegListFree( setup.segments );
254 setup.segments = nonempty_segments;
255
256 // Cleanup memory from SFT catalog
257 XLALDestroySFTCatalog( sft_catalog );
258
259 }
260
261 // Compute segment list range
262 LIGOTimeGPS segments_start, segments_end;
263 XLAL_CHECK_MAIN( XLALSegListRange( setup.segments, &segments_start, &segments_end ) == XLAL_SUCCESS, XLAL_EFUNC );
264 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 );
265
266 // Set reference time
267 if ( UVAR_SET( ref_time ) ) {
268 setup.ref_time = uvar->ref_time;
269 } else {
270 setup.ref_time = segments_start;
271 XLALGPSAdd( &setup.ref_time, 0.5 * XLALGPSDiff( &segments_end, &segments_start ) );
272 }
273 LogPrintf( LOG_NORMAL, "Reference time = %" LAL_GPS_FORMAT " GPS\n", LAL_GPS_PRINT( setup.ref_time ) );
274
275 // Restrict ephemerides to range of segment list +/- 1 day
276 {
277 LIGOTimeGPS ephem_start = segments_start, ephem_end = segments_end;
278 XLALGPSAdd( &ephem_start, -LAL_DAYSID_SI );
279 XLALGPSAdd( &ephem_end, +LAL_DAYSID_SI );
280 XLAL_CHECK( XLALRestrictEphemerisData( setup.ephemerides, &ephem_start, &ephem_end ) == XLAL_SUCCESS, XLAL_EFUNC );
281 }
282
283 // Parse list of detectors
284 MultiLALDetector detector_info;
285 {
286 char *detectors_string = XLALConcatStringVector( uvar->detectors, "," );
287 XLAL_CHECK_MAIN( detectors_string != NULL, XLAL_EFUNC );
288 XLAL_CHECK_MAIN( XLALParseMultiLALDetector( &detector_info, uvar->detectors ) == XLAL_SUCCESS, XLAL_EINVAL, "Invalid value '%s' for " UVAR_STR( detectors ), detectors_string );
289 XLALFree( detectors_string );
290 }
291
292 // Parse detector motion string
293 const DetectorMotionType detector_motion = XLALParseDetectorMotionString( uvar->detector_motion );
294 XLAL_CHECK_MAIN( xlalErrno == 0, XLAL_EINVAL, "Invalid value '%s' for " UVAR_STR( detector_motion ), uvar->detector_motion );
295
296 // Compute reduced supersky metrics at fiducial frequency of 100Hz
297 // - Fiducial frequency is stored in coordinate transform data, so
298 // metrics can later be rescaled by search code
299 LogPrintf( LOG_NORMAL, "Computing reduced supersky metrics ...\n" );
300 const double fiducial_freq = 100.0;
301 /// Metric type for all-sky/directed search)
302 const SuperskyMetricType metric_type = ( strcmp( uvar->metric_type_str, "all-sky" ) == 0 ) ? SUPERSKY_METRIC_TYPE : SUPERSKY_DIRECTED_METRIC_TYPE;
303 setup.metrics = XLALComputeSuperskyMetrics( metric_type, uvar->spindowns, &setup.ref_time, setup.segments, fiducial_freq, &detector_info, NULL, detector_motion, setup.ephemerides );
304 XLAL_CHECK_MAIN( setup.metrics != NULL, XLAL_EFUNC );
305 LogPrintf( LOG_NORMAL, "Finished computing reduced supersky metrics\n" );
306
307 ////////// Output setup data //////////
308
309 // Open output file
310 LogPrintf( LOG_NORMAL, "Opening output file '%s' for writing ...\n", uvar->output_file );
311 FITSFile *file = XLALFITSFileOpenWrite( uvar->output_file );
312 XLAL_CHECK_MAIN( file != NULL, XLAL_EFUNC );
315
316 // Write setup data
318
319 // Close output file
321 LogPrintf( LOG_NORMAL, "Closed output file '%s'\n", uvar->output_file );
322
323 ////////// Cleanup memory and exit //////////
324
325 // Cleanup memory from setup data
326 XLALWeaveSetupDataClear( &setup );
327
328 // Cleanup memory from user input
330
331 // Check for memory leaks
333
334 LogPrintf( LOG_NORMAL, "Finished successfully!\n" );
335
336 return EXIT_SUCCESS;
337
338}
339
340// Local Variables:
341// c-file-style: "linux"
342// c-basic-offset: 2
343// 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:41
int XLALWeaveSetupDataWrite(FITSFile *file, const WeaveSetupData *setup)
Write setup data to a FITS file.
Definition: SetupData.c:57
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)
SuperskyMetricType
Type of supersky metric to compute.
SuperskyMetrics * XLALComputeSuperskyMetrics(const SuperskyMetricType metric_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.
@ SUPERSKY_DIRECTED_METRIC_TYPE
Metric for directed 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_ENOMEM
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