Example #1
0
def MagTimePlot(Db,
                Mag0=[],
                Mag1=[],
                Year0=[],
                Year1=[],
                CompTable=[],
                OutFile=[]):

    if not Mag0:
        Mag0 = min(Db.Extract('MagSize'))
    if not Mag1:
        Mag1 = max(Db.Extract('MagSize'))

    if not Year0:
        Year0 = min(Db.Extract('Year'))
    if not Year1:
        Year1 = max(Db.Extract('Year'))

    DbS = Sel.MagRangeSelect(Db, Mag0, Mag1, Owrite=0, TopEdge=True)
    DbS = Sel.TimeSelect(DbS, Year0, Year1, Owrite=0)

    X = DbS.Extract('Year')
    Y = DbS.Extract('MagSize')

    plt.figure(figsize=(7, 4))

    plt.plot(X,
             Y,
             'o',
             markersize=3,
             color=[0, 0, 0],
             markeredgecolor=[0, 0, 0],
             markeredgewidth=1.5)

    # Plot completeness
    if CompTable:
        PlotCompTable(CompTable)

    plt.gca().yaxis.grid(color='0.', linestyle='-')
    plt.gca().xaxis.grid(color='0.65', linestyle='--')

    plt.gca().xaxis.set_ticks_position('none')
    plt.gca().yaxis.set_ticks_position('none')

    plt.title('Time-Magnitude Distribution', fontsize=14, fontweight='bold')
    plt.xlabel('Years', fontsize=14, fontweight='bold')
    plt.ylabel('Magnitude', fontsize=14, fontweight='bold')

    plt.axis([Year0, Year1, Mag0, Mag1])
    # plt.tight_layout()
    plt.show(block=False)

    if OutFile:
        plt.savefig(OutFile, bbox_inches='tight', dpi=150)
Example #2
0
def GetEventRates(Db, CompTable, Area=1.):
  """
  Method to compute observed annual rates (incremental and cumulative) from a given
  completeness table. In this implementation, completeness is one window per
  magnitude bin in M. Example:
  CompTable = [[4.50, 0.25, 2000., 2013.],
               [4.75, 0.25, 1980., 2013.],
               [5.00, 0.25, 1970., 2013.],
               [5.25, 0.25, 1960., 2013.],
               [5.50, 0.50, 1950., 2013.],
               [6.00, 1.50, 1901., 2013.]]
  """

  Enum = []
  Data = [[],[]]

  for CT in CompTable:

    MinM = CT[0]
    MaxM = CT[0]+CT[1]
    MinY = CT[2]
    MaxY = CT[3]

    # Catalogue selection (Magnitude-Year)
    DbM = Sel.MagRangeSelect(Db, MinM, MaxM)
    DbY = Sel.TimeSelect(DbM, MinY, MaxY)

    # Computing incremental rates
    RY = float(DbY.Size())/float(MaxY-MinY)
    Enum.append(RY/float(Area))

    # Data per magnitude bin
    Data[0].append(DbY.Extract(Key='Year'))
    Data[1].append(DbY.Extract(Key='MagSize'))

  # Cumulative distribution
  Ecum = np.cumsum(Enum[::-1])[::-1]

  return Enum, Ecum, Data
Example #3
0
def RateDensityPlot(Db,
                    Mag0=[],
                    Mag1=[],
                    MBin=0.25,
                    Year0=[],
                    Year1=[],
                    Delta=2,
                    CompTable=[],
                    Normalise=True,
                    OutFile=[]):

    if not Mag0:
        Mag0 = min(Db.Extract('MagSize'))
    if not Mag1:
        Mag1 = max(Db.Extract('MagSize'))
    MBins = np.arange(Mag0, Mag1 + MBin, MBin)

    if not Year0:
        Year0 = min(Db.Extract('Year'))
    if not Year1:
        Year1 = max(Db.Extract('Year'))
    YBins = np.arange(Year0, Year1 + Delta, Delta)

    Histo = np.zeros((np.size(MBins), np.size(YBins)))

    # Catalogue selection (Magnitude-Year)
    DbM = Sel.MagRangeSelect(Db, Mag0, Mag1, TopEdge=True)
    DbY = Sel.TimeSelect(DbM, Year0, Year1)

    M = DbY.Extract('MagSize')
    Y = DbY.Extract('Year')

    Hist = np.histogram2d(Y, M, bins=(YBins, MBins))[0]
    Hist = np.transpose(Hist)

    if Normalise:
        for I in range(0, len(Hist)):
            Max = np.max(Hist[I])
            if Max > 0:
                Hist[I] = Hist[I] / Max

    # Plot
    plt.figure(figsize=(7, 4))

    plt.pcolormesh(YBins, MBins, Hist, cmap='Greys', vmin=0)

    # Plot completeness
    if CompTable:
        PlotCompTable(CompTable)

    plt.gca().xaxis.grid(color='0.65', linestyle='--')
    plt.gca().yaxis.grid(color='0.', linestyle='-')

    plt.gca().xaxis.set_ticks_position('none')
    plt.gca().yaxis.set_ticks_position('none')

    plt.title('Occurrence Rate Density', fontsize=14, fontweight='bold')
    plt.xlabel('Years', fontsize=12, fontweight='bold')
    plt.ylabel('Magnitude', fontsize=12, fontweight='bold')

    plt.gca().xaxis.grid(color='0.65', linestyle='-')
    plt.gca().yaxis.grid(color='0.65', linestyle='-')

    plt.axis([Year0, Year1, Mag0, Mag1])
    # plt.tight_layout()
    plt.show(block=False)

    if OutFile:
        plt.savefig(OutFile, bbox_inches='tight', dpi=150)