def test_field_cut_off_axis_octree(): ds = fake_octree_ds() cut = ds.all_data().cut_region('obj["density"]>0.5') p1 = OffAxisProjectionPlot(ds, [1, 0, 0], 'density') p2 = OffAxisProjectionPlot(ds, [1, 0, 0], 'density', data_source=cut) assert_equal(p2.frb["density"].min() == 0.0, True) # Lots of zeros assert_equal((p1.frb["density"] == p2.frb["density"]).all(), False) p3 = OffAxisSlicePlot(ds, [1, 0, 0], 'density') p4 = OffAxisSlicePlot(ds, [1, 0, 0], 'density', data_source=cut) assert_equal((p3.frb["density"] == p4.frb["density"]).all(), False) p4rho = p4.frb["density"] assert_equal(p4rho.min() == 0.0, True) # Lots of zeros assert_equal(p4rho[p4rho > 0.0].min() >= 0.5, True)
def test_text_callback(): with _cleanup_fname() as prefix: ax = "z" vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density",), units=("g/cm**3",)) p = ProjectionPlot(ds, ax, ("gas", "density")) p.annotate_text([0.5, 0.5, 0.5], "dinosaurs!") assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, ("gas", "density")) p.annotate_text([0.5, 0.5, 0.5], "dinosaurs!") assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, ("gas", "density")) p.annotate_text([0.5, 0.5, 0.5], "dinosaurs!") assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", ("gas", "density")) p.annotate_text( [0.5, 0.5], "dinosaurs!", coord_system="axis", text_args={"color": "red"} ) p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density",), units=("g/cm**3",), geometry="spherical") p = ProjectionPlot(ds, "r", ("gas", "density")) p.annotate_text([0.5, 0.5, 0.5], "dinosaurs!") assert_raises(YTDataTypeUnsupported, p.save, prefix) p = ProjectionPlot(ds, "r", ("gas", "density")) p.annotate_text( [0.5, 0.5], "dinosaurs!", coord_system="axis", text_args={"color": "red"} ) assert_fname(p.save(prefix)[0])
def setUpClass(cls): test_ds = fake_random_ds(64) normal = [1, 1, 1] ds_region = test_ds.region([0.5] * 3, [0.4] * 3, [0.6] * 3) projections = [] projections_ds = [] projections_c = [] projections_wf = [] projections_w = {} for dim in range(3): projections.append(ProjectionPlot(test_ds, dim, "density")) projections_ds.append( ProjectionPlot(test_ds, dim, "density", data_source=ds_region)) for center in CENTER_SPECS: projections_c.append( ProjectionPlot(test_ds, dim, "density", center=center)) for width in WIDTH_SPECS: projections_w[width] = ProjectionPlot(test_ds, dim, 'density', width=width) for wf in WEIGHT_FIELDS: projections_wf.append( ProjectionPlot(test_ds, dim, "density", weight_field=wf)) cls.slices = [SlicePlot(test_ds, dim, "density") for dim in range(3)] cls.projections = projections cls.projections_ds = projections_ds cls.projections_c = projections_c cls.projections_wf = projections_wf cls.projections_w = projections_w cls.offaxis_slice = OffAxisSlicePlot(test_ds, normal, "density") cls.offaxis_proj = OffAxisProjectionPlot(test_ds, normal, "density")
def test_timestamp_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", )) p = ProjectionPlot(ds, ax, "density") p.annotate_timestamp() assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_timestamp() assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, "density") p.annotate_timestamp() assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_timestamp(corner='lower_right', redshift=True, draw_inset_box=True) p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", ), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_timestamp(coord_system="data") assert_raises(YTDataTypeUnsupported, p.save, prefix) p = ProjectionPlot(ds, "r", "density") p.annotate_timestamp(coord_system="axis") assert_fname(p.save(prefix)[0])
def test_arrow_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0,1.0,1.0] ds = fake_amr_ds(fields = ("density",)) p = ProjectionPlot(ds, ax, "density") p.annotate_arrow([0.5,0.5,0.5]) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_arrow([0.5,0.5,0.5]) assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, "density") p.annotate_arrow([0.5,0.5,0.5]) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_arrow([0.5,0.5], coord_system='axis', length=0.05) p.annotate_arrow([[0.5,0.6],[0.5,0.6],[0.5,0.6]], coord_system='data', length=0.05) p.annotate_arrow([[0.5,0.6,0.8],[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='data', length=0.05) p.annotate_arrow([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='axis', length=0.05) p.annotate_arrow([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='figure', length=0.05) p.annotate_arrow([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='plot', length=0.05) p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields = ("density",), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_arrow([0.5,0.5,0.5]) assert_raises(YTDataTypeUnsupported, p.save, prefix) p = ProjectionPlot(ds, "r", "density") p.annotate_arrow([0.5,0.5], coord_system="axis") assert_fname(p.save(prefix)[0])
def test_marker_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0,1.0,1.0] ds = fake_amr_ds(fields = ("density",)) p = ProjectionPlot(ds, ax, "density") p.annotate_marker([0.5,0.5,0.5]) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_marker([0.5,0.5,0.5]) assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, "density") p.annotate_marker([0.5,0.5,0.5]) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") coord = ds.arr([0.75, 0.75, 0.75], 'unitary') coord.convert_to_units('kpc') p.annotate_marker(coord, coord_system='data') p.annotate_marker([0.5,0.5], coord_system='axis', marker='*') p.annotate_marker([[0.5,0.6],[0.5,0.6],[0.5,0.6]], coord_system='data') p.annotate_marker([[0.5,0.6,0.8],[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='data') p.annotate_marker([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='axis') p.annotate_marker([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='figure') p.annotate_marker([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='plot') p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields = ("density",), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_marker([0.5,0.5,0.5]) assert_raises(YTDataTypeUnsupported, p.save, prefix) p = ProjectionPlot(ds, "r", "density") p.annotate_marker([0.5,0.5], coord_system="axis") assert_fname(p.save(prefix)[0])
def test_scale_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0,1.0,1.0] ds = fake_amr_ds(fields = ("density",)) p = ProjectionPlot(ds, ax, "density") p.annotate_scale() yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_scale() yield assert_fname, p.save(prefix)[0] p = OffAxisSlicePlot(ds, vector, "density") p.annotate_scale() yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_scale(corner='upper_right', coeff=10., unit='kpc') yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, "x", "density") p.annotate_scale(text_args={"size": 24}) yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, "x", "density") p.annotate_scale(text_args={"font": 24}) yield assert_raises, YTPlotCallbackError with _cleanup_fname() as prefix: ds = fake_amr_ds(fields = ("density",), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_scale() yield assert_raises, YTDataTypeUnsupported, p.save, prefix p = ProjectionPlot(ds, "r", "density") p.annotate_scale(coord_system="axis") yield assert_raises, YTDataTypeUnsupported, p.save, prefix
def test_marker_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0,1.0,1.0] ds = fake_amr_ds(fields = ("density",)) p = ProjectionPlot(ds, ax, "density") p.annotate_marker([0.5,0.5,0.5]) yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_marker([0.5,0.5,0.5]) yield assert_fname, p.save(prefix)[0] p = OffAxisSlicePlot(ds, vector, "density") p.annotate_marker([0.5,0.5,0.5]) yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_marker([0.5,0.5], coord_system='axis', marker='*') p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields = ("density",), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_marker([0.5,0.5,0.5]) yield assert_raises, YTDataTypeUnsupported, p.save, prefix p = ProjectionPlot(ds, "r", "density") p.annotate_marker([0.5,0.5], coord_system="axis") yield assert_fname, p.save(prefix)[0]
def test_ray_callback(): with _cleanup_fname() as prefix: ax = "z" vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density",), units=("g/cm**3",)) ray = ds.ray((0.1, 0.2, 0.3), (0.6, 0.8, 0.5)) oray = ds.ortho_ray(0, (0.3, 0.4)) p = ProjectionPlot(ds, ax, ("gas", "density")) p.annotate_ray(oray) p.annotate_ray(ray) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, ("gas", "density")) p.annotate_ray(oray) p.annotate_ray(ray) assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, ("gas", "density")) p.annotate_ray(oray) p.annotate_ray(ray) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", ("gas", "density")) p.annotate_ray(oray) p.annotate_ray(ray, color="red") p.save(prefix) check_axis_manipulation(p, prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density",), units=("g/cm**3",), geometry="spherical") ray = ds.ray((0.1, 0.2, 0.3), (0.6, 0.8, 0.5)) oray = ds.ortho_ray(0, (0.3, 0.4)) p = ProjectionPlot(ds, "r", ("gas", "density")) assert_raises(YTDataTypeUnsupported, p.annotate_ray, oray) assert_raises(YTDataTypeUnsupported, p.annotate_ray, ray)
def test_line_callback(): with _cleanup_fname() as prefix: ax = "z" vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density",), units=("g/cm**3",)) p = ProjectionPlot(ds, ax, ("gas", "density")) p.annotate_line([0.1, 0.1, 0.1], [0.5, 0.5, 0.5]) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, ("gas", "density")) p.annotate_line([0.1, 0.1, 0.1], [0.5, 0.5, 0.5]) assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, ("gas", "density")) p.annotate_line([0.1, 0.1, 0.1], [0.5, 0.5, 0.5]) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", ("gas", "density")) p.annotate_line([0.1, 0.1], [0.5, 0.5], coord_system="axis", color="red") p.save(prefix) check_axis_manipulation(p, prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density",), units=("g/cm**3",), geometry="spherical") p = ProjectionPlot(ds, "r", ("gas", "density")) assert_raises( YTDataTypeUnsupported, p.annotate_line, [0.1, 0.1, 0.1], [0.5, 0.5, 0.5] ) p.annotate_line([0.1, 0.1], [0.5, 0.5], coord_system="axis") assert_fname(p.save(prefix)[0])
def test_ray_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", )) ray = ds.ray((0.1, 0.2, 0.3), (.6, .8, .5)) oray = ds.ortho_ray(0, (0.3, 0.4)) p = ProjectionPlot(ds, ax, "density") p.annotate_ray(oray) p.annotate_ray(ray) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_ray(oray) p.annotate_ray(ray) assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, "density") p.annotate_ray(oray) p.annotate_ray(ray) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_ray(oray) p.annotate_ray(ray, plot_args={'color': 'red'}) p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", ), geometry="spherical") ray = ds.ray((0.1, 0.2, 0.3), (0.6, 0.8, 0.5)) oray = ds.ortho_ray(0, (0.3, 0.4)) p = ProjectionPlot(ds, "r", "density") p.annotate_ray(oray) assert_raises(YTDataTypeUnsupported, p.save, prefix) p = ProjectionPlot(ds, "r", "density") p.annotate_ray(ray) assert_raises(YTDataTypeUnsupported, p.save, prefix)
def test_sphere_callback(): with _cleanup_fname() as prefix: ax = "z" vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density",)) p = ProjectionPlot(ds, ax, "density") p.annotate_sphere([0.5, 0.5, 0.5], 0.1) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_sphere([0.5, 0.5, 0.5], 0.1) assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, "density") p.annotate_sphere([0.5, 0.5, 0.5], 0.1) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_sphere([0.5, 0.5], 0.1, coord_system="axis", text="blah") p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density",), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_sphere([0.5, 0.5, 0.5], 0.1) assert_raises(YTDataTypeUnsupported, p.save, prefix) p = ProjectionPlot(ds, "r", "density") p.annotate_sphere([0.5, 0.5], 0.1, coord_system="axis", text="blah") assert_fname(p.save(prefix)[0])
def test_text_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", )) p = ProjectionPlot(ds, ax, "density") p.annotate_text([0.5, 0.5, 0.5], 'dinosaurs!') assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_text([0.5, 0.5, 0.5], 'dinosaurs!') assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, "density") p.annotate_text([0.5, 0.5, 0.5], 'dinosaurs!') assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_text([0.5, 0.5], 'dinosaurs!', coord_system='axis', text_args={'color': 'red'}) p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", ), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_text([0.5, 0.5, 0.5], 'dinosaurs!') assert_raises(YTDataTypeUnsupported, p.save, prefix) p = ProjectionPlot(ds, "r", "density") p.annotate_text([0.5, 0.5], 'dinosaurs!', coord_system='axis', text_args={'color': 'red'}) assert_fname(p.save(prefix)[0])
def test_on_off_compare(): # fake density field that varies in the x-direction only den = np.arange(32 ** 3) / 32 ** 2 + 1 den = den.reshape(32, 32, 32) den = np.array(den, dtype=np.float64) data = dict(density=(den, "g/cm**3")) bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [-1.5, 1.5]]) ds = load_uniform_grid(data, den.shape, length_unit="Mpc", bbox=bbox, nprocs=64) sl_on = SlicePlot(ds, "z", [("gas", "density")]) L = [0, 0, 1] north_vector = [0, 1, 0] sl_off = OffAxisSlicePlot( ds, L, ("gas", "density"), center=[0, 0, 0], north_vector=north_vector ) assert_array_almost_equal( sl_on.frb[("gas", "density")], sl_off.frb[("gas", "density")] ) sl_on.set_buff_size((800, 400)) sl_on._recreate_frb() sl_off.set_buff_size((800, 400)) sl_off._recreate_frb() assert_array_almost_equal( sl_on.frb[("gas", "density")], sl_off.frb[("gas", "density")] )
def test_scale_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", )) p = ProjectionPlot(ds, ax, "density") p.annotate_scale() yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_scale() yield assert_fname, p.save(prefix)[0] p = OffAxisSlicePlot(ds, vector, "density") p.annotate_scale() yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_scale(corner='upper_right', coeff=10., unit='kpc') p.save(prefix)
def test_sphere_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", )) p = ProjectionPlot(ds, ax, "density") p.annotate_sphere([0.5, 0.5, 0.5], 0.1) yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_sphere([0.5, 0.5, 0.5], 0.1) yield assert_fname, p.save(prefix)[0] p = OffAxisSlicePlot(ds, vector, "density") p.annotate_sphere([0.5, 0.5, 0.5], 0.1) yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_sphere([0.5, 0.5], 0.1, coord_system='axis', text='blah') p.save(prefix)
def test_marker_callback(): with _cleanup_fname() as prefix: ax = "z" vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", ), units=("g/cm**3", )) p = ProjectionPlot(ds, ax, ("gas", "density")) p.annotate_marker([0.5, 0.5, 0.5]) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, ("gas", "density")) p.annotate_marker([0.5, 0.5, 0.5]) assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, ("gas", "density")) p.annotate_marker([0.5, 0.5, 0.5]) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", ("gas", "density")) coord = ds.arr([0.75, 0.75, 0.75], "unitary") coord.convert_to_units("kpc") p.annotate_marker(coord, coord_system="data") p.annotate_marker([0.5, 0.5], coord_system="axis", marker="*") p.annotate_marker([[0.5, 0.6], [0.5, 0.6], [0.5, 0.6]], coord_system="data") p.annotate_marker([[0.5, 0.6, 0.8], [0.5, 0.6, 0.8], [0.5, 0.6, 0.8]], coord_system="data") p.annotate_marker([[0.5, 0.6, 0.8], [0.5, 0.6, 0.8]], coord_system="axis") p.annotate_marker([[0.5, 0.6, 0.8], [0.5, 0.6, 0.8]], coord_system="figure") p.annotate_marker([[0.5, 0.6, 0.8], [0.5, 0.6, 0.8]], coord_system="plot") p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", ), units=("g/cm**3", ), geometry="spherical") p = ProjectionPlot(ds, "r", ("gas", "density")) p.annotate_marker([0.5, 0.5, 0.5]) assert_raises(YTDataTypeUnsupported, p.save, prefix) p = ProjectionPlot(ds, "r", ("gas", "density")) p.annotate_marker([0.5, 0.5], coord_system="axis") assert_fname(p.save(prefix)[0])
def test_line_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", )) p = ProjectionPlot(ds, ax, "density") p.annotate_line([0.1, 0.1, 0.1], [0.5, 0.5, 0.5]) yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_line([0.1, 0.1, 0.1], [0.5, 0.5, 0.5]) yield assert_fname, p.save(prefix)[0] p = OffAxisSlicePlot(ds, vector, "density") p.annotate_line([0.1, 0.1, 0.1], [0.5, 0.5, 0.5]) yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_line([0.1, 0.1], [0.5, 0.5], coord_system='axis', plot_args={'color': 'red'}) p.save(prefix)
def test_timestamp_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", )) p = ProjectionPlot(ds, ax, "density") p.annotate_timestamp() yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_timestamp() yield assert_fname, p.save(prefix)[0] p = OffAxisSlicePlot(ds, vector, "density") p.annotate_timestamp() yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_timestamp(corner='lower_right', redshift=True, draw_inset_box=True) p.save(prefix)
def test_scale_callback(): with _cleanup_fname() as prefix: ax = "z" vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", ), units=("g/cm**3", )) p = ProjectionPlot(ds, ax, "density") p.annotate_scale() assert_fname(p.save(prefix)[0]) p = ProjectionPlot(ds, ax, "density", width=(0.5, 1.0)) p.annotate_scale() assert_fname(p.save(prefix)[0]) p = ProjectionPlot(ds, ax, "density", width=(1.0, 1.5)) p.annotate_scale() assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_scale() assert_fname(p.save(prefix)[0]) p = OffAxisSlicePlot(ds, vector, "density") p.annotate_scale() assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_scale(corner="upper_right", coeff=10.0, unit="kpc") assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, "x", "density") p.annotate_scale(text_args={"size": 24}) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, "x", "density") p.annotate_scale(text_args={"font": 24}) assert_raises(YTPlotCallbackError) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", ), units=("g/cm**3", ), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_scale() assert_raises(YTDataTypeUnsupported, p.save, prefix) p = ProjectionPlot(ds, "r", "density") p.annotate_scale(coord_system="axis") assert_raises(YTDataTypeUnsupported, p.save, prefix)
def test_ray_callback(): with _cleanup_fname() as prefix: ax = 'z' vector = [1.0, 1.0, 1.0] ds = fake_amr_ds(fields=("density", )) ray = ds.ray((0.1, 0.2, 0.3), (1.6, 1.8, 1.5)) oray = ds.ortho_ray(0, (0.3, 0.4)) p = ProjectionPlot(ds, ax, "density") p.annotate_ray(oray) p.annotate_ray(ray) yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_ray(oray) p.annotate_ray(ray) yield assert_fname, p.save(prefix)[0] p = OffAxisSlicePlot(ds, vector, "density") p.annotate_ray(oray) p.annotate_ray(ray) yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_ray(oray) p.annotate_ray(ray, plot_args={'color': 'red'}) p.save(prefix)
def test_offaxis_slice_plot(self): test_ds = fake_random_ds(16) slc = OffAxisSlicePlot(test_ds, [1, 1, 1], "density") for fname in TEST_FLNMS: assert assert_fname(slc.save(fname)[0])