From 5bafc986f4468747538de2ac1bcb4378b2f178b3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Machado Poletti Valle Date: Mon, 6 Nov 2023 15:24:33 +0100 Subject: [PATCH] Rerun tests --- .github/workflows/test.yml | 2 +- karabo/simulation/sky_model.py | 2 - karabo/test/test_simulation.py | 70 +++++++++++++++++----------------- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index efda28a8..811e2ada 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,7 +46,7 @@ jobs: export RUN_GPU_TESTS=false export RUN_NOTEBOOK_TESTS=true pip install . --no-deps - pytest karabo/test/test_simulation.py + pytest --cov=./ --cov-report=xml - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 env: diff --git a/karabo/simulation/sky_model.py b/karabo/simulation/sky_model.py index f390f4a6..44cf25ce 100644 --- a/karabo/simulation/sky_model.py +++ b/karabo/simulation/sky_model.py @@ -525,7 +525,6 @@ def filter_by_radius( raise KaraboSkyModelError( "`sources` is None, add sources before calling `filter_by_radius`." ) - print(copied_sky.sources) inner_circle = SphericalCircle( (ra0_deg * u.deg, dec0_deg * u.deg), inner_radius_deg * u.deg, # pyright: ignore @@ -536,7 +535,6 @@ def filter_by_radius( ) outer_sources = outer_circle.contains_points(copied_sky[:, 0:2]) inner_sources = inner_circle.contains_points(copied_sky[:, 0:2]) - print(np.version.version) filtered_sources = np.logical_and(outer_sources, np.logical_not(inner_sources)) filtered_sources_idxs = np.where(filtered_sources == True)[0] # noqa copied_sky.sources = copied_sky.sources[filtered_sources_idxs] diff --git a/karabo/test/test_simulation.py b/karabo/test/test_simulation.py index e9afe865..474d5b0a 100644 --- a/karabo/test/test_simulation.py +++ b/karabo/test/test_simulation.py @@ -52,6 +52,41 @@ def continuous_noise_fits_downloader( ) +def test_parallelization_by_observation() -> None: + sky = SkyModel.get_GLEAM_Sky([76]) + phase_center = [250, -80] + CENTER_FREQUENCIES_HZ = [100e6, 101e6] + CHANNEL_BANDWIDTHS_HZ = [1.0, 2.0] + N_CHANNELS = [2, 4] + + sky = sky.filter_by_radius(0, 2.0, phase_center[0], phase_center[1]) + telescope = Telescope.constructor("ASKAP") + + simulation = InterferometerSimulation(channel_bandwidth_hz=1e6, time_average_sec=1) + + obs_parallized = ObservationParallized( + center_frequencies_hz=CENTER_FREQUENCIES_HZ, + channel_bandwidths_hz=CHANNEL_BANDWIDTHS_HZ, + phase_centre_ra_deg=phase_center[0], + phase_centre_dec_deg=phase_center[1], + number_of_time_steps=24, + n_channels=N_CHANNELS, + ) + + visibilities = simulation.run_simulation(telescope, sky, obs_parallized) + + for i, vis in enumerate(visibilities): + imager = Imager( + vis, imaging_npixel=512, imaging_cellsize=3.878509448876288e-05 + ) # imaging cellsize is over-written in the Imager based on max uv dist. + dirty = imager.get_dirty_image() + with tempfile.TemporaryDirectory() as tmpdir: + dirty.write_to_file(os.path.join(tmpdir, f"dirty_{i}.fits"), overwrite=True) + assert dirty.header["CRVAL4"] == CENTER_FREQUENCIES_HZ[i] + assert dirty.header["NAXIS4"] == N_CHANNELS[i] + assert dirty.header["CDELT4"] == CHANNEL_BANDWIDTHS_HZ[i] + + def test_oskar_simulation_basic(sky_data: NDArray[np.float64]) -> None: # Tests oskar simulation. Should use GPU if available and if not, CPU. sky = SkyModel() @@ -242,38 +277,3 @@ def test_simulation_noise_meerkat( assert set(golden_continuous_noise_fits_header.keys()) == set( continuous_noise_fits_header.keys() ) - - -def test_parallelization_by_observation() -> None: - sky = SkyModel.get_GLEAM_Sky([76]) - phase_center = [250, -80] - CENTER_FREQUENCIES_HZ = [100e6, 101e6] - CHANNEL_BANDWIDTHS_HZ = [1.0, 2.0] - N_CHANNELS = [2, 4] - - sky = sky.filter_by_radius(0, 2.0, phase_center[0], phase_center[1]) - telescope = Telescope.constructor("ASKAP") - - simulation = InterferometerSimulation(channel_bandwidth_hz=1e6, time_average_sec=1) - - obs_parallized = ObservationParallized( - center_frequencies_hz=CENTER_FREQUENCIES_HZ, - channel_bandwidths_hz=CHANNEL_BANDWIDTHS_HZ, - phase_centre_ra_deg=phase_center[0], - phase_centre_dec_deg=phase_center[1], - number_of_time_steps=24, - n_channels=N_CHANNELS, - ) - - visibilities = simulation.run_simulation(telescope, sky, obs_parallized) - - for i, vis in enumerate(visibilities): - imager = Imager( - vis, imaging_npixel=512, imaging_cellsize=3.878509448876288e-05 - ) # imaging cellsize is over-written in the Imager based on max uv dist. - dirty = imager.get_dirty_image() - with tempfile.TemporaryDirectory() as tmpdir: - dirty.write_to_file(os.path.join(tmpdir, f"dirty_{i}.fits"), overwrite=True) - assert dirty.header["CRVAL4"] == CENTER_FREQUENCIES_HZ[i] - assert dirty.header["NAXIS4"] == N_CHANNELS[i] - assert dirty.header["CDELT4"] == CHANNEL_BANDWIDTHS_HZ[i]