diff --git a/.gitignore b/.gitignore index 005f4bab3..ca50439cf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,10 @@ test_autoarray/mask/files/mask/mask_out.fits test_autoarray/plot/wrap/base/files/ test_autoarray/structures/grids/files/grid_2d.fits -test_autoarray/dataset/files/array/output_test/uv_wavelengths.fits -test_autoarray/dataset/files/array/output_test/visibilities.fits +# Test output: tests write results into output_test/ dirs and read them back. +# Never track them -- a change to the autonerves FITS writer would otherwise +# rewrite a committed binary and dirty every contributor's tree (PyAutoArray#483). +test_autoarray/**/output_test/ test_autoarray/dataset/plot/files/ test_autoarray/fit/plot/files/ test_autoarray/structures/arrays/one_d/files/array/ diff --git a/test_autoarray/dataset/files/array/output_test/noise_map.fits b/test_autoarray/dataset/files/array/output_test/noise_map.fits deleted file mode 100644 index 73d09cbd9..000000000 Binary files a/test_autoarray/dataset/files/array/output_test/noise_map.fits and /dev/null differ diff --git a/test_autoarray/dataset/files/arrays/output_test/background_noise_map.fits b/test_autoarray/dataset/files/arrays/output_test/background_noise_map.fits deleted file mode 100644 index e2d837941..000000000 Binary files a/test_autoarray/dataset/files/arrays/output_test/background_noise_map.fits and /dev/null differ diff --git a/test_autoarray/dataset/files/arrays/output_test/background_sky_map.fits b/test_autoarray/dataset/files/arrays/output_test/background_sky_map.fits deleted file mode 100644 index d394dd475..000000000 Binary files a/test_autoarray/dataset/files/arrays/output_test/background_sky_map.fits and /dev/null differ diff --git a/test_autoarray/dataset/files/arrays/output_test/exposure_time_map.fits b/test_autoarray/dataset/files/arrays/output_test/exposure_time_map.fits deleted file mode 100644 index 2fa6ae960..000000000 Binary files a/test_autoarray/dataset/files/arrays/output_test/exposure_time_map.fits and /dev/null differ diff --git a/test_autoarray/dataset/files/arrays/output_test/image.fits b/test_autoarray/dataset/files/arrays/output_test/image.fits deleted file mode 100644 index 7f3001a57..000000000 Binary files a/test_autoarray/dataset/files/arrays/output_test/image.fits and /dev/null differ diff --git a/test_autoarray/dataset/files/arrays/output_test/noise_map.fits b/test_autoarray/dataset/files/arrays/output_test/noise_map.fits deleted file mode 100644 index bab8564c1..000000000 Binary files a/test_autoarray/dataset/files/arrays/output_test/noise_map.fits and /dev/null differ diff --git a/test_autoarray/dataset/files/arrays/output_test/poisson_noise_map.fits b/test_autoarray/dataset/files/arrays/output_test/poisson_noise_map.fits deleted file mode 100644 index a29600448..000000000 Binary files a/test_autoarray/dataset/files/arrays/output_test/poisson_noise_map.fits and /dev/null differ diff --git a/test_autoarray/dataset/files/arrays/output_test/psf.fits b/test_autoarray/dataset/files/arrays/output_test/psf.fits deleted file mode 100644 index db4a4cae7..000000000 Binary files a/test_autoarray/dataset/files/arrays/output_test/psf.fits and /dev/null differ diff --git a/test_autoarray/dataset/imaging/test_dataset.py b/test_autoarray/dataset/imaging/test_dataset.py index b9616a7c4..6d19276da 100644 --- a/test_autoarray/dataset/imaging/test_dataset.py +++ b/test_autoarray/dataset/imaging/test_dataset.py @@ -1,9 +1,7 @@ import copy -import os import numpy as np import pytest -import shutil import autoarray as aa @@ -13,18 +11,6 @@ test_data_path = Path(Path(__file__).resolve().parent) / "files" -@pytest.fixture(name="test_data_path") -def make_test_data_path(): - test_data_path = Path(__file__).resolve().parent / "files" / "array" / "output_test" - - if test_data_path.exists(): - shutil.rmtree(test_data_path) - - os.makedirs(test_data_path) - - return test_data_path - - def test__grid__uses_mask_and_settings__lp_grid_matches_grid_2d_7x7( image_7x7, noise_map_7x7, @@ -162,9 +148,7 @@ def test__from_fits__all_data_in_one_fits_file_multiple_hdus__loads_data_psf_noi assert dataset.noise_map.mask.pixel_scales == (0.1, 0.1) -def test__from_fits__small_datasets_env_caps_data_and_noise_map( - test_data_path, monkeypatch -): +def test__from_fits__small_datasets_env_caps_data_and_noise_map(tmp_path, monkeypatch): """When PYAUTO_SMALL_DATASETS=1, Imaging.from_fits center-crops data and noise_map to (15, 15) at pixel_scales=0.6 so they stay shape-consistent with masks built via Mask2D.circular under the same env var. PSF is left @@ -172,17 +156,17 @@ def test__from_fits__small_datasets_env_caps_data_and_noise_map( from astropy.io import fits fits.writeto( - Path(test_data_path) / "data_30x30.fits", + tmp_path / "data_30x30.fits", data=np.ones((30, 30), dtype=np.float64), overwrite=True, ) fits.writeto( - Path(test_data_path) / "noise_map_30x30.fits", + tmp_path / "noise_map_30x30.fits", data=2.0 * np.ones((30, 30), dtype=np.float64), overwrite=True, ) fits.writeto( - Path(test_data_path) / "psf_5x5.fits", + tmp_path / "psf_5x5.fits", data=(1.0 / 25.0) * np.ones((5, 5), dtype=np.float64), overwrite=True, ) @@ -191,9 +175,9 @@ def test__from_fits__small_datasets_env_caps_data_and_noise_map( dataset = aa.Imaging.from_fits( pixel_scales=0.08, - data_path=Path(test_data_path) / "data_30x30.fits", - psf_path=Path(test_data_path) / "psf_5x5.fits", - noise_map_path=Path(test_data_path) / "noise_map_30x30.fits", + data_path=tmp_path / "data_30x30.fits", + psf_path=tmp_path / "psf_5x5.fits", + noise_map_path=tmp_path / "noise_map_30x30.fits", ) assert dataset.data.shape_native == (16, 16) @@ -202,20 +186,18 @@ def test__from_fits__small_datasets_env_caps_data_and_noise_map( assert dataset.psf.kernel.shape_native == (5, 5) -def test__from_fits__small_datasets_env_unset__shape_unchanged( - test_data_path, monkeypatch -): +def test__from_fits__small_datasets_env_unset__shape_unchanged(tmp_path, monkeypatch): """Sanity: with the env var unset, from_fits returns the on-disk shape unchanged, even for files larger than the cap.""" from astropy.io import fits fits.writeto( - Path(test_data_path) / "data_30x30.fits", + tmp_path / "data_30x30.fits", data=np.ones((30, 30), dtype=np.float64), overwrite=True, ) fits.writeto( - Path(test_data_path) / "noise_map_30x30.fits", + tmp_path / "noise_map_30x30.fits", data=2.0 * np.ones((30, 30), dtype=np.float64), overwrite=True, ) @@ -224,8 +206,8 @@ def test__from_fits__small_datasets_env_unset__shape_unchanged( dataset = aa.Imaging.from_fits( pixel_scales=0.08, - data_path=Path(test_data_path) / "data_30x30.fits", - noise_map_path=Path(test_data_path) / "noise_map_30x30.fits", + data_path=tmp_path / "data_30x30.fits", + noise_map_path=tmp_path / "noise_map_30x30.fits", ) assert dataset.data.shape_native == (30, 30) @@ -233,25 +215,23 @@ def test__from_fits__small_datasets_env_unset__shape_unchanged( assert dataset.pixel_scales == (0.08, 0.08) -def test__output_to_fits__round_trips_data_psf_noise_map_correctly( - imaging_7x7, test_data_path -): +def test__output_to_fits__round_trips_data_psf_noise_map_correctly(imaging_7x7, tmp_path): from autoarray.dataset.plot.imaging_plots import fits_imaging fits_imaging( dataset=imaging_7x7, - 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", + data_path=tmp_path / "data.fits", + psf_path=tmp_path / "psf.fits", + noise_map_path=tmp_path / "noise_map.fits", overwrite=True, ) dataset = aa.Imaging.from_fits( pixel_scales=0.1, - 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", + data_path=tmp_path / "data.fits", + psf_path=tmp_path / "psf.fits", + noise_map_path=tmp_path / "noise_map.fits", ) assert (dataset.data.native == np.ones((7, 7))).all() diff --git a/test_autoarray/dataset/interferometer/test_dataset.py b/test_autoarray/dataset/interferometer/test_dataset.py index a9c1ecb18..c8823c7df 100644 --- a/test_autoarray/dataset/interferometer/test_dataset.py +++ b/test_autoarray/dataset/interferometer/test_dataset.py @@ -1,6 +1,4 @@ import numpy as np -import os -import shutil import autoarray as aa import pytest @@ -127,7 +125,7 @@ def test__from_fits__all_files_in_one_fits__load_using_different_hdus(mask_2d_7x assert (dataset.uv_wavelengths[:, 1] == 3.0 * np.ones(3)).all() -def test__output_all_arrays(mask_2d_7x7): +def test__output_all_arrays(mask_2d_7x7, tmp_path): test_data_path = Path(Path(__file__).resolve().parent) / "files" dataset = aa.Interferometer.from_fits( @@ -137,28 +135,21 @@ def test__output_all_arrays(mask_2d_7x7): uv_wavelengths_path=Path(test_data_path) / "3x2_fives_sixes.fits", ) - test_data_path = Path(Path(__file__).resolve().parent) / "files" / "array" / "output_test" - - if Path(test_data_path).exists(): - shutil.rmtree(test_data_path) - - os.makedirs(test_data_path) - from autoarray.dataset.plot.interferometer_plots import fits_interferometer fits_interferometer( dataset=dataset, - 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", + data_path=tmp_path / "data.fits", + noise_map_path=tmp_path / "noise_map.fits", + uv_wavelengths_path=tmp_path / "uv_wavelengths.fits", overwrite=True, ) dataset = aa.Interferometer.from_fits( real_space_mask=mask_2d_7x7, - 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", + data_path=tmp_path / "data.fits", + noise_map_path=tmp_path / "noise_map.fits", + uv_wavelengths_path=tmp_path / "uv_wavelengths.fits", ) assert (dataset.data == np.array([1.0 + 2.0j, 1.0 + 2.0j, 1.0 + 2.0j])).all() diff --git a/test_autoarray/mask/test_mask_2d.py b/test_autoarray/mask/test_mask_2d.py index 403d3ea02..54ed3a20d 100644 --- a/test_autoarray/mask/test_mask_2d.py +++ b/test_autoarray/mask/test_mask_2d.py @@ -1,8 +1,6 @@ from astropy.io import fits -import os import numpy as np import pytest -import shutil import autoarray as aa from autoarray import exc @@ -407,30 +405,25 @@ def test__from_pixel_coordinates__two_coordinates_buffer_1__two_separate_unmaske # --------------------------------------------------------------------------- -def test__from_fits__output_to_fits__roundtrip_preserves_values_pixel_scales_and_header(): +def test__from_fits__output_to_fits__roundtrip_preserves_values_pixel_scales_and_header( + tmp_path, +): mask = aa.Mask2D.from_fits( file_path=Path(test_data_path) / "3x3_ones.fits", hdu=0, pixel_scales=(1.0, 1.0), ) - output_path = Path(Path(__file__).resolve().parent) / "files" / "array" / "output_test" - - if Path(output_path).exists(): - shutil.rmtree(output_path) - - os.makedirs(output_path) - from autonerves.fitsable import output_to_fits output_to_fits( values=mask.astype("float"), - file_path=Path(output_path) / "mask.fits", + file_path=tmp_path / "mask.fits", header_dict=mask.header_dict, ext_name="mask", ) mask = aa.Mask2D.from_fits( - file_path=Path(output_path) / "mask.fits", + file_path=tmp_path / "mask.fits", hdu=0, pixel_scales=(1.0, 1.0), origin=(2.0, 2.0), @@ -440,7 +433,7 @@ def test__from_fits__output_to_fits__roundtrip_preserves_values_pixel_scales_and assert mask.pixel_scales == (1.0, 1.0) assert mask.origin == (2.0, 2.0) - header = aa.header_obj_from(file_path=Path(output_path) / "mask.fits", hdu=0) + header = aa.header_obj_from(file_path=tmp_path / "mask.fits", hdu=0) assert header["PIXSCAY"] == 1.0 assert header["PIXSCAX"] == 1.0 diff --git a/test_autoarray/structures/arrays/files/array/output_test/array.fits b/test_autoarray/structures/arrays/files/array/output_test/array.fits deleted file mode 100644 index 82bbcb8fd..000000000 Binary files a/test_autoarray/structures/arrays/files/array/output_test/array.fits and /dev/null differ diff --git a/test_autoarray/structures/arrays/files/output_test/array.fits b/test_autoarray/structures/arrays/files/output_test/array.fits deleted file mode 100644 index 7f3001a57..000000000 Binary files a/test_autoarray/structures/arrays/files/output_test/array.fits and /dev/null differ diff --git a/test_autoarray/structures/arrays/files/output_test/masked_array.fits b/test_autoarray/structures/arrays/files/output_test/masked_array.fits deleted file mode 100644 index 7f3001a57..000000000 Binary files a/test_autoarray/structures/arrays/files/output_test/masked_array.fits and /dev/null differ diff --git a/test_autoarray/structures/arrays/files/output_test/values_test.dat b/test_autoarray/structures/arrays/files/output_test/values_test.dat deleted file mode 100644 index 32ecc300a..000000000 --- a/test_autoarray/structures/arrays/files/output_test/values_test.dat +++ /dev/null @@ -1 +0,0 @@ -[6.0, 7.0, 8.0] \ No newline at end of file diff --git a/test_autoarray/structures/arrays/files/values/output_test/values_test.dat b/test_autoarray/structures/arrays/files/values/output_test/values_test.dat deleted file mode 100644 index 32ecc300a..000000000 --- a/test_autoarray/structures/arrays/files/values/output_test/values_test.dat +++ /dev/null @@ -1 +0,0 @@ -[6.0, 7.0, 8.0] \ No newline at end of file diff --git a/test_autoarray/structures/arrays/test_uniform_1d.py b/test_autoarray/structures/arrays/test_uniform_1d.py index 06c2a92b7..f9e6540fb 100644 --- a/test_autoarray/structures/arrays/test_uniform_1d.py +++ b/test_autoarray/structures/arrays/test_uniform_1d.py @@ -9,8 +9,6 @@ fits_path = Path(__file__).resolve().parent / "files" / "array_1d" -test_data_path = Path(__file__).resolve().parent / "files" / "array" / "output_test" - def create_fits( fits_path, @@ -154,25 +152,20 @@ def test__from_fits__4_element_fits__header_bitpix_is_minus_64(): clean_fits(fits_path=fits_path) -def test__output_to_fits__ones_array__fits_file_has_correct_values_and_header(): +def test__output_to_fits__ones_array__fits_file_has_correct_values_and_header(tmp_path): arr = aa.Array1D.ones(shape_native=(3,), pixel_scales=1.0) - if test_data_path.exists(): - shutil.rmtree(test_data_path) - - os.makedirs(test_data_path) - from autonerves.fitsable import output_to_fits - output_to_fits(values=arr.native.array.astype("float"), file_path=test_data_path / "array.fits", header_dict=arr.mask.header_dict) + output_to_fits(values=arr.native.array.astype("float"), file_path=tmp_path / "array.fits", header_dict=arr.mask.header_dict) array_from_out = aa.Array1D.from_fits( - file_path=test_data_path / "array.fits", hdu=0, pixel_scales=1.0 + file_path=tmp_path / "array.fits", hdu=0, pixel_scales=1.0 ) assert (array_from_out.native == np.ones((3,))).all() header_load = aa.header_obj_from( - file_path=test_data_path / "array.fits", hdu=0 + file_path=tmp_path / "array.fits", hdu=0 ) assert header_load["PIXSCA"] == 1.0 diff --git a/test_autoarray/structures/arrays/test_uniform_2d.py b/test_autoarray/structures/arrays/test_uniform_2d.py index 2cfa4aa51..2540c0c8e 100644 --- a/test_autoarray/structures/arrays/test_uniform_2d.py +++ b/test_autoarray/structures/arrays/test_uniform_2d.py @@ -1,10 +1,8 @@ from astropy.io import fits -import os from pathlib import Path import numpy as np import pytest -import shutil import autoarray as aa @@ -191,24 +189,20 @@ def test__from_yx_and_values__3x2_grid__native_matches_expected_pixel_layout(): assert (array_2d.native == np.array([[3.0, 2.0], [6.0, 4.0], [5.0, 1.0]])).all() -def test__output_to_fits__3x3_ones__fits_file_has_ones_and_correct_pixel_scale_header(): +def test__output_to_fits__3x3_ones__fits_file_has_ones_and_correct_pixel_scale_header( + tmp_path, +): files_path = Path(__file__).resolve().parent / "files" array_2d = aa.Array2D.from_fits( file_path=files_path / "3x3_ones.fits", hdu=0, pixel_scales=1.0 ) - output_test_path = files_path / "array" / "output_test" - if output_test_path.exists(): - shutil.rmtree(output_test_path) - - os.makedirs(output_test_path) - from autonerves.fitsable import output_to_fits - output_to_fits(values=array_2d.native.array.astype("float"), file_path=output_test_path / "array.fits", header_dict=array_2d.mask.header_dict) + output_to_fits(values=array_2d.native.array.astype("float"), file_path=tmp_path / "array.fits", header_dict=array_2d.mask.header_dict) array_from_fits = aa.Array2D.from_fits( - file_path=output_test_path / "array.fits", hdu=0, pixel_scales=1.0 + file_path=tmp_path / "array.fits", hdu=0, pixel_scales=1.0 ) assert (array_from_fits.native == np.ones((3, 3))).all() diff --git a/test_autoarray/structures/test_visibilities.py b/test_autoarray/structures/test_visibilities.py index 782651ba0..1e2c3507c 100644 --- a/test_autoarray/structures/test_visibilities.py +++ b/test_autoarray/structures/test_visibilities.py @@ -1,8 +1,6 @@ -import os from pathlib import Path import numpy as np import pytest -import shutil import autoarray as aa from autoarray.structures import visibilities as vis @@ -86,25 +84,18 @@ def test__from_fits__makes_visibilities_without_other_inputs(): assert (visibilities.slim == np.array([2.0 + 2.0j, 2.0 + 2.0j, 2.0 + 2.0j])).all() -def test__output_to_fits(): +def test__output_to_fits(tmp_path): files_path = Path(__file__).resolve().parent / "files" visibilities = aa.Visibilities.from_fits( file_path=files_path / "3x2_ones.fits", hdu=0 ) - output_test_path = files_path / "output_test" - - if output_test_path.exists(): - shutil.rmtree(output_test_path) - - os.makedirs(output_test_path) - from autonerves.fitsable import output_to_fits - output_to_fits(values=visibilities.in_array, file_path=output_test_path / "data.fits") + output_to_fits(values=visibilities.in_array, file_path=tmp_path / "data.fits") visibilities_from_out = aa.Visibilities.from_fits( - file_path=output_test_path / "data.fits", hdu=0 + file_path=tmp_path / "data.fits", hdu=0 ) assert ( visibilities_from_out.slim == np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j])