def _test_halo_array(): conn = ps.RemoteSnapshotConnection(handler, "tiny.000640") f = conn.get_view(ps.ObjectSpecification(1)) f_local = pynbody.load(tangos.config.base+"test_simulations/test_tipsy/tiny.000640").halos()[1] assert len(f)==len(f_local) assert (f['x'] == f_local['x']).all() assert (f.gas['temp'] == f_local.gas['temp']).all()
def _test_underlying_class(): conn = ps.RemoteSnapshotConnection(handler, "tiny.000640") f = conn.get_view(ps.ObjectSpecification(1)) f_local = pynbody.load(tangos.config.base + "test_simulations/test_tipsy/tiny.000640").halos()[1] f_local.physical_units() npt.assert_almost_equal(f['tipsy_specific_derived_array'],f_local['tipsy_specific_derived_array'], decimal=4) assert f.connection.underlying_pynbody_class is pynbody.snapshot.tipsy.TipsySnap
def _test_remote_file_index(): conn = ps.RemoteSnapshotConnection(handler, "tiny.000640") f = conn.get_view(ps.ObjectSpecification(1)) f_local = pynbody.load(tangos.config.base+"test_simulations/test_tipsy/tiny.000640").halos()[1] local_index_list = f_local.get_index_list(f_local.ancestor) index_list = f['remote-index-list'] assert (index_list==local_index_list).all()
def _test_simsnap_arrays(): test_filter = pynbody.filt.Sphere('5000 kpc') conn = ps.RemoteSnapshotConnection(handler, "tiny.000640") f = conn.get_view(test_filter) f_local = pynbody.load(tangos.config.base+"test_simulations/test_tipsy/tiny.000640")[test_filter] f_local.physical_units() assert (f['x'] == f_local['x']).all() assert (f.gas['iord'] == f_local.gas['iord']).all()
def _test_simsnap_properties(): test_filter = pynbody.filt.Sphere('5000 kpc') conn = ps.RemoteSnapshotConnection(handler, "tiny.000640") f = conn.get_view(test_filter) f_local = pynbody.load(tangos.config.base+"test_simulations/test_tipsy/tiny.000640")[test_filter] f_local.physical_units() assert len(f)==len(f_local) assert len(f.dm)==len(f_local.dm) assert len(f.gas)==len(f_local.gas) assert len(f.star)==len(f_local.star) assert f.properties['boxsize']==f_local.properties['boxsize']
def _test_lazy_evaluation_is_local(): conn = ps.RemoteSnapshotConnection(handler, "tiny.000640") f = conn.get_view(ps.ObjectSpecification(1)) f_local = pynbody.load(tangos.config.base+"test_simulations/test_tipsy/tiny.000640").halos()[1] f_local.physical_units() centre_offset = (-6017.0,-123.8,566.4) f['pos']-=centre_offset f_local['pos']-=centre_offset npt.assert_almost_equal(f['x'], f_local['x'], decimal=4) # This is the critical test: if the lazy-evaluation of 'r' takes place on the server, it will not be using # the updated version of the position array. This is undesirable for two reasons: first, because the pynbody # snapshot seen by the client is inconsistent in a way that would never happen with a normal snapshot. Second, # because it means extra "derived" arrays are being calculated across the entire snapshot which we want to # avoid in a memory-bound situation. npt.assert_almost_equal(f['r'], f_local['r'], decimal=4)
def _test_nonexistent_array(): test_filter = pynbody.filt.Sphere('5000 kpc') conn = ps.RemoteSnapshotConnection(handler, "tiny.000640") f = conn.get_view(test_filter) with npt.assert_raises(KeyError): f['nonexistent']