Exemple #1
0
])  #np.array([3557.418383, -324.384367])
catalog['x'] = r0[0] - catalog.x  # shift so that main shock position is (0,0)
catalog['y'] = r0[1] - catalog.y
catalog['Distance_from_origin'] = (catalog.x**2 + catalog.y**2)**0.5
catalog = catalog.dropna()

# reduce events to a random sample of k elements
#catalog = catalog.sample(frac=0.45, replace=False)
#==============================================================================

eq.plot_catalog(catalog, 1, np.array([0, 0]), color='Generation')

N = len(catalog)
k = 20  # int(N**0.5)

r, densities = eq.plot_ED(catalog, k=k, plot=False)  # get distance, density
df_dens = pd.DataFrame({'distance': r, 'density': densities})
#df_dens = df_dens[(df_dens.distance > 10**1.2) & (df_dens.distance < 10**2.6)]
r = df_dens.distance
densities = df_dens.density  #* np.exp()

#rho0 = np.mean(densities[0:100])
#rmax = (r.max())
#rmin = (r.min())
#n_edges = 30
##bin_edges = np.linspace(np.log10(rmin), np.log10(rmax), n_edges) #np.array([r[i] for i in range(0, len(r), q)])
##bin_edges = 10**bin_edges
#bin_edges = np.linspace(rmin, rmax, n_edges) #np.array([r[i] for i in range(0, len(r), q)])
#const = (rmax, rmin, r, bin_edges, n_edges, rho0)
#
#lb = [50, 1]#, 1e-4]
Exemple #2
0
#eq.generate_catalog(t0, r0, catalog_list, gen, True,
#                    Tf,M0,A,alpha,b,c,cprime,p,pprime,Mc,smin)

#catalogs = pd.concat(catalog_list)
#catalogs.to_pickle('catalogs.pkl')

# read in catalog and plot
catalogs_raw = pd.read_pickle(
    'catalogs.pkl')  # read in .pkl file storing dataframe generated above

# plot catalog
#eq.plot_catalog(catalogs_raw, M0, r0, color = 'Density')
#eq.plot_catalog(catalogs_raw, M0, r0, color = 'Time')

#eq.plot_catalog(catalog, 1, np.array([0,0]), color = 'Generation')
distances, densities = eq.plot_ED(catalogs_raw,
                                  plot=False)  # get distance, density

# need to be in log space
#distances = np.log10(distances)
#densities = np.log10(densities)

# perform particle swarm optimisation in parameter space on log likelihood
rho0 = np.mean(densities[0:5])
rmax = distances.max()
r = distances
const = (rho0, rmax, r)

lb = [1e-5, 1e-5]
ub = [r.max(), 5]

theta0, llk0 = pso(eq.LLK_rho, lb, ub, args=const, maxiter=100)
Exemple #3
0
    'Distance': ['-'] * len(events_all),
    'x': [event.x for event in events_all],
    'y': [event.y for event in events_all],
    'Generation': [0] * len(events_all),
    'Distance_from_origin':
    [event.distance_from_origin for event in events_all]
})
cols = [
    'n_avg', 'Events', 'Magnitude', 'Generation', 'x', 'y', 'Distance', 'Time',
    'Distance_from_origin'
]
catalog = catalog.reindex(columns=cols)
catalog = catalog[catalog.Magnitude <= 6]

eq.plot_catalog(catalog, 1, np.array([0, 0]), color='Generation')
distance_all, density_all = eq.plot_ED(catalog,
                                       plot=True)  # get distance, density
dist_min = np.log(distance_all.min())
dist_max = np.log(distance_all.max())
density_min = np.log(density_all.min())
density_max = np.log(density_all.max())

for k in np.arange(K):
    events = np.random.choice(events_all, N)
    # format events in the pd dataframe format defined by generate_catalog etc.
    catalog = pd.DataFrame({
        'Magnitude': [event.magnitude for event in events],
        'Events':
        '-',
        'n_avg':
        '-',
        'Time': [0] * len(events),
Exemple #4
0
start = datetime.now()
x0 = np.mean(data.x) - 20
y0 = np.mean(data.y) -150

data['x'] = x0 - data.x # shift so that main shock position is (0,0)
data['y'] = y0 - data.y
data['Distance_from_origin'] = (data.x**2 + data.y**2)**0.5
data['Distance_from_origin'] /= 1000 # set in km
data = data.dropna()
data = data.sample(frac = 0.03, replace = False)

eq.plot_catalog(data, 1, np.array([0,0]), color = 'Generation')

N = len(data)
k = 40 #int(N**0.5)
r, densities = eq.plot_ED(data, k = k,  plot = False) # get distance, density
df_dens = pd.DataFrame({'distance':r, 'density':densities})
df_dens = df_dens[(df_dens.distance > 10**1.4) & (df_dens.distance <= 10**3)]
r = np.array(df_dens.distance)
densities = np.array(df_dens.density) 

#==============================================================================
## perform particle swarm optimisation (MLE)
#rho0 = np.mean(densities[0:5])
#rmax = (r.max())
#rmin = (r.min())
#n_edges = 15
##bin_edges = np.linspace(np.log10(rmin), np.log10(rmax), n_edges) #np.array([r[i] for i in range(0, len(r), q)])
##bin_edges = 10**bin_edges
#bin_edges = np.linspace(rmin, rmax, n_edges) #np.array([r[i] for i in range(0, len(r), q)])
#const = (rmax, rmin, r, bin_edges, n_edges, rho0)