Skip to content

Commit

Permalink
Add json default output
Browse files Browse the repository at this point in the history
  • Loading branch information
ebachelet committed Nov 2, 2024
1 parent ea46569 commit af2fc4a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
9 changes: 6 additions & 3 deletions pyLIMA/fits/ML_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pyLIMA.priors import parameters_boundaries
from pyLIMA.priors import parameters_priors


class FitException(Exception):
pass

Expand Down Expand Up @@ -1230,7 +1229,8 @@ def check_telescopes_fluxes_limits(self, telescopes_fluxes):

return new_fluxes

def fit_outputs(self, bokeh_plot=None, bokeh_plot_name=None):
def fit_outputs(self, bokeh_plot=None, bokeh_plot_name=None,
json_name='./pyLIMA_fit.json'):
"""
Produce the standard plots output
Expand All @@ -1251,9 +1251,12 @@ def fit_outputs(self, bokeh_plot=None, bokeh_plot_name=None):
implemented yet)
bokeh_figure : bokehh.fig, a bokeh.figure containing all the above
"""
#Non standard call to libraries, but otherwise slow-down codes significantly
from bokeh.layouts import gridplot
from bokeh.plotting import output_file, save
from pyLIMA.outputs import pyLIMA_plots
from pyLIMA.outputs import pyLIMA_plots, file_outputs

file_outputs.json_output(self,json_name=json_name)

matplotlib_lightcurves = None
matplotlib_geometry = None
Expand Down
69 changes: 54 additions & 15 deletions pyLIMA/outputs/file_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,60 @@
import numpy as np


def json_output(array_parameters, parameters_name, filename='parameters',
output_directory='./'):
fit_results = {}

for index, key in enumerate(parameters_name):
value = array_parameters[:, index]
param_dic = {}
param_dic['value'] = value
param_dic['comment'] = ''
param_dic['format'] = 'float'
param_dic['unit'] = ''
fit_results[key] = param_dic

with open(output_directory + filename + '_.json', 'w') as outfile:
json.dump(fit_results, outfile)
def json_output(fit_object,json_name='./pyLIMA_fit.json'):
dictionnary = {}

dictionnary['Event'] = {'Name':fit_object.model.event.name}
dictionnary['Model'] = {'Type':fit_object.model.model_type()}
dictionnary['FitParameters'] = {'Parameters':fit_object.fit_parameters}
dictionnary['FitPriors'] = {'Parameters':fit_object.priors_parameters}
dictionnary['FitResults'] = {}

for key, value in fit_object.fit_results.items():

if isinstance(value, np.ndarray):

tosave = value.tolist()
else:

tosave = value

if key == 'fit_object':

pass

else:

try:

dictionnary['FitResults'][key] = tosave

except TypeError:

pass

with open(json_name, 'w') as outfile:
json.dump(dictionnary,outfile,indent=4)





# def json_output(array_parameters, parameters_name, filename='parameters',
# output_directory='./'):
# fit_results = {}
#
# for index, key in enumerate(parameters_name):
# value = array_parameters[:, index]
# param_dic = {}
# param_dic['value'] = value
# param_dic['comment'] = ''
# param_dic['format'] = 'float'
# param_dic['unit'] = ''
# fit_results[key] = param_dic
#
# with open(output_directory + filename + '_.json', 'w') as outfile:
# json.dump(fit_results, outfile)


def numpy_output(array_parameters, filename='parameters', output_directory='./'):
Expand Down

0 comments on commit af2fc4a

Please sign in to comment.