Commit ba725e2f authored by Pablo Iturrieta Rebolledo's avatar Pablo Iturrieta Rebolledo
Browse files

finalized parallelizing

parent aaab76c5
import os, sys
currentdir = os.path.dirname(os.path.realpath(__file__))
parentdir = os.path.dirname(currentdir)
sys.path.append(parentdir)
import fiona
from codes import get_models
from codes import paths
......@@ -16,6 +20,8 @@ import cartopy
import seaborn as sns
import time
def get_simulations(model, catalog, lons, lats):
forecast_data = model.spatial_counts()
......@@ -115,6 +121,7 @@ def K_r_parallel(data):
# Get the model rates
rates = model.spatial_counts(cartesian=True)
rates[rates==0] = np.nan
rates_array = robjects.FloatVector(rates.T.ravel())
rates_mat = robjects.r['matrix'](rates_array, nrow=rates.shape[0])
image = spat_geom.im(rates_mat, Xregion_array, Yregion_array)
......@@ -295,9 +302,16 @@ def plot_results(Results, alpha=0.05):
def run_parallel():
models = get_models.ten_years()
catalog = get_catalogs.filter_10yr_01_2010(get_catalogs.bollettino())
catalogs = [get_catalogs.filter_10yr_01_2010(get_catalogs.bollettino()),
get_catalogs.filter_10yr_01_2010(get_catalogs.emrcmt()),
get_catalogs.filter_10yr_01_2010(get_catalogs.horus())]
cat_names = ['bollettino',
'emrcmt',
'horus']
Results = dict.fromkeys([i.name for i in models])
for catalog, cat_name in zip(catalogs, cat_names):
for model in models:
print(model.name)
......@@ -313,7 +327,7 @@ def run_parallel():
lons = model.get_longitudes()
lats = model.get_latitudes()
nsim = 16
nsim = 240
sim_catalogs = iter([(get_simulations(model, catalog, lons, lats)[0], model) for i in range(nsim)])
Rk_sims = []
......@@ -321,7 +335,7 @@ def run_parallel():
Rpcf_sims = []
PCF_sims = []
start = time.process_time()
p = Pool(8)
p = Pool(16)
A = p.map(K_r_parallel, sim_catalogs)
p.close()
for K in A:
......@@ -354,7 +368,7 @@ def run_parallel():
'pcf_cat': pcf_cat,
'rpcf_cat': rpcf_cat}
with open(paths.get_kripley_result_path('KRipley_bolletino', 10), 'wb') as file_:
with open(paths.get_kripley_result_path('KRipley_%s' % cat_name, 10), 'wb') as file_:
pickle.dump(Results, file_)
......@@ -381,7 +395,7 @@ def run():
lons = model.get_longitudes()
lats = model.get_latitudes()
nsim = 16
nsim = 200
sim_catalogs = iter([get_simulations(model, catalog, lons, lats) for i in range(nsim)])
Rk_sims = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment