Esempio n. 1
0
def test_stream_sph_projection():
    ds = fake_sph_orientation_ds()
    proj = ds.proj(("gas", "density"), 2)
    frb = proj.to_frb(ds.domain_width[0], (256, 256))
    image = frb["gas", "density"]
    assert image.max() > 0
    assert image.shape == (256, 256)
Esempio n. 2
0
def test_basic_rotation_4():
    """ Rotation of x-axis to z-axis and original z-axis to y-axis with the use
    of the north_vector. All fake particles on z-axis should now be on the
    y-Axis.  All fake particles on the x-axis should now be on the z-axis, and
    all fake particles on the y-axis should now be on the x-axis.

    (0, 0, 1) -> (0, 1)
    (0, 0, 2) -> (0, 2)
    (0, 0, 3) -> (0, 3)
    In addition, (0, 0, 0) should contribute to the local maxima at (0, 0):
    (0, 0, 0) -> (0, 0)
    x-axis particles should be rotated and contribute to the local maxima at (0, 0):
    (1, 0, 0) -> (0, 0)
    and the y-axis particles shift into the positive x direction:
    (0, 1, 0) -> (1, 0)
    (0, 2, 0) -> (2, 0)
    """
    expected_maxima = ([0., 0., 0., 0., 1., 2.], [1., 2., 3., 0., 0., 0.])
    normal_vector = [1., 0., 0.]
    north_vector = [0., 0., 1.]
    resolution = (64, 64)
    ds = fake_sph_orientation_ds()
    left_edge = ds.domain_left_edge
    right_edge = ds.domain_right_edge
    center = (left_edge + right_edge) / 2
    width = (right_edge - left_edge)
    buf1 = OffAP.off_axis_projection(ds,
                                     center,
                                     normal_vector,
                                     width,
                                     resolution, ('gas', 'density'),
                                     north_vector=north_vector)
    find_compare_maxima(expected_maxima, buf1, resolution, width)
Esempio n. 3
0
def test_center_1():
    """Change the center to [0, 3, 0]
    Every point will be shifted by 3 in the y-domain
    With this, we should not be able to see any of the y-axis particles
    (0, 1, 0) -> (0, -2)
    (0, 2, 0) -> (0, -1)
    (0, 0, 1) -> (0, -3)
    (0, 0, 2) -> (0, -3)
    (0, 0, 3) -> (0, -3)
    (0, 0, 0) -> (0, -3)
    (1, 0, 0) -> (1, -3)
    """
    expected_maxima = ([0.0, 0.0, 0.0, 1.0], [-2.0, -1.0, -3.0, -3.0])
    normal_vector = [0.0, 0.0, 1.0]
    resolution = (64, 64)
    ds = fake_sph_orientation_ds()
    left_edge = ds.domain_left_edge
    right_edge = ds.domain_right_edge
    # center = [(left_edge[0] + right_edge[0])/2,
    #            left_edge[1],
    #           (left_edge[2] + right_edge[2])/2]
    center = [0.0, 3.0, 0.0]
    width = right_edge - left_edge
    buf1 = OffAP.off_axis_projection(
        ds, center, normal_vector, width, resolution, ("gas", "density")
    )
    find_compare_maxima(expected_maxima, buf1, resolution, width)
Esempio n. 4
0
def test_no_rotation():
    """Determines if a projection processed through
    off_axis_projection with no rotation will give the same
    image buffer if processed directly through
    pixelize_sph_kernel_projection
    """
    normal_vector = [0.0, 0.0, 1.0]
    resolution = (64, 64)
    ds = fake_sph_orientation_ds()
    ad = ds.all_data()
    left_edge = ds.domain_left_edge
    right_edge = ds.domain_right_edge
    center = (left_edge + right_edge) / 2
    width = right_edge - left_edge
    px = ad[("all", "particle_position_x")]
    py = ad[("all", "particle_position_y")]
    hsml = ad[("all", "smoothing_length")]
    quantity_to_smooth = ad[("gas", "density")]
    density = ad[("io", "density")]
    mass = ad[("io", "particle_mass")]
    bounds = [-4, 4, -4, 4, -4, 4]

    buf2 = np.zeros(resolution)
    buf1 = OffAP.off_axis_projection(
        ds, center, normal_vector, width, resolution, ("gas", "density")
    )
    pixelize_sph_kernel_projection(
        buf2, px, py, hsml, mass, density, quantity_to_smooth, bounds
    )
    assert_almost_equal(buf1.ndarray_view(), buf2)
Esempio n. 5
0
def test_basic_rotation_3():
    """Rotation of z-axis onto negative z-axis.
    All fake particles on z-axis should now be of the negative z-Axis.
    fake_sph_orientation has three z-axis particles,
    so we should have a local maxima at (0, 0)
    (0, 0, 1) -> (0, 0)
    (0, 0, 2) -> (0, 0)
    (0, 0, 3) -> (0, 0)
    In addition, (0, 0, 0) should also contribute to the local maxima at (0, 0):
    (0, 0, 0) -> (0, 0)
    x-axis particles should be rotated as such:
    (1, 0, 0) -> (0, -1)
    and same goes for y-axis particles:
    (0, 1, 0) -> (-1, 0)
    (0, 2, 0) -> (-2, 0)
    """
    expected_maxima = ([0.0, 0.0, -1.0, -2.0], [0.0, -1.0, 0.0, 0.0])
    normal_vector = [0.0, 0.0, -1.0]
    resolution = (64, 64)
    ds = fake_sph_orientation_ds()
    left_edge = ds.domain_left_edge
    right_edge = ds.domain_right_edge
    center = (left_edge + right_edge) / 2
    width = right_edge - left_edge
    buf1 = OffAP.off_axis_projection(
        ds, center, normal_vector, width, resolution, ("gas", "density")
    )
    find_compare_maxima(expected_maxima, buf1, resolution, width)
Esempio n. 6
0
def test_basic_rotation_2():
    """ Rotation of x-axis onto z-axis. All particles on z-axis should now be on the negative x-Axis
    fake_sph_orientation has three z-axis particles, so there should be three x-axis particles 
    after rotation 
    (0, 0, 1) -> (-1, 0)
    (0, 0, 2) -> (-2, 0)
    (0, 0, 3) -> (-3, 0)
    In addition, we should find a local maxima at (0, 0) due to:
    (0, 0, 0) -> (0, 0)
    (1, 0, 0) -> (0, 0)
    and the two particles on the y-axis should not change its position:
    (0, 1, 0) -> (0, 1)
    (0, 2, 0) -> (0, 2)
    """
    expected_maxima = ([-1., -2., -3., 0., 0., 0.], [0., 0., 0., 0., 1., 2.])
    normal_vector = [1., 0., 0.]
    north_vector = [0., 1., 0.]
    resolution = (64, 64)
    ds = fake_sph_orientation_ds()
    left_edge = ds.domain_left_edge
    right_edge = ds.domain_right_edge
    center = (left_edge + right_edge) / 2
    width = (right_edge - left_edge)
    buf1 = OffAP.off_axis_projection(ds,
                                     center,
                                     normal_vector,
                                     width,
                                     resolution, ('gas', 'density'),
                                     north_vector=north_vector)
    find_compare_maxima(expected_maxima, buf1, resolution, width)
Esempio n. 7
0
def test_in_memory_sph_derived_quantities():
    ds = fake_sph_orientation_ds()
    ad = ds.all_data()

    ang_mom = ad.quantities.angular_momentum_vector()
    assert_equal(ang_mom, [0, 0, 0])

    bv = ad.quantities.bulk_velocity()
    assert_equal(bv, [0, 0, 0])

    com = ad.quantities.center_of_mass()
    assert_equal(com, [1 / 7, (1 + 2) / 7, (1 + 2 + 3) / 7])

    ex = ad.quantities.extrema(['x', 'y', 'z'])
    for fex, ans in zip(ex, [[0, 1], [0, 2], [0, 3]]):
        assert_equal(fex, ans)

    for d, v, l in zip('xyz', [1, 2, 3], [[1, 0, 0], [0, 2, 0], [0, 0, 3]]):
        max_d, x, y, z = ad.quantities.max_location(d)
        assert_equal(max_d, v)
        assert_equal([x, y, z], l)

    for d in 'xyz':
        min_d, x, y, z = ad.quantities.min_location(d)
        assert_equal(min_d, 0)
        assert_equal([x, y, z], [0, 0, 0])

    tot_m = ad.quantities.total_mass()
    assert_equal(tot_m, [7, 0])

    weighted_av_z = ad.quantities.weighted_average_quantity('z', 'z')
    assert_equal(weighted_av_z, 7 / 3)
Esempio n. 8
0
def test_chained_selection():
    ds = fake_sph_orientation_ds()

    for (center, radius), answer in SPHERE_ANSWERS.items():
        sph = ds.sphere(center, radius)
        region = ds.box(ds.domain_left_edge, ds.domain_right_edge, data_source=sph)
        assert_equal(region["gas", "density"].shape[0], answer)
Esempio n. 9
0
def test_basic_rotation_1():
    """All particles on Z-axis should now be on the negative Y-Axis
    fake_sph_orientation has three z-axis particles,
    so there should be three y-axis particles after rotation
    (0, 0, 1) -> (0, -1)
    (0, 0, 2) -> (0, -2)
    (0, 0, 3) -> (0, -3)
    In addition, we should find a local maxima at (0, 0) due to:
    (0, 0, 0) -> (0, 0)
    (0, 1, 0) -> (0, 0)
    (0, 2, 0) -> (0, 0)
    and the one particle on the x-axis should not change its position:
    (1, 0, 0) -> (1, 0)
    """
    expected_maxima = ([0.0, 0.0, 0.0, 0.0, 1.0], [0.0, -1.0, -2.0, -3.0, 0.0])
    normal_vector = [0.0, 1.0, 0.0]
    north_vector = [0.0, 0.0, -1.0]
    resolution = (64, 64)
    ds = fake_sph_orientation_ds()
    left_edge = ds.domain_left_edge
    right_edge = ds.domain_right_edge
    center = (left_edge + right_edge) / 2
    width = right_edge - left_edge
    buf1 = OffAP.off_axis_projection(
        ds,
        center,
        normal_vector,
        width,
        resolution,
        ("gas", "density"),
        north_vector=north_vector,
    )
    find_compare_maxima(expected_maxima, buf1, resolution, width)
Esempio n. 10
0
def test_cutting():
    ds = fake_sph_orientation_ds()
    for (normal, center), answer in CUTTING_ANSWERS.items():
        for i in range(-1, 2):
            cen = [c + 0.1 * i for c in center]
            cut = ds.cutting(normal, cen)
            assert_equal(cut["gas", "density"].shape[0], answer)
Esempio n. 11
0
def test_ray():
    ds = fake_sph_orientation_ds()
    for (start_point, end_point), answer in RAY_ANSWERS.items():
        for i in range(-1, 2):
            start = np.array([s + i * 0.1 for s in start_point])
            end = np.array([e + i * 0.1 for e in end_point])
            ray = ds.ray(start, end)
            assert_equal(ray["gas", "density"].shape[0], answer)
Esempio n. 12
0
def test_slice():
    ds = fake_sph_orientation_ds()
    for (ax, coord), answer in SLICE_ANSWERS.items():
        # test that we can still select particles even if we offset the slice
        # within each particle's smoothing volume
        for i in range(-1, 2):
            sl = ds.slice(ax, coord + i * 0.1)
            assert_equal(sl["gas", "density"].shape[0], answer)
Esempio n. 13
0
def test_profile_sph_data():
    ds = fake_sph_orientation_ds()
    # test we create a profile without raising YTIllDefinedProfile
    yt.create_profile(
        ds.all_data(),
        [("gas", "density"), ("gas", "temperature")],
        [("gas", "kinetic_energy_density")],
        weight_field=None,
    )
Esempio n. 14
0
def test_disk():
    ds = fake_sph_orientation_ds()
    for (center, normal, radius, height), answer in DISK_ANSWERS.items():
        # test that disks enclosing a particle's smoothing region
        # correctly select SPH particles
        for i in range(-1, 2):
            cent = np.array([c + i * 0.1 for c in center])
            disk = ds.disk(cent, normal, radius, height)
            assert_equal(disk["gas", "density"].shape[0], answer)
Esempio n. 15
0
def test_sphere():
    ds = fake_sph_orientation_ds()
    for (center, radius), answer in SPHERE_ANSWERS.items():
        # test that spheres enclosing a particle's smoothing region
        # correctly select SPH particles
        for i in range(-1, 2):
            for j in range(-1, 2):
                cent = np.array([c + i * 0.1 for c in center])
                rad = radius + 0.1 * j
                sph = ds.sphere(cent, rad)
                assert_equal(sph["gas", "density"].shape[0], answer)
Esempio n. 16
0
 def test_set_linear_scaling_for_none_extrema(self):
     # See Issue #3431
     # Ensures that extrema are calculated in the same way on subsequent passes
     # through the PhasePlot machinery.
     ds = fake_sph_orientation_ds()
     p = yt.PhasePlot(
         ds,
         ("all", "particle_position_spherical_theta"),
         ("all", "particle_position_spherical_radius"),
         ("all", "particle_mass"),
         weight_field=None,
     )
     p.set_log(("all", "particle_position_spherical_theta"), False)
     p.save()
Esempio n. 17
0
def test_boolean_selection():
    ds = fake_sph_orientation_ds()

    sph = ds.sphere([0, 0, 0], 0.5)

    sph2 = ds.sphere([1, 0, 0], 0.5)

    reg = ds.all_data()

    neg = reg - sph

    assert_equal(neg["gas", "density"].shape[0], 6)

    plus = sph + sph2

    assert_equal(plus["gas", "density"].shape[0], 2)

    intersect = sph & sph2

    assert_equal(intersect["gas", "density"].shape[0], 0)

    intersect = reg & sph2

    assert_equal(intersect["gas", "density"].shape[0], 1)

    exclusive = sph ^ sph2

    assert_equal(exclusive["gas", "density"].shape[0], 2)

    exclusive = sph ^ reg

    assert_equal(exclusive["gas", "density"].shape[0], 6)

    intersect = ds.intersection([sph, sph2])

    assert_equal(intersect["gas", "density"].shape[0], 0)

    intersect = ds.intersection([reg, sph2])

    assert_equal(intersect["gas", "density"].shape[0], 1)

    union = ds.union([sph, sph2])

    assert_equal(union["gas", "density"].shape[0], 2)

    union = ds.union([sph, reg])

    assert_equal(union["gas", "density"].shape[0], 7)
Esempio n. 18
0
def test_center_3():
    """ Change the center to the left edge, or [0, -8, 0] 
    Every point will be shifted by 8 in the y-domain
    With this, we should not be able to see anything !
    """
    expected_maxima = ([], [])
    normal_vector = [0., 0., 1.]
    resolution = (64, 64)
    ds = fake_sph_orientation_ds()
    left_edge = ds.domain_left_edge
    right_edge = ds.domain_right_edge
    center = [0., -1., 0.]
    width = [(right_edge[0] - left_edge[0]), left_edge[1],
             (right_edge[2] - left_edge[2])]
    buf1 = OffAP.off_axis_projection(ds, center, normal_vector, width,
                                     resolution, ('gas', 'density'))
    find_compare_maxima(expected_maxima, buf1, resolution, width)
Esempio n. 19
0
def test_compare_arbitrary_grid_slice():
    ds = fake_sph_orientation_ds()
    c = np.array([0.0, 0.0, 0.0])
    width = 1.5
    buff_size = 51
    field = ("gas", "density")

    # buffer from arbitrary grid
    ag = ds.arbitrary_grid(c - width / 2, c + width / 2, [buff_size] * 3)
    buff_ag = ag[field][:, :, int(np.floor(buff_size / 2))].d.T

    # buffer from slice
    p = SlicePlot(ds, "z", field, center=c, width=width)
    p.set_buff_size(51)
    buff_slc = p.frb.data[field].d

    assert_equal(buff_slc, buff_ag)
Esempio n. 20
0
def test_region():
    ds = fake_sph_orientation_ds()
    for (left_edge, right_edge), answer in REGION_ANSWERS.items():
        # test that regions enclosing a particle's smoothing region
        # correctly select SPH particles
        for i in range(-1, 2):
            for j in range(-1, 2):
                le = np.array([le + i * 0.1 for le in left_edge])
                re = np.array([re + j * 0.1 for re in right_edge])

                # check if we went off the edge of the domain
                whl = le < ds.domain_left_edge
                le[whl] = ds.domain_left_edge[whl]
                whr = re > ds.domain_right_edge
                re[whr] = ds.domain_right_edge[whr]

                reg = ds.box(le, re)
                assert_equal(reg["gas", "density"].shape[0], answer)
Esempio n. 21
0
def test_point():
    ds = fake_sph_orientation_ds()
    field_data = ds.stream_handler.fields["stream_file"]
    ppos = [field_data["io", f"particle_position_{d}"] for d in "xyz"]
    ppos = np.array(ppos).T
    for pos in ppos:
        for i in range(-1, 2):
            offset = 0.1 * np.array([i, 0, 0])
            pt = ds.point(pos + offset)
            assert_equal(pt["gas", "density"].shape[0], 1)
        for j in range(-1, 2):
            offset = 0.1 * np.array([0, j, 0])
            pt = ds.point(pos + offset)
            assert_equal(pt["gas", "density"].shape[0], 1)
        for k in range(-1, 2):
            offset = 0.1 * np.array([0, 0, k])
            pt = ds.point(pos + offset)
            assert_equal(pt["gas", "density"].shape[0], 1)
Esempio n. 22
0
def test_point():
    ds = fake_sph_orientation_ds()
    field_data = ds.stream_handler.fields['stream_file']
    ppos = [field_data['io', 'particle_position_%s' % d] for d in 'xyz']
    ppos = np.array(ppos).T
    for pos in ppos:
        for i in range(-1, 2):
            offset = 0.1 * np.array([i, 0, 0])
            pt = ds.point(pos + offset)
            assert_equal(pt['gas', 'density'].shape[0], 1)
        for j in range(-1, 2):
            offset = 0.1 * np.array([0, j, 0])
            pt = ds.point(pos + offset)
            assert_equal(pt['gas', 'density'].shape[0], 1)
        for k in range(-1, 2):
            offset = 0.1 * np.array([0, 0, k])
            pt = ds.point(pos + offset)
            assert_equal(pt['gas', 'density'].shape[0], 1)
Esempio n. 23
0
def test_center_2():
    """ Change the center to [0, -1, 0] 
    Every point will be shifted by 1 in the y-domain
    With this, we should not be able to see any of the y-axis particles
    (0, 1, 0) -> (0, 2)
    (0, 2, 0) -> (0, 3)
    (0, 0, 1) -> (0, 1)
    (0, 0, 2) -> (0, 1)
    (0, 0, 3) -> (0, 1)
    (0, 0, 0) -> (0, 1)
    (1, 0, 0) -> (1, 1)
    """
    expected_maxima = ([0., 0., 0., 1.], [2., 3., 1., 1.])
    normal_vector = [0., 0., 1.]
    resolution = (64, 64)
    ds = fake_sph_orientation_ds()
    left_edge = ds.domain_left_edge
    right_edge = ds.domain_right_edge
    center = [0., -1., 0.]
    width = (right_edge - left_edge)
    buf1 = OffAP.off_axis_projection(ds, center, normal_vector, width,
                                     resolution, ('gas', 'density'))
    find_compare_maxima(expected_maxima, buf1, resolution, width)
Esempio n. 24
0
def test_profile_sph_data():
    ds = fake_sph_orientation_ds()
    # test we create a profile without raising YTIllDefinedProfile
    yt.create_profile(ds.all_data(), ['density', 'temperature'],
                      ['kinetic_energy'], weight_field=None)