LALPulsar  6.1.0.1-fe68b98
PSDutils.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013, 2020 David Keitel
3  * Copyright (C) 2010, 2013, 2014, 2016, 2017, 2022 Karl Wette
4  * Copyright (C) 2010 Chris Messenger
5  * Copyright (C) 2007, 2013 John T. Whelan
6  * Copyright (C) 2006 Badri Krishnan
7  * Copyright (C) 2004--2006, 2008--2013, 2016 Reinhard Prix
8  * Copyright (C) 2004, 2005 Bernd Machenschalk
9  * Copyright (C) 2004, 2005 Alicia Sintes
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with with program; see the file COPYING. If not, write to the
23  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24  * MA 02110-1301 USA
25  */
26 
27 #ifndef _PSDUTILS_H /* Double-include protection. */
28 #define _PSDUTILS_H
29 
30 #ifdef __cplusplus /* C++ protection. */
31 extern "C" {
32 #endif
33 
34 /* includes */
35 #include <stdlib.h>
36 
37 #include <lal/LALStdlib.h>
38 #include <lal/SFTfileIO.h>
39 
40 /**
41  * \defgroup PSDutils_h Header PSDutils.h
42  * \ingroup lalpulsar_sft
43  *
44  * \brief Module for computing PSD (Power Spectral Density) estimates and handling related structures
45  *
46  * Overview:
47  * \ref PSD-type-cdtor-func "create/destroy functions",
48  * \ref PSD-type-mod-func "modify functions",
49  * \ref PSD-type-prop-func "property functions",
50  * \ref PSD-type-gen-func "generation functions",
51  * \ref PSD-file-write-func "file writing functions".
52  */
53 
54 /** @{ */
55 
56 /*---------- exported types ----------*/
57 
58 /** Special type for holding a PSD vector (over several SFTs) */
60 
61 /** A collection of PSD vectors -- one for each IFO in a multi-IFO search */
62 typedef struct tagMultiPSDVector {
63 #ifdef SWIG /* SWIG interface directives */
64  SWIGLAL( ARRAY_1D( MultiPSDVector, PSDVector *, data, UINT4, length ) );
65 #endif /* SWIG */
66  UINT4 length; /**< number of ifos */
67  PSDVector **data; /**< sftvector for each ifo */
69 
70 /** One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs */
71 typedef struct tagMultiNoiseWeights {
72 #ifdef SWIG /* SWIG interface directives */
73  SWIGLAL( ARRAY_1D( MultiNoiseWeights, REAL8Vector *, data, UINT4, length ) );
74 #endif /* SWIG */
75  UINT4 length; /**< number of detectors */
76  REAL8Vector **data; /**< weights-vector for each detector */
77  REAL8 Sinv_Tsft; /**< normalization factor used: \f$ \mathcal{S}^{-1}\,T_\mathrm{SFT} \f$ (using single-sided PSD!) */
78  BOOLEAN isNotNormalized; /**< if true: weights are saved unnormalized (divide by Sinv_Tsft to get normalized version). */
80 
81 /** common types of mathematical operations over an array */
82 typedef enum tagMathOpType {
83  MATH_OP_ARITHMETIC_SUM = 0, /**< \f$ \sum_k x_k \f$ */
84  MATH_OP_ARITHMETIC_MEAN, /**< \f$ \sum_k x_k / N \f$ */
85  MATH_OP_ARITHMETIC_MEDIAN, /**< \f$ x_1 \leq \dots \leq x_{N/2} \leq \dots \leq x_n \f$ */
86  MATH_OP_HARMONIC_SUM, /**< \f$ 1 / \sum_k (1/x_k) \f$ */
87  MATH_OP_HARMONIC_MEAN, /**< \f$ N / \sum_k (1/x_k) \f$ */
88  MATH_OP_POWERMINUS2_SUM, /**< \f$ 1 / \sqrt{ \sum_k (1/x_k^2) } \f$ */
89  MATH_OP_POWERMINUS2_MEAN, /**< \f$ 1 / \sqrt{ \sum_k (1/x_k^2) / N } \f$ */
90  MATH_OP_MINIMUM, /**< \f$ \min_k(x_k) \f$ */
91  MATH_OP_MAXIMUM, /**< \f$ \max_k(x_k) \f$ */
94 
95 /*---------- global variables ----------*/
96 
97 extern const UserChoices MathOpTypeChoices;
98 
99 /*---------- exported prototypes [API] ----------*/
100 
101 /**
102  * \name PSD type create/destroy functions
103  * \anchor PSD-type-cdtor-func
104  */
105 /** @{ */
106 
107 void XLALDestroyPSDVector( PSDVector *vect );
108 void XLALDestroyMultiPSDVector( MultiPSDVector *multvect );
109 
113 
114 /** @} */
115 
116 /**
117  * \name PSD type modify functions
118  * \anchor PSD-type-mod-func
119  */
120 /** @{ */
121 
122 int XLALCropMultiPSDandSFTVectors( MultiPSDVector *multiPSDVect, MultiSFTVector *multiSFTVect, UINT4 firstBin, UINT4 lastBin );
123 
124 /** @} */
125 
126 /**
127  * \name PSD type property functions
128  * \anchor PSD-type-prop-func
129  */
130 /** @{ */
131 
132 MultiNoiseWeights *XLALComputeMultiNoiseWeights( const MultiPSDVector *rngmed, UINT4 blocksRngMed, UINT4 excludePercentile );
133 
134 /** @} */
135 
136 /**
137  * \name PSD generation functions
138  * \anchor PSD-type-gen-func
139  */
140 /** @{ */
141 
142 REAL8FrequencySeries *XLALComputeSegmentDataQ( const MultiPSDVector *multiPSDVect, LALSeg segment );
143 REAL8 XLALMathOpOverArray( const REAL8 *data, const size_t length, const MathOpType optype );
144 REAL8 XLALGetMathOpNormalizationFactorFromTotalNumberOfSFTs( const UINT4 totalNumSFTs, const MathOpType optypeSFTs );
145 
146 int XLALComputePSDandNormSFTPower( REAL8Vector **finalPSD, MultiPSDVector **multiPSDVector, REAL8Vector **normSFT, MultiSFTVector *inputSFTs, const BOOLEAN returnMultiPSDVector, const BOOLEAN returnNormSFT,
147  const UINT4 blocksRngMed, const MathOpType PSDmthopSFTs, const MathOpType PSDmthopIFOs, const MathOpType nSFTmthopSFTs, const MathOpType nSFTmthopIFOs,
148  const BOOLEAN normalizeByTotalNumSFTs, const REAL8 FreqMin, const REAL8 FreqBand, const BOOLEAN normalizeSFTsInPlace );
149 int XLALComputePSDfromSFTs( REAL8Vector **finalPSD, MultiSFTVector *inputSFTs, const UINT4 blocksRngMed, const MathOpType PSDmthopSFTs, const MathOpType PSDmthopIFOs,
150  const BOOLEAN normalizeByTotalNumSFTs, const REAL8 FreqMin, const REAL8 FreqBand );
151 
152 /** @} */
153 
154 /**
155  * \name PSD file writing functions
156  * \anchor PSD-file-write-func
157  */
158 /** @{ */
159 
160 int XLALDumpMultiPSDVector( const CHAR *outbname, const MultiPSDVector *multiPSDVect );
161 
162 int XLALWritePSDtoFilePointer( FILE *fpOut, REAL8Vector *PSDVect, REAL8Vector *normSFTVect, BOOLEAN outputNormSFT, BOOLEAN outFreqBinEnd, INT4 PSDmthopBins, INT4 nSFTmthopBins,
163  INT4 binSize, INT4 binStep, REAL8 Freq0, REAL8 dFreq );
164 
165 /** @} */
166 
167 /** @} */
168 
169 #ifdef __cplusplus
170 } /* Close C++ protection */
171 #endif
172 
173 #endif /* Close double-include protection */
unsigned char BOOLEAN
double REAL8
char CHAR
uint32_t UINT4
int32_t INT4
int XLALDumpMultiPSDVector(const CHAR *outbname, const MultiPSDVector *multiPSDVect)
Dump complete multi-PSDVector over IFOs, timestamps and frequency-bins into per-IFO ASCII output-file...
Definition: PSDutils.c:936
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.
Definition: PSDutils.c:1056
int XLALCropMultiPSDandSFTVectors(MultiPSDVector *multiPSDVect, MultiSFTVector *multiSFTVect, UINT4 firstBin, UINT4 lastBin)
Function that truncates the PSD in place to the requested frequency-bin interval [firstBin,...
Definition: PSDutils.c:195
MultiNoiseWeights * XLALCopyMultiNoiseWeights(const MultiNoiseWeights *multiWeights)
Create a full copy of a MultiNoiseWeights object.
Definition: PSDutils.c:143
const UserChoices MathOpTypeChoices
Definition: PSDutils.c:44
int XLALComputePSDfromSFTs(REAL8Vector **finalPSD, MultiSFTVector *inputSFTs, const UINT4 blocksRngMed, const MathOpType PSDmthopSFTs, const MathOpType PSDmthopIFOs, const BOOLEAN normalizeByTotalNumSFTs, const REAL8 FreqMin, const REAL8 FreqBand)
Compute the PSD (power spectral density) over a MultiSFTVector.
Definition: PSDutils.c:894
void XLALDestroyPSDVector(PSDVector *vect)
Destroy a PSD-vector.
Definition: PSDutils.c:74
void XLALDestroyMultiPSDVector(MultiPSDVector *multvect)
Destroy a multi PSD-vector.
Definition: PSDutils.c:102
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.
Definition: PSDutils.c:677
MultiNoiseWeights * XLALComputeMultiNoiseWeights(const MultiPSDVector *rngmed, UINT4 blocksRngMed, UINT4 excludePercentile)
Computes weight factors arising from MultiSFTs with different noise floors.
Definition: PSDutils.c:285
REAL8FrequencySeriesVector PSDVector
Special type for holding a PSD vector (over several SFTs)
Definition: PSDutils.h:59
void XLALDestroyMultiNoiseWeights(MultiNoiseWeights *weights)
Destroy a MultiNoiseWeights object.
Definition: PSDutils.c:172
MultiNoiseWeights * XLALCreateMultiNoiseWeights(const UINT4 length)
Create a MultiNoiseWeights of the given length.
Definition: PSDutils.c:125
MathOpType
common types of mathematical operations over an array
Definition: PSDutils.h:82
REAL8 XLALMathOpOverArray(const REAL8 *data, const size_t length, const MathOpType optype)
Compute various types of "math operations" over the entries of an array.
Definition: PSDutils.c:491
REAL8FrequencySeries * XLALComputeSegmentDataQ(const MultiPSDVector *multiPSDVect, LALSeg segment)
Compute the "data-quality factor" over the given SFTs.
Definition: PSDutils.c:375
REAL8 XLALGetMathOpNormalizationFactorFromTotalNumberOfSFTs(const UINT4 totalNumSFTs, const MathOpType optypeSFTs)
Compute an additional normalization factor from the total number of SFTs to be applied after a loop o...
Definition: PSDutils.c:627
@ MATH_OP_MINIMUM
Definition: PSDutils.h:90
@ MATH_OP_HARMONIC_SUM
Definition: PSDutils.h:86
@ MATH_OP_POWERMINUS2_SUM
Definition: PSDutils.h:88
@ MATH_OP_HARMONIC_MEAN
Definition: PSDutils.h:87
@ MATH_OP_MAXIMUM
Definition: PSDutils.h:91
@ MATH_OP_ARITHMETIC_SUM
Definition: PSDutils.h:83
@ MATH_OP_LAST
Definition: PSDutils.h:92
@ MATH_OP_ARITHMETIC_MEDIAN
Definition: PSDutils.h:85
@ MATH_OP_POWERMINUS2_MEAN
Definition: PSDutils.h:89
@ MATH_OP_ARITHMETIC_MEAN
Definition: PSDutils.h:84
One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs.
Definition: PSDutils.h:71
REAL8 Sinv_Tsft
normalization factor used: (using single-sided PSD!)
Definition: PSDutils.h:77
UINT4 length
number of detectors
Definition: PSDutils.h:75
REAL8Vector ** data
weights-vector for each detector
Definition: PSDutils.h:76
BOOLEAN isNotNormalized
if true: weights are saved unnormalized (divide by Sinv_Tsft to get normalized version).
Definition: PSDutils.h:78
A collection of PSD vectors – one for each IFO in a multi-IFO search.
Definition: PSDutils.h:62
PSDVector ** data
sftvector for each ifo
Definition: PSDutils.h:67
UINT4 length
number of ifos
Definition: PSDutils.h:66
A collection of SFT vectors – one for each IFO in a multi-IFO search.
Definition: SFTfileIO.h:179
A vector of REAL8FrequencySeries.