40#include <gsl/gsl_rng.h>
41#include <gsl/gsl_randist.h>
43#include <lal/LALgetopt.h>
44#include <lal/BandPassTimeSeries.h>
46#include <lal/EPSearch.h>
47#include <lal/LALFrStream.h>
48#include <lal/FrequencySeries.h>
49#include <lal/GenerateBurst.h>
50#include <lal/LALConstants.h>
51#include <lal/LALDatatypes.h>
52#include <lal/LALError.h>
53#include <lal/LALFrameIO.h>
54#include <lal/LALStdlib.h>
55#include <lal/LIGOLwXML.h>
56#include <lal/LIGOLwXMLArray.h>
57#include <lal/LIGOLwXMLRead.h>
58#include <lal/LIGOMetadataTables.h>
59#include <lal/LIGOMetadataUtils.h>
60#include <lal/Random.h>
61#include <lal/RealFFT.h>
62#include <lal/ResampleTimeSeries.h>
63#include <lal/SnglBurstUtils.h>
64#include <lal/TimeFreqFFT.h>
65#include <lal/TimeSeries.h>
67#include <lal/Window.h>
73#define PROGRAM_NAME "lalapps_power"
74#define CVS_REVISION "$Revision$"
75#define CVS_SOURCE "$Source$"
76#define CVS_DATE "$Date$"
93static size_t min(
size_t a,
size_t b)
109 return !((
x - 1) &
x);
237 static char default_comment[] =
"";
294"Usage: %s [option ...]\n" \
295"The following options are recognized. Options not surrounded in [] are\n" \
297" --bandwidth <Hz>\n" \
298" [--calibration-cache <cache file name>]\n" \
299" --channel-name <name>\n" \
300" --confidence-threshold <confidence>\n" \
301" [--dump-diagnostics <XML file name>]\n" \
302" --filter-corruption <samples>\n" \
303" --frame-cache <cache file name>\n" \
304" [--gaussian-noise-rms <RMS amplitude>]\n",
program);
306" --gps-end-time <seconds>\n" \
307" --gps-start-time <seconds>\n" \
309" --high-pass <Hz>\n" \
310" [--injection-file <XML file name>]\n" \
311" --low-freq-cutoff <Hz>\n" \
312" [--max-event-rate <Hz>]\n" \
313" --max-tile-bandwidth <Hz>\n" \
314" --max-tile-duration <seconds>\n" \
315" [--mdc-cache <cache file name>]\n" \
316" [--mdc-channel <name>]\n" \
317" [--output <filename>]\n" \
318" --psd-average-points <samples>\n" \
319" [--ram-limit <MebiBytes>]\n" \
320" --resample-rate <Hz>\n" \
321" [--seed <seed>]\n");
323" --tile-stride-fraction <fraction>\n" \
324" [--user-tag <comment>]\n" \
325" --window-length <samples>\n");
331 XLALPrintError(
"%s: error: invalid argument for --%s: %s\n", prog, arg, msg);
349 int got_all_arguments = 1;
352 for(option_index = 0; long_options[option_index].
name; option_index++) {
353 switch(long_options[option_index].val) {
416 got_all_arguments = 0;
421 XLALPrintError(
"%s: must provide exactly one of --frame-cache or --gaussian-noise-rms\n", prog);
422 got_all_arguments = 0;
425 return got_all_arguments;
437 snprintf((*proc_param)->program,
sizeof((*proc_param)->program),
PROGRAM_NAME);
438 snprintf((*proc_param)->type,
sizeof((*proc_param)->type),
"%s",
type);
439 snprintf((*proc_param)->param,
sizeof((*proc_param)->param),
"--%s", param);
440 snprintf((*proc_param)->value,
sizeof((*proc_param)->value),
"%s", value ? value :
"");
442 return &(*proc_param)->next;
446#define ADD_PROCESS_PARAM(process, type) \
447 do { paramaddpoint = add_process_param(paramaddpoint, process, type, long_options[option_index].name, LALoptarg); } while(0)
459 int args_are_bad = 0;
507 do switch (
c =
LALgetopt_long(argc, argv,
"", long_options, &option_index)) {
511 sprintf(msg,
"must be greater than 0 and a power of 2 (%g specified)",
options->
bandwidth);
546 sprintf(msg,
"range error parsing \"%s\"",
LALoptarg);
555 sprintf(msg,
"range error parsing \"%s\"",
LALoptarg);
575 sprintf(msg,
"must not be negative (%f Hz specified)",
options->
flow);
606 sprintf(msg,
"must be greater than or equal to 4 and a power of 2 (%i specified)", window_length);
612 sprintf(msg,
"failure generating %d sample Hann window", window_length);
626 sprintf(msg,
"--dump-diagnostics given but diagnostic code not included at compile time");
644 sprintf(msg,
"must be greater than 0 (%i specified)", atoi(
LALoptarg));
664 sprintf(msg,
"must be a power of 2 in the rage [2,16384] (%d specified)",
options->
resample_rate);
769 XLALPrintError(
"%s: error: GPS start time > GPS stop time\n", argv[0]);
779 XLALPrintWarning(
"warning: no calibration cache is provided: software injections and hrss will be computed with unit response\n");
820 int size = 1024, required_size;
828 if(required_size <
size)
831 size = required_size;
895 if((
int) series_type < 0) {
900 switch(series_type) {
933 XLALPrintError(
"get_time_series(): error: invalid channel data type %d\n", series_type);
943 XLALPrintError(
"get_time_series(): error: gap in data detected between GPS times %d.%09u s and %d.%09u s\n",
start.gpsSeconds,
start.gpsNanoSeconds,
end.gpsSeconds,
end.gpsNanoSeconds);
972 REAL8 resampledeltaT,
986 highpassParam.
nMax = 8;
988 highpassParam.
f1 = -1.0;
989 highpassParam.
a2 = 0.9;
990 highpassParam.
a1 = -1.0;
1034 series->
data->data[
i] = gsl_ran_gaussian(rng, rms);
1078 new = malloc(
sizeof(*
new));
1096 if(new->has_sim_burst_table) {
1099 new->sim_burst_table_head = NULL;
1106 !new->process_table_head ||
1107 !new->process_params_table_head ||
1108 !new->search_summary_table_head ||
1109 !new->time_slide_table_head ||
1110 (new->has_sim_burst_table && !new->sim_burst_table_head)
1205 if((
unsigned) psd_length >
series->
data->length) {
1210 for(
i = 0;
i + psd_length <
series->
data->length + psd_shift;
i += psd_shift) {
1235 addpoint = &(*addpoint)->
next;
1327 SnglBurst **EventAddPoint = &_sngl_burst_table;
1334 gsl_rng *rng = NULL;
1373 snprintf(_search_summary_table->
ifos,
sizeof(_search_summary_table->
ifos),
"%s",
options->
ifo);
1374 _search_summary_table->
nnodes = 1;
1435 XLALPrintError(
"%s: error: failure reading input data\n", argv[0]);
1456 XLALPrintError(
"%s: error: failure allocating data for Gaussian noise\n", argv[0]);
1460 rng = gsl_rng_alloc(gsl_rng_mt19937);
1467 if(gettimeofday(&
t, NULL)) {
1469 XLALPrintError(
"%s: error: cannot get time of day to seed random number generator\n", argv[0]);
1472 seed = 1000 * (
t.tv_sec +
t.tv_usec * 1
e-6);
1474 gsl_rng_set(rng,
seed);
1482 XLALPrintError(
"%s: error: oops, don't know how to get data\n", argv[0]);
int XLALButterworthREAL8TimeSeries(REAL8TimeSeries *series, PassBandParamStruc *params)
int XLALStrToGPS(LIGOTimeGPS *t, const char *nptr, char **endptr)
const LALVCSInfo lalAppsVCSIdentInfo
Identable VCS and build information for LALApps.
lal_errhandler_t lal_errhandler
int LAL_ERR_EXIT(LALStatus *stat, const char *func, const char *file, const int line, volatile const char *id)
void LALCheckMemoryLeaks(void)
int LALgetopt_long(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
#define required_argument
int XLALCloseLIGOLwXMLFile(LIGOLwXMLStream *xml)
LIGOLwXMLStream * XLALOpenLIGOLwXMLFile(const char *path)
int XLALWriteLIGOLwXMLSnglBurstTable(LIGOLwXMLStream *, const SnglBurst *)
int XLALWriteLIGOLwXMLProcessTable(LIGOLwXMLStream *, const ProcessTable *)
int XLALWriteLIGOLwXMLProcessParamsTable(LIGOLwXMLStream *, const ProcessParamsTable *)
int XLALWriteLIGOLwXMLSearchSummaryTable(LIGOLwXMLStream *, const SearchSummaryTable *)
int XLALLIGOLwHasTable(const char *filename, const char *table_name)
ProcessParamsTable * XLALProcessParamsTableFromLIGOLw(const char *filename)
ProcessTable * XLALProcessTableFromLIGOLw(const char *filename)
TimeSlide * XLALTimeSlideTableFromLIGOLw(const char *filename)
SearchSummaryTable * XLALSearchSummaryTableFromLIGOLw(const char *fileName)
SimBurst * XLALSimBurstTableFromLIGOLw(const char *filename)
int XLALSnglBurstTableLength(SnglBurst *head)
int XLALCompareSnglBurstByPeakTimeAndSNR(const SnglBurst *const *a, const SnglBurst *const *b)
SnglBurst ** XLALSortSnglBurst(SnglBurst **head, int(*comparefunc)(const SnglBurst *const *, const SnglBurst *const *))
LIGOTimeGPS * XLALGPSTimeNow(LIGOTimeGPS *gpstime)
int XLALOverlappedSegmentsCommensurate(int target_length, int segment_length, int segment_shift)
int XLALEPGetTimingParameters(int window_length, int max_tile_length, double fractional_tile_stride, int *psd_length, int *psd_shift, int *window_shift, int *window_pad, int *tiling_length)
SnglBurst * XLALEPSearch(LIGOLwXMLStream *diagnostics, const REAL8TimeSeries *tseries, REAL8Window *window, double flow, double bandwidth, double confidence_threshold, double fractional_stride, double maxTileBandwidth, double maxTileDuration)
void XLALDestroyCache(LALCache *cache)
LALCache * XLALCacheImport(const char *fname)
int XLALFrStreamClose(LALFrStream *stream)
LALFrStream * XLALFrStreamCacheOpen(LALCache *cache)
int XLALFrStreamSetMode(LALFrStream *stream, int mode)
LAL_FR_STREAM_VERBOSE_MODE
LALTYPECODE XLALFrStreamGetTimeSeriesType(const char *chname, LALFrStream *stream)
REAL8TimeSeries * XLALFrStreamReadREAL8TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, REAL8 duration, size_t lengthlimit)
REAL4TimeSeries * XLALFrStreamReadREAL4TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, REAL8 duration, size_t lengthlimit)
int XLALResampleREAL8TimeSeries(REAL8TimeSeries *series, REAL8 dt)
REAL8TimeSeries * XLALShrinkREAL8TimeSeries(REAL8TimeSeries *series, size_t first, size_t length)
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
REAL8TimeSeries * XLALCutREAL8TimeSeries(const REAL8TimeSeries *series, size_t first, size_t length)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
const LALUnit lalStrainUnit
const LALUnit lalADCCountUnit
void XLALDestroyREAL8Window(REAL8Window *window)
REAL8Window * XLALCreateHannREAL8Window(UINT4 length)
#define XLAL_ERROR_NULL(...)
int int int XLALPrintInfo(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
int XLALSetErrno(int errnum)
#define XLAL_REAL8_FAIL_NAN
#define XLAL_TRY(statement, errnum)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
int int XLALPrintWarning(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
int XLALPrintProgressBar(double)
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
REAL8 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
LIGOTimeGPS * XLALINT8NSToGPS(LIGOTimeGPS *epoch, INT8 ns)
INT8 XLALGPSToINT8NS(const LIGOTimeGPS *epoch)
int XLALBurstInjectSignals(REAL8TimeSeries *h, const SimBurst *sim_burst, const TimeSlide *time_slide_table_head, const COMPLEX16FrequencySeries *response)
char name[LIGOMETA_SOURCE_MAX]
static int is_power_of_2(int x)
int main(int argc, char *argv[])
static void gaussian_noise(REAL8TimeSeries *series, REAL8 rms, gsl_rng *rng)
#define ADD_PROCESS_PARAM(process, type)
static ProcessParamsTable ** add_process_param(ProcessParamsTable **proc_param, const ProcessTable *process, const char *type, const char *param, const char *value)
static int XLALEPConditionData(REAL8TimeSeries *series, REAL8 flow, REAL8 resampledeltaT, INT4 corruption)
static void options_free(struct options *options)
static size_t min(size_t a, size_t b)
static void print_missing_argument(const char *prog, const char *arg)
static void destroy_injection_document(struct injection_document *doc)
static REAL8TimeSeries * get_time_series(const char *cachefilename, const char *chname, LIGOTimeGPS start, LIGOTimeGPS end, size_t lengthlimit)
static struct injection_document * load_injection_document(const char *filename)
static REAL8TimeSeries * add_mdc_injections(const char *mdccachefile, const char *channel_name, REAL8TimeSeries *series)
static SnglBurst ** analyze_series(SnglBurst **addpoint, REAL8TimeSeries *series, int psd_length, int psd_shift, struct options *options)
static void print_usage(const char *program)
static struct options * options_new(void)
static int all_required_arguments_present(char *prog, struct LALoption *long_options, const struct options *options)
static struct options * parse_command_line(int argc, char *argv[], const ProcessTable *process, ProcessParamsTable **paramaddpoint)
static int double_is_power_of_2(double x)
static void print_bad_argument(const char *prog, const char *arg, const char *msg)
static int add_xml_injections(REAL8TimeSeries *h, const struct injection_document *injection_document)
static void output_results(char *file, const ProcessTable *_process_table, const ProcessParamsTable *_process_params_table, const SearchSummaryTable *_search_summary_table, const SnglBurst *_sngl_burst_table)
const char *const vcsDate
const char *const vcsStatus
CHAR ifos[LIGOMETA_IFOS_MAX]
CHAR comment[LIGOMETA_COMMENT_MAX]
CHAR comment[LIGOMETA_COMMENT_MAX]
LIGOTimeGPS out_start_time
CHAR ifos[LIGOMETA_IFOS_MAX]
LIGOTimeGPS in_start_time
struct tagSnglBurst * next
SearchSummaryTable * search_summary_table_head
SimBurst * sim_burst_table_head
ProcessTable * process_table_head
ProcessParamsTable * process_params_table_head
TimeSlide * time_slide_table_head
char * mdc_cache_filename
LIGOLwXMLStream * diagnostics
double confidence_threshold
char * injection_filename
char * cal_cache_filename