Ejemplo n.º 1
0
    def compute_deficit(self, func=lambda (s,t): abs(1-(t/s)**2)**(1/2)):
        """
    Calculate the deficit of thise NoiseBudget as the normalised quadrature
    difference ratio the sum of the NoiseTerms and the target. Defaults to:

    deficit = $\sqrt{1 - \left(\frac{target}{sum of terms}\right)^2}

    Keyword arguments:

        func : callable
            any callable function that accepts noise sum and target arrays
        """
        if self.target is None:
            raise RuntimeError("NoiseBudget target has not been set. "+\
                               "Run NoiseBudget.set_target(mytarget).")
        if self.noise_sum is None:
            raise RuntimeError("NoiseBudget sum has not be computed. "+\
                               "Run NoiseBudget.compute_noise_sum().")
        deficit        = NoiseTerm('%d budget deficit' % self.name)
        deficit.epoch  = self.target.epoch
        deficit.deltaF = self.target.deltaF
        deficit.f0     = self.target.f0
        data           = func(self.noise_sum.spectrum, self.target.spectrum)
        deficit.frequencyseries = seriesutils.fromarray(data,\
                                                        name=deficit.name,\
                                                        epoch=deficit.epoch,\
                                                        deltaT=deficit.deltaF,\
                                                        f0=deficit.f0,\
                                                        frequencyseries=True)
        return deficit
Ejemplo n.º 2
0
    def loadreference(self, referencefile, epoch=seriesutils.lal.LIGOTimeGPS(),\
                      sampleUnits=seriesutils.lal.lalStrainUnit, fcol=0,acol=1):
        """
    Read the reference spectrum from a two-column file of frequency and ASD.

    Arguments:

        referencefile : str
            path to file with space-delimited columns of frequency and ASD

    Keyword arguments:

        epoch : lal.LIGOTimeGPS
            GPS epoch of this reference
        sampleUnits : lal.LALUnit
            amplitude unit for reference spectrum
        fcol : int
            number of column holding frequency array, default 0
        acol : int
            number of column holding amplitude array, default 1
        """
        f, data = numpy.loadtxt(referencefile, dtype=float, unpack=True,\
                                usecols=[fcol, acol])
        deltaF  = f[1]-f[0]
        f0      = f[0]
        self.ref_frequencyseries = seriesutils.fromarray(data, str(self.name),
                                                         epoch=epoch,\
                                                         deltaT=deltaF, f0=f0,\
                                                         frequencyseries=True)
        self.ref_spectrum = data
        self.ref_f0       = f0
        self.ref_deltaF   = deltaF
Ejemplo n.º 3
0
def fetch_raw_data(channel, start, end):
    from pylal import seriesutils
    from lal import LIGOTimeGPS

    cache = get_cache(IFO_TO_FRAMETYPE[channel.ifo])
    try:
        data = cache.fetch("{0.ifo}:{0.subsystem}_{0.name}".format(channel),
                           start, end)
        dt = data.metadata.dt
    except ValueError:
        print "WARNING: raw data missing for {0}-{1} on {2}"\
              .format(start, end, channel)
        data = np.zeros(NUM_SAMPLES, dtype=np.float64)
        dt = 1.0/SAMPLING_RATE

    return seriesutils.fromarray(data, 
                                 epoch=LIGOTimeGPS(start),
                                 deltaT=dt)
Ejemplo n.º 4
0
def create_h5_data(coinc, group):
   
    #defining important variables
    file_name = str(coinc["id"])+".cache"
    start_time = coinc['times'][0]-2
    end_time = coinc['times'][0]+2
    freq = coinc['freqs'][0]
    channels = group.channels

    #temporary file, will create better file naming system soon
    name=RAW_DIR+str(coinc["id"])+'.h5'
    try:
        os.remove(name)
    except OSError:
        pass
        
    #open h5 file
    with hdf5.write_h5(name) as h5:


        #for each channel, generate bandpassed data
        for channel in channels:
            print coinc
            channel_name=channel[1]+':'+channel[2]+'_'+channel[3]
            f=open(RAW_DIR+file_name)
            framedata = frutils.FrameCache(lal.Cache.fromfile(f),verbose=False).fetch(channel_name, start_time, end_time)
            f.close()
            data = np.array(framedata)
            deltaT=framedata.metadata.dt
            timeseries = seriesutils.fromarray(data, deltaT=framedata.metadata.dt)
            seriesutils.bandpass(timeseries,channel['weighted_freqs'][0],channel['weighted_freqs'][1])
            band_passed_data=timeseries.data.data
            times = np.arange(start_time, end_time, deltaT)

            #send bandpassed data to a dataset in the h5 file.
            table = h5.create_dataset(name=str(channel[0]),
                                     data=band_passed_data)
            table.attrs.start_time = start_time
            table.attrs.end_time = end_time
            table.attrs.sample_rate=int(1.0/deltaT)
Ejemplo n.º 5
0
 def compute_noise_sum(self, name="Noise sum"):
     """
 Calculate the quadrature sum of terms in the NoiseBudget. All terms whose
 sum attribute evaluates to True will be included.
     """    
     # get metadata from first sum term
     sum_terms = [t for t in self if t.sum]
     if len(sum_terms):
         t = sum_terms[0]
         epoch = t.epoch
         deltaF = t.deltaF
         f0    = t.f0
     else:
         raise RuntimeError("No NoiseTerms were set to be included in the "+\
                            "budget sum.")
     self.noise_sum = NoiseTerm(name=name)
     data = (numpy.asarray([t.spectrum for t in\
                           sum_terms])**2).sum(axis=0)**(1/2)
     self.noise_sum.frequencyseries =\
         seriesutils.fromarray(data, str(name), epoch=epoch,\
                               deltaT=deltaF, f0=f0, frequencyseries=True)
     self.noise_sum.fromarray