Beispiel #1
0
class array2SeqView(object):
    def __init__(self, start, sampling, N):

        try:
            self.start = float(start)
        except ValueError:
            logging.info("starting time not defined")
        try:
            self.sampling = float(sampling)
        except ValueError:
            logging.info("sampling not defined")
        try:
            self.N = N
        except ValueError:
            logging.info("lenght not defined")
        self.SV = SV(self.start, 1.0 / self.sampling, self.N)

    def Fill(self, start, array):

        self.SV.SetStart(start)
        for i in range(self.N):
            self.SV.FillPoint(0, i, float(array[i]))
        return self.SV

    def SetStart(self, N):
        self.SV.SetStart(float(self.N) / self.sampling)

    def GetStart(self):
        return self.SV.GetStart()
Beispiel #2
0
    def segmentProcess(self,
                       segment,
                       wavThresh=WaveletThreshold.dohonojohnston):
        gpsStart = segment[0]
        gpsEnd = segment[1]
        logging.info(
            "Analyzing segment: %s-%s for channel %s downslampled at %dHz" %
            (gpsStart, gpsEnd, self.par.channel, self.par.resampling))
        start_time = time.time()
        ID = str(self.par.run) + '_' + str(self.par.channel) + '_' + str(
            int(gpsStart))
        dir_chunk = self.par.outdir + ID + '/'
        self.par.LSLfile = dir_chunk + "LSLcoeff-AR%s-fs%s-%s.txt" % (
            self.par.ARorder, self.par.resampling, self.par.channel)
        # create the output dir
        if not os.path.exists(dir_chunk):
            os.makedirs(dir_chunk)
        if not os.path.isfile(dir_chunk + 'ProcessEnded.check'):
            if os.path.isfile(self.par.LSLfile):
                logging.info('Load LSL parameter')
                LSL = LSLLearning(self.par.ARorder, self.par.sigma,
                                  self.Elambda)
                LSL.Load(self.par.LSLfile)
            else:
                logging.info('Start LSL parameter estimation')
                streamL = FrameIChannel(self.par.file, self.par.channel,
                                        self.learn, gpsStart)
                data = SV()
                data_ds = SV()
                self.par.Noutdata = int(5 * self.par.len * self.par.resampling)
                dsL = downsamplig(self.par)
                self.par.sigma = 0.0
                while self.par.sigma == 0.0:
                    streamL.GetData(data)
                    dsL.Process(data, data_ds)
                    # estimate rough sigma
                    y = np.empty(self.par.Noutdata)
                    for j in range(self.par.Noutdata):
                        y[j] = data_ds.GetY(0, j)
                    self.par.sigma = np.std(y) * np.std(
                        y) * self.par.resampling

                logging.info('Rough Estimated sigma= %s' % self.par.sigma)
                LSL = LSLLearning(self.par.ARorder, self.par.sigma,
                                  self.Elambda)
                dataw = SV()
                ######################
                streamL.GetData(data)
                dsL.Process(data, data_ds)
                LSL(data_ds, dataw)
                LSL.Save(self.par.LSLfile)
                del data, data_ds, dataw, dsL, streamL
            self.par.sigma = np.sqrt(LSL.GetSigma())
            # sigma for the noise
            logging.info('LSL Estimated sigma= %s' % self.par.sigma)

            ## update the self.parameters to be saved in local json file
            self.par.ID = ID
            self.par.dir = dir_chunk
            self.par.gps = gpsStart
            self.par.gpsStart = gpsStart
            self.par.gpsEnd = gpsEnd

            ######################
            # self.parameter for sequence of data and the resampling
            self.par.Noutdata = int(self.par.len * self.par.resampling)
            ds = downsamplig(self.par)
            # gpsstart = gpsStart - self.par.preWhite * self.par.len
            streaming = FrameIChannel(self.par.file, self.par.channel,
                                      self.par.len, gpsStart)
            data = SV()
            data_ds = SV()
            dataw = SV()
            lsl = LSLfilter(LSL, self.Alambda, self.par.Noutdata, False)
            ###---preheating---###
            # reading data, downsampling and whitening
            streaming.GetData(data)
            ds.Process(data, data_ds)
            for i in range(self.par.preWhite):
                streaming.GetData(data)
                ds.Process(data, data_ds)
                lsl(data_ds, dataw)

            ### WDF process
            WDF = wdf(self.par, wavThresh)
            # WDF=wdf(self.par)
            ## register obesevers to WDF process
            # put 0 to save only metaself.parameters, 1 for wavelet coefficients and 2 for waveform estimation
            savetrigger = SingleEventPrintTriggers(self.par, self.fullPrint)
            parameterestimation = ParameterEstimation(self.par)
            parameterestimation.register(savetrigger)
            WDF.register(parameterestimation)
            filejson = 'parametersUsed.json'
            self.par.dump(self.par.dir + filejson)
            ###Start detection loop
            logging.info("Starting detection loop")
            while data.GetStart() < gpsEnd:
                streaming.GetData(data)
                ds.Process(data, data_ds)
                lsl(data_ds, dataw)
                WDF.SetData(dataw)
                WDF.Process()

            elapsed_time = time.time() - start_time
            timeslice = gpsEnd - gpsStart
            logging.info('analyzed %s seconds in %s seconds' %
                         (timeslice, elapsed_time))
            fileEnd = self.par.dir + "ProcessEnded.check"
            open(fileEnd, 'a').close()
        else:
            logging.info('Segment already processed')
Beispiel #3
0
    def segmentProcess(self,
                       segment,
                       wavThresh=WaveletThreshold.dohonojohnston):
        gpsStart = segment[0]
        gpsEnd = segment[1]
        logging.info(
            "Analyzing segment: %s-%s for channel %s downslampled at %dHz" %
            (gpsStart, gpsEnd, self.par.channel, self.par.resampling))
        start_time = time.time()
        ID = str(self.par.run) + '_' + str(self.par.channel) + '_' + str(
            int(gpsStart))
        dir_chunk = self.par.outdir + ID + '/'
        # create the output dir
        if not os.path.exists(dir_chunk):
            os.makedirs(dir_chunk)
        if not os.path.isfile(dir_chunk + 'ProcessEnded.check'):
            # self.parameter for whitening and its estimation self.parameters
            whiten = Whitening(self.par.ARorder)
            self.par.ARfile = dir_chunk + "ARcoeff-AR%s-fs%s-%s.txt" % (
                self.par.ARorder, self.par.resampling, self.par.channel)
            self.par.LVfile = dir_chunk + "LVcoeff-AR%s-fs%s-%s.txt" % (
                self.par.ARorder, self.par.resampling, self.par.channel)

            if os.path.isfile(self.par.ARfile) and os.path.isfile(
                    self.par.LVfile):
                logging.info('Load AR parameters')
                whiten.ParametersLoad(self.par.ARfile, self.par.LVfile)
            else:
                logging.info('Start AR parameter estimation')
                ######## read data for AR estimation###############
                # self.parameter for sequence of data.
                # Add a 100.0 seconds delay to not include too much after lock noise in the estimation
                if (gpsEnd - gpsStart >= self.learnlen + 100.0):
                    gpsE = gpsStart + 100.0
                else:
                    gpsE = gpsEnd - self.learnlen
                strLearn = FrameIChannel(self.par.file, self.par.channel,
                                         self.learnlen, gpsE)
                Learn = SV()
                Learn_DS = SV()
                self.par.Noutdata = int(self.par.learn * self.par.resampling)
                ds = downsamplig(self.par)
                strLearn.GetData(Learn)
                ds.Process(Learn, Learn_DS)
                whiten.ParametersEstimate(Learn_DS)
                whiten.ParametersSave(self.par.ARfile, self.par.LVfile)
                del Learn, ds, strLearn, Learn_DS
            # sigma for the noise
            self.par.sigma = whiten.GetSigma()
            logging.info('Estimated sigma= %s' % self.par.sigma)
            ## update the self.parameters to be saved in local json file
            self.par.ID = ID
            self.par.dir = dir_chunk
            self.par.gps = gpsStart
            self.par.gpsStart = gpsStart
            self.par.gpsEnd = gpsEnd

            ######################
            # self.parameter for sequence of data and the resampling
            self.par.Noutdata = int(self.par.len * self.par.resampling)
            ds = downsamplig(self.par)
            # gpsstart = gpsStart - self.par.preWhite * self.par.len
            streaming = FrameIChannel(self.par.file, self.par.channel,
                                      self.par.len, gpsStart)
            data = SV()
            data_ds = SV()
            dataw = SV()
            ###---preheating---###
            # reading data, downsampling and whitening
            for i in range(self.par.preWhite):
                streaming.GetData(data)
                ds.Process(data, data_ds)
                whiten.Process(data_ds, dataw)
            ### WDF process
            WDF = wdf(self.par, wavThresh)
            # WDF=wdf(self.par)
            ## register obesevers to WDF process
            # put 0 to save only metaself.parameters, 1 for wavelet coefficients and 2 for waveform estimation
            savetrigger = SingleEventPrintTriggers(self.par, self.fullPrint)
            parameterestimation = ParameterEstimation(self.par)
            parameterestimation.register(savetrigger)
            WDF.register(parameterestimation)
            filejson = 'parametersUsed.json'
            self.par.dump(self.par.dir + filejson)
            ###Start detection loop
            logging.info("Starting detection loop")
            while data.GetStart() < gpsEnd:
                streaming.GetData(data)
                ds.Process(data, data_ds)
                whiten.Process(data_ds, dataw)
                WDF.SetData(dataw)
                WDF.Process()

            elapsed_time = time.time() - start_time
            timeslice = gpsEnd - gpsStart
            logging.info('analyzed %s seconds in %s seconds' %
                         (timeslice, elapsed_time))
            fileEnd = self.par.dir + "ProcessEnded.check"
            open(fileEnd, 'a').close()
        else:
            logging.info('Segment already processed')
Beispiel #4
0
def main():
    logging.basicConfig(level=logging.INFO)
    logging.info("read Parameters")
    par = Parameters()
    par.load("fileParameters.json")
    # logging.info(par.__dict__)
    # Parameter for sequence of data
    gpsE = float(par.gpsStart) + 10.0
    Learn = SV()
    Learn_DS = SV()
    # logging.info(par.sampling, par.resampling)

    # parameter for whitening and its estimation parameters
    whiten = Whitening(par.ARorder)
    ###Name of the files where the whitening parameters are saved
    LVfile = "./ARparameters/LVstate_%s_%s_%s.txt" % (par.ARorder, par.channel,
                                                      int(par.gps))
    ARfile = "./ARparameters/ARstate_%s_%s_%s.txt" % (par.ARorder, par.channel,
                                                      int(par.gps))
    if par.estimation == "True":
        logging.info('Start AR parameter estimation')
        ######## read data for AR estimation###############
        learnlen = 2.0 * float(par.learn)
        strLearn = FrameIChannel(par.file, par.channel, learnlen, gpsE)
        par.Noutdata = int(par.learn * par.resampling)
        ds = downsamplig(par)
        strLearn.GetData(Learn)
        ds.Process(Learn, Learn_DS)
        whiten.ParametersEstimate(Learn_DS)
        whiten.ParametersSave(ARfile, LVfile)
    else:
        logging.info('Load AR parameter')
        whiten.ParametersLoad(ARfile, LVfile)

    ######################
    # Parameter for sequence of data
    # read data
    par.Noutdata = int(par.len * par.resampling)
    ds = downsamplig(par)
    gpsstart = par.gpsStart - par.len
    streaming = FrameIChannel(par.file, par.channel, par.lenStart, gpsstart)
    data = SV()
    data_ds = SV()
    dataw = SV()
    ###---preheating---###
    streaming.GetData(data)
    ds.Process(data, data_ds)
    whiten.Process(data_ds, dataw)
    ### WDF process
    # sigma for the noise
    par.sigma = whiten.GetSigma()
    logging.info('Estimated sigma= %s' % par.sigma)
    par.Ncoeff = par.window

    ###Start detection loop
    logging.info("Starting detection loop")

    streaming.SetDataLength(par.len)
    startT = data.GetStart()
    ## gpsEnd=par.gpsEnd +par.lenStart
    clf = joblib.load('./pipelines/pca-gmm.pkl')
    WDF = wdf(par)

    observable = Observable()
    observableO = Observable()
    clustering = Clustering(par)
    savetrigger = PrintTriggers(par)
    classifier = Classifier(par, clf)
    observable.register(clustering)
    observableO.register(savetrigger)
    observableO.register(classifier)
    while data.GetStart() < par.gpsEnd:
        streaming.GetData(data)
        ds.Process(data, data_ds)
        whiten.Process(data_ds, dataw)
        WDF.SetData(dataw)
        while WDF.wdf2classify.GetDataNeeded() > 0:
            ev = WDF.FindEvents()
            observable.update_observers(ev)
            cev = clustering.CEV
            observableO.update_observers(cev)
    logging.info(classifier.classified)
    logging.info('Program terminated')
    par.dump("fileParametersUsed.json")
Beispiel #5
0
def main(param):
    start_time = time.time()
    logging.basicConfig(level=logging.INFO)
    logging.info("read Parameters")
    par = Parameters()
    par.load(param)
    ID = str(par.channel) + '_' + str(par.gps)
    par.outdir = par.outdir + ID + '/'
    if not os.path.exists(par.outdir):
        os.makedirs(par.outdir)
    par.ID = ID

    # parameter for whitening and its estimation parameters
    whiten = Whitening(par.ARorder)
    par.ARfile = par.outdir + "ARfile.txt"
    par.LVfile = par.outdir + "LVfile.txt"

    if os.path.isfile(par.ARfile) and os.path.isfile(par.LVfile):
        logging.info('Load AR parameter')
        whiten.ParametersLoad(par.ARfile, par.LVfile)
    else:
        logging.info('Start AR parameter estimation')
        ######## read data for AR estimation###############
        # Parameter for sequence of data
        gpsE = float(par.gps) + 10.0
        Learn = SV()
        Learn_DS = SV()
        learnlen = 2.0 * float(par.learn)
        strLearn = FrameIChannel(par.file, par.channel, 1.0, gpsE)
        strLearn.GetData(Learn)

        par.sampling = int(1.0 / Learn.GetSampling())
        par.resampling = int(sampling / 2)

        strLearn = FrameIChannel(par.file, par.channel, learnlen, gpsE)
        par.Noutdata = int(par.learn * par.resampling)
        ds = downsamplig(par)
        strLearn.GetData(Learn)
        ds.Process(Learn, Learn_DS)
        whiten.ParametersEstimate(Learn_DS)
        whiten.ParametersSave(par.ARfile, par.LVfile)

    ######################
    # Parameter for sequence of data
    # read data
    par.Noutdata = int(par.len * par.resampling)
    ds = downsamplig(par)
    gpsstart = par.gpsStart - par.len
    streaming = FrameIChannel(par.file, par.channel, par.lenStart, gpsstart)
    data = SV()
    data_ds = SV()
    dataw = SV()
    ###---preheating---###
    streaming.GetData(data)
    ds.Process(data, data_ds)
    whiten.Process(data_ds, dataw)
    ### WDF process
    # sigma for the noise
    par.sigma = whiten.GetSigma()
    logging.info('Estimated sigma= %s' % par.sigma)
    par.Ncoeff = par.window
    streaming.SetDataLength(par.len)

    WDF = wdf(par)
    clustering = Clustering(par)
    savetrigger = PrintTriggers(par)
    clustering.register(savetrigger)
    WDF.register(clustering)
    ###Start detection loop
    logging.info("Starting detection loop")
    while data.GetStart() < par.gpsEnd:
        streaming.GetData(data)
        ds.Process(data, data_ds)
        whiten.Process(data_ds, dataw)
        WDF.SetData(dataw)
        WDF.Process()
    logging.info('Program terminated')
    par.dump(par.outdir + "fileParametersUsed.json")
    elapsed_time = time.time() - start_time
    timeslice=par.gpsEnd-par.gpsStart
    logging.info('analyzed %s seconds in %s seconds' % (timeslice,elapsed_time))