Ejemplo n.º 1
0
 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 = gate.apply_gates_to_fd(h, self.gates)
     return h
Ejemplo n.º 2
0
 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 = gate.apply_gates_to_fd(h, self.gates)
     return h
Ejemplo n.º 3
0
def data_from_cli(opts):
    """Loads the data needed for a likelihood evaluator 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
    strain_dict = strain_from_cli_multi_ifos(opts, opts.instruments,
                                             precision="double")
    # apply gates if not waiting to overwhiten
    if not opts.gate_overwhitened:
        logging.info("Applying gates to strain data")
        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,
                                                    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
    logging.info("FFT strain")
    stilde_dict = {}
    length_dict = {}
    delta_f_dict = {}
    low_frequency_cutoff_dict = low_frequency_cutoff_from_cli(opts)
    for ifo in opts.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, opts.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 likelihood generator
        for ifo in gates:
            stilde_dict[ifo] *= psd_dict[ifo]

    return strain_dict, stilde_dict, psd_dict
Ejemplo n.º 4
0
def data_from_cli(opts):
    """Loads the data needed for a likelihood evaluator 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
    strain_dict = strain_from_cli_multi_ifos(opts, opts.instruments,
                                             precision="double")
    # apply gates if not waiting to overwhiten
    if not opts.gate_overwhitened:
        logging.info("Applying gates to strain data")
        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,
                                                    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
    logging.info("FFT strain")
    stilde_dict = {}
    length_dict = {}
    delta_f_dict = {}
    low_frequency_cutoff_dict = low_frequency_cutoff_from_cli(opts)
    for ifo in opts.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, opts.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 likelihood generator
        for ifo in gates:
            stilde_dict[ifo] *= psd_dict[ifo]

    return strain_dict, stilde_dict, psd_dict