37#include <gsl/gsl_sort.h>
38#include <gsl/gsl_math.h>
40#include <lal/LALStdlib.h>
41#include <lal/LALConstants.h>
42#include <lal/AVFactories.h>
43#include <lal/SeqFactories.h>
44#include <lal/SFTfileIO.h>
45#include <lal/Random.h>
46#include <lal/PulsarDataTypes.h>
47#include <lal/UserInput.h>
48#include <lal/NormalizeSFTRngMed.h>
49#include <lal/LALInitBarycenter.h>
50#include <lal/SFTClean.h>
51#include <lal/Segments.h>
52#include <lal/FrequencySeries.h>
54#include <lal/LogPrintf.h>
55#include <lal/LALPulsarVCSInfo.h>
58#define COMPUTEPSDC_ENORM 0
59#define COMPUTEPSDC_ESUB 1
60#define COMPUTEPSDC_EARG 2
61#define COMPUTEPSDC_EBAD 3
62#define COMPUTEPSDC_EFILE 4
63#define COMPUTEPSDC_ENULL 5
64#define COMPUTEPSDC_EMEM 6
66#define COMPUTEPSDC_MSGENORM "Normal exit"
67#define COMPUTEPSDC_MSGESUB "Subroutine failed"
68#define COMPUTEPSDC_MSGEARG "Error parsing arguments"
69#define COMPUTEPSDC_MSGEBAD "Bad argument values"
70#define COMPUTEPSDC_MSGEFILE "Could not create output file"
71#define COMPUTEPSDC_MSGENULL "Null Pointer"
72#define COMPUTEPSDC_MSGEMEM "Out of memory"
163 if ( ( inputSFTs =
XLALReadSFTs( &cfg, &uvar ) ) == NULL ) {
174 if ( ( fpRand = fopen(
"/dev/urandom",
"r" ) ) == NULL ) {
175 fprintf( stderr,
"Error in opening /dev/urandom" );
179 if ( ( ranCount = fread( &
seed,
sizeof(
seed ), 1, fpRand ) ) != 1 ) {
180 fprintf( stderr,
"Error in getting random seed" );
197 BOOLEAN returnMultiPSDVector = ( uvar.outputSpectBname || uvar.dumpMultiPSDVector || uvar.outputQ );
202 returnMultiPSDVector,
209 uvar.normalizeByTotalNumSFTs,
216 if ( uvar.outputSpectBname ) {
221 if ( uvar.dumpMultiPSDVector ) {
229 if ( uvar.outputQ ) {
248 finalBinSize = uvar.binSize;
250 finalBinSize = (
UINT4 )floor( uvar.binSizeHz / dFreq + 0.5 );
258 finalBinStep = uvar.binStep;
260 finalBinStep = (
UINT4 )floor( uvar.binStepHz / dFreq + 0.5 );
262 finalBinStep = finalBinSize;
269 XLAL_CHECK_MAIN( ( fpOut = fopen( uvar.outputPSD,
"wb" ) ) != NULL,
XLAL_EIO,
"Unable to open output file %s for writing", uvar.outputPSD );
271 for (
int a = 0;
a < argc;
a++ ) {
272 fprintf( fpOut,
"%%%% argv[%d]: '%s'\n",
a, argv[
a] );
274 XLAL_CHECK_MAIN(
XLALWritePSDtoFilePointer( fpOut, finalPSD, normSFT, uvar.outputNormSFT, uvar.outFreqBinEnd, uvar.PSDmthopBins, uvar.nSFTmthopBins, finalBinSize, finalBinStep, Freq0, dFreq ) ==
XLAL_SUCCESS,
XLAL_EFUNC );
280 if ( returnMultiPSDVector ) {
339 " - '<SFT file>;<SFT file>;...', where <SFT file> may contain wildcards\n - 'list:<file containing list of SFT files>'" );
355 "arithsum (0), arithmean (1), arithmedian (2), "
356 "harmsum (3), harmmean (4), "
357 "powerminus2sum (5), powerminus2mean (6), "
358 "min (7), max (8)" );
360 "see --PSDmthopSFTs" );
363 "see --PSDmthopSFTs" );
365 "see --PSDmthopSFTs" );
367 XLALRegisterUvarMember( normalizeByTotalNumSFTs,
BOOLEAN, 0, OPTIONAL,
"For harmsum/powerminus2sum, apply normalization factor from total number of SFTs over all IFOs (mimics harmmean/powerminus2mean over a combined set of all SFTs)" );
372 "see --PSDmthopSFTs" );
374 "see --PSDmthopSFTs" );
376 "(in number of bins, default is bin size)" );
378 "(in Hz, default is bin size)" );
383 "(names must contain IFO name)" );
385 XLALRegisterUvarMember( dumpMultiPSDVector,
BOOLEAN,
'd', OPTIONAL,
"Output multi-PSD vector over IFOs, timestamps, and frequencies into file(s) '<outputPSD>-IFO'" );
388 XLALRegisterUvarMember(
fStart,
REAL8,
'f', DEVELOPER,
"Start Frequency to load from SFT and compute PSD, including rngmed wings (BETTER: use --Freq instead)" );
389 XLALRegisterUvarMember( fBand,
REAL8,
'b', DEVELOPER,
"Frequency Band to load from SFT and compute PSD, including rngmed wings (BETTER: use --FreqBand instead)" );
425 XLALPrintError(
"ERROR: --binSize(-z) and --binSizeHz(-Z) are mutually exclusive" );
429 XLALPrintError(
"ERROR: --binSize(-z) must be strictly positive" );
433 XLALPrintError(
"ERROR: --binSizeHz(-Z) must be strictly positive" );
437 XLALPrintError(
"ERROR: --binStep(-p) and --binStepHz(-P) are mutually exclusive" );
441 XLALPrintError(
"ERROR: --binStep(-p) must be strictly positive" );
445 XLALPrintError(
"ERROR: --binStepHz(-P) must be strictly positive" );
452 XLAL_CHECK( !( have_fStart && have_Freq ),
XLAL_EINVAL,
"use only one of --fStart OR --Freq (see --help)" );
453 XLAL_CHECK( !( have_fBand && have_FreqBand ),
XLAL_EINVAL,
"use only one of --fBand OR --FreqBand (see --help)" );
454 XLAL_CHECK( !( ( have_fStart && have_FreqBand ) || ( have_Freq && have_fBand ) ),
XLAL_EINVAL,
"don't mix {--fStart,--fBand} with {--Freq,--FreqBand} inputs (see --help)" );
470 float num, *row_data;
476 if ( !bname || !multiPSD || multiPSD->
length == 0 ) {
482 UINT4 len = strlen( bname ) + 4;
494 if ( ( fname =
LALMalloc( len *
sizeof(
CHAR ) ) ) == NULL ) {
499 sprintf( fname,
"%s-%c%c", bname, tmp[0], tmp[1] );
501 if ( (
fp = fopen( fname,
"wb" ) ) == NULL ) {
508 if ( ( fwrite( (
char * ) &num,
sizeof(
float ), 1,
fp ) ) != 1 ) {
519 if ( fwrite( (
char * ) row_data,
sizeof(
float ),
numBins,
fp ) !=
numBins ) {
531 if ( ( fwrite( (
char * ) &num,
sizeof(
float ), 1,
fp ) != 1 ) ||
532 ( fwrite( (
char * ) row_data,
sizeof(
float ),
numBins,
fp ) !=
numBins ) ) {
581 LIGOTimeGPS startTimeGPS = {0, 0}, endTimeGPS = {0, 0};
596 constraints.detector = uvar->
IFO;
598 constraints.detector = NULL;
603 constraints.minStartTime = &startTimeGPS;
608 constraints.maxStartTime = &endTimeGPS;
616 constraints.timestamps = inputTimeStampsVector;
625 if ( ( catalog == NULL ) || ( catalog->
length == 0 ) ) {
632 if ( inputTimeStampsVector ) {
642 REAL8 rngmedSideBand = rngmedSideBandBins * dFreq;
661 if ( endTimeGPS.gpsSeconds == 0 ) {
702 if ( !series || !fname ) {
708 if ( (
fp = fopen( fname,
"wb" ) ) == NULL ) {
728 fprintf(
fp,
"%%%% Units = %s\n", unitStr );
730 fprintf(
fp,
"%%%% Freq [Hz] Data(Freq)\n" );
int main(int argc, char *argv[])
MultiSFTVector * XLALReadSFTs(ConfigVariables_t *cfg, const UserVariables_t *uvar)
Load all SFTs according to user-input, returns multi-SFT vector.
#define COMPUTEPSDC_EFILE
int initUserVars(int argc, char *argv[], UserVariables_t *uvar)
register all "user-variables"
int XLALWriteREAL8FrequencySeries_to_file(const REAL8FrequencySeries *series, const char *fname)
Write given REAL8FrequencySeries into file.
int vrbflg
defined in lal/lib/std/LALError.c
#define COMPUTEPSDC_MSGEFILE
#define COMPUTEPSDC_ENULL
#define COMPUTEPSDC_MSGENULL
#define COMPUTEPSDC_MSGEMEM
void LALfwriteSpectrograms(LALStatus *status, const CHAR *bname, const MultiPSDVector *multiPSD)
Write a multi-PSD into spectrograms for each IFO.
#define __func__
log an I/O error, i.e.
lal_errhandler_t lal_errhandler
int LAL_ERR_EXIT(LALStatus *stat, const char *func, const char *file, const int line, volatile const char *id)
#define LAL_CALL(function, statusptr)
void LALCheckMemoryLeaks(void)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
#define ABORT(statusptr, code, mesg)
#define ATTATCHSTATUSPTR(statusptr)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
void XLALDestroyREAL8FrequencySeries(REAL8FrequencySeries *series)
#define XLAL_INIT_DECL(var,...)
int XLALOutputVCSInfo(FILE *fp, const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
void void LogPrintfVerbatim(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
int XLALDumpMultiPSDVector(const CHAR *outbname, const MultiPSDVector *multiPSDVect)
Dump complete multi-PSDVector over IFOs, timestamps and frequency-bins into per-IFO ASCII output-file...
int XLALWritePSDtoFilePointer(FILE *fpOut, REAL8Vector *PSDVect, REAL8Vector *normSFTVect, BOOLEAN outputNormSFT, BOOLEAN outFreqBinEnd, INT4 PSDmthopBins, INT4 nSFTmthopBins, INT4 binSize, INT4 binStep, REAL8 Freq0, REAL8 dFreq)
Write a PSD vector as an ASCII table to an open output file pointer.
const UserChoices MathOpTypeChoices
void XLALDestroyMultiPSDVector(MultiPSDVector *multvect)
Destroy a multi PSD-vector.
int XLALComputePSDandNormSFTPower(REAL8Vector **finalPSD, MultiPSDVector **multiPSDVector, REAL8Vector **normSFT, MultiSFTVector *inputSFTs, const BOOLEAN returnMultiPSDVector, const BOOLEAN returnNormSFT, const UINT4 blocksRngMed, const MathOpType PSDmthopSFTs, const MathOpType PSDmthopIFOs, const MathOpType nSFTmthopSFTs, const MathOpType nSFTmthopIFOs, const BOOLEAN normalizeByTotalNumSFTs, const REAL8 FreqMin, const REAL8 FreqBand, const BOOLEAN normalizeSFTsInPlace)
Compute the PSD (power spectral density) and the "normalized power" over a MultiSFTVector.
REAL8FrequencySeries * XLALComputeSegmentDataQ(const MultiPSDVector *multiPSDVect, LALSeg segment)
Compute the "data-quality factor" over the given SFTs.
@ MATH_OP_ARITHMETIC_MEDIAN
@ MATH_OP_ARITHMETIC_MEAN
void LALCreateRandomParams(LALStatus *status, RandomParams **params, INT4 seed)
void LALDestroyRandomParams(LALStatus *status, RandomParams **params)
void LALRemoveKnownLinesInMultiSFTVector(LALStatus *status, MultiSFTVector *MultiSFTVect, INT4 width, INT4 window, LALStringVector *linefiles, RandomParams *randPar)
top level function to remove lines from a multi sft vector given a list of files containing list of k...
void XLALDestroySFTCatalog(SFTCatalog *catalog)
Free an 'SFT-catalogue'.
MultiSFTVector * XLALLoadMultiSFTs(const SFTCatalog *inputCatalog, REAL8 fMin, REAL8 fMax)
Function to load a catalog of SFTs from possibly different detectors.
void XLALDestroyMultiSFTVector(MultiSFTVector *multvect)
Destroy a multi SFT-vector.
SFTCatalog * XLALSFTdataFind(const CHAR *file_pattern, const SFTConstraints *constraints)
Find the list of SFTs matching the file_pattern and satisfying the given constraints,...
LIGOTimeGPSVector * XLALReadTimestampsFile(const CHAR *fname)
backwards compatible wrapper to XLALReadTimestampsFileConstrained() without GPS-time constraints
void XLALDestroyTimestampVector(LIGOTimeGPSVector *vect)
De-allocate a LIGOTimeGPSVector.
char * XLALUnitAsString(char *string, UINT4 length, const LALUnit *input)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
#define XLAL_ERROR_NULL(...)
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_MAIN(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
COMPLEX8FrequencySeries * data
Pointer to the data array.
Config variables 'derived' from user-input.
LALSeg dataSegment
the data-segment for which PSD was computed
REAL8 FreqMin
frequency of first PSD bin for output
REAL8 FreqBand
width of frequency band for output
A vector of 'timestamps' of type LIGOTimeGPS.
A collection of PSD vectors – one for each IFO in a multi-IFO search.
PSDVector ** data
sftvector for each ifo
UINT4 length
number of ifos
A collection of SFT vectors – one for each IFO in a multi-IFO search.
SFTVector ** data
sftvector for each ifo
REAL8FrequencySeries * data
Pointer to the data array.
UINT4 length
Number of elements in array.
An "SFT-catalogue": a vector of SFTdescriptors, as returned by XLALSFTdataFind()
SFTDescriptor * data
array of data-entries describing matched SFTs
UINT4 length
number of SFTs in catalog
'Constraints' for SFT-matching: which detector, within which time-stretch and which timestamps exactl...
SFTtype header
SFT-header info.
INT4 PSDmthopSFTs
for PSD, type of math.
INT4 binSize
output PSD bin size in no.
REAL8 endTime
last SFT-timestamp to include
INT4 blocksRngMed
number of running-median bins to use
REAL8 binStepHz
output PSD bin step in Hz
INT4 nSFTmthopIFOs
for norm.
LALStringVector * linefiles
INT4 PSDmthopBins
for PSD, type of math.
REAL8 startTime
earliest SFT-timestamp to include
BOOLEAN outputNormSFT
output normalised SFT power?
REAL8 fStart
Start Frequency to load from SFT and compute PSD, including wings (it is RECOMMENDED to use –Freq ins...
CHAR * outputQ
output the 'data-quality factor' Q(f) into this file
REAL8 binSizeHz
output PSD bin size in Hz
BOOLEAN outFreqBinEnd
output the end frequency of each bin?
REAL8 Freq
physical start frequency to compute PSD for (excluding rngmed wings)
LIGOTimeGPS startTime
Start-time of requested signal in detector-frame (GPS seconds)
BOOLEAN normalizeByTotalNumSFTs
apply normalization factor from total number of SFTs over all IFOs
BOOLEAN dumpMultiPSDVector
output multi-PSD vector over IFOs, timestamps, and frequencies into file(s)
INT4 binStep
output PSD bin step in no.
INT4 nSFTmthopBins
for norm.
CHAR * inputData
directory for input sfts
CHAR * outputPSD
directory for output sfts
INT4 PSDmthopIFOs
for PSD, type of math.
REAL8 FreqBand
physical frequency band to compute PSD for (excluding rngmed wings)
REAL8 fBand
Frequency Band to load from SFT and compute PSD, including wings (it is RECOMMENDED to use –FreqBand ...
INT4 nSFTmthopSFTs
for norm.
CHAR * IFO
Detector: H1, L1, H2, V1, ...