コード例 #1
0
def open_verify_pf(pf,mttime=False):
    '''
    Verify that we can get the file and check
    the value of PF_MTTIME if needed.
    Returns pf_object
    '''

    logging.debug( 'Look for parameter file: %s' % pf )

    if mttime:
        logging.debug( 'Verify that %s is newer than %s' % (pf,mttime) )

        PF_STATUS = stock.pfrequire(pf, mttime)
        if PF_STATUS == stock.PF_MTIME_NOT_FOUND:
            logging.warning( 'Problems looking for %s. PF_MTTIME_NOT_FOUND.' % pf )
            logging.error( 'No MTTIME in PF file. Need a new version of the %s file!!!' % pf )
        elif PF_STATUS == stock.PF_MTIME_OLD:
            logging.warning( 'Problems looking for %s. PF_MTTIME_OLD.' % pf )
            logging.error( 'Need a new version of the %s file!!!' % pf )
        elif PF_STATUS == stock.PF_SYNTAX_ERROR:
            logging.warning( 'Problems looking for %s. PF_SYNTAX_ERROR.' % pf )
            logging.error( 'Need a working version of the %s file!!!' % pf )
        elif PF_STATUS == stock.PF_NOT_FOUND:
            logging.warning( 'Problems looking for %s. PF_NOT_FOUND.' % pf )
            logging.error( 'No file  %s found!!!' % pf )

        logging.debug( '%s => PF_MTIME_OK' % pf )

    try:
        return stock.pfread( pf )
    except Exception,e:
        logging.error( 'Problem looking for %s => %s' % ( pf, e ) )
コード例 #2
0
ファイル: functions.py プロジェクト: basaks/antelope_contrib
def open_verify_pf(pf, mttime=False):
    '''
    Verify that we can get the file and check
    the value of PF_MTTIME if needed.
    Returns pf_object
    '''

    logging.debug('Look for parameter file: %s' % pf)

    if mttime:
        logging.debug('Verify that %s is newer than %s' % (pf, mttime))

        PF_STATUS = stock.pfrequire(pf, mttime)
        if PF_STATUS == stock.PF_MTIME_NOT_FOUND:
            logging.warning('Problems looking for %s. PF_MTTIME_NOT_FOUND.' %
                            pf)
            logging.error(
                'No MTTIME in PF file. Need a new version of the %s file!!!' %
                pf)
        elif PF_STATUS == stock.PF_MTIME_OLD:
            logging.warning('Problems looking for %s. PF_MTTIME_OLD.' % pf)
            logging.error('Need a new version of the %s file!!!' % pf)
        elif PF_STATUS == stock.PF_SYNTAX_ERROR:
            logging.warning('Problems looking for %s. PF_SYNTAX_ERROR.' % pf)
            logging.error('Need a working version of the %s file!!!' % pf)
        elif PF_STATUS == stock.PF_NOT_FOUND:
            logging.warning('Problems looking for %s. PF_NOT_FOUND.' % pf)
            logging.error('No file  %s found!!!' % pf)

        logging.debug('%s => PF_MTIME_OK' % pf)

    try:
        return stock.pfread(pf)
    except Exception, e:
        logging.error('Problem looking for %s => %s' % (pf, e))
コード例 #3
0
def dynamic_loader(module):
    '''
    Load some libs defined on the pf file.
    '''
    logging.debug( "load dbmoment.%s" % module )
    try:
        return __import__("dbmoment.%s" % module, globals(), locals(), [module], -1)
    except Exception,e:
        logging.error("Import Error: [%s] => [%s]" % (module,e) )
コード例 #4
0
ファイル: functions.py プロジェクト: basaks/antelope_contrib
def dynamic_loader(module):
    '''
    Load some libs defined on the pf file.
    '''
    logging.debug("load dbmoment.%s" % module)
    try:
        return __import__("dbmoment.%s" % module, globals(), locals(),
                          [module], -1)
    except Exception, e:
        logging.error("Import Error: [%s] => [%s]" % (module, e))
コード例 #5
0
ファイル: functions.py プロジェクト: basaks/antelope_contrib
def cleanup(folder):
    """
    There are serveral files that we produce and keep
    in the tmp directory. Some are known but others are
    random names.
    """

    try:
        if not os.path.isdir(folder): os.makedirs(folder)
    except Exception, e:
        logging.error("Problems while creating folder [%s] %s" % (folder, e))
コード例 #6
0
def cleanup(folder):
    """
    There are serveral files that we produce and keep
    in the tmp directory. Some are known but others are
    random names.
    """

    try:
        if not os.path.isdir(folder): os.makedirs(folder)
    except Exception,e:
        logging.error("Problems while creating folder [%s] %s" % (folder,e))
コード例 #7
0
ファイル: functions.py プロジェクト: basaks/antelope_contrib
def get_model_pf(mfile, path=[], forced=None):
    '''
    EARTH VELOCITY MODEL FILE:

    Need to verify if we have the listed velocity model.
    The file has a PF format but is not placed on the
    regular folder with the rest of the parameter files
    from contrib. That requires a full search on several
    paths that we get from a parameter in the dbmoment.pf
    file.
    '''
    pf = False

    # Maybe we have an entry in command-line
    if forced:
        try:
            logging.info('Look for model: %s' % os.path.abspath(forced))
            pf = stock.pfin(os.path.abspath(forced))
        except:
            # Maybe we should look for it on the model_path array
            mfile = forced

    # If not on command-line then get value from parameter file
    if not pf:
        for d in path:
            try:
                logging.info('Look for model: %s' % os.path.join(d, mfile))
                pf = stock.pfin(os.path.join(d, mfile))
            except:
                pass
            else:
                break  # Stop if we find one

    if not pf:
        logging.error('Missing [%s] in [%s]' % (mfile, ', '.join(path)))

    return pf
コード例 #8
0
def get_model_pf( mfile, path=[], forced=None):
    '''
    EARTH VELOCITY MODEL FILE:

    Need to verify if we have the listed velocity model.
    The file has a PF format but is not placed on the
    regular folder with the rest of the parameter files
    from contrib. That requires a full search on several
    paths that we get from a parameter in the dbmoment.pf
    file.
    '''
    pf = False

    # Maybe we have an entry in command-line
    if forced:
        try:
            logging.info('Look for model: %s' % os.path.abspath(forced) )
            pf = stock.pfin(os.path.abspath(forced))
        except:
            # Maybe we should look for it on the model_path array
            mfile = forced

    # If not on command-line then get value from parameter file
    if not pf:
        for d in path:
            try:
                logging.info('Look for model: %s' % os.path.join(d, mfile) )
                pf = stock.pfin(os.path.join(d, mfile) )
            except:
                pass
            else:
                break # Stop if we find one

    if not pf:
        logging.error('Missing [%s] in [%s]' % ( mfile, ', '.join(path) ) )

    return pf
コード例 #9
0
ファイル: functions.py プロジェクト: basaks/antelope_contrib
def plot_results(id,
                 stations,
                 results,
                 event,
                 folder='./',
                 acknowledgement='dbmoment'):

    from __main__ import logging

    total = 1

    #N = len(stations.keys())
    total_stations = len(stations.keys()) + 2
    gcf = pyplot.gcf()
    #fig = pyplot.figure(figsize=( 20, (3*N) ))
    fig = pyplot.figure(figsize=(20, 3 * total_stations))

    max_all = []
    min_all = []
    points_all = []

    #for sta in sorted(stations.keys()):
    for sta in sorted(stations.keys(), key=lambda x: stations[x].realdistance):
        axs = stations[sta].max_min_all()
        points_all.append(axs[1])
        min_all.append(axs[2])
        max_all.append(axs[3])

    max_plot = max(max_all)
    min_plot = min(min_all)
    points_plot = max(points_all)

    # First panel
    text = "%s \n" % event.strtime
    text += "\n"
    text += "ID: %s   %s\n" % (id, results['estatus'])
    text += "\n"
    text += "Location: \n"
    text += "   Lat:    %s \n" % event.lat
    text += "   Lon:    %s \n" % event.lon
    text += "   Depth:  %s km\n" % event.depth
    text += "Filter:    %s \n" % event.filter
    text += "Model:     %s" % event.model
    ax = fig.add_subplot(total_stations, 3, total, frameon=False)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.patch.set_alpha(0.0)
    ax.annotate(text, (0, 1),
                xycoords="axes fraction",
                va="top",
                ha="left",
                fontsize=12,
                bbox=dict(edgecolor='none', boxstyle="round, pad=2", fc="w"))
    total += 1

    # Second panel
    text = "Mw:       %s \n" % results['Mw']
    text += "Strike:%s Rake:%s Dip:%s\n" % \
            ( results['Strike'], results['Rake'], results['Dip'] )
    text += "Pdc:      %0d %%\n" % (results['Pdc'] * 100)
    text += "Pclvd:    %0d %%\n" % (results['Pclvd'] * 100)
    text += "VAR:   %s \n" % results['Variance']
    text += "VarRed:     %s \n" % results['VarRed']
    text += "Var/Pdc:    %s \n" % results['Var/Pdc']
    text += "Mo:         %s \n" % results['Mo']
    text += "Mxx:%0.3f  Mxy:%0.3f  Mxz:%0.3f\n" % (float(
        results['Mxx']), float(results['Mxy']), float(results['Mxz']))
    text += "Myy:%0.3f  Myz:%0.3f  Mzz:%0.3f\n" % (float(
        results['Myy']), float(results['Myz']), float(results['Mzz']))
    ax = fig.add_subplot(total_stations, 3, total, frameon=False)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.patch.set_alpha(0.0)
    ax.annotate(text, (0, 1),
                xycoords="axes fraction",
                va="top",
                ha="left",
                fontsize=12,
                bbox=dict(edgecolor='none', boxstyle="round, pad=2", fc="w"))
    total += 1

    # Only run if library ObsPy is present on system.
    if beachball:
        # Third panel for beachball
        ax = fig.add_subplot(total_stations, 3, total, frameon=False)
        ax.xaxis.set_visible(False)
        ax.yaxis.set_visible(False)
        ax.patch.set_alpha(0.0)

        ax.annotate('ObsPy used for beachball image', (0.5, 0),
                    xycoords="axes fraction",
                    va="top",
                    ha="left",
                    fontsize=7,
                    bbox=dict(edgecolor='none',
                              boxstyle="round, pad=2",
                              fc="w"))

        # TEST FOR COMPARING 3 and 6 components methods
        #mt = [ float(results['Mxx']), float(results['Myy']), float(results['Mzz']),
        #    float(results['Mxy']), float(results['Mxz']), float(results['Myz']) ]
        #mt2 = [ results['Strike'][0], results['Dip'][0], results['Rake'][0], ]
        #bb = beachball(mt, mopad_basis='NED', xy=(-50, -50),width=80)
        #bb2 = beachball(mt2, xy=(50,50), width=80)
        #ax.add_collection( bb )
        #ax.add_collection( bb2 )

        mt = [
            float(results['Mxx']),
            float(results['Myy']),
            float(results['Mzz']),
            float(results['Mxy']),
            float(results['Mxz']),
            float(results['Myz'])
        ]
        bb = beachball(mt, mopad_basis='NED')
        ax.add_collection(bb)
        ax.set_xlim((-110, 110))
        ax.set_ylim((-110, 110))
        ax.set_aspect("equal")

    total += 1

    #for sta in sorted(stations.keys()):
    for sta in sorted(stations.keys(),
                      key=lambda x: float(stations[x].realdistance)):

        logging.debug('Plot traces for results on %s' % sta)
        if not stations[sta].real:
            logging.error('Empty Records for data on %s' % sta)
        if not stations[sta].synth_zrt:
            logging.error('Empty Records for converted ZRT on %s' % sta)

        distance = int(float(stations[sta].realdistance))
        azimuth = int(float(stations[sta].azimuth))
        #real = stations[sta].real
        convertedsynth = stations[sta].synth_zrt
        try:
            zcor = results['zcor'][sta]
        except:
            zcor = '-'
        variance = round(results['variance'][sta], 1)

        # Scale all traces the same way
        #axs = stations[sta].max_min_all()
        axs = (0, points_plot, min_plot, max_plot)

        #for chan, data in real:
        for chan in ['T', 'R', 'Z']:
            ax = fig.add_subplot(total_stations, 3, total)
            #real_line, = pyplot.plot(data, label='data' )
            real_line, = pyplot.plot(stations[sta].real.get(chan),
                                     label='data')
            synth_line, = pyplot.plot(stations[sta].synth_zrt.get(chan),
                                      linestyle='--',
                                      label='synth')

            pyplot.legend(loc=5, fontsize=8)

            pyplot.axis(axs)
            pyplot.ylabel('centimeters', fontsize=8)
            pyplot.yticks(size=8)

            ax.get_xaxis().set_ticks([])
            #ax.get_yaxis().set_ticks([])
            ax.yaxis.set_major_formatter(pyplot.FormatStrFormatter('%.1e'))

            # Top of plot
            pyplot.text(0.5,
                        0.9,
                        r'$\mathbf{%s}\ -\ \mathbf{%s}\ \ %s_{km}\ \ %s ^o$' %
                        (sta, chan, distance, azimuth),
                        horizontalalignment='center',
                        fontsize=13,
                        verticalalignment='center',
                        transform=ax.transAxes)

            # Bottom of plot
            text = "zcor:%s   variance_reduction:%s%%" % (zcor, variance)
            pyplot.text(0.5,
                        0.1,
                        text,
                        horizontalalignment='center',
                        fontsize=11,
                        verticalalignment='center',
                        transform=ax.transAxes)

            pyplot.draw()
            total += 1

    title = "%s Mw    " % results['Mw']
    title += "%s   " % event.strtime
    pyplot.suptitle(title, fontsize=18, ha='center')

    text = "%s \n" % event.strtime

    # Acknowledgement panel
    ax = fig.add_subplot(total_stations, 3, total, frameon=False)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.patch.set_alpha(0.0)
    ax.annotate(unicode(acknowledgement, "utf-8"), (0, 0),
                xycoords="axes fraction",
                va="bottom",
                ha="left",
                fontsize=8,
                bbox=dict(edgecolor='gray', boxstyle="round, pad=2", fc="w"))

    # Extra info panel
    total += 1
    text = "%s\n" % ' '.join(sys.argv)
    #text += "%s\n" % os.environ['ANTELOPE']
    text += "Generated at %s" % stock.strtime(stock.now())

    ax = fig.add_subplot(total_stations, 3, total, frameon=False)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.patch.set_alpha(0.0)
    ax.annotate(unicode(text, "utf-8"), (0, 0),
                xycoords="axes fraction",
                va="bottom",
                ha="left",
                fontsize=8,
                bbox=dict(edgecolor='gray', boxstyle="round, pad=2", fc="w"))

    try:
        if not os.path.isdir(folder): os.makedirs(folder)
    except Exception, e:
        logging.error("Problems while creating folder [%s] %s" % (folder, e))
コード例 #10
0
ファイル: functions.py プロジェクト: basaks/antelope_contrib
def readHelm(inputfile):
    """
    Routine to read Helmberger Format Seismograms
    Returning full object:
        traces[chan]['data'] = data
        return traces

    """
    logging.debug('readHelm: %s' % inputfile)
    results = {}

    fo = open(inputfile, "r")

    # Number of channels
    try:
        total_chans = int(fo.readline().strip())
        logging.debug("Total channels [%s]" % total_chans)
    except:
        logging.error("NOT VALID FILE [%s]" % inputfile)

    if total_chans == 1:
        channels = 'X'
    if total_chans == 3:
        # From dbmoment.xpy code. Also in data.py
        global seismic_channels
        channels = seismic_channels
    else:
        # From dbmoment.xpy code.
        global synth_channels
        channels = synth_channels

    # Data Format
    try:
        data_format = fo.readline().strip()
        logging.debug('file format: %s' % data_format)
        temp = re.match("\((\d+)e(\d+)\.(\d+)\)", data_format)
        perline = int(temp.group(1))
        spaces = int(temp.group(2))
        logging.debug('perline: %s  spaces: %s' % (perline, spaces))

    except:
        logging.error("NOT VALID FILE [%s]" % inputfile)

    for chan in range(total_chans):
        channame = channels[chan]
        logging.debug("chan %s" % channame)
        try:
            header1 = fo.readline().strip().split()
            header2 = fo.readline().strip().split()
            total_points = int(header2[0])
            samplerate = 1 / float(header2[1])
        except:
            logging.error("NOT VALID FILE [%s]" % inputfile)

        if not total_points or not samplerate:
            logging.error("NOT VALID FILE [%s]" % inputfile)

        cache = []
        logging.debug("Total points [%s]" % total_points)
        logging.debug("Sampelrate [%s]" % samplerate)

        while (total_points > 0):
            row = fo.readline().strip('\n')
            #logging.info('row: %s' % row)
            #logging.info('missing: %s' % total_points)
            if not row: logging.error('Problems readHelm(%s)' % inputfile)

            while (len(row) > 0):
                point = float(row[0:spaces])
                row = row[spaces:]
                #logging.info('%s' % point)
                cache.append(point)
                total_points -= 1

            #row = [float(row[i:i+spaces]) for i in range(0, perline)]
            #cache.extend( row )
            #total_points -= len( row )

        cache = array(cache)
        if total_chans == 1: return cache

        if not results:
            # need new object
            results = Records(samplerate)
            results.file = inputfile

        results.trace(channame, cache)

    return results
コード例 #11
0
ファイル: functions.py プロジェクト: basaks/antelope_contrib
    except Exception, e:
        logging.error("Problems while creating folder [%s] %s" % (folder, e))

    filelist = [
        'dbmoment*.Helm_data', 'temp_data*', 'tmp_data*', 'tmp*', 'mt_inv*',
        'run_fkrsort', 'run_filter', 'TEMP_MODEL', 'GREEN.1', 'junk', 'plot',
        'vec'
    ]

    for f in filelist:
        try:
            temp_file = "%s/%s" % (folder, f)
            logging.debug('unlink( %s )' % temp_file)
            map(os.unlink, glob.glob(temp_file))
        except Exception, e:
            logging.error('Cannot remove temp file %s [%s]' % (temp_file, e))


def new_Helm_header(samples, samplerate):
    temp = '     %0.4e     %0.4e      0  0  0.00\n' % (0, 0)
    temp += '%8d   %0.5f  %.4e\n' % (samples, 1 / samplerate, 0)
    return temp


def fix_format_data(point, decimals, total):
    new = "%0.*e" % (decimals, point)
    return new.rjust(total)


#def makeHelm(traces, index_min, index_max, append='', outputfile='', perline=7, total=14, decimal=5, folder='.dbmoment'):
def makeHelm(traces,
コード例 #12
0
def plot_results( id, stations, results, event, folder='./',
                       acknowledgement='dbmoment'):

    from __main__ import logging

    total = 1


    #N = len(stations.keys())
    total_stations = len(stations.keys()) + 2
    gcf = pyplot.gcf()
    #fig = pyplot.figure(figsize=( 20, (3*N) ))
    fig = pyplot.figure(figsize=( 20, 3 * total_stations ))

    max_all = []
    min_all = []
    points_all = []

    #for sta in sorted(stations.keys()):
    for sta in sorted(stations.keys(), key=lambda x: stations[x].realdistance):
        axs = stations[sta].max_min_all()
        points_all.append( axs[1] )
        min_all.append( axs[2] )
        max_all.append( axs[3] )

    max_plot = max(max_all)
    min_plot =  min(min_all)
    points_plot = max(points_all)



    # First panel
    text = "%s \n" % event.strtime
    text += "\n"
    text += "ID: %s   %s\n" % (id, results['estatus'] )
    text += "\n"
    text += "Location: \n"
    text += "   Lat:    %s \n" % event.lat
    text += "   Lon:    %s \n" % event.lon
    text += "   Depth:  %s km\n" % event.depth
    text += "Filter:    %s \n" % event.filter
    text += "Model:     %s" % event.model
    ax = fig.add_subplot(total_stations,3,total, frameon=False)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.patch.set_alpha(0.0)
    ax.annotate( text, (0, 1), xycoords="axes fraction", va="top", ha="left",
                 fontsize=12, bbox=dict(edgecolor='none',boxstyle="round, pad=2", fc="w"))
    total += 1

    # Second panel
    text = "Mw:       %s \n" % results['Mw']
    text += "Strike:%s Rake:%s Dip:%s\n" % \
            ( results['Strike'], results['Rake'], results['Dip'] )
    text += "Pdc:      %0d %%\n" % (results['Pdc'] * 100)
    text += "Pclvd:    %0d %%\n" % (results['Pclvd'] * 100)
    text += "VAR:   %s \n" % results['Variance']
    text += "VarRed:     %s \n" % results['VarRed']
    text += "Var/Pdc:    %s \n" % results['Var/Pdc']
    text += "Mo:         %s \n" % results['Mo']
    text += "Mxx:%0.3f  Mxy:%0.3f  Mxz:%0.3f\n" % (float(results['Mxx']), float(results['Mxy']), float(results['Mxz']))
    text += "Myy:%0.3f  Myz:%0.3f  Mzz:%0.3f\n" % (float(results['Myy']), float(results['Myz']), float(results['Mzz']))
    ax = fig.add_subplot(total_stations,3,total, frameon=False)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.patch.set_alpha(0.0)
    ax.annotate( text, (0, 1), xycoords="axes fraction", va="top", ha="left",
                 fontsize=12, bbox=dict(edgecolor='none',boxstyle="round, pad=2", fc="w"))
    total += 1

    # Only run if library ObsPy is present on system.
    if beachball:
        # Third panel for beachball
        ax = fig.add_subplot(total_stations,3,total, frameon=False)
        ax.xaxis.set_visible(False)
        ax.yaxis.set_visible(False)
        ax.patch.set_alpha(0.0)

        ax.annotate( 'ObsPy used for beachball image', (0.5, 0), xycoords="axes fraction", va="top", ha="left",
                     fontsize=7, bbox=dict(edgecolor='none',boxstyle="round, pad=2", fc="w"))

        # TEST FOR COMPARING 3 and 6 components methods
        #mt = [ float(results['Mxx']), float(results['Myy']), float(results['Mzz']),
        #    float(results['Mxy']), float(results['Mxz']), float(results['Myz']) ]
        #mt2 = [ results['Strike'][0], results['Dip'][0], results['Rake'][0], ]
        #bb = beachball(mt, mopad_basis='NED', xy=(-50, -50),width=80)
        #bb2 = beachball(mt2, xy=(50,50), width=80)
        #ax.add_collection( bb )
        #ax.add_collection( bb2 )

        mt = [ float(results['Mxx']), float(results['Myy']), float(results['Mzz']),
            float(results['Mxy']), float(results['Mxz']), float(results['Myz']) ]
        bb = beachball(mt, mopad_basis='NED')
        ax.add_collection( bb )
        ax.set_xlim((-110, 110))
        ax.set_ylim((-110, 110))
        ax.set_aspect("equal")

    total += 1

    #for sta in sorted(stations.keys()):
    for sta in sorted(stations.keys(), key=lambda x: float(stations[x].realdistance) ):

        logging.debug('Plot traces for results on %s' % sta )
        if not stations[sta].real:
            logging.error('Empty Records for data on %s' % sta )
        if not stations[sta].synth_zrt:
            logging.error('Empty Records for converted ZRT on %s' % sta)

        distance = int( float(stations[sta].realdistance) )
        azimuth = int( float(stations[sta].azimuth) )
        #real = stations[sta].real
        convertedsynth = stations[sta].synth_zrt
        try:
            zcor = results['zcor'][sta]
        except:
            zcor = '-'
        variance = round( results['variance'][sta], 1)

        # Scale all traces the same way
        #axs = stations[sta].max_min_all()
        axs = (0, points_plot, min_plot, max_plot)


        #for chan, data in real:
        for chan in ['T', 'R', 'Z']:
            ax = fig.add_subplot(total_stations,3,total)
            #real_line, = pyplot.plot(data, label='data' )
            real_line, = pyplot.plot(stations[sta].real.get(chan), label='data' )
            synth_line, = pyplot.plot(stations[sta].synth_zrt.get(chan), linestyle='--', label='synth')

            pyplot.legend(loc=5, fontsize=8)

            pyplot.axis( axs )
            pyplot.ylabel('centimeters', fontsize=8)
            pyplot.yticks(size=8)

            ax.get_xaxis().set_ticks([])
            #ax.get_yaxis().set_ticks([])
            ax.yaxis.set_major_formatter(pyplot.FormatStrFormatter('%.1e'))

            # Top of plot
            pyplot.text (0.5, 0.9, r'$\mathbf{%s}\ -\ \mathbf{%s}\ \ %s_{km}\ \ %s ^o$' % (sta,chan,distance,azimuth),
                  horizontalalignment='center', fontsize=13,
                  verticalalignment='center', transform = ax.transAxes)

            # Bottom of plot
            text = "zcor:%s   variance_reduction:%s%%" % (zcor, variance)
            pyplot.text (0.5, 0.1,text, horizontalalignment='center', fontsize=11,
                  verticalalignment='center', transform = ax.transAxes)


            pyplot.draw()
            total += 1

    title = "%s Mw    " % results['Mw']
    title += "%s   " % event.strtime
    pyplot.suptitle(title, fontsize=18, ha='center')

    text = "%s \n" % event.strtime

    # Acknowledgement panel
    ax = fig.add_subplot(total_stations,3,total, frameon=False)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.patch.set_alpha(0.0)
    ax.annotate( unicode(acknowledgement, "utf-8"), (0, 0), xycoords="axes fraction", va="bottom", ha="left",
                 fontsize=8, bbox=dict(edgecolor='gray',boxstyle="round, pad=2", fc="w"))

    # Extra info panel
    total += 1
    text = "%s\n" % ' '.join( sys.argv )
    #text += "%s\n" % os.environ['ANTELOPE']
    text += "Generated at %s" % stock.strtime( stock.now() )

    ax = fig.add_subplot(total_stations,3,total, frameon=False)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.patch.set_alpha(0.0)
    ax.annotate( unicode(text, "utf-8"), (0, 0), xycoords="axes fraction", va="bottom", ha="left",
                 fontsize=8, bbox=dict(edgecolor='gray',boxstyle="round, pad=2", fc="w"))

    try:
        if not os.path.isdir(folder): os.makedirs(folder)
    except Exception,e:
        logging.error("Problems while creating folder [%s] %s" % (folder,e))
コード例 #13
0
def readHelm(inputfile):
    """
    Routine to read Helmberger Format Seismograms
    Returning full object:
        traces[chan]['data'] = data
        return traces

    """
    logging.debug('readHelm: %s' % inputfile)
    results = {}


    fo = open(inputfile, "r")

    # Number of channels
    try:
        total_chans = int( fo.readline().strip() )
        logging.debug( "Total channels [%s]" % total_chans )
    except:
        logging.error("NOT VALID FILE [%s]" % inputfile)

    if total_chans == 1:
        channels = 'X'
    if total_chans == 3:
        # From dbmoment.xpy code. Also in data.py
        global seismic_channels
        channels = seismic_channels
    else:
        # From dbmoment.xpy code.
        global synth_channels
        channels = synth_channels

    # Data Format
    try:
        data_format = fo.readline().strip()
        logging.debug('file format: %s' % data_format )
        temp = re.match("\((\d+)e(\d+)\.(\d+)\)",data_format)
        perline = int(temp.group(1))
        spaces = int(temp.group(2))
        logging.debug('perline: %s  spaces: %s' % (perline, spaces) )


    except:
        logging.error( "NOT VALID FILE [%s]" % inputfile )

    for chan in range(total_chans):
        channame = channels[chan]
        logging.debug( "chan %s" % channame )
        try:
            header1 = fo.readline().strip().split()
            header2 = fo.readline().strip().split()
            total_points = int( header2[0] )
            samplerate =  1/float( header2[1] )
        except:
            logging.error( "NOT VALID FILE [%s]" % inputfile )

        if not total_points or not samplerate:
            logging.error( "NOT VALID FILE [%s]" % inputfile )

        cache = []
        logging.debug( "Total points [%s]" % total_points )
        logging.debug( "Sampelrate [%s]" % samplerate )

        while (total_points > 0):
            row = fo.readline().strip('\n')
            #logging.info('row: %s' % row)
            #logging.info('missing: %s' % total_points)
            if not row: logging.error( 'Problems readHelm(%s)' % inputfile )

            while ( len(row) > 0 ):
                point = float(row[0:spaces])
                row = row[spaces:]
                #logging.info('%s' % point)
                cache.append( point )
                total_points -= 1

            #row = [float(row[i:i+spaces]) for i in range(0, perline)]
            #cache.extend( row )
            #total_points -= len( row )

        cache = array( cache )
        if total_chans == 1: return cache

        if not results:
            # need new object
            results =  Records(samplerate)
            results.file = inputfile

        results.trace( channame, cache )

    return results
コード例 #14
0
        'run_fkrsort',
        'run_filter',
        'TEMP_MODEL',
        'GREEN.1',
        'junk',
        'plot',
        'vec'
    ]

    for f in filelist:
        try:
            temp_file = "%s/%s" % (folder,f)
            logging.debug( 'unlink( %s )' % temp_file )
            map( os.unlink, glob.glob( temp_file ) )
        except Exception, e:
            logging.error('Cannot remove temp file %s [%s]' % (temp_file,e) )

def new_Helm_header(samples,samplerate):
    temp = '     %0.4e     %0.4e      0  0  0.00\n' % (0,0)
    temp += '%8d   %0.5f  %.4e\n' % (samples,1/samplerate,0)
    return temp

def fix_format_data(point, decimals, total):
    new = "%0.*e" % (decimals,point)
    return new.rjust(total)

#def makeHelm(traces, index_min, index_max, append='', outputfile='', perline=7, total=14, decimal=5, folder='.dbmoment'):
def makeHelm(traces, append='', outputfile='', perline=7, total=14, decimal=5, folder='.dbmoment'):
    """
    Routine to write Helmberger Format Seismograms
    """