From 86019f82794de4a4d901e8d441f427464a7c45b4 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Thu, 7 May 2026 10:35:50 +0100 Subject: [PATCH] refactor: replace os.path with pathlib Drop legacy `from os import path` and `os.path.X` usages in workspace scripts in favour of `pathlib.Path`. Follow-up to library refactor in PyAutoLabs/PyAutoFit#1257. Co-Authored-By: Claude Opus 4.7 (1M context) --- plotting_alignment/imaging_delaunay.py | 9 ++++----- plotting_alignment/imaging_rectangular.py | 9 ++++----- .../imaging_rectangular_no_interp.py | 9 ++++----- .../plot/imaging/orientation/parametric.py | 12 ++++++------ .../plot/imaging/orientation/pix.py | 12 ++++++------ .../plot/imaging/orientation/simulator.py | 12 ++++++------ .../interferometer/orientation/parametric.py | 12 ++++++------ .../plot/interferometer/orientation/pix.py | 12 ++++++------ .../plot/interferometer/orientation/simulator.py | 16 ++++++++-------- slam_pipeline/dspl.py | 12 ++++++------ slam_pipeline/light_dark_mge.py | 9 ++++----- 11 files changed, 60 insertions(+), 64 deletions(-) diff --git a/plotting_alignment/imaging_delaunay.py b/plotting_alignment/imaging_delaunay.py index 03eb978..5f549ed 100644 --- a/plotting_alignment/imaging_delaunay.py +++ b/plotting_alignment/imaging_delaunay.py @@ -34,7 +34,6 @@ import numpy as np import jax from jax import grad -from os import path import autofit as af import autolens as al @@ -79,9 +78,9 @@ dataset_path = Path("dataset", "imaging", dataset_type, dataset_name) dataset = al.Imaging.from_fits( - data_path=path.join(dataset_path, "data.fits"), - psf_path=path.join(dataset_path, "psf.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), + data_path=Path(dataset_path) / "data.fits", + psf_path=Path(dataset_path) / "psf.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", pixel_scales=pixel_scale, over_sample_size_lp=sub_size, over_sample_size_pixelization=sub_size, @@ -250,7 +249,7 @@ import autolens.plot as aplt import os -file_path = os.path.join(al.__version__) +file_path = Path(al.__version__) instance = model.instance_from_prior_medians() diff --git a/plotting_alignment/imaging_rectangular.py b/plotting_alignment/imaging_rectangular.py index 5a49dfc..7301935 100644 --- a/plotting_alignment/imaging_rectangular.py +++ b/plotting_alignment/imaging_rectangular.py @@ -34,7 +34,6 @@ import numpy as np import jax from jax import grad -from os import path import autofit as af import autolens as al @@ -78,9 +77,9 @@ dataset_path = Path("dataset", "imaging", dataset_type, dataset_name) dataset = al.Imaging.from_fits( - data_path=path.join(dataset_path, "data.fits"), - psf_path=path.join(dataset_path, "psf.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), + data_path=Path(dataset_path) / "data.fits", + psf_path=Path(dataset_path) / "psf.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", pixel_scales=pixel_scale, over_sample_size_lp=sub_size, over_sample_size_pixelization=sub_size, @@ -246,7 +245,7 @@ import autolens.plot as aplt import os -file_path = os.path.join(al.__version__) +file_path = Path(al.__version__) instance = model.instance_from_prior_medians() diff --git a/plotting_alignment/imaging_rectangular_no_interp.py b/plotting_alignment/imaging_rectangular_no_interp.py index 1f075ad..6653c0e 100644 --- a/plotting_alignment/imaging_rectangular_no_interp.py +++ b/plotting_alignment/imaging_rectangular_no_interp.py @@ -34,7 +34,6 @@ import numpy as np import jax from jax import grad -from os import path import autofit as af import autolens as al @@ -78,9 +77,9 @@ dataset_path = Path("dataset", "imaging", dataset_type, dataset_name) dataset = al.Imaging.from_fits( - data_path=path.join(dataset_path, "data.fits"), - psf_path=path.join(dataset_path, "psf.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), + data_path=Path(dataset_path) / "data.fits", + psf_path=Path(dataset_path) / "psf.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", pixel_scales=pixel_scale, over_sample_size_lp=sub_size, over_sample_size_pixelization=sub_size, @@ -244,7 +243,7 @@ import autolens.plot as aplt import os -file_path = os.path.join(al.__version__) +file_path = Path(al.__version__) instance = model.instance_from_prior_medians() diff --git a/plotting_alignment/plot/imaging/orientation/parametric.py b/plotting_alignment/plot/imaging/orientation/parametric.py index c53c110..80eac26 100644 --- a/plotting_alignment/plot/imaging/orientation/parametric.py +++ b/plotting_alignment/plot/imaging/orientation/parametric.py @@ -15,9 +15,9 @@ # %cd $workspace_path # print(f"Working Directory has been set to `{workspace_path}`") -from os import path import autolens as al import autolens.plot as aplt +from pathlib import Path """ __Dataset__ @@ -26,12 +26,12 @@ """ dataset_type = "imaging" dataset_name = "orientation" -dataset_path = path.join("dataset", dataset_type, dataset_name) +dataset_path = Path("dataset") / dataset_type / dataset_name dataset = al.Imaging.from_fits( - data_path=path.join(dataset_path, "data.fits"), - psf_path=path.join(dataset_path, "psf.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), + data_path=Path(dataset_path) / "data.fits", + psf_path=Path(dataset_path) / "psf.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", pixel_scales=0.1, ) @@ -78,7 +78,7 @@ __Output__ """ output = aplt.Output( - path=path.join("plot", "imaging", "orientation", "plots", "parametric"), + path=Path("plot") / "imaging" / "orientation" / "plots" / "parametric", format="png", ) diff --git a/plotting_alignment/plot/imaging/orientation/pix.py b/plotting_alignment/plot/imaging/orientation/pix.py index 7d8fd43..4c975a8 100644 --- a/plotting_alignment/plot/imaging/orientation/pix.py +++ b/plotting_alignment/plot/imaging/orientation/pix.py @@ -15,9 +15,9 @@ # %cd $workspace_path # print(f"Working Directory has been set to `{workspace_path}`") -from os import path import autolens as al import autolens.plot as aplt +from pathlib import Path """ __Dataset__ @@ -26,12 +26,12 @@ """ dataset_type = "imaging" dataset_name = "orientation" -dataset_path = path.join("dataset", dataset_type, dataset_name) +dataset_path = Path("dataset") / dataset_type / dataset_name dataset = al.Imaging.from_fits( - data_path=path.join(dataset_path, "data.fits"), - psf_path=path.join(dataset_path, "psf.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), + data_path=Path(dataset_path) / "data.fits", + psf_path=Path(dataset_path) / "psf.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", pixel_scales=0.1, ) @@ -76,7 +76,7 @@ __Output__ """ output = aplt.Output( - path=path.join("plot", "imaging", "orientation", "plots", "pix_delaunay"), + path=Path("plot") / "imaging" / "orientation" / "plots" / "pix_delaunay", format="png", ) diff --git a/plotting_alignment/plot/imaging/orientation/simulator.py b/plotting_alignment/plot/imaging/orientation/simulator.py index e005a22..fbb98d7 100644 --- a/plotting_alignment/plot/imaging/orientation/simulator.py +++ b/plotting_alignment/plot/imaging/orientation/simulator.py @@ -26,9 +26,9 @@ # %cd $workspace_path # print(f"Working Directory has been set to `{workspace_path}`") -from os import path import autolens as al import autolens.plot as aplt +from pathlib import Path """ __Dataset Paths__ @@ -37,7 +37,7 @@ """ dataset_type = "imaging" dataset_name = "orientation" -dataset_path = path.join("dataset", dataset_type, dataset_name) +dataset_path = Path("dataset") / dataset_type / dataset_name """ __Simulate__ @@ -122,9 +122,9 @@ Output the simulated dataset to the dataset path as .fits files. """ dataset.output_to_fits( - data_path=path.join(dataset_path, "data.fits"), - psf_path=path.join(dataset_path, "psf.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), + data_path=Path(dataset_path) / "data.fits", + psf_path=Path(dataset_path) / "psf.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", overwrite=True, ) @@ -146,7 +146,7 @@ """ al.output_to_json( obj=tracer, - file_path=path.join(dataset_path, "tracer.json"), + file_path=Path(dataset_path) / "tracer.json", ) """ diff --git a/plotting_alignment/plot/interferometer/orientation/parametric.py b/plotting_alignment/plot/interferometer/orientation/parametric.py index ed30bd7..5ac1019 100644 --- a/plotting_alignment/plot/interferometer/orientation/parametric.py +++ b/plotting_alignment/plot/interferometer/orientation/parametric.py @@ -15,10 +15,10 @@ # %cd $workspace_path # print(f"Working Directory has been set to `{workspace_path}`") -from os import path import numpy as np import autolens as al import autolens.plot as aplt +from pathlib import Path """ __Dataset__ @@ -27,16 +27,16 @@ """ dataset_type = "interferometer" dataset_name = "orientation" -dataset_path = path.join("dataset", dataset_type, dataset_name) +dataset_path = Path("dataset") / dataset_type / dataset_name real_space_mask = al.Mask2D.circular( shape_native=(200, 200), pixel_scales=0.05, radius=4.0, centre=(0.5, 0.5) ) dataset = al.Interferometer.from_fits( - data_path=path.join(dataset_path, "data.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), - uv_wavelengths_path=path.join(dataset_path, "uv_wavelengths.fits"), + data_path=Path(dataset_path) / "data.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", + uv_wavelengths_path=Path(dataset_path) / "uv_wavelengths.fits", real_space_mask=real_space_mask, transformer_class=al.TransformerNUFFT, ) @@ -75,7 +75,7 @@ __Output__ """ output = aplt.Output( - path=path.join("plot", "interferometer", "orientation", "plots", "parametric"), + path=Path("plot") / "interferometer" / "orientation" / "plots" / "parametric", format="png", ) diff --git a/plotting_alignment/plot/interferometer/orientation/pix.py b/plotting_alignment/plot/interferometer/orientation/pix.py index d98acaf..ae8426c 100644 --- a/plotting_alignment/plot/interferometer/orientation/pix.py +++ b/plotting_alignment/plot/interferometer/orientation/pix.py @@ -15,10 +15,10 @@ # %cd $workspace_path # print(f"Working Directory has been set to `{workspace_path}`") -from os import path import numpy as np import autolens as al import autolens.plot as aplt +from pathlib import Path """ __Dataset__ @@ -27,16 +27,16 @@ """ dataset_type = "interferometer" dataset_name = "orientation" -dataset_path = path.join("dataset", dataset_type, dataset_name) +dataset_path = Path("dataset") / dataset_type / dataset_name real_space_mask = al.Mask2D.circular( shape_native=(800, 800), pixel_scales=0.05, radius=4.0, centre=(0.5, 0.5) ) dataset = al.Interferometer.from_fits( - data_path=path.join(dataset_path, "data.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), - uv_wavelengths_path=path.join(dataset_path, "uv_wavelengths.fits"), + data_path=Path(dataset_path) / "data.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", + uv_wavelengths_path=Path(dataset_path) / "uv_wavelengths.fits", real_space_mask=real_space_mask, transformer_class=al.TransformerNUFFT, ) @@ -73,7 +73,7 @@ __Output__ """ output = aplt.Output( - path=path.join("plot", "interferometer", "orientation", "plots", "pix_delaunay"), + path=Path("plot") / "interferometer" / "orientation" / "plots" / "pix_delaunay", format="png", ) diff --git a/plotting_alignment/plot/interferometer/orientation/simulator.py b/plotting_alignment/plot/interferometer/orientation/simulator.py index bc8388b..fcf5961 100644 --- a/plotting_alignment/plot/interferometer/orientation/simulator.py +++ b/plotting_alignment/plot/interferometer/orientation/simulator.py @@ -14,9 +14,9 @@ # %cd $workspace_path # print(f"Working Directory has been set to `{workspace_path}`") -from os import path import autolens as al import autolens.plot as aplt +from pathlib import Path """ The `dataset_type` describes the type of data being simulated (in this case, `Interferometer` data) and `dataset_name` @@ -28,7 +28,7 @@ """ dataset_type = "interferometer" dataset_name = "orientation" -dataset_path = path.join("dataset", dataset_type, dataset_name) +dataset_path = Path("dataset") / dataset_type / dataset_name """ @@ -46,9 +46,9 @@ can be fitted extremely efficiently. The `autolens_workspace` includes ALMA uv_wavelengths files for simulating much high resolution datasets (which can be performed by replacing "sma.fits" below with "alma.fits"). """ -uv_wavelengths_path = path.join("dataset", dataset_type, "uv_wavelengths") +uv_wavelengths_path = Path("dataset") / dataset_type / "uv_wavelengths" uv_wavelengths = al.ndarray_via_fits_from( - file_path=path.join(uv_wavelengths_path, "sma.fits"), hdu=0 + file_path=Path(uv_wavelengths_path) / "sma.fits", hdu=0 ) """ @@ -123,9 +123,9 @@ Output the simulated dataset to the dataset path as .fits files. """ dataset.output_to_fits( - data_path=path.join(dataset_path, "data.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), - uv_wavelengths_path=path.join(dataset_path, "uv_wavelengths.fits"), + data_path=Path(dataset_path) / "data.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", + uv_wavelengths_path=Path(dataset_path) / "uv_wavelengths.fits", overwrite=True, ) @@ -147,7 +147,7 @@ """ al.output_to_json( obj=tracer, - file_path=path.join(dataset_path, "tracer.json"), + file_path=Path(dataset_path) / "tracer.json", ) """ diff --git a/slam_pipeline/dspl.py b/slam_pipeline/dspl.py index 56cb4e5..b3aa1f1 100644 --- a/slam_pipeline/dspl.py +++ b/slam_pipeline/dspl.py @@ -35,7 +35,6 @@ def fit(): # print(f"Working Directory has been set to `{workspace_path}`") import os - from os import path import autofit as af import autolens as al @@ -48,12 +47,12 @@ def fit(): Load the `Imaging` data, define the `Mask2D` and plot them. """ dataset_name = "with_lens_light" - dataset_path = path.join("dataset", "imaging", dataset_name) + dataset_path = Path("dataset") / "imaging" / dataset_name dataset = al.Imaging.from_fits( - data_path=path.join(dataset_path, "data.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), - psf_path=path.join(dataset_path, "psf.fits"), + data_path=Path(dataset_path) / "data.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", + psf_path=Path(dataset_path) / "psf.fits", pixel_scales=0.2, ) @@ -75,7 +74,7 @@ def fit(): The settings of autofit, which controls the output paths, parallelization, database use, etc. """ settings_search = af.SettingsSearch( - path_prefix=path.join("slam", "source_pix", "mass_total", "base"), + path_prefix=Path("slam") / "source_pix" / "mass_total" / "base", number_of_cores=1, session=None, ) @@ -85,6 +84,7 @@ def fit(): The redshifts of the lens and source galaxies, which are used to perform unit converions of the model and data (e.g. from arc-seconds to kiloparsecs, masses to solar masses, etc.). +from pathlib import Path """ redshift_lens = 0.5 redshift_source = 1.0 diff --git a/slam_pipeline/light_dark_mge.py b/slam_pipeline/light_dark_mge.py index b272ac9..d906790 100644 --- a/slam_pipeline/light_dark_mge.py +++ b/slam_pipeline/light_dark_mge.py @@ -35,7 +35,6 @@ def fit(): # print(f"Working Directory has been set to `{workspace_path}`") import os - from os import path from pathlib import Path import autofit as af @@ -49,12 +48,12 @@ def fit(): Load the `Imaging` data, define the `Mask2D` and plot them. """ dataset_name = "with_lens_light" - dataset_path = path.join("dataset", "imaging", dataset_name) + dataset_path = Path("dataset") / "imaging" / dataset_name dataset = al.Imaging.from_fits( - data_path=path.join(dataset_path, "data.fits"), - noise_map_path=path.join(dataset_path, "noise_map.fits"), - psf_path=path.join(dataset_path, "psf.fits"), + data_path=Path(dataset_path) / "data.fits", + noise_map_path=Path(dataset_path) / "noise_map.fits", + psf_path=Path(dataset_path) / "psf.fits", pixel_scales=0.2, )