Skip to content

Commit 984d83d

Browse files
committed
move gleam test to only run checks on rank 0
1 parent 53aa9d0 commit 984d83d

File tree

1 file changed

+81
-72
lines changed

1 file changed

+81
-72
lines changed

tests/test_run.py

Lines changed: 81 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,10 @@ def test_run_paramdict_uvsim(rename_beamfits, tmp_path):
272272
msg = ""
273273
params = pyuvsim.simsetup._config_str_to_dict(param_file)
274274

275-
with uvtest.check_warnings(warn_type, match=msg):
275+
if pyuvsim.mpi.rank > 0:
276+
with check_warnings(warn_type, match=msg):
277+
pyuvsim.run_uvsim(params, return_uv=True)
278+
else:
276279
pyuvsim.run_uvsim(params, return_uv=True)
277280

278281

@@ -288,25 +291,27 @@ def test_run_gleam_uvsim(spectral_type):
288291
params["sources"].pop("max_flux")
289292

290293
uv_out = pyuvsim.run_uvsim(params, return_uv=True)
291-
assert uv_out.telescope_name == "Triangle"
292-
293-
file_name = f"gleam_triangle_{spectral_type}.uvh5"
294-
uv_in = UVData.from_file(os.path.join(SIM_DATA_PATH, file_name))
295-
# This can be removed when we require pyuvdata >= 3.0
296-
if hasattr(uv_in, "use_current_array_shapes"):
297-
uv_in.use_future_array_shapes()
298-
uv_in.conjugate_bls()
299-
uv_in.reorder_blts()
300-
uv_in.integration_time = np.full_like(uv_in.integration_time, 11.0)
301-
# This just tests that we get the same answer as an earlier run, not that
302-
# the data are correct (that's covered in other tests)
303-
uv_out.history = uv_in.history
304-
if hasattr(uv_out, "telescope"):
305-
assert uv_in.telescope._location == uv_out.telescope._location
306-
else:
307-
# this can be removed when we require pyuvdata >= 3.0
308-
assert uv_in._telescope_location == uv_out._telescope_location
309-
assert uv_in == uv_out
294+
295+
if pyuvsim.mpi.rank == 0:
296+
assert uv_out.telescope_name == "Triangle"
297+
298+
file_name = f"gleam_triangle_{spectral_type}.uvh5"
299+
uv_in = UVData.from_file(os.path.join(SIM_DATA_PATH, file_name))
300+
# This can be removed when we require pyuvdata >= 3.0
301+
if hasattr(uv_in, "use_current_array_shapes"):
302+
uv_in.use_future_array_shapes()
303+
uv_in.conjugate_bls()
304+
uv_in.reorder_blts()
305+
uv_in.integration_time = np.full_like(uv_in.integration_time, 11.0)
306+
# This just tests that we get the same answer as an earlier run, not that
307+
# the data are correct (that's covered in other tests)
308+
uv_out.history = uv_in.history
309+
if hasattr(uv_out, "telescope"):
310+
assert uv_in.telescope._location == uv_out.telescope._location
311+
else:
312+
# this can be removed when we require pyuvdata >= 3.0
313+
assert uv_in._telescope_location == uv_out._telescope_location
314+
assert uv_in == uv_out
310315

311316

312317
@pytest.mark.filterwarnings("ignore:The reference_frequency is aliased as `frequency`")
@@ -476,21 +481,21 @@ def test_sim_on_moon(future_shapes, goto_tempdir, selenoid):
476481
assert uvutils._check_history_version(uv_out.history, uv_obj.filename[0])
477482
assert uvutils._check_history_version(uv_out.history, "Npus =")
478483

479-
assert uv_out.extra_keywords["world"] == "moon"
480-
assert uv_out._telescope_location.ellipsoid == selenoid
481-
assert np.allclose(uv_out.data_array[:, :, 0], 0.5)
484+
assert uv_out.extra_keywords["world"] == "moon"
485+
assert uv_out._telescope_location.ellipsoid == selenoid
486+
assert np.allclose(uv_out.data_array[:, :, 0], 0.5)
482487

483-
# Lunar Frame Roundtripping
484-
param_dict["filing"]["outdir"] = str(tmpdir)
488+
# Lunar Frame Roundtripping
489+
param_dict["filing"]["outdir"] = str(tmpdir)
485490

486-
uv_filename = pyuvsim.utils.write_uvdata(
487-
uv_out, param_dict, return_filename=True, quiet=True
488-
)
489-
uv_compare = UVData()
490-
uv_compare.read(uv_filename, use_future_array_shapes=future_shapes)
491-
assert np.allclose(uv_out.telescope_location, uv_compare.telescope_location)
492-
assert uv_out._telescope_location.frame == uv_compare._telescope_location.frame
493-
assert uv_compare._telescope_location.ellipsoid == selenoid
491+
uv_filename = pyuvsim.utils.write_uvdata(
492+
uv_out, param_dict, return_filename=True, quiet=True
493+
)
494+
uv_compare = UVData()
495+
uv_compare.read(uv_filename, use_future_array_shapes=future_shapes)
496+
assert np.allclose(uv_out.telescope_location, uv_compare.telescope_location)
497+
assert uv_out._telescope_location.frame == uv_compare._telescope_location.frame
498+
assert uv_compare._telescope_location.ellipsoid == selenoid
494499

495500
# Cleanup
496501
os.remove(uv_filename)
@@ -544,46 +549,50 @@ def test_lunar_gauss(goto_tempdir, selenoid):
544549

545550
params["filing"]["outdir"] = str(tmpdir)
546551

547-
uv_out = pyuvsim.run_uvsim(params, return_uv=True, quiet=True)
548-
assert uv_out._telescope_location.ellipsoid == selenoid
552+
try:
553+
uv_out = pyuvsim.run_uvsim(params, return_uv=True, quiet=True)
554+
except SpiceUNKNOWNFRAME as err:
555+
pytest.skip("SpiceUNKNOWNFRAME error: " + str(err))
549556

550-
# Skymodel and update positions
551-
552-
# Init sky model
553-
sm = pyradiosky.SkyModel(
554-
name="source0",
555-
ra=Longitude(308.32686, unit="deg"),
556-
dec=Latitude(-21, unit="deg"),
557-
stokes=units.Quantity([1, 0, 0, 0], unit="Jy"),
558-
spectral_type="flat",
559-
frame="fk5",
560-
)
557+
if pyuvsim.mpi.rank == 0:
558+
assert uv_out._telescope_location.ellipsoid == selenoid
559+
# Skymodel and update positions
560+
561+
# Init sky model
562+
sm = pyradiosky.SkyModel(
563+
name="source0",
564+
ra=Longitude(308.32686, unit="deg"),
565+
dec=Latitude(-21, unit="deg"),
566+
stokes=units.Quantity([1, 0, 0, 0], unit="Jy"),
567+
spectral_type="flat",
568+
frame="fk5",
569+
)
561570

562-
if hasattr(uv_out, "telescope"):
563-
pos = uv_out.telescope.location_lat_lon_alt_degrees
564-
else:
565-
# this can be removed when we require pyuvdata >= 3.0
566-
pos = uv_out.telescope_location_lat_lon_alt_degrees
567-
568-
# Creating the analytical gaussian
569-
Alt = np.zeros(uv_out.Ntimes)
570-
Az = np.zeros(uv_out.Ntimes)
571-
refTimes = uv_out.get_times(0, 1)
572-
telescope_location_obj = MoonLocation(
573-
Longitude(pos[1], unit="deg"),
574-
Latitude(pos[0], unit="deg"),
575-
units.Quantity(pos[2], unit="m"),
576-
ellipsoid=selenoid,
577-
)
578-
for t in range(uv_out.Ntimes):
579-
sm.update_positions(Time(refTimes[t], format="jd"), telescope_location_obj)
580-
Alt[t] = sm.alt_az[0, 0]
581-
Az[t] = sm.alt_az[1, 0]
571+
if hasattr(uv_out, "telescope"):
572+
pos = uv_out.telescope.location_lat_lon_alt_degrees
573+
else:
574+
# this can be removed when we require pyuvdata >= 3.0
575+
pos = uv_out.telescope_location_lat_lon_alt_degrees
576+
577+
# Creating the analytical gaussian
578+
Alt = np.zeros(uv_out.Ntimes)
579+
Az = np.zeros(uv_out.Ntimes)
580+
refTimes = uv_out.get_times(0, 1)
581+
telescope_location_obj = MoonLocation(
582+
Longitude(pos[1], unit="deg"),
583+
Latitude(pos[0], unit="deg"),
584+
units.Quantity(pos[2], unit="m"),
585+
ellipsoid=selenoid,
586+
)
587+
for t in range(uv_out.Ntimes):
588+
sm.update_positions(Time(refTimes[t], format="jd"), telescope_location_obj)
589+
Alt[t] = sm.alt_az[0, 0]
590+
Az[t] = sm.alt_az[1, 0]
582591

583-
sigma = 0.5
584-
Vis = 0.5 * np.exp(-np.power((Alt - np.pi / 2) / sigma, 2))
592+
sigma = 0.5
593+
Vis = 0.5 * np.exp(-np.power((Alt - np.pi / 2) / sigma, 2))
585594

586-
# Check that the analytical visibility agrees with the simulation
587-
assert np.allclose(
588-
Vis, np.abs(uv_out.get_data(0, 1)[:, 0, 0]), rtol=1e-04, atol=1e-04
589-
)
595+
# Check that the analytical visibility agrees with the simulation
596+
assert np.allclose(
597+
Vis, np.abs(uv_out.get_data(0, 1)[:, 0, 0]), rtol=1e-04, atol=1e-04
598+
)

0 commit comments

Comments
 (0)