From 862724b2b1d66842ae9389fc73c5c65942b3f2f3 Mon Sep 17 00:00:00 2001 From: Tyler Cox Date: Thu, 22 Aug 2024 16:07:48 -0700 Subject: [PATCH] fix coordinate transform issue --- fftvis/simulate.py | 7 ++++--- fftvis/tests/test_compare_matvis.py | 11 +++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fftvis/simulate.py b/fftvis/simulate.py index ae0bf75..238fdbd 100644 --- a/fftvis/simulate.py +++ b/fftvis/simulate.py @@ -251,6 +251,7 @@ def simulate( # Rotate the array to the xy-plane rotation_matrix = utils.get_plane_to_xy_rotation_matrix(antvecs) + rotation_matrix = rotation_matrix.astype(real_dtype) rotated_antvecs = np.dot(rotation_matrix.T, antvecs.T) rotated_ants = {ant: rotated_antvecs[:, antkey_to_idx[ant]] for ant in ants} @@ -304,9 +305,6 @@ def simulate( ty = ty[above_horizon] tz = tz[above_horizon] - # Rotate source coordinates with rotation matrix - tx, ty, tz = np.dot(rotation_matrix.T, [tx, ty, tz]) - # Number of above horizon points nsim_sources = above_horizon.sum() @@ -324,6 +322,9 @@ def simulate( # Compute azimuth and zenith angles az, za = conversions.enu_to_az_za(enu_e=tx, enu_n=ty, orientation="uvbeam") + # Rotate source coordinates with rotation matrix. + tx, ty, tz = np.dot(rotation_matrix.T, [tx, ty, tz]) + for fi in range(nfreqs): # Compute uv coordinates u[:], v[:], w[:] = blx * freqs[fi], bly * freqs[fi], blz * freqs[fi] diff --git a/fftvis/tests/test_compare_matvis.py b/fftvis/tests/test_compare_matvis.py index d83be35..907cbe1 100644 --- a/fftvis/tests/test_compare_matvis.py +++ b/fftvis/tests/test_compare_matvis.py @@ -138,6 +138,7 @@ def test_simulate_non_coplanar(): # Set up the antenna positions antpos = {k: np.array([k * 10, 0, k]) for k in range(nants)} + antpos_flat = {k: np.array([k * 10, 0, 0]) for k in range(nants)} # Define a Gaussian beam beam = AnalyticBeam("gaussian", diameter=14.0) @@ -151,6 +152,9 @@ def test_simulate_non_coplanar(): mvis = matvis.simulate_vis( antpos, sky_model, ra, dec, freqs, lsts, beams=[beam], precision=2 ) + mvis_flat = matvis.simulate_vis( + antpos_flat, sky_model, ra, dec, freqs, lsts, beams=[beam], precision=2 + ) # Use fftvis to simulate visibilities fvis = simulate.simulate_vis( @@ -160,10 +164,5 @@ def test_simulate_non_coplanar(): # Check that the results are the same assert np.allclose(mvis, fvis, atol=1e-5) - # Use fftvis to simulate visibilities with flat array - fvis_flat = simulate.simulate_vis( - antpos, sky_model, ra, dec, freqs, lsts, beam, precision=2, eps=1e-10, flat_array_tol=np.inf - ) - # Check that the results are different - assert not np.allclose(fvis, fvis_flat, atol=1e-5) + assert not np.allclose(mvis_flat, fvis, atol=1e-5)