Ejemplo n.º 1
0
def sortSeis(gsac, opts):
    'Sort seismograms by file indices, quality factors, or a given header'
    sortby = opts.sortby
    # determine increase/decrease order
    if sortby[-1] == '-':
        sortincrease = False
        sortby = sortby[:-1]
    else:
        sortincrease = True
    opts.labelqual = False
    # sort
    if sortby == 'i':  # by file indices
        gsac.selist, gsac.delist = seleSeis(gsac.saclist)
    elif sortby.isdigit() or sortby in opts.qheaders + [
            'all',
    ]:  # by quality factors
        opts.labelqual = True
        if sortby == '1' or sortby == 'ccc':
            opts.qweights = [1, 0, 0]
        elif sortby == '2' or sortby == 'snr':
            opts.qweights = [0, 1, 0]
        elif sortby == '3' or sortby == 'coh':
            opts.qweights = [0, 0, 1]
        gsac.selist, gsac.delist = sortSeisQual(gsac.saclist, opts.qheaders,
                                                opts.qweights, opts.qfactors,
                                                sortincrease)
    else:  # by a given header
        gsac.selist, gsac.delist = sortSeisHeader(gsac.saclist, sortby,
                                                  sortincrease)
    return
Ejemplo n.º 2
0
def sortSeis(gsac, opts):
	'Sort seismograms by file indices, quality factors, time difference, or a given header.'
	sortby = opts.sortby
	# determine increase/decrease order
	if sortby[-1] == '-':
		sortincrease = False
		sortby = sortby[:-1]
	else:
		sortincrease = True
	opts.labelqual = True 
	# sort 
	if sortby == 'i':   # by file indices
		gsac.selist, gsac.delist = seleSeis(gsac.saclist)
	elif sortby == 't':	# by time difference
		ipick = opts.qcpara.ichdrs[0]
		wpick = 't'+str(opts.reltime)
		if ipick == wpick:
			print ('Same time pick: {0:s} and {1:s}. Exit'.format(ipick, wpick))
			sys.exit()
		gsac.selist, gsac.delist = sortSeisHeaderDiff(gsac.saclist, ipick, wpick, sortincrease)
	elif sortby.isdigit() or sortby in opts.qheaders + ['all',]: # by quality factors
		if sortby == '1' or sortby == 'ccc':
			opts.qweights = [1, 0, 0]
		elif sortby == '2' or sortby == 'snr':
			opts.qweights = [0, 1, 0]
		elif sortby == '3' or sortby == 'coh':
			opts.qweights = [0, 0, 1]
		gsac.selist, gsac.delist = sortSeisQual(gsac.saclist, opts.qheaders, opts.qweights, opts.qfactors, sortincrease)
	else: # by a given header
		gsac.selist, gsac.delist = sortSeisHeader(gsac.saclist, sortby, sortincrease)
	return
Ejemplo n.º 3
0
def sortSeis(gsac, opts):
	'Sort seismograms by file indices, quality factors, or a given header'
	sortby = opts.sortby
	# determine increase/decrease order
	if sortby[-1] == '-':
		sortincrease = False
		sortby = sortby[:-1]
	else:
		sortincrease = True
	opts.labelqual = False
	# sort 
	if sortby == 'i':  # by file indices
		gsac.selist, gsac.delist = seleSeis(gsac.saclist)
	elif sortby.isdigit() or sortby in opts.qheaders + ['all',]: # by quality factors
		opts.labelqual = True
		if sortby == '1' or sortby == 'ccc':
			opts.qweights = [1, 0, 0]
		elif sortby == '2' or sortby == 'snr':
			opts.qweights = [0, 1, 0]
		elif sortby == '3' or sortby == 'coh':
			opts.qweights = [0, 0, 1]
		gsac.selist, gsac.delist = sortSeisQual(gsac.saclist, opts.qheaders, opts.qweights, opts.qfactors, sortincrease)
	else:  # by a given header
		gsac.selist, gsac.delist = sortSeisHeader(gsac.saclist, sortby, sortincrease)
	return
Ejemplo n.º 4
0
    def sortSeis(self):
        sortincrease = True

        if self.opts.sortby == 'i':
            self.sacgroup.selist, self.sacgroup.delist = seleSeis(
                self.sacgroup.saclist)
        elif self.opts.sortby == 't':
            ipick = self.opts.qcpara.ichdrs[0]
            wpick = 't' + str(self.opts.reltime)
            if ipick == wpick:
                print('Same time pick: {0:s} and {1:s}. Exit'.format(
                    ipick, wpick))
                sys.exit()
            self.sacgroup.selist, self.sacgroup.delist = sortSeisHeaderDiff(
                self.sacgroup.saclist, ipick, wpick, sortincrease)
        elif self.opts.sortby.isdigit(
        ) or self.opts.sortby in self.opts.qheaders + [
                'all',
        ]:
            if self.opts.sortby == '1' or self.opts.sortby == 'ccc':
                self.opts.qweights = [1, 0, 0]
            elif self.opts.sortby == '2' or self.opts.sortby == 'snr':
                self.opts.qweights = [0, 1, 0]
            elif self.opts.sortby == '3' or self.opts.sortby == 'coh':
                self.opts.qweights = [0, 0, 1]
            self.sacgroup.selist, self.sacgroup.delist = sortSeisQual(
                self.sacgroup.saclist, self.opts.qheaders, self.opts.qweights,
                self.opts.qfactors, sortincrease)
        else:
            self.sacgroup.selist, self.sacgroup.delist = sortSeisHeader(
                self.sacgroup.saclist, self.opts.sortby, sortincrease)
Ejemplo n.º 5
0
def sortSeis(gsac, opts):
    "Sort seismograms by file indices, quality factors, time difference, or a given header."
    sortby = opts.sortby
    # determine increase/decrease order
    if sortby[-1] == "-":
        sortincrease = False
        sortby = sortby[:-1]
    else:
        sortincrease = True
    opts.labelqual = True
    # sort
    if sortby == "i":  # by file indices
        gsac.selist, gsac.delist = seleSeis(gsac.saclist)
    elif sortby == "t":  # by time difference
        ipick = opts.qcpara.ichdrs[0]
        wpick = "t" + str(opts.reltime)
        if ipick == wpick:
            print ("Same time pick: {0:s} and {1:s}. Exit".format(ipick, wpick))
            sys.exit()
        gsac.selist, gsac.delist = sortSeisHeaderDiff(gsac.saclist, ipick, wpick, sortincrease)
    elif sortby.isdigit() or sortby in opts.qheaders + ["all"]:  # by quality factors
        if sortby == "1" or sortby == "ccc":
            opts.qweights = [1, 0, 0]
        elif sortby == "2" or sortby == "snr":
            opts.qweights = [0, 1, 0]
        elif sortby == "3" or sortby == "coh":
            opts.qweights = [0, 0, 1]
        gsac.selist, gsac.delist = sortSeisQual(gsac.saclist, opts.qheaders, opts.qweights, opts.qfactors, sortincrease)
    else:  # by a given header
        gsac.selist, gsac.delist = sortSeisHeader(gsac.saclist, sortby, sortincrease)
    return
Ejemplo n.º 6
0
def autoiccs(gsac, opts):
    """ Run ICCS and delete low quality seismograms automatically.
	"""
    saclist = gsac.saclist
    hdrsel = opts.ccpara.hdrsel
    minqual = opts.minqual
    minnsel = opts.minnsel
    minccc, minsnr, mincoh = minqual

    selist, delist = seleSeis(saclist)
    print (
        "\n*** Run ICCS until all low quality seismograms removed: Min_ccc={0:.2f} Min_snr={1:.1f} Min_coh={2:.2f} *** ".format(
            minccc, minsnr, mincoh
        )
    )
    rerun = True
    while rerun and len(selist) >= minnsel:
        stkdh, stkdata, quas = ccWeightStack(selist, opts)
        tquas = transpose(quas)
        indsel, inddel = [], []
        for i in range(len(selist)):
            sacdh = selist[i]
            ccc, snr, coh = tquas[i]
            if ccc < minccc or snr < minsnr or coh < mincoh:
                inddel.append(i)
                sacdh.sethdr(hdrsel, "False   ")
                sacdh.selected = False
                print (
                    "--> Seismogram: {0:s} quality factors {1:.2f} {2:.2f} {3:.2f} < min. Deleted. ".format(
                        sacdh.filename, ccc, snr, coh
                    )
                )
            else:
                indsel.append(i)
        if len(inddel) > 0:
            selist = [selist[i] for i in indsel]
        else:
            rerun = False
            gsac.stkdh = stkdh
    gsac.selist = selist
    nsel = len(selist)
    print ("\nDone selecting seismograms: {0:d} out of {1:d} selected.".format(nsel, len(saclist)))

    save = raw_input("Save to file? [y/n] \n")
    if save[0].lower() == "y":
        if opts.filemode == "sac":
            for sacdh in saclist:
                sacdh.writeHdrs()
            gsac.stkdh.savesac()
        elif opts.filemode == "pkl":
            print (" Saving gsac to pickle file...")
            writePickle(gsac, opts.pklfile, opts.zipmode)
            if opts.zipmode is not None:
                pklfile = opts.pklfile + "." + opts.zipmode
            else:
                pklfile = opts.pklfile
            if nsel < minnsel:
                os.rename(pklfile, "deleted." + pklfile)
                print ("  Less than {:d} seismograms selected. Remove pkl.".format(minnsel))
Ejemplo n.º 7
0
def autoiccs(gsac, opts):
    """ Run ICCS and delete low quality seismograms automatically.
	"""
    saclist = gsac.saclist
    hdrsel = opts.ccpara.hdrsel
    minqual = opts.minqual
    minnsel = opts.minnsel
    minccc, minsnr, mincoh = minqual

    selist, delist = seleSeis(saclist)
    print(
        '\n*** Run ICCS until all low quality seismograms removed: Min_ccc={0:.2f} Min_snr={1:.1f} Min_coh={2:.2f} *** '
        .format(minccc, minsnr, mincoh))
    rerun = True
    while rerun and len(selist) >= minnsel:
        stkdh, stkdata, quas = ccWeightStack(selist, opts)
        tquas = transpose(quas)
        indsel, inddel = [], []
        for i in list(range(len(selist))):
            sacdh = selist[i]
            ccc, snr, coh = tquas[i]
            if ccc < minccc or snr < minsnr or coh < mincoh:
                inddel.append(i)
                sacdh.sethdr(hdrsel, 'False   ')
                sacdh.selected = False
                print(
                    '--> Seismogram: {0:s} quality factors {1:.2f} {2:.2f} {3:.2f} < min. Deleted. '
                    .format(sacdh.filename, ccc, snr, coh))
            else:
                indsel.append(i)
        if len(inddel) > 0:
            selist = [selist[i] for i in indsel]
        else:
            rerun = False
            gsac.stkdh = stkdh
    gsac.selist = selist
    nsel = len(selist)
    print('\nDone selecting seismograms: {0:d} out of {1:d} selected.'.format(
        nsel, len(saclist)))

    #	save = raw_input('Save to file? [y/n] \n')
    save = input('Save to file? [y/n] \n')
    if save[0].lower() == 'y':
        if opts.filemode == 'sac':
            for sacdh in saclist:
                sacdh.writeHdrs()
            gsac.stkdh.savesac()
        elif opts.filemode == 'pkl':
            print(' Saving gsac to pickle file...')
            writePickle(gsac, opts.pklfile, opts.zipmode)
            if opts.zipmode is not None:
                pklfile = opts.pklfile + '.' + opts.zipmode
            else:
                pklfile = opts.pklfile
            if nsel < minnsel:
                os.rename(pklfile, 'deleted.' + pklfile)
                print('  Less than {:d} seismograms selected. Remove pkl.'.
                      format(minnsel))
Ejemplo n.º 8
0
	def sortSeis(self):
		sortincrease = True

		if self.opts.sortby == 'i':
			self.sacgroup.selist, self.sacgroup.delist = seleSeis(self.sacgroup.saclist)
		elif self.opts.sortby == 't':
			ipick = self.opts.qcpara.ichdrs[0]
			wpick = 't' + str(self.opts.reltime)
			if ipick == wpick:
				print ('Same time pick: {0:s} and {1:s}. Exit'.format(ipick, wpick))
				sys.exit()
			self.sacgroup.selist, self.sacgroup.delist = sortSeisHeaderDiff(self.sacgroup.saclist, ipick, wpick, sortincrease)
		elif self.opts.sortby.isdigit() or self.opts.sortby in self.opts.qheaders + ['all',]:
			if self.opts.sortby == '1' or self.opts.sortby == 'ccc':
				self.opts.qweights = [1, 0, 0]
			elif self.opts.sortby == '2' or self.opts.sortby == 'snr':
				self.opts.qweights = [0, 1, 0]
			elif self.opts.sortby == '3' or self.opts.sortby == 'coh':
				self.opts.qweights = [0, 0, 1]
			self.sacgroup.selist, self.sacgroup.delist = sortSeisQual(self.sacgroup.saclist, self.opts.qheaders, self.opts.qweights, self.opts.qfactors, sortincrease)
		else:
			self.sacgroup.selist, self.sacgroup.delist = sortSeisHeader(self.sacgroup.saclist, self.opts.sortby, sortincrease)
Ejemplo n.º 9
0
def main():
    opts, ifiles = getOptions()
    mcpara = MCConfig()
    gsac = loadData(ifiles, opts, mcpara)

    if opts.phase is None:
        phase = findPhase(ifiles[0])
        print('Found phase to be: ' + phase + '\n')
        mcpara.phase = phase

    opts.fstack = mcpara.fstack
    if opts.filemode == 'sac' and os.path.isfile(opts.fstack):
        print('Read array stack file: ' + opts.fstack)
        gsac.stkdh = SacDataHdrs(opts.fstack, opts.delta)

    getParams(gsac, mcpara, opts)
    if opts.allseis_on:
        solution = mccc(gsac, mcpara)
        gsac.selist, gsac.delist = gsac.saclist, []
    else:
        initQual(gsac.saclist, mcpara.hdrsel, [])
        gsac.selist, gsac.delist = seleSeis(gsac.saclist)
        solution = mccc(gsac, mcpara)
    saveData(gsac, opts)
Ejemplo n.º 10
0
def main():
	opts, ifiles = getOptions()
	mcpara = MCConfig()
	gsac = loadData(ifiles, opts, mcpara)

	if opts.phase is None:
		phase = findPhase(ifiles[0])
		print ('Found phase to be: ' + phase + '\n')
		mcpara.phase = phase

	opts.fstack = mcpara.fstack
	if opts.filemode == 'sac' and os.path.isfile(opts.fstack):
		print ('Read array stack file: ' + opts.fstack )
		gsac.stkdh = SacDataHdrs(opts.fstack, opts.delta)

	getParams(gsac, mcpara, opts)
	if opts.allseis_on:
		solution = mccc(gsac, mcpara)
		gsac.selist, gsac.delist = gsac.saclist, []
	else:
		initQual(gsac.saclist, mcpara.hdrsel, [])
		gsac.selist, gsac.delist = seleSeis(gsac.saclist)
		solution = mccc(gsac, mcpara)
	saveData(gsac, opts)