io_util
Functions
-
int unpack_input_io_file(std::string input_param_file, std::unordered_map<std::string, int> *input_param_dict_int, std::unordered_map<std::string, std::string> *input_param_dict_str, std::unordered_map<std::string, double> *input_param_dict_dbl, std::unordered_map<std::string, float> *input_param_dict_flt, std::unordered_map<std::string, bool> *input_param_dict_bool)
-
int find_datatype(std::string type)
Takes in the shorthand for primitive datatypes in c++ and returns code based on type.
Returns:
0 -- Not found 1 -- int 2 -- string 3 -- double 4 -- float 5 -- bool
-
void read_file(std::string filename, double **output, int rows, int cols)
Utility to read in data.
Takes filename, and assigns to output[rows][cols]
File must be comma separated doubles
- Parameters:
filename – input filename, relative to execution directory
output – [out] array to store output, dimensions rowsXcols
rows – first dimension
cols – second dimension
-
void read_file(std::string filename, int **output, int rows, int cols)
Utility to read in data.
Takes filename, and assigns to output[rows][cols]
File must be comma separated doubles
integer version
- Parameters:
filename – input filename, relative to execution directory
output – [out] array to store output, dimensions rowsXcols
rows – first dimension
cols – second dimension
-
void read_file(std::string filename, double *output)
Utility to read in data (single dimension vector)
Takes filename, and assigns to output[i*rows + cols]
Output vector must be long enough, no check is done for the length
File must be comma separated doubles
- Parameters:
filename – input filename, relative to execution directory
output – [out] output array, assumed to have the proper length of total items
-
void read_file(std::string filename, int *output)
Utility to read in data (single dimension vector)
Takes filename, and assigns to output[i*rows + cols]
Output vector must be long enough, no check is done for the length
File must be comma separated doubles
Int version
- Parameters:
filename – input filename, relative to execution directory
output – [out] output array, assumed to have the proper length of total items
-
void write_file(std::string filename, double **input, int rows, int cols)
Utility to write 2D array to file.
Grid of data, comma separated
Grid has rows rows and cols columns
- Parameters:
filename – Filename of output file, relative to execution directory
input – Input 2D array pointer array[rows][cols]
rows – First dimension of array
cols – second dimension of array
-
void write_file(std::string filename, int **input, int rows, int cols)
Utility to write 2D array to file.
Grid of data, comma separated
Grid has rows rows and cols columns
integer version
- Parameters:
filename – Filename of output file, relative to execution directory
input – Input 2D array pointer array[rows][cols]
rows – First dimension of array
cols – second dimension of array
-
void write_file(std::string filename, double *input, int length)
Utility to write 1D array to file.
Single column of data
- Parameters:
filename – Filename of output file, relative to execution directory
input – input 1D array pointer array[length]
length – length of array
-
void write_file(std::string filename, int *input, int length)
Utility to write 1D array to file.
Single column of data
integer version
- Parameters:
filename – Filename of output file, relative to execution directory
input – input 1D array pointer array[length]
length – length of array
-
void read_LOSC_data_file(std::string filename, double *output, double *data_start_time, double *duration, double *fs)
Read data file from LIGO Open Science Center.
Convenience function for cutting off the first few lines of text
- Parameters:
filename – input filename
output – [out] Output data
data_start_time – [out] GPS start time of the data in file
duration – [out] Duration of the signal
fs – [out] Sampling frequency of the data
-
void read_LOSC_PSD_file(std::string filename, double **output, int rows, int cols)
Read PSD file from LIGO Open Science Center.
Convenience function for cutting off the first few lines of text
-
void allocate_LOSC_data(std::string *data_files, std::string psd_file, int num_detectors, int psd_length, int data_file_length, double trigger_time, double post_merger_duration, std::complex<double> **data, double **psds, double **freqs)
Prepare data for MCMC directly from LIGO Open Science Center.
Trims data for Tobs (determined by PSD file) 3/4*Tobs in front of trigger, and 1/4*Tobs behind or max 2 seconds on the end
Currently, default to sampling frequency and observation time set by PSD — cannot be customized
Output is in order of PSD columns — string vector of detectos MUST match order of PSD cols
Output shapes—
psds = [num_detectors][psd_length] data = [num_detectors][psd_length] freqs = [num_detectors][psd_length]
Total observation time = 1/( freq[i] - freq[i-1]) (from PSD file)
Sampling frequency fs = max frequency from PSD file
ALLOCATES MEMORY — must be freed to prevent memory leak
- Parameters:
data_files – Vector of strings for each detector file from LOSC
psd_file – String of psd file from LOSC
num_detectors – Number of detectors to use
psd_length – Length of the PSD file (number of rows of DATA)
data_file_length – Length of the data file (number of rows of DATA)
trigger_time – Time for the signal trigger (GPS)
post_merger_duration – Time after trigger to end the data
data – [out] Output array of data for each detector
psds – [out] Output array of psds for each detector
freqs – [out] Output array of freqs for each detector
-
void free_LOSC_data(std::complex<double> **data, double **psds, double **freqs, int num_detectors, int length)
/brief Free data allocated by prep_LOSC_data function
-
int count_lines_data_file(std::string file, int *count)
Takes in data file and returns the number of data elements in file.