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
12 changes: 6 additions & 6 deletions autogalaxy/analysis/chaining_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from os import path
from pathlib import Path

from autoconf import conf
from autoconf.dictable import from_json, output_to_json
Expand Down Expand Up @@ -267,11 +267,11 @@ def lp_chain_tracer_from(light_result, settings_search):
else:
unique_tag = ""

lp_chain_tracer_path = path.join(
conf.instance.output_path,
settings_search.path_prefix,
unique_tag,
"light_dark_lp_chain_tracer.json",
lp_chain_tracer_path = (
Path(conf.instance.output_path)
/ settings_search.path_prefix
/ unique_tag
/ "light_dark_lp_chain_tracer.json"
)

try:
Expand Down
3 changes: 2 additions & 1 deletion autogalaxy/plot/plot_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from pathlib import Path
import numpy as np

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -88,7 +89,7 @@ def _save_subplot(fig, output_path, output_filename, output_format=None,
plt.show()
else:
os.makedirs(str(output_path), exist_ok=True)
fpath = os.path.join(str(output_path), f"{output_filename}.{fmt}")
fpath = Path(output_path) / f"{output_filename}.{fmt}"
fig.savefig(fpath, dpi=dpi, bbox_inches="tight", pad_inches=0.1)
plt.close(fig)

Expand Down
3 changes: 2 additions & 1 deletion autogalaxy/util/plot_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from pathlib import Path
import numpy as np

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -88,7 +89,7 @@ def _save_subplot(fig, output_path, output_filename, output_format=None,
plt.show()
else:
os.makedirs(str(output_path), exist_ok=True)
fpath = os.path.join(str(output_path), f"{output_filename}.{fmt}")
fpath = Path(output_path) / f"{output_filename}.{fmt}"
fig.savefig(fpath, dpi=dpi, bbox_inches="tight", pad_inches=0.1)
plt.close(fig)

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 autogalaxy

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

from autoconf.dictable import from_json

import autofit as af
import autogalaxy as ag

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


def test__galaxies_via_instance(masked_imaging_7x7):
Expand Down
4 changes: 2 additions & 2 deletions test_autogalaxy/analysis/analysis/test_analysis_dataset.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
import numpy as np
from os import path

import autofit as af
import autogalaxy as ag
from pathlib import Path

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


def test__instance_with_associated_adapt_images_from__galaxy_name_image_dict(
Expand Down
26 changes: 12 additions & 14 deletions test_autogalaxy/analysis/test_plotter.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import csv
import shutil
import numpy as np
from os import path
from pathlib import Path
import pytest

import autogalaxy as ag

from autogalaxy.analysis.plotter import Plotter

directory = path.dirname(path.abspath(__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__galaxies(masked_imaging_7x7, galaxies_7x7, plot_path, plot_patch):
if path.exists(plot_path):
if plot_path.exists():
shutil.rmtree(plot_path)

plotter = Plotter(image_path=plot_path)
Expand All @@ -27,11 +27,11 @@ def test__galaxies(masked_imaging_7x7, galaxies_7x7, plot_path, plot_patch):
grid=masked_imaging_7x7.grids.lp,
)

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

image = ag.ndarray_via_fits_from(
file_path=path.join(plot_path, "galaxy_images.fits"), hdu=1
file_path=plot_path / "galaxy_images.fits", hdu=1
)

assert image.shape == (5, 5)
Expand All @@ -42,7 +42,7 @@ def test__inversion(
plot_path,
plot_patch,
):
if path.exists(plot_path):
if plot_path.exists():
shutil.rmtree(plot_path)

plotter = Plotter(image_path=plot_path)
Expand All @@ -51,10 +51,10 @@ def test__inversion(
inversion=rectangular_inversion_7x7_3x3,
)

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

with open(
path.join(plot_path, "source_plane_reconstruction_0.csv"), mode="r"
plot_path / "source_plane_reconstruction_0.csv", mode="r"
) as file:
reader = csv.reader(file)
header_list = next(reader) # ['y', 'x', 'reconstruction', 'noise_map']
Expand Down Expand Up @@ -90,12 +90,10 @@ def test__adapt_images(
adapt_images=adapt_images,
)

plot_path = path.join(plot_path)

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

image = ag.ndarray_via_fits_from(
file_path=path.join(plot_path, "adapt_images.fits"), hdu=1
file_path=plot_path / "adapt_images.fits", hdu=1
)

assert image.shape == (5, 5)
12 changes: 6 additions & 6 deletions test_autogalaxy/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import os
from os import path
from pathlib import Path
import pytest
from matplotlib import pyplot
from unittest.mock import MagicMock
Expand All @@ -20,7 +20,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 @@ -35,14 +35,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 @@ -52,7 +52,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)


### Datasets ###
Expand Down
4 changes: 2 additions & 2 deletions test_autogalaxy/ellipse/model/test_analysis_ellipse.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from os import path
from pathlib import Path

import autofit as af
import autogalaxy as ag

from autogalaxy.ellipse.model.result import ResultEllipse

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


def test__make_result__result_imaging_is_returned(masked_imaging_7x7):
Expand Down
11 changes: 3 additions & 8 deletions test_autogalaxy/galaxy/plot/test_adapt_plotters.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
from os import path
from pathlib import Path

import autogalaxy.plot as aplt
import pytest


@pytest.fixture(name="plot_path")
def make_adapt_plotter_setup():
return path.join(
"{}".format(path.dirname(path.realpath(__file__))),
"files",
"plots",
"adapt",
)
return Path(__file__).resolve().parent / "files" / "plots" / "adapt"


def test__plot_adapt_adapt_images(
Expand All @@ -22,4 +17,4 @@ def test__plot_adapt_adapt_images(
output_path=plot_path,
output_format="png",
)
assert path.join(plot_path, "adapt_images.png") in plot_patch.paths
assert str(plot_path / "adapt_images.png") in plot_patch.paths
12 changes: 5 additions & 7 deletions test_autogalaxy/galaxy/plot/test_galaxies_plotter.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from os import path
from pathlib import Path

import autogalaxy.plot as aplt
import pytest

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


@pytest.fixture(name="plot_path")
def make_plotter_setup():
return path.join(
"{}".format(path.dirname(path.realpath(__file__))), "files", "plots", "galaxies"
)
return Path(__file__).resolve().parent / "files" / "plots" / "galaxies"


def test__galaxies_sub_plot_output(galaxies_x2_7x7, grid_2d_7x7, plot_path, plot_patch):
Expand All @@ -20,12 +18,12 @@ def test__galaxies_sub_plot_output(galaxies_x2_7x7, grid_2d_7x7, plot_path, plot
output_path=plot_path,
output_format="png",
)
assert path.join(plot_path, "galaxies.png") in plot_patch.paths
assert str(plot_path / "galaxies.png") in plot_patch.paths

aplt.subplot_galaxy_images(
galaxies=galaxies_x2_7x7,
grid=grid_2d_7x7,
output_path=plot_path,
output_format="png",
)
assert path.join(plot_path, "galaxy_images.png") in plot_patch.paths
assert str(plot_path / "galaxy_images.png") in plot_patch.paths
18 changes: 8 additions & 10 deletions test_autogalaxy/galaxy/plot/test_galaxy_plotters.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from os import path
from pathlib import Path

import autogalaxy.plot as aplt
import pytest

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


@pytest.fixture(name="plot_path")
def make_galaxy_plotter_setup():
return path.join(
"{}".format(path.dirname(path.realpath(__file__))), "files", "plots", "galaxy"
)
return Path(__file__).resolve().parent / "files" / "plots" / "galaxy"


def test__subplots_galaxy_quantities__all_are_output(
Expand All @@ -26,7 +24,7 @@ def test__subplots_galaxy_quantities__all_are_output(
output_format="png",
)

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

aplt.subplot_galaxy_mass_profiles(
galaxy=gal_x1_lp_x1_mp,
Expand All @@ -39,7 +37,7 @@ def test__subplots_galaxy_quantities__all_are_output(
output_format="png",
)

assert path.join(plot_path, "convergence.png") in plot_patch.paths
assert path.join(plot_path, "potential.png") in plot_patch.paths
assert path.join(plot_path, "deflections_y.png") in plot_patch.paths
assert path.join(plot_path, "deflections_x.png") in plot_patch.paths
assert str(plot_path / "convergence.png") in plot_patch.paths
assert str(plot_path / "potential.png") in plot_patch.paths
assert str(plot_path / "deflections_y.png") in plot_patch.paths
assert str(plot_path / "deflections_x.png") in plot_patch.paths
6 changes: 2 additions & 4 deletions test_autogalaxy/galaxy/test_galaxy.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 pytest

from autoconf.dictable import from_json, output_to_json
Expand Down Expand Up @@ -734,9 +734,7 @@ def test__decorator__oversample_uniform__profile_offset_from_centre__correct_num


def test__output_to_and_load_from_json():
json_file = path.join(
"{}".format(path.dirname(path.realpath(__file__))), "files", "galaxy.json"
)
json_file = Path(__file__).resolve().parent / "files" / "galaxy.json"

g0 = ag.Galaxy(
redshift=1.0,
Expand Down
4 changes: 2 additions & 2 deletions test_autogalaxy/imaging/model/test_analysis_imaging.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from os import path
from pathlib import Path

import autofit as af
import autogalaxy as ag

from autogalaxy.imaging.model.result import ResultImaging

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


def test__make_result__result_imaging_is_returned(masked_imaging_7x7):
Expand Down
Loading
Loading