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
10 changes: 5 additions & 5 deletions autoarray/plot/output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from os import path
import os
from pathlib import Path
from typing import Union, List, Optional

from autoarray.structures.abstract_structure import Structure
Expand Down Expand Up @@ -100,7 +100,7 @@ def output_path_from(self, format):
return None

if self.format_folder:
output_path = path.join(self.path, format)
output_path = str(Path(self.path) / format)
else:
output_path = self.path

Expand Down Expand Up @@ -156,7 +156,7 @@ def savefig(self, filename: str, output_path: str, format: str):

try:
plt.savefig(
path.join(output_path, f"{filename}.{format}"),
str(Path(output_path) / f"{filename}.{format}"),
bbox_inches=self.bbox_inches,
pad_inches=0.1,
)
Expand Down Expand Up @@ -257,9 +257,9 @@ def to_figure_output_mode(self, filename: str):

import sys

script_name = path.split(sys.argv[0])[-1].replace(".py", "")
script_name = Path(sys.argv[0]).name.replace(".py", "")

output_path = path.join(os.getcwd(), "output_mode", script_name)
output_path = str(Path(os.getcwd()) / "output_mode" / script_name)
os.makedirs(output_path, exist_ok=True)

self.savefig(f"{COUNT}_{filename}", output_path, "png")
11 changes: 6 additions & 5 deletions autoarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import os
from pathlib import Path
from typing import List, Optional, Tuple

import numpy as np
Expand Down Expand Up @@ -310,16 +311,16 @@ def _output_mode_save(fig, filename):

import sys

script_name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
output_path = os.path.join(os.getcwd(), "output_mode", script_name)
script_name = Path(sys.argv[0]).stem
output_path = str(Path(os.getcwd()) / "output_mode" / script_name)
os.makedirs(output_path, exist_ok=True)

count = getattr(_output_mode_save, "_count", -1) + 1
_output_mode_save._count = count

try:
fig.savefig(
os.path.join(output_path, f"{count}_{filename}.png"),
str(Path(output_path) / f"{count}_{filename}.png"),
dpi=150,
bbox_inches="tight",
pad_inches=0.1,
Expand Down Expand Up @@ -371,7 +372,7 @@ def subplot_save(fig, output_path, output_filename, output_format=None):
os.makedirs(output_path, exist_ok=True)
try:
fig.savefig(
os.path.join(output_path, f"{output_filename}.{output_format}"),
str(Path(output_path) / f"{output_filename}.{output_format}"),
bbox_inches="tight",
pad_inches=0.1,
)
Expand Down Expand Up @@ -552,7 +553,7 @@ def save_figure(
continue
try:
fig.savefig(
os.path.join(path, f"{filename}.{fmt}"),
str(Path(path) / f"{filename}.{fmt}"),
dpi=dpi,
bbox_inches="tight",
pad_inches=0.1,
Expand Down
5 changes: 3 additions & 2 deletions autoarray/util/dataset_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
from pathlib import Path


def should_simulate(dataset_path):
Expand All @@ -18,7 +19,7 @@ def should_simulate(dataset_path):
subprocess.run([sys.executable, "scripts/.../simulator.py"], check=True)
"""
if os.environ.get("PYAUTO_SMALL_DATASETS") == "1":
if os.path.exists(dataset_path):
if Path(dataset_path).exists():
shutil.rmtree(dataset_path)

return not os.path.exists(dataset_path)
return not Path(dataset_path).exists()
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

# 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
# sys.path.insert(0, os.path.abspath('.'))
# from pathlib import Path
# sys.path.insert(0, str(Path(".").resolve()))

# -- Project information -----------------------------------------------------

Expand Down
12 changes: 6 additions & 6 deletions test_autoarray/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
import pytest
from matplotlib import pyplot

Expand All @@ -12,7 +12,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 @@ -25,7 +25,7 @@ def make_plot_patch(monkeypatch):
return plot_patch


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


@pytest.fixture(autouse=True, scope="session")
Expand All @@ -34,16 +34,16 @@ 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)


@pytest.fixture(autouse=True)
def set_config_path(request):
# if dirname(realpath(__file__)) in str(request.module):

conf.instance.push(
new_path=path.join(directory, "config"),
output_path=path.join(directory, "output"),
new_path=str(directory / "config"),
output_path=str(directory / "output"),
)


Expand Down
40 changes: 16 additions & 24 deletions test_autoarray/dataset/imaging/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import copy
import os
from os import path

import numpy as np
import pytest
Expand All @@ -9,23 +8,16 @@
import autoarray as aa

from autoarray import exc
from pathlib import Path

test_data_path = path.join(
"{}".format(path.dirname(path.realpath(__file__))),
"files",
)
test_data_path = Path(Path(__file__).resolve().parent) / "files"


@pytest.fixture(name="test_data_path")
def make_test_data_path():
test_data_path = path.join(
"{}".format(os.path.dirname(os.path.realpath(__file__))),
"files",
"array",
"output_test",
)
test_data_path = Path(__file__).resolve().parent / "files" / "array" / "output_test"

if os.path.exists(test_data_path):
if test_data_path.exists():
shutil.rmtree(test_data_path)

os.makedirs(test_data_path)
Expand Down Expand Up @@ -132,9 +124,9 @@ def test__no_noise_map__raises_exception():
def test__from_fits__separate_fits_files__loads_data_psf_noise_map_correctly():
dataset = aa.Imaging.from_fits(
pixel_scales=0.1,
data_path=path.join(test_data_path, "3x3_ones.fits"),
psf_path=path.join(test_data_path, "3x3_twos.fits"),
noise_map_path=path.join(test_data_path, "3x3_threes.fits"),
data_path=Path(test_data_path) / "3x3_ones.fits",
psf_path=Path(test_data_path) / "3x3_twos.fits",
noise_map_path=Path(test_data_path) / "3x3_threes.fits",
)

assert (dataset.data.native == np.ones((3, 3))).all()
Expand All @@ -151,11 +143,11 @@ def test__from_fits__separate_fits_files__loads_data_psf_noise_map_correctly():
def test__from_fits__all_data_in_one_fits_file_multiple_hdus__loads_data_psf_noise_map_correctly():
dataset = aa.Imaging.from_fits(
pixel_scales=0.1,
data_path=path.join(test_data_path, "3x3_multiple_hdu.fits"),
data_path=Path(test_data_path) / "3x3_multiple_hdu.fits",
data_hdu=0,
psf_path=path.join(test_data_path, "3x3_multiple_hdu.fits"),
psf_path=Path(test_data_path) / "3x3_multiple_hdu.fits",
psf_hdu=1,
noise_map_path=path.join(test_data_path, "3x3_multiple_hdu.fits"),
noise_map_path=Path(test_data_path) / "3x3_multiple_hdu.fits",
noise_map_hdu=2,
)

Expand All @@ -178,17 +170,17 @@ def test__output_to_fits__round_trips_data_psf_noise_map_correctly(

fits_imaging(
dataset=imaging_7x7,
data_path=path.join(test_data_path, "data.fits"),
psf_path=path.join(test_data_path, "psf.fits"),
noise_map_path=path.join(test_data_path, "noise_map.fits"),
data_path=Path(test_data_path) / "data.fits",
psf_path=Path(test_data_path) / "psf.fits",
noise_map_path=Path(test_data_path) / "noise_map.fits",
overwrite=True,
)

dataset = aa.Imaging.from_fits(
pixel_scales=0.1,
data_path=path.join(test_data_path, "data.fits"),
psf_path=path.join(test_data_path, "psf.fits"),
noise_map_path=path.join(test_data_path, "noise_map.fits"),
data_path=Path(test_data_path) / "data.fits",
psf_path=Path(test_data_path) / "psf.fits",
noise_map_path=Path(test_data_path) / "noise_map.fits",
)

assert (dataset.data.native == np.ones((7, 7))).all()
Expand Down
45 changes: 17 additions & 28 deletions test_autoarray/dataset/interferometer/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import numpy as np
import os
from os import path
import shutil

import autoarray as aa
import pytest

from autoarray.operators import transformer
from pathlib import Path

test_data_path = path.join(
"{}".format(path.dirname(path.realpath(__file__))),
"files",
)
test_data_path = Path(Path(__file__).resolve().parent) / "files"


def test__dirty_image__shape_native_matches_real_space_mask(
Expand Down Expand Up @@ -70,11 +67,11 @@ def test__dirty_signal_to_noise_map__shape_native_matches_real_space_mask(
def test__from_fits__all_files_in_one_fits__load_using_different_hdus(mask_2d_7x7):
dataset = aa.Interferometer.from_fits(
real_space_mask=mask_2d_7x7,
data_path=path.join(test_data_path, "3x2_multiple_hdu.fits"),
data_path=Path(test_data_path) / "3x2_multiple_hdu.fits",
visibilities_hdu=0,
noise_map_path=path.join(test_data_path, "3x2_multiple_hdu.fits"),
noise_map_path=Path(test_data_path) / "3x2_multiple_hdu.fits",
noise_map_hdu=1,
uv_wavelengths_path=path.join(test_data_path, "3x2_multiple_hdu.fits"),
uv_wavelengths_path=Path(test_data_path) / "3x2_multiple_hdu.fits",
uv_wavelengths_hdu=2,
)

Expand All @@ -85,26 +82,18 @@ def test__from_fits__all_files_in_one_fits__load_using_different_hdus(mask_2d_7x


def test__output_all_arrays(mask_2d_7x7):
test_data_path = path.join(
"{}".format(path.dirname(path.realpath(__file__))),
"files",
)
test_data_path = Path(Path(__file__).resolve().parent) / "files"

dataset = aa.Interferometer.from_fits(
real_space_mask=mask_2d_7x7,
data_path=path.join(test_data_path, "3x2_ones_twos.fits"),
noise_map_path=path.join(test_data_path, "3x2_threes_fours.fits"),
uv_wavelengths_path=path.join(test_data_path, "3x2_fives_sixes.fits"),
data_path=Path(test_data_path) / "3x2_ones_twos.fits",
noise_map_path=Path(test_data_path) / "3x2_threes_fours.fits",
uv_wavelengths_path=Path(test_data_path) / "3x2_fives_sixes.fits",
)

test_data_path = path.join(
"{}".format(path.dirname(path.realpath(__file__))),
"files",
"array",
"output_test",
)
test_data_path = Path(Path(__file__).resolve().parent) / "files" / "array" / "output_test"

if path.exists(test_data_path):
if Path(test_data_path).exists():
shutil.rmtree(test_data_path)

os.makedirs(test_data_path)
Expand All @@ -113,17 +102,17 @@ def test__output_all_arrays(mask_2d_7x7):

fits_interferometer(
dataset=dataset,
data_path=path.join(test_data_path, "data.fits"),
noise_map_path=path.join(test_data_path, "noise_map.fits"),
uv_wavelengths_path=path.join(test_data_path, "uv_wavelengths.fits"),
data_path=Path(test_data_path) / "data.fits",
noise_map_path=Path(test_data_path) / "noise_map.fits",
uv_wavelengths_path=Path(test_data_path) / "uv_wavelengths.fits",
overwrite=True,
)

dataset = aa.Interferometer.from_fits(
real_space_mask=mask_2d_7x7,
data_path=path.join(test_data_path, "data.fits"),
noise_map_path=path.join(test_data_path, "noise_map.fits"),
uv_wavelengths_path=path.join(test_data_path, "uv_wavelengths.fits"),
data_path=Path(test_data_path) / "data.fits",
noise_map_path=Path(test_data_path) / "noise_map.fits",
uv_wavelengths_path=Path(test_data_path) / "uv_wavelengths.fits",
)

assert (dataset.data == np.array([1.0 + 2.0j, 1.0 + 2.0j, 1.0 + 2.0j])).all()
Expand Down
Loading
Loading