Beispiel #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)
Beispiel #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
Beispiel #3
0
def SmoothMFD(Db,
              a,
              XY,
              Window=GaussWin,
              Par=50.,
              Delta=0.1,
              SphereGrid=False,
              Box=[],
              Buffer=[],
              Grid=[],
              Threshold=-100,
              Unwrap=False,
              ZeroRates=False):

    if isinstance(XY, CU.Polygon):
        P = cp.deepcopy(XY)
    else:
        P = CU.Polygon()
        P.Load(XY)

    if Par <= 0:
        Par = np.inf

    # Catalogue selection
    DbS = Sel.AreaSelect(Db, P, Owrite=0, Buffer=Buffer, Unwrap=Unwrap)
    x, y, z = Exp.GetHypocenter(DbS)

    # Unwrapping coordinates
    if Unwrap:
        x = [i if i > 0. else i + 360. for i in x]
        P.Unwrap()

    # Creating the mesh grid
    if Grid:
        XY = [G for G in Grid if P.IsInside(G[0], G[1])]
    else:
        if SphereGrid:
            XY = P.SphereGrid(Delta=Delta, Unwrap=Unwrap)
        else:
            XY = P.CartGrid(Dx=Delta, Dy=Delta, Bounds=Box)

    Win = []
    for xyP in XY:
        Win.append(0)
        for xyE in zip(x, y):
            Dis = CU.WgsDistance(xyP[1], xyP[0], xyE[1], xyE[0])
            Win[-1] += Window(Dis, Par)

    # Using homogenous zone if no events are found
    #if all(i == 0 for i in Win):
    #  Win = [1. for i in Win]

    # Scaling and normalising the rates
    Norm = np.sum(Win)

    A = []
    X = []
    Y = []
    for I, W in enumerate(Win):

        aT = -np.inf
        if Norm > 0. and W > 0.:
            aT = a + np.log10(W / Norm)
            if aT < Threshold:
                # Filter below threshold
                aT = -np.inf

        if ZeroRates:
            A.append(aT)
            X.append(XY[I][0])
            Y.append(XY[I][1])
        else:
            if aT > -np.inf:
                A.append(aT)
                X.append(XY[I][0])
                Y.append(XY[I][1])

    if Unwrap:
        # Wrap back longitudes
        X = [x if x < 180. else x - 360. for x in X]

    return X, Y, A
Beispiel #4
0
#-----------------------------------------------------------------------------------------
# Import Catalogues

Db1 = Cat.Database()
Db1.Load('data/isc-rev-africa-select.bin')

Db2 = Cat.Database()
Db2.Load('data/isc-gem-v3.bin')

#-----------------------------------------------------------------------------------------
# Duplicate findings

# Between Catalogues
Db3, Log = Sel.MergeDuplicate(Db1,
                              Db2,
                              Twin=60.,
                              Swin=50.,
                              Log=1,
                              Owrite=False)

# Within a catalogue
Log = Sel.MergeDuplicate(Db1, Twin=60., Swin=50., Log=1)

#-----------------------------------------------------------------------------------------
# Magnitude conversion

# Apply to all agency
Sel.MagConvert(Db1, '*', ['Ms', 'MS'], 'Mw', MR.MsMw_Scordillis2006)

# Apply to single agency
Sel.MagConvert(Db1, 'ISC', 'Ms', 'Mw', MR.MsMw_Scordillis2006)
Beispiel #5
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)