Esempio n. 1
0
    def lal(self):
        """Produces a LAL time series object equivalent to self.

        Returns
        -------
        lal_data : {lal.*TimeSeries}
            LAL time series object containing the same data as self.
            The actual type depends on the sample's dtype.  If the epoch of
            self is 'None', the epoch of the returned LAL object will be
            LIGOTimeGPS(0,0); otherwise, the same as that of self.

        Raises
        ------
        TypeError
            If time series is stored in GPU memory.
        """
        lal_data = None
        ep = self._epoch

        if self._data.dtype == _numpy.float32:
            lal_data = _lal.CreateREAL4TimeSeries("",ep,0,self.delta_t,_lal.SecondUnit,len(self))
        elif self._data.dtype == _numpy.float64:
            lal_data = _lal.CreateREAL8TimeSeries("",ep,0,self.delta_t,_lal.SecondUnit,len(self))
        elif self._data.dtype == _numpy.complex64:
            lal_data = _lal.CreateCOMPLEX8TimeSeries("",ep,0,self.delta_t,_lal.SecondUnit,len(self))
        elif self._data.dtype == _numpy.complex128:
            lal_data = _lal.CreateCOMPLEX16TimeSeries("",ep,0,self.delta_t,_lal.SecondUnit,len(self))

        lal_data.data.data[:] = self.numpy()

        return lal_data
Esempio n. 2
0
    def lal(self):
        """ Returns a LAL Object that contains this data """

        lal_data = None
        if type(self._data) is not _numpy.ndarray:
            raise TypeError("Cannot return lal type from the GPU")
        elif self._data.dtype == _numpy.float32:
            lal_data = _lal.CreateREAL4TimeSeries("", self._epoch, 0,
                                                  self.delta_t,
                                                  _lal.lalSecondUnit,
                                                  len(self))
        elif self._data.dtype == _numpy.float64:
            lal_data = _lal.CreateREAL8TimeSeries("", self._epoch, 0,
                                                  self.delta_t,
                                                  _lal.lalSecondUnit,
                                                  len(self))
        elif self._data.dtype == _numpy.complex64:
            lal_data = _lal.CreateCOMPLEX8TimeSeries("", self._epoch, 0,
                                                     self.delta_t,
                                                     _lal.lalSecondUnit,
                                                     len(self))
        elif self._data.dtype == _numpy.complex128:
            lal_data = _lal.CreateCOMPLEX16TimeSeries("", self._epoch, 0,
                                                      self.delta_t,
                                                      _lal.lalSecondUnit,
                                                      len(self))

        lal_data.data.data[:] = self._data

        return lal_data
Esempio n. 3
0
    def get_strain(self, fs, tmin=0, tmax=None, noise_sqrt_Sh=0, noise_seed=0):
        """
        Generate strain time series of a continuous-wave signal in the detector frame.

        @param fs: sampling frequency of strain time series, in Hz
        @param tmin: start time for strain time series, as offsets from self.__tstart
        @param tmax: start time for strain time series, as offsets from self.__tstart
        @param noise_sqrt_Sh: if >0, add Gaussian noise with square-root single-sided power
            spectral density given by this value, in Hz^(-1/2)
        @param noise_seed: use this need for the random number generator used to create noise

        @return (@b t, @b h), where:
            @b t = start of time strain time series, in GPS seconds;
            @b h = strain time series
        """

        # process tmin/tmax range (interpreted relative to self.__tstart)
        if (tmin < 0) or (tmin>=self.__Tdata):
            raise ValueError('tmin must be within [0,{}).'.format(self.__Tdata))
        if tmax is None:
            tmax = self.__Tdata
        elif (tmax <= 0) or (tmax>self.__Tdata):
            raise ValueError('tmax must be within (0,{}].'.format(self.__Tdata))
        tspan = tmax-tmin

        # create REAL4TimeSeries to store output time series
        Nh = int(fs*tspan)
        h = lal.CreateREAL4TimeSeries("h", self.__tstart+tmin, 0, 1.0 / fs,
                                      lal.DimensionlessUnit, Nh)

        # generate strain time series
        self._simulate_coherent_gw(h, noise_sqrt_Sh, noise_seed)
        return (h.epoch, h.data.data)
    def get_strain(self, fs, noise_sqrt_Sh=0):
        """
        Generate strain time series of a continuous-wave signal in the detector frame.

        @param fs: sampling frequency of strain time series, in Hz
        @param noise_sqrt_Sh: if >0, add Gaussian noise with square-root single-sided power
            spectral density given by this value, in Hz^(-1/2)

        @return (@b t, @b h), where:
            @b t = start of time strain time series, in GPS seconds;
            @b h = strain time series
        """

        # create REAL4TimeSeries to store output time series
        N_h = int(fs * self.__T)
        h = lal.CreateREAL4TimeSeries("h", self.__gps_t0, 0, 1.0 / fs,
                                      lal.DimensionlessUnit, N_h)

        # generate strain time series
        self._simulate_coherent_gw(h, noise_sqrt_Sh)
        return (h.epoch, h.data.data)
    def get_strain_blocks(self, fs, T_block, noise_sqrt_Sh=0):
        """
        Generate strain time series of a continuous-wave signal in the detector frame, in contiguous blocks.

        @param fs: sampling frequency of strain time series, in Hz
        @param T_block: length of each block, in seconds; should divide evenly into @b T
        @param noise_sqrt_Sh: if >0, add Gaussian noise with square-root single-sided power
            spectral density given by this value, in Hz^(-1/2)

        @return (@b t, @b h, @b i, @b N), where:
            @b t = start of time strain time series, in GPS seconds;
            @b h = strain time series;
            @b i = block index, starting from zero;
            @b N = number of blocks

        This is a Python generator function and so should be called as follows:
        ~~~
        S = CWSimulator(...)
        for t, h, i, N in S.get_strain_blocks(...):
            ...
        ~~~
        """

        # work out number of blocks
        N_block = int(round(self.__T / T_block))
        if T_block * N_block > self.__T:
            raise ValueError(
                "Length of block T_block=%g does not divide evenly into T=%g" %
                (T_block, self.__T))

        # create REAL4TimeSeries to store output time series
        N_h = int(fs * T_block)
        h = lal.CreateREAL4TimeSeries("h", self.__gps_t0, 0, 1.0 / fs,
                                      lal.DimensionlessUnit, N_h)

        # generate strain time series in blocks of length 'T_block'
        for i_block in xrange(0, N_block):
            self._simulate_coherent_gw(h, noise_sqrt_Sh)
            yield h.epoch, h.data.data, i_block, N_block
            h.epoch += T_block
Esempio n. 6
0
    def _make_series(self, array, epoch, row_number):
        """For internal use only."""
        para = {
            "name":
            "%s_%d_%d" % (self.instrument, self.bank_number, row_number),
            "epoch": epoch,
            "deltaT": self.deltaT,
            "f0": 0,
            "sampleUnits": lal.DimensionlessUnit,
            "length": len(array)
        }
        if array.dtype == numpy.float32:
            tseries = lal.CreateREAL4TimeSeries(**para)
        elif array.dtype == numpy.float64:
            tseries = lal.CreateREAL8TimeSeries(**para)
        elif array.dtype == numpy.complex64:
            tseries = lal.CreateCOMPLEX8TimeSeries(**para)
        elif array.dtype == numpy.complex128:
            tseries = lal.CreateCOMPLEX16TimeSeries(**para)
        else:
            raise ValueError("unsupported type : %s " % array.dtype)

        tseries.data.data = array
        return tseries
Esempio n. 7
0
# check module load
print("checking module load ...")
import lal
from lal import globalvar as lalglobalvar
lal_c_si = lal.C_SI
lal_180_pi = lal.LAL_180_PI
print("PASSED module load")

# check memory allocation
print("checking memory allocation ...")
if not lal.NoDebug:
    lal.CheckMemoryLeaks()
    mem1 = lal.Detector()
    mem2 = lal.CreateCOMPLEX8Vector(5)
    mem3 = lal.CreateREAL8Vector(3)
    mem4 = lal.CreateREAL4TimeSeries("test", lal.LIGOTimeGPS(0), 100, 0.1,
                                     lal.DimensionlessUnit, 10)
    print("*** below should be an error message from CheckMemoryLeaks() ***")
    try:
        lal.CheckMemoryLeaks()
        expected_exception = True
    except:
        pass
    assert (not expected_exception)
    print("*** above should be an error message from CheckMemoryLeaks() ***")
    del mem1
    del mem2
    del mem3
    del mem4
    lal.CheckMemoryLeaks()
    print("PASSED memory allocation")
else: