diff --git a/autofit/config/general.ini b/autofit/config/general.ini index 4d2d5cb36..d9ca45a14 100644 --- a/autofit/config/general.ini +++ b/autofit/config/general.ini @@ -4,6 +4,7 @@ log_file=output.log log_level=INFO samples_to_csv=False model_results_decimal_places=3 +info_whitespace_length=80 remove_files=False force_pickle_overwrite=False identifier_version=4 diff --git a/autofit/mapper/prior_model/abstract.py b/autofit/mapper/prior_model/abstract.py index eb136cad3..acd53b1cd 100644 --- a/autofit/mapper/prior_model/abstract.py +++ b/autofit/mapper/prior_model/abstract.py @@ -27,13 +27,12 @@ from autofit.text import formatter as frm from autofit.text.formatter import TextFormatter from autofit.tools.util import split_paths +from autofit.tools.util import info_whitespace logger = logging.getLogger( __name__ ) -LINE_LENGTH = 80 - class Limits: @staticmethod @@ -1554,8 +1553,9 @@ def info(self) -> str: parameter of the overall model. This information is extracted from each priors *model_info* property. """ + formatter = TextFormatter( - line_length=LINE_LENGTH + line_length=info_whitespace() ) for t in self.path_instance_tuples_for_class( @@ -1603,7 +1603,7 @@ def parameterization(self) -> str: from .prior_model import PriorModel formatter = TextFormatter( - line_length=LINE_LENGTH + line_length=info_whitespace() ) for t in self.path_instance_tuples_for_class( diff --git a/autofit/text/samples_text.py b/autofit/text/samples_text.py index 970b0ce33..cb47cabd9 100644 --- a/autofit/text/samples_text.py +++ b/autofit/text/samples_text.py @@ -4,7 +4,6 @@ logger = logging.getLogger(__name__) - def values_from_samples(samples, median_pdf_model): if median_pdf_model: @@ -15,7 +14,8 @@ def values_from_samples(samples, median_pdf_model): def summary( samples, sigma=3.0, median_pdf_model=True, indent=1, line_length=None ) -> str: - """ Create a string summarizing the results of the `NonLinearSearch` at an input sigma value. + """ + Create a string summarizing the results of the `NonLinearSearch` at an input sigma value. This function is used for creating the model.results files of a non-linear search. diff --git a/autofit/text/text_util.py b/autofit/text/text_util.py index 6ab72f922..ce8a7f55a 100644 --- a/autofit/text/text_util.py +++ b/autofit/text/text_util.py @@ -1,6 +1,6 @@ from autoconf import conf from autofit.text import formatter as frm, samples_text - +from autofit.tools.util import info_whitespace def padding(item, target=6): string = str(item) @@ -14,7 +14,6 @@ def result_info_from(samples) -> str: Output the full model.results file, which include the most-likely model, most-probable model at 1 and 3 sigma confidence and information on the maximum log likelihood. """ - results = [] if hasattr(samples, "log_evidence"): @@ -24,7 +23,7 @@ def result_info_from(samples) -> str: frm.add_whitespace( str0="Bayesian Evidence ", str1="{:.8f}".format(samples.log_evidence), - whitespace=90 + whitespace=info_whitespace() ) ] results += ["\n"] @@ -33,7 +32,7 @@ def result_info_from(samples) -> str: frm.add_whitespace( str0="Maximum Log Likelihood ", str1="{:.8f}".format(max(samples.log_likelihood_list)), - whitespace=90 + whitespace=info_whitespace() ) ] results += ["\n"] @@ -41,7 +40,7 @@ def result_info_from(samples) -> str: frm.add_whitespace( str0="Maximum Log Posterior ", str1="{:.8f}".format(max(samples.log_posterior_list)), - whitespace=90 + whitespace=info_whitespace() ) ] results += ["\n"] @@ -50,7 +49,7 @@ def result_info_from(samples) -> str: results += ["Maximum Log Likelihood Model:\n\n"] - formatter = frm.TextFormatter() + formatter = frm.TextFormatter(line_length=info_whitespace()) for i, prior_path in enumerate(samples.model.unique_prior_paths): formatter.add( @@ -62,9 +61,9 @@ def result_info_from(samples) -> str: if samples.pdf_converged: - results += samples_text.summary(samples=samples, sigma=3.0, indent=4, line_length=90) + results += samples_text.summary(samples=samples, sigma=3.0, indent=4, line_length=info_whitespace()) results += ["\n"] - results += samples_text.summary(samples=samples, sigma=1.0, indent=4, line_length=90) + results += samples_text.summary(samples=samples, sigma=1.0, indent=4, line_length=info_whitespace()) else: @@ -72,11 +71,11 @@ def result_info_from(samples) -> str: "\n WARNING: The samples have not converged enough to compute a PDF and model errors. \n " "The model below over estimates errors. \n\n" ] - results += samples_text.summary(samples=samples, sigma=1.0, indent=4, line_length=90) + results += samples_text.summary(samples=samples, sigma=1.0, indent=4, line_length=info_whitespace()) results += ["\n\ninstances\n"] - formatter = frm.TextFormatter() + formatter = frm.TextFormatter(line_length=info_whitespace()) for t in samples.model.path_float_tuples: formatter.add(*t) diff --git a/autofit/tools/util.py b/autofit/tools/util.py index ca69f7b00..37f848733 100644 --- a/autofit/tools/util.py +++ b/autofit/tools/util.py @@ -8,6 +8,7 @@ import numpy as np +from autoconf import conf def split_paths(func): """ @@ -141,3 +142,7 @@ def numpy_array_from_json(file_path: str): """ with open(file_path, "r") as f: return np.asarray(json.load(f)) + + +def info_whitespace(): + return conf.instance["general"]["output"]["info_whitespace_length"] \ No newline at end of file diff --git a/test_autofit/config/general.ini b/test_autofit/config/general.ini index bc81dbc7c..26040ce94 100644 --- a/test_autofit/config/general.ini +++ b/test_autofit/config/general.ini @@ -4,6 +4,7 @@ log_file=output.log log_level=INFO samples_to_csv=False model_results_decimal_places=3 +info_whitespace_length=80 remove_files=True force_pickle_overwrite=False identifier_version=3 diff --git a/test_autofit/non_linear/test_analysis.py b/test_autofit/non_linear/test_analysis.py index fb9579da5..4a40954e5 100644 --- a/test_autofit/non_linear/test_analysis.py +++ b/test_autofit/non_linear/test_analysis.py @@ -213,7 +213,7 @@ def test_set_number_of_cores( multi_analysis.n_cores = 1 assert multi_analysis._log_likelihood_function.__name__ == "_summed_log_likelihood" - multi_analysis.n_cores = 1 + multi_analysis.n_cores = 2 assert isinstance( multi_analysis._log_likelihood_function, AnalysisPool diff --git a/test_autofit/text/test_text_util.py b/test_autofit/text/test_text_util.py index 5df23f0bd..6b7eed16d 100644 --- a/test_autofit/text/test_text_util.py +++ b/test_autofit/text/test_text_util.py @@ -37,7 +37,7 @@ def test__results_to_file(samples): samples=samples, ) - assert "Maximum Log Likelihood 1.00000000\n" in result_info + assert "Maximum Log Likelihood 1.00000000\n" in result_info def test__search_summary_to_file(model): file_search_summary = path.join(text_path, "search.summary")