Commit ccf10cd1 authored by Médéric Boquien's avatar Médéric Boquien

We need to sort the sed.info before saving the data. The reason is that the...

We need to sort the sed.info before saving the data. The reason is that the dictionary orders the keys with a hash so it appears random. In addition the order also changes from one process to another (I suspect the hash also depends on a seed). Thanks to Yannick for pointing out this issue.
parent c0f0b6c3
......@@ -170,6 +170,8 @@ def save_table_best(filename, obsid, chi2, chi2_red, variables, fluxes,
best_model_table.add_column(Column(np_chi2, name="chi_square"))
best_model_table.add_column(Column(np_chi2_red, name="reduced_chi_square"))
info_keys = list(info_keys)
info_keys.sort()
for index, name in enumerate(info_keys):
column = Column(np_variables[:, index], name=name)
best_model_table.add_column(column)
......
......@@ -124,7 +124,7 @@ def init_analysis(params, filters, analysed, redshifts, fluxes, variables,
global gbl_redshifts, gbl_w_redshifts, gbl_analysed_averages
global gbl_analysed_std, gbl_best_fluxes, gbl_best_parameters
global gbl_best_chi2, gbl_best_chi2_red, gbl_save, gbl_n_obs
global gbl_lim_flag, gbl_phase
global gbl_lim_flag, gbl_phase, gbl_keys
gbl_analysed_averages = np.ctypeslib.as_array(analysed_averages[0])
gbl_analysed_averages = gbl_analysed_averages.reshape(analysed_averages[1])
......@@ -151,6 +151,7 @@ def init_analysis(params, filters, analysed, redshifts, fluxes, variables,
gbl_n_obs = n_obs
gbl_phase = phase
gbl_keys = None
def sed(idx):
......@@ -210,6 +211,7 @@ def analysis(idx, obs):
"""
# Tolerance threshold under which any flux or error is considered as 0.
global gbl_keys
tolerance = 1e-12
obs_fluxes = np.array([obs[name] for name in gbl_filters])
......@@ -382,7 +384,11 @@ def analysis(idx, obs):
gbl_best_fluxes[idx, :] = gbl_model_fluxes[wz[0][wvalid[0][best_index]], :] \
*norm_facts[best_index]
gbl_best_parameters[idx, :] = list(sed.info.values())
if gbl_keys is None:
gbl_keys = list(sed.info.keys())
gbl_keys.sort()
gbl_best_parameters[idx, :] = np.array([sed.info[k] for k in gbl_keys])
gbl_best_chi2[idx] = chi2_[best_index]
gbl_best_chi2_red[idx] = chi2_[best_index] / obs_fluxes.size
......
......@@ -118,7 +118,7 @@ class SaveFluxes(AnalysisModule):
# Retrieve an arbitrary SED to obtain the list of output parameters
warehouse = SedWarehouse()
sed = warehouse.get_sed(creation_modules, params.from_index(0))
info = sed.info
info = list(sed.info.keys())
n_info = len(sed.info)
del warehouse, sed
......
......@@ -37,7 +37,7 @@ def init_fluxes(params, filters, save_sed, fluxes, info, t_begin, n_computed):
"""
global gbl_model_fluxes, gbl_model_info, gbl_n_computed, gbl_t_begin
global gbl_params, gbl_previous_idx, gbl_filters, gbl_save_sed
global gbl_warehouse
global gbl_warehouse, gbl_keys
gbl_model_fluxes = np.ctypeslib.as_array(fluxes[0])
gbl_model_fluxes = gbl_model_fluxes.reshape(fluxes[1])
......@@ -58,6 +58,7 @@ def init_fluxes(params, filters, save_sed, fluxes, info, t_begin, n_computed):
gbl_warehouse = SedWarehouse()
gbl_keys = None
def fluxes(idx):
"""Worker process to retrieve a SED and affect the relevant data to shared
......@@ -70,7 +71,7 @@ def fluxes(idx):
handler.
"""
global gbl_previous_idx
global gbl_previous_idx, gbl_keys
if gbl_previous_idx > -1:
gbl_warehouse.partial_clear_cache(
gbl_params.index_module_changed(gbl_previous_idx, idx))
......@@ -89,7 +90,10 @@ def fluxes(idx):
gbl_filters])
gbl_model_fluxes[idx, :] = model_fluxes
gbl_model_info[idx, :] = list(sed.info.values())
if gbl_keys is None:
gbl_keys = list(sed.info.keys())
gbl_keys.sort()
gbl_model_info[idx, :] = np.array([sed.info[k] for k in gbl_keys])
with gbl_n_computed.get_lock():
gbl_n_computed.value += 1
......
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