def __init__(self, gps_t0, T, wf, gps_tref_wf, dt_wf, phi_0, psi, alpha, delta, det_name, earth_ephem_file="earth00-19-DE405.dat.gz", sun_ephem_file="sun00-19-DE405.dat.gz"): """ Initialise a continuous-wave signal simulator. @param gps_t0: start time of signal, in GPS seconds @param T: total duration of signal, in seconds @param wf: function which computes signal phase and amplitudes as functions of time: @b dphi, @b aplus, @b across = @b wf(dt), where: @b dt = time since reference time @b gps_tref_wf; @b dphi = phase of signal at time @b dt relative to reference time @b gps_tref_wf, in radians; @b aplus = strain amplitude of plus polarisation at time @b dt; @b across = strain amplitude of cross polarisation at time @b dt @param gps_tref_wf: reference time for signal phase, in GPS seconds @param dt_wf: sampling time of the function @c wf; this need only be small enough to ensure that @c dphi, @c aplus, and @c across are smoothly interpolated, and does not need to make the desired sampling frequency of the output strain time series @param phi_0: initial phase of the gravitational-wave signal at @b gps_t0, in radians @param psi: polarisation angle of the gravitational-wave source, in radians @param alpha: right ascension of the gravitational-wave source, in radians @param delta: declination of the gravitational-wave source, in radians @param det_name: name of the gravitational-wave detector to simulate a response for; e.g. @c "H1" for LIGO Hanford, @c "L1" for LIGO Livingston, @c "V1" for Virgo @param earth_ephem_file: name of file to load Earth ephemeris from @param sun_ephem_file: name of file to load Sun ephemeris from """ # store arguments self.__gps_t0 = gps_t0 self.__T = T # parse detector name try: _, self.__det_index = lalpulsar.GetCWDetectorPrefix(det_name) assert (self.__det_index >= 0) except: raise ValueError("Invalid detector name det_name='%s'" % det_name) # load Earth and Sun ephemerides self.__ephemerides = lalpulsar.InitBarycenter(earth_ephem_file, sun_ephem_file) # start signal time series 'T_pad_wf' before/after output strain time series # to add sufficient padding for maximum Doppler modulation time shifts, otherwise # lalpulsar.PulsarSimulateCoherentGW() will output zeros without complaint (unless # you run with LAL_DEBUG_LEVEL=warning) T_pad_wf = 2.0 * lal.AU_SI / lal.C_SI gps_t0_wf = gps_t0 - T_pad_wf N_wf = int(math.ceil(float(T + 2 * T_pad_wf) / float(dt_wf))) # create REAL8TimeSeries to store signal phase self.__phi = lal.CreateREAL8TimeSeries("phi", gps_t0_wf, 0, dt_wf, lal.DimensionlessUnit, N_wf) # create REAL4TimeVectorSeries to store signal amplitudes # - LAL provides no creator function for this type, so must be done manually self.__a = lal.REAL4TimeVectorSeries() self.__a.name = "a+,ax" self.__a.epoch = gps_t0_wf self.__a.deltaT = dt_wf self.__a.f0 = 0 self.__a.sampleUnits = lal.StrainUnit self.__a.data = lal.CreateREAL4VectorSequence(N_wf, 2) # call wf() to fill time series of signal phase and amplitudes dt = float(gps_t0_wf - gps_tref_wf) for i in xrange(0, N_wf): dphi, aplus, across = wf(dt) self.__phi.data.data[i] = phi_0 + dphi self.__a.data.data[i][0] = aplus self.__a.data.data[i][1] = across dt += dt_wf # create and initialise PulsarCoherentGW struct self.__waveform = lalpulsar.PulsarCoherentGW() self.__waveform.position.system = lal.COORDINATESYSTEM_EQUATORIAL self.__waveform.position.longitude = alpha self.__waveform.position.latitude = delta self.__waveform.psi = psi self.__waveform.phi = self.__phi self.__waveform.a = self.__a # create and initialise PulsarDetectorResponse struct self.__detector = lalpulsar.PulsarDetectorResponse() self.__detector.site = lal.CachedDetectors[self.__det_index] self.__detector.ephemerides = self.__ephemerides
assert ((c16.data == 3 * c16dat).all()) c16 = c16dat retn, c16 = lal.swig_lal_test_copyinout_COMPLEX16Vector(c16) assert (retn) assert ((c16 == 3 * c16dat).all()) del c16 del c16out del c16dat lal.CheckMemoryLeaks() r4dat = numpy.array([[1.2, 2.3, 3.4], [4.5, 5.6, 6.7]], dtype=numpy.float32) r8dat = numpy.array([[3.4, 4.5], [5.6, 6.7], [7.8, 8.9]], dtype=numpy.float64) c8dat = numpy.array(numpy.vectorize(complex)(r4dat, 8 + r4dat), dtype=numpy.complex64) c16dat = numpy.array(numpy.vectorize(complex)(r8dat, 16 + r8dat), dtype=numpy.complex128) r4 = lal.CreateREAL4VectorSequence(r4dat.shape[0], r4dat.shape[1]) r4.data = r4dat r4out = lal.CreateREAL4VectorSequence(r4dat.shape[0], r4dat.shape[1]) r4out.data = numpy.zeros(numpy.shape(r4dat), dtype=r4dat.dtype) assert (lal.swig_lal_test_viewin_REAL4VectorSequence(r4out, r4)) assert ((r4out.data == r4.data).all()) r4out.data = numpy.zeros(numpy.shape(r4dat), dtype=r4dat.dtype) assert (lal.swig_lal_test_viewin_REAL4VectorSequence(r4out, r4dat)) assert ((r4out.data == r4dat).all()) r4out.data = numpy.zeros(numpy.shape(r4dat), dtype=r4dat.dtype) assert (lal.swig_lal_test_viewinout_REAL4VectorSequence(r4out, r4)) assert ((2 * r4out.data == r4.data).all()) r4out.data = numpy.zeros(numpy.shape(r4dat), dtype=r4dat.dtype) assert (lal.swig_lal_test_viewinout_REAL4VectorSequence(r4out, r4dat)) assert ((2 * r4out.data == r4dat).all()) r4.data = r4dat
def __init__(self, tref, tstart, Tdata, waveform, dt_wf, phi0, psi, alpha, delta, det_name, earth_ephem_file="earth00-40-DE405.dat.gz", sun_ephem_file="sun00-40-DE405.dat.gz", tref_at_det=False, extra_comment=None): """ Initialise a continuous-wave signal simulator. @param tref: reference time of signal phase at Solar System barycentre, in GPS seconds (but see @b tref_at_det) @param tstart: start time of signal, in GPS seconds @param Tdata: total duration of signal, in seconds @param waveform: function which computes signal phase and amplitudes as functions of time: @b dphi, @b aplus, @b across = @b waveform(dt), where: @b dt = time since reference time @b tref; @b dphi = phase of signal at time @b dt relative to reference time @b tref, in radians; @b aplus = strain amplitude of plus polarisation at time @b dt; @b across = strain amplitude of cross polarisation at time @b dt @param dt_wf: sampling time of the function @c waveform; this need only be small enough to ensure that @c dphi, @c aplus, and @c across are smoothly interpolated, and does not need to make the desired sampling frequency of the output strain time series @param phi0: initial phase of the gravitational-wave signal at @b tstart, in radians @param psi: polarisation angle of the gravitational-wave source, in radians @param alpha: right ascension of the gravitational-wave source, in radians @param delta: declination of the gravitational-wave source, in radians @param det_name: name of the gravitational-wave detector to simulate a response for; e.g. @c "H1" for LIGO Hanford, @c "L1" for LIGO Livingston, @c "V1" for Virgo @param earth_ephem_file: name of file to load Earth ephemeris from @param sun_ephem_file: name of file to load Sun ephemeris from @param tref_at_det: default False; if True, shift reference time @b tref so that @b dt = 0 is @b tref in @e detector frame instead of Solar System barycentre frame, useful if e.g. one wants to turn on signal only for @b dt > 0, one can use @b tref as the turn-on time @param extra_comment: additional text to add to comment string in frame/SFT headers (not filenames), e.g. for wrapper script commandlines """ self.__origin_str = "Generated by %s, %s-%s (%s)" % (__file__, git_version.id, git_version.status, git_version.date) if extra_comment: self.__origin_str += ", "+extra_comment # store arguments self.__tstart = tstart self.__Tdata = Tdata # parse detector name try: _, self.__site_index = lalpulsar.FindCWDetector(det_name, True) assert(self.__site_index >= 0) except: raise ValueError("Invalid detector name det_name='%s'" % det_name) self.__site = lal.CachedDetectors[self.__site_index] # load Earth and Sun ephemerides self.__ephemerides = lalpulsar.InitBarycenter(earth_ephem_file, sun_ephem_file) if tref_at_det: # calculate barycentric delay at reference time bary_state = lalpulsar.EarthState() bary_input = lalpulsar.BarycenterInput() bary_emit = lalpulsar.EmissionTime() bary_input.tgps = tref bary_input.site = self.__site for i in range(0, 3): bary_input.site.location[i] /= lal.C_SI bary_input.alpha = alpha bary_input.delta = delta bary_input.dInv = 0.0 lalpulsar.BarycenterEarth(bary_state, bary_input.tgps, self.__ephemerides) lalpulsar.Barycenter(bary_emit, bary_input, bary_state) # adjust reference time so that dt = 0 is tref in detector frame tref += bary_emit.deltaT # start signal time series 'Tpad_wf' before/after output strain time series # add sufficient padding to signal for maximum Doppler modulation time shifts, otherwise # lalpulsar.PulsarSimulateCoherentGW() will output zeros without complaint (unless # you run with LAL_DEBUG_LEVEL=warning) Tpad_wf = 2.0 * lal.AU_SI / lal.C_SI tstart_wf = tstart - Tpad_wf Nwf = int(math.ceil(float(Tdata + 2*Tpad_wf) / float(dt_wf))) # create REAL8TimeSeries to store signal phase self.__phi = lal.CreateREAL8TimeSeries("phi", tstart_wf, 0, dt_wf, lal.DimensionlessUnit, Nwf) # create REAL4TimeVectorSeries to store signal amplitudes # - LAL provides no creator function for this type, so must be done manually self.__a = lal.REAL4TimeVectorSeries() self.__a.name = "a+,ax" self.__a.epoch = tstart_wf self.__a.deltaT = dt_wf self.__a.f0 = 0 self.__a.sampleUnits = lal.StrainUnit self.__a.data = lal.CreateREAL4VectorSequence(Nwf, 2) # call waveform() to fill time series of signal phase and amplitudes dt = float(tstart_wf - tref) for i in range(0, Nwf): dphi, aplus, across = waveform(dt) self.__phi.data.data[i] = phi0 + dphi self.__a.data.data[i][0] = aplus self.__a.data.data[i][1] = across dt += dt_wf # create and initialise PulsarCoherentGW struct self.__wf = lalpulsar.PulsarCoherentGW() self.__wf.position.system = lal.COORDINATESYSTEM_EQUATORIAL self.__wf.position.longitude = alpha self.__wf.position.latitude = delta self.__wf.psi = psi self.__wf.phi = self.__phi self.__wf.a = self.__a # create and initialise PulsarDetectorResponse struct self.__detector = lalpulsar.PulsarDetectorResponse() self.__detector.site = self.__site self.__detector.ephemerides = self.__ephemerides