Skip to content

Commit 40c8359

Browse files
committed
Change distribution outputs files
1 parent 96251a7 commit 40c8359

2 files changed

Lines changed: 52 additions & 19 deletions

File tree

pyLIMA/fits/MCMC_fit.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,17 @@ def fit(self, initial_population=[], computational_pool=False):
176176

177177
def reconstruct_chains(self, mcmc_samples, mcmc_prob):
178178

179+
179180
rangei, rangej, rangek = mcmc_samples.shape
180181

181-
#MCMC_chains = np.zeros((rangei, rangej, rangek + 2))
182-
#MCMC_chains[:, :, :-2] = mcmc_samples
183-
#MCMC_chains[:, :, -2] = mcmc_prob
184-
#MCMC_chains[:, :, -1] = np.zeros(mcmc_prob.shape)
182+
MCMC_chains = np.zeros((rangei, rangej, rangek + 2))
183+
MCMC_chains[:, :, :-2] = mcmc_samples
184+
MCMC_chains[:, :, -2] = mcmc_prob
185+
MCMC_chains[:, :, -1] = np.zeros(mcmc_prob.shape)
186+
187+
if self.telescopes_fluxes_method=='fit':
188+
189+
return MCMC_chains,MCMC_chains
185190

186191
Rangei,Rangej = self.trials_parameters[:,:-2].shape
187192
#MCMC_chains_with_fluxes = np.zeros((rangei,rangej,Rangej+2))
@@ -204,9 +209,8 @@ def reconstruct_chains(self, mcmc_samples, mcmc_prob):
204209
MCMC_chains_with_fluxes = np.array(MCMC_FLUXES)[MCMC_rebuild].reshape(rangei,
205210
rangej,
206211
Rangej + 2)
207-
MCMC_chains = mcmc_samples
212+
MCMC_chains[:,:,-1] = MCMC_chains_with_fluxes[:,:,-1]
208213

209-
return MCMC_chains, MCMC_chains_with_fluxes
210214

211215
#MCMC_FLUXES = np.zeros((MCMC_unique.shape[0],trials_unique.shape[1]))
212216
#match = []
@@ -259,26 +263,24 @@ def reconstruct_chains(self, mcmc_samples, mcmc_prob):
259263
# MCMC_chains_with_fluxes[:,j][:,-1] = np.array(unique_priors)[
260264
# unique_sample[1].ravel()]
261265

262-
#columns_to_swap = []
263-
#if self.rescale_photometry:
264-
# columns_to_swap += self.rescale_photometry_parameters_index
266+
columns_to_swap = []
267+
if self.rescale_photometry:
268+
columns_to_swap += self.rescale_photometry_parameters_index
265269

266-
#if self.rescale_astrometry:
267-
# columns_to_swap += self.rescale_photometry_parameters_index
270+
if self.rescale_astrometry:
271+
columns_to_swap += self.rescale_photometry_parameters_index
268272

269-
#if (columns_to_swap != []):
273+
if (columns_to_swap != []):
270274

271-
# old_column = columns_to_swap
272-
# new_column = np.arange(old_column[-1]+1,Rangej-1,1).tolist()
275+
old_column = columns_to_swap
276+
new_column = np.arange(old_column[-1]+1,Rangej-1,1).tolist()
273277

274-
# MCMC_chains_with_fluxes[:, :, old_column + new_column] =
275-
# # MCMC_chains_with_fluxes[:, :,
276-
# new_column +
277-
# old_column]
278+
MCMC_chains_with_fluxes[:, :, old_column + new_column] = MCMC_chains_with_fluxes[:, :,new_column +old_column]
278279

279280
#MCMC_chains[:,:,-1] = np.copy(MCMC_chains_with_fluxes[:,:,-1])
280281

281282

283+
return MCMC_chains, MCMC_chains_with_fluxes
282284

283285
def samples_to_plot(self):
284286

pyLIMA/outputs/file_outputs.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def json_output(fit_object,json_name='./pyLIMA_fit.json'):
1313
dictionnary['FitPriors'] = {'Parameters':fit_object.priors_parameters}
1414
dictionnary['FitResults'] = {}
1515

16+
distributions_to_output = {}
17+
1618
for key, value in fit_object.fit_results.items():
1719

1820
if isinstance(value, np.ndarray):
@@ -30,17 +32,46 @@ def json_output(fit_object,json_name='./pyLIMA_fit.json'):
3032

3133
try:
3234

33-
dictionnary['FitResults'][key] = tosave
35+
if (key == 'MCMC_chains'):
36+
37+
header = [key for key in fit_object.fit_parameters.keys()]
38+
distributions_to_output[key] = [tosave,header]
39+
40+
elif (key == 'MCMC_chains_with_fluxes'):
41+
42+
header = [key for key in fit_object.priors_parameters.keys()] +[
43+
'priors',
44+
fit_object.loss_function ]
45+
distributions_to_output[key] = [tosave,header]
46+
47+
elif (key == 'DE_population'):
48+
49+
header = [key for key in fit_object.priors_parameters.keys()]
50+
51+
distributions_to_output[key] = [tosave,header]
52+
53+
else:
54+
55+
dictionnary['FitResults'][key] = tosave
3456

3557
except TypeError:
3658

3759
pass
3860

61+
3962
with open(json_name, 'w') as outfile:
4063
json.dump(dictionnary,outfile,indent=4)
4164

4265

66+
for key in distributions_to_output.keys():
67+
68+
dist_name = json_name[:-5]+'_'+key+'.npz'
69+
np.savez(dist_name,pyLIMA_distribution=distributions_to_output[key][0],
70+
header=distributions_to_output[key][1]+[
71+
fit_object.loss_function, 'priors'])
4372

73+
# with open(dist_name, 'w') as outfile:
74+
# json.dump(distributions_to_output,outfile,indent=4)
4475

4576

4677
# def json_output(array_parameters, parameters_name, filename='parameters',

0 commit comments

Comments
 (0)