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

Modified N-M-S-L-CL tests to include New ForecastModel format (without...

Modified N-M-S-L-CL tests to include New ForecastModel format   (without saving metadata in a different object)
parent 7766738d
......@@ -137,9 +137,9 @@ def run(use_saved=False):
for yr, type in itertools.product(years, types):
result_path = filepaths.get_csep_result_path(test, yr, type)
if use_saved:
Result = process_forecasts_batch([i[0] for i in models[yr]], catalogs[yr], load_obj=result_path)
Result = process_forecasts_batch(models[yr], catalogs[yr], load_obj=result_path)
else:
Result = process_forecasts_batch([i[0] for i in models[yr]], catalogs[yr], save_obj=result_path)
Result = process_forecasts_batch(models[yr], catalogs[yr], save_obj=result_path)
Results[yr] = Result
plot_results(Result, years=yr, savepath=filepaths.get_csep_fig_path(test, yr, type))
......
......@@ -139,9 +139,9 @@ def run(use_saved=False):
for yr, type in itertools.product(years, types):
result_path = filepaths.get_csep_result_path(test, yr, type)
if use_saved:
Result = process_forecasts_batch([i[0] for i in models[yr]], catalogs[yr], load_obj=result_path)
Result = process_forecasts_batch(models[yr], catalogs[yr], load_obj=result_path)
else:
Result = process_forecasts_batch([i[0] for i in models[yr]], catalogs[yr], save_obj=result_path)
Result = process_forecasts_batch(models[yr], catalogs[yr], save_obj=result_path)
Results[yr] = Result
plot_results(Result, years=yr, savepath=filepaths.get_csep_fig_path(test, yr, type))
......
......@@ -126,9 +126,9 @@ def run(use_saved=False):
for yr, type in itertools.product(years, types):
result_path = filepaths.get_csep_result_path(test, yr, type)
if use_saved:
Result = process_forecasts_batch([i[0] for i in models[yr]],catalogs[yr], load_obj=result_path)
Result = process_forecasts_batch(models[yr],catalogs[yr], load_obj=result_path)
else:
Result = process_forecasts_batch([i[0] for i in models[yr]],catalogs[yr], save_obj=result_path)
Result = process_forecasts_batch(models[yr],catalogs[yr], save_obj=result_path)
Results[yr] = Result
plot_results(Result, years=yr, savepath=filepaths.get_csep_fig_path(test, yr, type))
......
......@@ -138,9 +138,9 @@ def run(use_saved=False):
## Get the name of the python object where to save results, or to load them
result_path = filepaths.get_csep_result_path(test, yr, type)
if use_saved:
Result = process_forecasts_batch([i[0] for i in models[yr]],catalogs[yr], load_obj=result_path)
Result = process_forecasts_batch(models[yr],catalogs[yr], load_obj=result_path)
else:
Result = process_forecasts_batch([i[0] for i in models[yr]],catalogs[yr], save_obj=result_path)
Result = process_forecasts_batch(models[yr],catalogs[yr], save_obj=result_path)
Results[yr] = Result
plot_results(Result, years=yr, savepath=filepaths.get_csep_fig_path(test, yr, type))
......
......@@ -122,9 +122,9 @@ def run(use_saved=False):
for yr, type in itertools.product(years, types):
result_path = filepaths.get_csep_result_path(test, yr, type)
if use_saved:
Result = process_forecasts_batch([i[0] for i in models[yr]], catalogs[yr], load_obj=result_path)
Result = process_forecasts_batch(models[yr], catalogs[yr], load_obj=result_path)
else:
Result = process_forecasts_batch([i[0] for i in models[yr]], catalogs[yr], save_obj=result_path)
Result = process_forecasts_batch(models[yr], catalogs[yr], save_obj=result_path)
Results[yr] = Result
plot_results(Result, years=yr, savepath=filepaths.get_csep_fig_path(test, yr, type))
......
......@@ -77,7 +77,7 @@ def plot_single_results(Results, Forecasts, years, ref_model=0,folder=False):
]
ax.legend(handles=legend_elements, loc='lower right')
if folder:
plt.savefig(os.path.join(folder, 'TW_%i_ref%s.png' % (years, Forecasts[ref_model][0].name)), dpi=300)
plt.savefig(os.path.join(folder, 'TW_%i_ref%s.png' % (years, Forecasts[ref_model].name)), dpi=300)
plt.show()
......@@ -177,9 +177,9 @@ def run(use_saved=False):
for yr in years:
result_path = filepaths.get_csep_result_path(test, yr)
if use_saved:
Result = process_forecasts_batch([i[0] for i in models[yr]], catalogs[yr], load_obj=result_path)
Result = process_forecasts_batch(models[yr], catalogs[yr], load_obj=result_path)
else:
Result = process_forecasts_batch([i[0] for i in models[yr]], catalogs[yr], save_obj=result_path)
Result = process_forecasts_batch(models[yr], catalogs[yr], save_obj=result_path)
Results[yr] = Result
tw_figs_path = os.path.join(filepaths.csep_figs, 'tw_single')
......
......@@ -6,7 +6,6 @@ import numpy as np
import ntpath
from codes import filepaths
def forecast_xmlreader(filename_):
"""
......@@ -86,21 +85,19 @@ def forecast_xmlreader(filename_):
mi_floor, mi_roof, d, flag])
np.savetxt(filename_dat, data_Hijm, fmt=save_fmt, delimiter='\t')
metadata = {'name': name,
'author': author,
'author_xml': author_xml,
'name_xml': name_xml,
'start_date' : start_date,
'end_date' : end_date,
'm_bin_width': m_bin_width,
'cell_dim': cell_dim,
'depth': depth}
forecast = csep.load_gridded_forecast(filename_dat,
name=name)
## Add metadata to CSEPGriddedForecast object
forecast.author = author
forecast.author_xml = author_xml
forecast.name_xml = name_xml
forecast.start_date = start_date
forecast.end_date = end_date
forecast.m_bin_width = m_bin_width
forecast.cell_dim = cell_dim
forecast.depth = depth
os.remove(filename_dat)
return forecast, metadata
return forecast
def process_models():
......@@ -108,14 +105,14 @@ def process_models():
Batch_5yr_models = []
Batch_10yr_models = []
for model in filepaths.models_5yr:
Forecast, metadata = forecast_xmlreader(model)
Batch_5yr_models.append([Forecast, metadata])
Forecast = forecast_xmlreader(model)
Batch_5yr_models.append(Forecast)
with open(filepaths.models_5yr_obj, 'wb') as obj:
pickle.dump(Batch_5yr_models, obj)
for model in filepaths.models_10yr:
Forecast, metadata = forecast_xmlreader(model)
Batch_10yr_models.append([Forecast, metadata])
Forecast = forecast_xmlreader(model)
Batch_10yr_models.append(Forecast)
with open(filepaths.models_10yr_obj, 'wb') as obj:
pickle.dump(Batch_10yr_models, obj)
......
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