Skip to content

Commit

Permalink
fix coordinate transform issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-a-cox committed Aug 22, 2024
1 parent 6222764 commit 862724b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 4 additions & 3 deletions fftvis/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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()

Expand All @@ -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]
Expand Down
11 changes: 5 additions & 6 deletions fftvis/tests/test_compare_matvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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)

0 comments on commit 862724b

Please sign in to comment.