예제 #1
0
파일: generator.py 프로젝트: lenona/pycbc
 def generate(self, *args):
     """Generates a waveform, applies a time shift and the detector response
     function."""
     self.current_params.update(dict(zip(self.variable_args, args)))
     # FIXME: use the following when we switch to 2.7
     # rfparams = {param: self.current_params[param]
     #    for param in self.rframe_generator.variable_args}
     rfparams = dict([(param, self.current_params[param]) for param in self.rframe_generator.variable_args])
     hp, hc = self.rframe_generator.generate_from_kwargs(**rfparams)
     h = {}
     if self.detector_names != ["RF"]:
         # we'll need the frequency points for applying the time shift
         fseries = hp.sample_frequencies.numpy()
         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, fseries=fseries, copy=False)
     elif "tc" in self.current_params:
         # apply the time shift if specified
         fseries = hp.sample_frequencies.numpy()
         h["RF"] = apply_fd_time_shift(hp, self.current_params["tc"], fseries=fseries, copy=False)
     else:
         # just return the plus polarization
         h["RF"] = hp
     return h
예제 #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 = strain.apply_gates_to_fd(h, self.gates)
     return h
예제 #3
0
파일: generator.py 프로젝트: cmbiwer/pycbc
 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
예제 #4
0
 def _shift_and_ifft(self, fdsinx, tshift, fseries=None):
     """Calls apply_fd_time_shift, and iFFTs to the time domain.
     """
     start_time = self.time_series.start_time
     tdshift = apply_fd_time_shift(fdsinx, start_time+tshift,
                                   fseries=fseries)
     return tdshift.to_timeseries()
예제 #5
0
파일: generator.py 프로젝트: pbacon42/pycbc
 def generate(self, *args):
     """Generates a waveform, applies a time shift and the detector response
     function."""
     self.current_params.update(dict(zip(self.variable_args, args)))
     # FIXME: use the following when we switch to 2.7
     #rfparams = {param: self.current_params[param]
     #    for param in self.rframe_generator.variable_args}
     rfparams = dict([(param, self.current_params[param])
                      for param in self.rframe_generator.variable_args])
     hp, hc = self.rframe_generator.generate_from_kwargs(**rfparams)
     hp._epoch = hc._epoch = self._epoch
     h = {}
     if 'tc' in self.current_params:
         try:
             kmin = int(self.current_params['f_lower'] / hp.delta_f)
         except KeyError:
             kmin = 0
     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,
                                              kmin=kmin,
                                              copy=False)
     else:
         # no detector response, just use the + polarization
         if 'tc' in self.current_params:
             hp = apply_fd_time_shift(hp,
                                      self.current_params['tc'],
                                      kmin=kmin,
                                      copy=False)
         h['RF'] = hp
     return h
예제 #6
0
 def generate(self, *args):
     """Generates a waveform, applies a time shift and the detector response
     function."""
     self.current_params.update(dict(zip(self.variable_args, args)))
     # FIXME: use the following when we switch to 2.7
     #rfparams = {param: self.current_params[param]
     #    for param in self.rframe_generator.variable_args}
     rfparams = dict([(param, self.current_params[param])
         for param in self.rframe_generator.variable_args])
     hp, hc = self.rframe_generator.generate_from_kwargs(**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)
     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
     return h
예제 #7
0
 def _shift_and_ifft(self, fdsinx, tshift, fseries=None):
     """Calls apply_fd_time_shift, and iFFTs to the time domain.
     """
     start_time = self.time_series.start_time
     tdshift = apply_fd_time_shift(fdsinx, start_time+tshift,
                                   fseries=fseries)
     if not isinstance(tdshift, FrequencySeries):
         # cast to FrequencySeries so time series will work
         tdshift = FrequencySeries(tdshift, delta_f=fdsinx.delta_f,
                                   epoch=fdsinx.epoch)
     return tdshift.to_timeseries()
예제 #8
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 self.rframe_generator.variable_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)
     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
     return h
 def _shift_and_ifft(self, fdsinx, tshift, fseries=None):
     """Calls apply_fd_time_shift, and iFFTs to the time domain.
     """
     start_time = self.time_series.start_time
     tdshift = apply_fd_time_shift(fdsinx,
                                   start_time + tshift,
                                   fseries=fseries)
     if not isinstance(tdshift, FrequencySeries):
         # cast to FrequencySeries so time series will work
         tdshift = FrequencySeries(tdshift,
                                   delta_f=fdsinx.delta_f,
                                   epoch=fdsinx.epoch)
     return tdshift.to_timeseries()
예제 #10
0
파일: generator.py 프로젝트: sfairhur/pycbc
 def generate(self, *args):
     """Generates a waveform, applies a time shift and the detector response
     function."""
     self.current_params.update(dict(zip(self.variable_args, args)))
     # FIXME: use the following when we switch to 2.7
     #rfparams = {param: self.current_params[param]
     #    for param in self.rframe_generator.variable_args}
     rfparams = dict([(param, self.current_params[param])
         for param in self.rframe_generator.variable_args])
     hp, hc = self.rframe_generator.generate_from_kwargs(**rfparams)
     hp._epoch = hc._epoch = self._epoch
     h = {}
     if 'tc' in self.current_params:
         try:
             kmin = int(self.current_params['f_lower']/hp.delta_f)
         except KeyError:
             kmin = 0
     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, kmin=kmin, copy=False)
     else:
         # no detector response, just use the + polarization
         if 'tc' in self.current_params:
             hp = apply_fd_time_shift(hp, self.current_params['tc'],
                         kmin=kmin, copy=False)
         h['RF'] = hp
     return h
예제 #11
0
    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
예제 #12
0
    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