Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autofit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .database.aggregator import Aggregator
from .aggregator.summary.aggregate_csv import AggregateCSV
from .aggregator.summary.aggregate_images import AggregateImages
from .aggregator.summary.aggregate_fits import AggregateFITS, FitFITS
from .aggregator.summary.aggregate_fits import AggregateFITS, FITSFit
from .database.aggregator import Query
from autofit.aggregator.fit_interface import Fit
from .aggregator.search_output import SearchOutput
Expand Down
4 changes: 4 additions & 0 deletions autofit/aggregator/summary/aggregate_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ def save(self, path: Union[str, Path]):
path
The path to save the file to
"""

folder_path = path.parent if path.suffix else path
folder_path.mkdir(parents=True, exist_ok=True)

with open(path, "w") as f:
writer = csv.DictWriter(
f,
Expand Down
2 changes: 1 addition & 1 deletion autofit/aggregator/summary/aggregate_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def subplot_filename(subplot: Enum) -> str:
)


class FitFITS(Enum):
class FITSFit(Enum):
"""
The HDUs that can be extracted from the fit.fits file.
"""
Expand Down
2 changes: 1 addition & 1 deletion autofit/non_linear/fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
Interfaces with any non-linear search to fit the model to the data and return a log likelihood via
the analysis.

The interface of a non-linear search and fitness function is summarized as follows:
The interface of a non-linear search and fitness function is summarised as follows:

1) The non-linear search samples a new set of model parameters, which are passed to the fitness
function's `__call__` method.
Expand Down
4 changes: 2 additions & 2 deletions autofit/non_linear/paths/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def _save_metadata(self, search_name):

def _save_model_info(self, model):
"""
Save the model.info file, which summarizes every parameter and prior.
Save the model.info file, which summarises every parameter and prior.
"""
with open_(self.output_path / "model.info", "w+") as f:
f.write(model.info)
Expand All @@ -476,7 +476,7 @@ def _save_model_info(self, model):

def _save_model_start_point(self, info):
"""
Save the model.start file, which summarizes the start point of every parameter.
Save the model.start file, which summarises the start point of every parameter.
"""
with open_(self.output_path / "model.start", "w+") as f:
f.write(info)
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ A few examples of the options available include:

- For the ``samples.csv`` file, all samples with a weight below a certain value can be automatically removed.

- Customization of the ``samples_summary.json`` file, which summarizes the results of the model-fit (e.g. the maximum
- Customization of the ``samples_summary.json`` file, which summarises the results of the model-fit (e.g. the maximum
log likelihood model, the median PDF model and 3 sigma error). These results are computed using the full set of
samples, ensuring samples removal via a weight cut does not impact the results.

Expand Down
16 changes: 8 additions & 8 deletions test_autofit/aggregator/summary_files/test_aggregate_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def test_add_column(

dicts = load_output()

assert dicts[0]["galaxies_lens_bulge_centre_centre_0"] == "-1.0"
assert dicts[1]["galaxies_lens_bulge_centre_centre_0"] == "-5.0"
assert dicts[0]["galaxies_lens_bulge_centre_centre_0"] == "-1.0" or "-5.0"
assert dicts[1]["galaxies_lens_bulge_centre_centre_0"] == "-5.0" or "-1.0"


def test_use_max_log_likelihood(
Expand All @@ -79,8 +79,8 @@ def test_use_max_log_likelihood(

dicts = load_output()

assert dicts[0]["galaxies_lens_bulge_centre_centre_0"] == "-1.0"
assert dicts[1]["galaxies_lens_bulge_centre_centre_0"] == "-5.0"
assert dicts[0]["galaxies_lens_bulge_centre_centre_0"] == "-1.0" or "-5.0"
assert dicts[1]["galaxies_lens_bulge_centre_centre_0"] == "-5.0" or "-1.0"


def test_add_named_column(
Expand All @@ -96,8 +96,8 @@ def test_add_named_column(

dicts = load_output()

assert dicts[0]["centre_0"] == "-1.0"
assert dicts[1]["centre_0"] == "-5.0"
assert dicts[0]["centre_0"] == "-1.0" or "-5.0"
assert dicts[1]["centre_0"] == "-5.0" or "-1.0"


def test_add_latent_column(
Expand All @@ -112,8 +112,8 @@ def test_add_latent_column(

dicts = load_output()

assert dicts[0]["latent_value"] == "1.0"
assert dicts[1]["latent_value"] == "2.0"
assert dicts[0]["latent_value"] == "1.0" or "2.0"
assert dicts[1]["latent_value"] == "2.0" or "1.0"


def test_computed_column(
Expand Down
16 changes: 8 additions & 8 deletions test_autofit/aggregator/summary_files/test_aggregate_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def make_summary(aggregator):
def test_aggregate(summary):
result = summary.extract_fits(
[
af.FitFITS.ModelImage,
af.FitFITS.ResidualMap,
af.FITSFit.ModelImage,
af.FITSFit.ResidualMap,
],
)
assert len(result) == 5
Expand All @@ -25,8 +25,8 @@ def test_output_to_file(summary, output_directory):
folder,
name="id",
hdus=[
af.FitFITS.ModelImage,
af.FitFITS.ResidualMap,
af.FITSFit.ModelImage,
af.FITSFit.ResidualMap,
],
)
assert list(folder.glob("*"))
Expand All @@ -37,11 +37,11 @@ def test_list_of_names(summary, output_directory):
output_directory,
["one", "two"],
[
af.FitFITS.ModelImage,
af.FitFITS.ResidualMap,
af.FITSFit.ModelImage,
af.FITSFit.ResidualMap,
],
)
assert [path.name for path in Path(output_directory).glob("*.fits")] == [
assert set([path.name for path in Path(output_directory).glob("*.fits")]) == set([
"one.fits",
"two.fits",
]
])
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ def test_list_of_names(aggregate, output_directory):
SubplotFit.SourceModelImage,
],
)
assert [path.name for path in Path(output_directory).glob("*.png")] == [
assert set([path.name for path in Path(output_directory).glob("*.png")]) == set([
"two.png",
"one.png",
]
])


def test_output_to_folder_name(
Expand Down
13 changes: 7 additions & 6 deletions test_autofit/aggregator/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ def make_directory():


def test_without(directory):

aggregator = Aggregator.from_directory(directory)
model = list(aggregator)[0].model
assert model.cls is af.Gaussian
model_list = [agg.model for agg in aggregator]

assert any([getattr(model, "cls", False) is af.Gaussian for model in model_list])


def test_with():
aggregator = Aggregator.from_directory(
Path(__file__).parent,
reference={"": get_class_path(af.Exponential)},
)
output = list(aggregator)[0]
model = output.model
assert model.cls is af.Exponential

output_list = list(aggregator)
model_list = [output.model for output in output_list]
assert any([getattr(model, "cls", False) is af.Exponential for model in model_list])

@pytest.fixture(name="database_path")
def database_path(output_directory):
Expand Down
Loading