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
4 changes: 2 additions & 2 deletions autolens/analysis/positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""
import numpy as np
from typing import Optional
from os import path
from pathlib import Path

import autoarray as aa
import autofit as af
Expand Down Expand Up @@ -124,7 +124,7 @@ def output_positions_info(

flag = "w+" if overwrite_file else "a+"

with open_(path.join(output_path, "positions.info"), flag) as f:
with open_(Path(output_path) / "positions.info", flag) as f:

positions_fit = SourceMaxSeparation(
data=self.positions,
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# documentation root, use Path(...).resolve() to make it absolute, like shown here.
#

import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, str(Path(".").resolve()))

import autolens

Expand Down
4 changes: 2 additions & 2 deletions test_autolens/analysis/analysis/test_analysis_dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os import path
from pathlib import Path
import os
import pytest

Expand All @@ -9,7 +9,7 @@
import autolens as al
from autolens import exc

directory = path.dirname(path.realpath(__file__))
directory = Path(__file__).resolve().parent


def test__modify_before_fit__inversion_no_positions_likelihood__raises_exception(
Expand Down
4 changes: 2 additions & 2 deletions test_autolens/analysis/analysis/test_analysis_lens.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from os import path
from pathlib import Path
import pytest

import autofit as af
import autolens as al

directory = path.dirname(path.realpath(__file__))
directory = Path(__file__).resolve().parent


def test__tracer_for_instance(analysis_imaging_7x7):
Expand Down
4 changes: 2 additions & 2 deletions test_autolens/analysis/test_analysis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from os import path
from pathlib import Path
import os
import pytest

Expand All @@ -10,7 +10,7 @@
import autolens as al
from autolens import exc

directory = path.dirname(path.realpath(__file__))
directory = Path(__file__).resolve().parent


def test__tracer_for_instance(analysis_imaging_7x7):
Expand Down
17 changes: 8 additions & 9 deletions test_autolens/analysis/test_plotter.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import os
import shutil
from os import path
from pathlib import Path

import pytest
import autolens as al
from autolens.analysis import plotter as vis

directory = path.dirname(path.realpath(__file__))
directory = Path(__file__).resolve().parent


@pytest.fixture(name="plot_path")
def make_plotter_plotter_setup():
return path.join("{}".format(directory), "files")
return directory / "files"


def test__tracer(masked_imaging_7x7, tracer_x2_plane_7x7, plot_path, plot_patch):
if os.path.exists(plot_path):
if plot_path.exists():
shutil.rmtree(plot_path)

plotter = vis.Plotter(image_path=plot_path)
Expand All @@ -25,21 +24,21 @@ def test__tracer(masked_imaging_7x7, tracer_x2_plane_7x7, plot_path, plot_patch)
grid=masked_imaging_7x7.grids.lp,
)

assert path.join(plot_path, "galaxies_images.png") in plot_patch.paths
assert str(plot_path / "galaxies_images.png") in plot_patch.paths

image = al.ndarray_via_fits_from(
file_path=path.join(plot_path, "tracer.fits"), hdu=0
file_path=plot_path / "tracer.fits", hdu=0
)

assert image.shape == (5, 5)


def test__image_with_positions(image_7x7, positions_x2, plot_path, plot_patch):
if os.path.exists(plot_path):
if plot_path.exists():
shutil.rmtree(plot_path)

plotter = vis.Plotter(image_path=plot_path)

plotter.image_with_positions(image=image_7x7, positions=positions_x2)

assert path.join(plot_path, "image_with_positions.png") in plot_patch.paths
assert str(plot_path / "image_with_positions.png") in plot_patch.paths
8 changes: 3 additions & 5 deletions test_autolens/analysis/test_positions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from os import path
from pathlib import Path
import pytest

from autoconf.dictable import output_to_json, from_json, from_dict
Expand All @@ -21,9 +21,7 @@ def test__check_positions_on_instantiation():


def test__output_positions_info():
output_path = path.join(
"{}".format(os.path.dirname(os.path.realpath(__file__))), "files"
)
output_path = Path(__file__).resolve().parent / "files"

positions_likelihood = al.PositionsLH(
positions=al.Grid2DIrregular([(1.0, 2.0), (3.0, 4.0)]), threshold=0.1
Expand All @@ -35,7 +33,7 @@ def test__output_positions_info():

positions_likelihood.output_positions_info(output_path=output_path, tracer=tracer)

positions_file = path.join(output_path, "positions.info")
positions_file = output_path / "positions.info"

with open_(positions_file, "r") as f:
output = f.readlines()
Expand Down
4 changes: 2 additions & 2 deletions test_autolens/analysis/test_result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
from pathlib import Path
import numpy as np
import pytest

Expand All @@ -9,7 +9,7 @@
from autolens.analysis import result as res
from autolens.imaging.model.result import ResultImaging

directory = os.path.dirname(os.path.realpath(__file__))
directory = Path(__file__).resolve().parent


def test__max_log_likelihood_tracer(
Expand Down
12 changes: 6 additions & 6 deletions test_autolens/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from os import path
from pathlib import Path
from unittest.mock import MagicMock

import pytest
Expand All @@ -21,7 +21,7 @@ def __init__(self):
self.paths = []

def __call__(self, path, *args, **kwargs):
self.paths.append(path)
self.paths.append(str(path))


@pytest.fixture(name="plot_patch")
Expand All @@ -34,14 +34,14 @@ def make_plot_patch(monkeypatch):
return plot_patch


directory = path.dirname(path.realpath(__file__))
directory = Path(__file__).resolve().parent


@pytest.fixture(autouse=True)
def set_config_path(request):
conf.instance.push(
new_path=path.join(directory, "config"),
output_path=path.join(directory, "output"),
new_path=directory / "config",
output_path=directory / "output",
)


Expand All @@ -51,7 +51,7 @@ def remove_logs():
for d, _, files in os.walk(directory):
for file in files:
if file.endswith(".log"):
os.remove(path.join(d, file))
os.remove(Path(d) / file)


############
Expand Down
4 changes: 2 additions & 2 deletions test_autolens/imaging/model/test_analysis_imaging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os import path
from pathlib import Path
import pytest

import autofit as af
Expand All @@ -10,7 +10,7 @@
from autolens import exc


directory = path.dirname(path.realpath(__file__))
directory = Path(__file__).resolve().parent


def test__make_result__result_imaging_is_returned(masked_imaging_7x7):
Expand Down
23 changes: 11 additions & 12 deletions test_autolens/imaging/model/test_plotter_imaging.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import os
import shutil
from os import path
from pathlib import Path

import pytest
import autolens as al
from autolens.imaging.model.plotter import PlotterImaging

directory = path.dirname(path.realpath(__file__))
directory = Path(__file__).resolve().parent


@pytest.fixture(name="plot_path")
def make_plotter_plotter_setup():
return path.join("{}".format(directory), "files")
return directory / "files"


def test__fit_imaging(
fit_imaging_x2_plane_inversion_7x7, plot_path, plot_patch
):
if os.path.exists(plot_path):
if plot_path.exists():
shutil.rmtree(plot_path)

plotter = PlotterImaging(image_path=plot_path)
Expand All @@ -26,30 +25,30 @@ def test__fit_imaging(
fit=fit_imaging_x2_plane_inversion_7x7,
)

assert path.join(plot_path, "tracer.png") in plot_patch.paths
assert path.join(plot_path, "fit.png") in plot_patch.paths
assert path.join(plot_path, "fit_log10.png") in plot_patch.paths
assert str(plot_path / "tracer.png") in plot_patch.paths
assert str(plot_path / "fit.png") in plot_patch.paths
assert str(plot_path / "fit_log10.png") in plot_patch.paths

image = al.ndarray_via_fits_from(
file_path=path.join(plot_path, "fit.fits"), hdu=0
file_path=plot_path / "fit.fits", hdu=0
)

assert image.shape == (5, 5)

image = al.ndarray_via_fits_from(
file_path=path.join(plot_path, "model_galaxy_images.fits"), hdu=0
file_path=plot_path / "model_galaxy_images.fits", hdu=0
)

assert image.shape == (5, 5)

def test__fit_imaging_combined(
fit_imaging_x2_plane_inversion_7x7, plot_path, plot_patch
):
if path.exists(plot_path):
if plot_path.exists():
shutil.rmtree(plot_path)

visualizer = PlotterImaging(image_path=plot_path)

visualizer.fit_imaging_combined(fit_list=2 * [fit_imaging_x2_plane_inversion_7x7])

assert path.join(plot_path, "fit_combined.png") in plot_patch.paths
assert str(plot_path / "fit_combined.png") in plot_patch.paths
Loading
Loading