def gate_overwhitened_data(stilde_dict, psd_dict, gates): """Applies gates to overwhitened data. Parameters ---------- stilde_dict : dict Dictionary of detectors -> frequency series data to apply the gates to. psd_dict : dict Dictionary of detectors -> PSD to use for overwhitening. gates : dict Dictionary of detectors -> gates. Returns ------- dict : Dictionary of detectors -> frequency series data with the gates applied after overwhitening. The returned data is not overwhitened. """ logging.info("Applying gates to overwhitened data") # overwhiten the data out = {} for det in gates: out[det] = stilde_dict[det] / psd_dict[det] # now apply the gate out = apply_gates_to_fd(out, gates) # now unwhiten for det in gates: out[det] *= psd_dict[det] return out
def generate(self, **kwargs): """Generates a waveform, applies a time shift and the detector response function from the given kwargs. """ self.current_params.update(kwargs) rfparams = { param: self.current_params[param] for param in kwargs if param not in self.location_args } hp, hc = self.rframe_generator.generate(**rfparams) if isinstance(hp, TimeSeries): df = self.current_params['delta_f'] hp = hp.to_frequencyseries(delta_f=df) hc = hc.to_frequencyseries(delta_f=df) # time-domain waveforms will not be shifted so that the peak amp # happens at the end of the time series (as they are for f-domain), # so we add an additional shift to account for it tshift = 1. / df - abs(hp._epoch) else: tshift = 0. hp._epoch = hc._epoch = self._epoch h = {} if self.detector_names != ['RF']: for detname, det in self.detectors.items(): # apply detector response function fp, fc = det.antenna_pattern( self.current_params['ra'], self.current_params['dec'], self.current_params['polarization'], self.current_params['tc']) thish = fp * hp + fc * hc # apply the time shift tc = self.current_params['tc'] + \ det.time_delay_from_earth_center(self.current_params['ra'], self.current_params['dec'], self.current_params['tc']) h[detname] = apply_fd_time_shift(thish, tc + tshift, copy=False) if self.recalib: # recalibrate with given calibration model h[detname] = \ self.recalib[detname].map_to_adjust(h[detname], **self.current_params) else: # no detector response, just use the + polarization if 'tc' in self.current_params: hp = apply_fd_time_shift(hp, self.current_params['tc'] + tshift, copy=False) h['RF'] = hp if self.gates is not None: # resize all to nearest power of 2 for d in h.values(): d.resize(ceilpow2(len(d) - 1) + 1) h = strain.apply_gates_to_fd(h, self.gates) return h
def generate(self, **kwargs): """Generates a waveform, applies a time shift and the detector response function from the given kwargs. """ self.current_params.update(kwargs) rfparams = {param: self.current_params[param] for param in kwargs if param not in self.location_args} hp, hc = self.rframe_generator.generate(**rfparams) if isinstance(hp, TimeSeries): df = self.current_params['delta_f'] hp = hp.to_frequencyseries(delta_f=df) hc = hc.to_frequencyseries(delta_f=df) # time-domain waveforms will not be shifted so that the peak amp # happens at the end of the time series (as they are for f-domain), # so we add an additional shift to account for it tshift = 1./df - abs(hp._epoch) else: tshift = 0. hp._epoch = hc._epoch = self._epoch h = {} if self.detector_names != ['RF']: for detname, det in self.detectors.items(): # apply detector response function fp, fc = det.antenna_pattern(self.current_params['ra'], self.current_params['dec'], self.current_params['polarization'], self.current_params['tc']) thish = fp*hp + fc*hc # apply the time shift tc = self.current_params['tc'] + \ det.time_delay_from_earth_center(self.current_params['ra'], self.current_params['dec'], self.current_params['tc']) h[detname] = apply_fd_time_shift(thish, tc+tshift, copy=False) if self.recalib: # recalibrate with given calibration model h[detname] = \ self.recalib[detname].map_to_adjust(h[detname], **self.current_params) else: # no detector response, just use the + polarization if 'tc' in self.current_params: hp = apply_fd_time_shift(hp, self.current_params['tc']+tshift, copy=False) h['RF'] = hp if self.gates is not None: # resize all to nearest power of 2 for d in h.values(): d.resize(ceilpow2(len(d)-1) + 1) h = strain.apply_gates_to_fd(h, self.gates) return h
def generate(self, **kwargs): """Generates and returns a waveform decompsed into separate modes. Returns ------- dict : Dictionary of ``detector names -> modes -> (ulm, vlm)``, where ``ulm, vlm`` are the frequency-domain representations of the real and imaginary parts, respectively, of the complex time series representation of the ``hlm``. """ self.current_params.update(kwargs) rfparams = {param: self.current_params[param] for param in kwargs if param not in self.location_args} hlms = self.rframe_generator.generate(**rfparams) h = {det: {} for det in self.detectors} for mode in hlms: ulm, vlm = hlms[mode] if isinstance(ulm, TimeSeries): df = self.current_params['delta_f'] ulm = ulm.to_frequencyseries(delta_f=df) vlm = vlm.to_frequencyseries(delta_f=df) # time-domain waveforms will not be shifted so that the peak # amplitude happens at the end of the time series (as they are # for f-domain), so we add an additional shift to account for # it tshift = 1./df - abs(ulm._epoch) else: tshift = 0. ulm._epoch = vlm._epoch = self._epoch if self.detector_names != ['RF']: for detname, det in self.detectors.items(): # apply the time shift tc = self.current_params['tc'] + \ det.time_delay_from_earth_center( self.current_params['ra'], self.current_params['dec'], self.current_params['tc']) detulm = apply_fd_time_shift(ulm, tc+tshift, copy=True) detvlm = apply_fd_time_shift(vlm, tc+tshift, copy=True) if self.recalib: # recalibrate with given calibration model detulm = self.recalib[detname].map_to_adjust( detulm, **self.current_params) detvlm = self.recalib[detname].map_to_adjust( detvlm, **self.current_params) h[detname][mode] = (detulm, detvlm) else: # no detector response, just apply time shift if 'tc' in self.current_params: ulm = apply_fd_time_shift(ulm, self.current_params['tc']+tshift, copy=False) vlm = apply_fd_time_shift(vlm, self.current_params['tc']+tshift, copy=False) h['RF'][mode] = (ulm, vlm) if self.gates is not None: # resize all to nearest power of 2 ulms = {} vlms = {} for det in h: ulm, vlm = h[det][mode] ulm.resize(ceilpow2(len(ulm)-1) + 1) vlm.resize(ceilpow2(len(vlm)-1) + 1) ulms[det] = ulm vlms[det] = vlm ulms = strain.apply_gates_to_fd(ulms, self.gates) vlms = strain.apply_gates_to_fd(ulms, self.gates) for det in ulms: h[det][mode] = (ulms[det], vlms[det]) return h
def generate(self, **kwargs): """Generates a waveform polarizations and applies a time shift. Returns ------- dict : Dictionary of ``detector names -> (hp, hc)``, where ``hp, hc`` are the plus and cross polarization, respectively. """ self.current_params.update(kwargs) rfparams = {param: self.current_params[param] for param in kwargs if param not in self.location_args} hp, hc = self.rframe_generator.generate(**rfparams) if isinstance(hp, TimeSeries): df = self.current_params['delta_f'] hp = hp.to_frequencyseries(delta_f=df) hc = hc.to_frequencyseries(delta_f=df) # time-domain waveforms will not be shifted so that the peak amp # happens at the end of the time series (as they are for f-domain), # so we add an additional shift to account for it tshift = 1./df - abs(hp._epoch) else: tshift = 0. hp._epoch = hc._epoch = self._epoch h = {} if self.detector_names != ['RF']: for detname, det in self.detectors.items(): # apply the time shift tc = self.current_params['tc'] + \ det.time_delay_from_earth_center(self.current_params['ra'], self.current_params['dec'], self.current_params['tc']) dethp = apply_fd_time_shift(hp, tc+tshift, copy=True) dethc = apply_fd_time_shift(hc, tc+tshift, copy=True) if self.recalib: # recalibrate with given calibration model dethp = self.recalib[detname].map_to_adjust( dethp, **self.current_params) dethc = self.recalib[detname].map_to_adjust( dethc, **self.current_params) h[detname] = (dethp, dethc) else: # no detector response, just use the + polarization if 'tc' in self.current_params: hp = apply_fd_time_shift(hp, self.current_params['tc']+tshift, copy=False) hc = apply_fd_time_shift(hc, self.current_params['tc']+tshift, copy=False) h['RF'] = (hp, hc) if self.gates is not None: # resize all to nearest power of 2 hps = {} hcs = {} for det in h: hp = h[det] hc = h[det] hp.resize(ceilpow2(len(hp)-1) + 1) hc.resize(ceilpow2(len(hc)-1) + 1) hps[det] = hp hcs[det] = hc hps = strain.apply_gates_to_fd(hps, self.gates) hcs = strain.apply_gates_to_fd(hps, self.gates) h = {det: (hps[det], hcs[det]) for det in h} return h
def data_from_cli(opts): """Loads the data needed for a model from the given command-line options. Gates specifed on the command line are also applied. Parameters ---------- opts : ArgumentParser parsed args Argument options parsed from a command line string (the sort of thing returned by `parser.parse_args`). Returns ------- strain_dict : dict Dictionary of instruments -> `TimeSeries` strain. stilde_dict : dict Dictionary of instruments -> `FrequencySeries` strain. psd_dict : dict Dictionary of instruments -> `FrequencySeries` psds. """ # get gates to apply gates = gates_from_cli(opts) psd_gates = psd_gates_from_cli(opts) # get strain time series instruments = opts.instruments if opts.instruments is not None else [] strain_dict = strain_from_cli_multi_ifos(opts, instruments, precision="double") # apply gates if not waiting to overwhiten if not opts.gate_overwhitened: strain_dict = apply_gates_to_td(strain_dict, gates) # get strain time series to use for PSD estimation # if user has not given the PSD time options then use same data as analysis if opts.psd_start_time and opts.psd_end_time: logging.info("Will generate a different time series for PSD " "estimation") psd_opts = opts psd_opts.gps_start_time = psd_opts.psd_start_time psd_opts.gps_end_time = psd_opts.psd_end_time psd_strain_dict = strain_from_cli_multi_ifos(psd_opts, instruments, precision="double") # apply any gates logging.info("Applying gates to PSD data") psd_strain_dict = apply_gates_to_td(psd_strain_dict, psd_gates) elif opts.psd_start_time or opts.psd_end_time: raise ValueError("Must give --psd-start-time and --psd-end-time") else: psd_strain_dict = strain_dict # FFT strain and save each of the length of the FFT, delta_f, and # low frequency cutoff to a dict stilde_dict = {} length_dict = {} delta_f_dict = {} low_frequency_cutoff_dict = low_frequency_cutoff_from_cli(opts) for ifo in instruments: stilde_dict[ifo] = strain_dict[ifo].to_frequencyseries() length_dict[ifo] = len(stilde_dict[ifo]) delta_f_dict[ifo] = stilde_dict[ifo].delta_f # get PSD as frequency series psd_dict = psd_from_cli_multi_ifos(opts, length_dict, delta_f_dict, low_frequency_cutoff_dict, instruments, strain_dict=psd_strain_dict, precision="double") # apply any gates to overwhitened data, if desired if opts.gate_overwhitened and opts.gate is not None: logging.info("Applying gates to overwhitened data") # overwhiten the data for ifo in gates: stilde_dict[ifo] /= psd_dict[ifo] stilde_dict = apply_gates_to_fd(stilde_dict, gates) # unwhiten the data for the model for ifo in gates: stilde_dict[ifo] *= psd_dict[ifo] return strain_dict, stilde_dict, psd_dict
def data_from_cli(opts): """Loads the data needed for a model from the given command-line options. Gates specifed on the command line are also applied. Parameters ---------- opts : ArgumentParser parsed args Argument options parsed from a command line string (the sort of thing returned by `parser.parse_args`). Returns ------- strain_dict : dict Dictionary of instruments -> `TimeSeries` strain. stilde_dict : dict Dictionary of instruments -> `FrequencySeries` strain. psd_dict : dict Dictionary of instruments -> `FrequencySeries` psds. """ # get gates to apply gates = gates_from_cli(opts) psd_gates = psd_gates_from_cli(opts) # get strain time series instruments = opts.instruments if opts.instruments is not None else [] strain_dict = strain_from_cli_multi_ifos(opts, instruments, precision="double") # apply gates if not waiting to overwhiten if not opts.gate_overwhitened: strain_dict = apply_gates_to_td(strain_dict, gates) # get strain time series to use for PSD estimation # if user has not given the PSD time options then use same data as analysis if opts.psd_start_time and opts.psd_end_time: logging.info("Will generate a different time series for PSD " "estimation") psd_opts = opts psd_opts.gps_start_time = psd_opts.psd_start_time psd_opts.gps_end_time = psd_opts.psd_end_time psd_strain_dict = strain_from_cli_multi_ifos(psd_opts, instruments, precision="double") # apply any gates logging.info("Applying gates to PSD data") psd_strain_dict = apply_gates_to_td(psd_strain_dict, psd_gates) elif opts.psd_start_time or opts.psd_end_time: raise ValueError("Must give --psd-start-time and --psd-end-time") else: psd_strain_dict = strain_dict # FFT strain and save each of the length of the FFT, delta_f, and # low frequency cutoff to a dict stilde_dict = {} length_dict = {} delta_f_dict = {} low_frequency_cutoff_dict = low_frequency_cutoff_from_cli(opts) for ifo in instruments: stilde_dict[ifo] = strain_dict[ifo].to_frequencyseries() length_dict[ifo] = len(stilde_dict[ifo]) delta_f_dict[ifo] = stilde_dict[ifo].delta_f # get PSD as frequency series psd_dict = psd_from_cli_multi_ifos( opts, length_dict, delta_f_dict, low_frequency_cutoff_dict, instruments, strain_dict=psd_strain_dict, precision="double") # apply any gates to overwhitened data, if desired if opts.gate_overwhitened and opts.gate is not None: logging.info("Applying gates to overwhitened data") # overwhiten the data for ifo in gates: stilde_dict[ifo] /= psd_dict[ifo] stilde_dict = apply_gates_to_fd(stilde_dict, gates) # unwhiten the data for the model for ifo in gates: stilde_dict[ifo] *= psd_dict[ifo] return strain_dict, stilde_dict, psd_dict