def test_projection_plot_c(self): test_ds = fake_random_ds(16) for center in CENTER_SPECS: proj = ProjectionPlot(test_ds, 0, ("gas", "density"), center=center) proj.save()
def test_projection_plot_m(self): test_ds = fake_random_ds(16) for method in PROJECTION_METHODS: proj = ProjectionPlot(test_ds, 0, ("gas", "density"), method=method) proj.save()
def test_projection_plot_wf(self): test_ds = fake_random_ds(16) for wf in WEIGHT_FIELDS: proj = ProjectionPlot(test_ds, 0, ("gas", "density"), weight_field=wf) proj.save()
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_projection_plot_ds(self): test_ds = fake_random_ds(16) reg = test_ds.region([0.5] * 3, [0.4] * 3, [0.6] * 3) for dim in range(3): proj = ProjectionPlot(test_ds, dim, ("gas", "density"), data_source=reg) proj.save()
def setUp(self): from yt.config import ytcfg newConfig = { ("yt", "default_colormap"): "viridis", ("plot", "gas", "log"): False, ("plot", "gas", "density", "units"): "lb/yard**3", ("plot", "gas", "density", "path_length_units"): "mile", ("plot", "gas", "density", "cmap"): "plasma", ("plot", "gas", "temperature", "log"): True, ("plot", "gas", "temperature", "linthresh"): 100, ("plot", "gas", "temperature", "cmap"): "hot", ("plot", "gas", "pressure", "log"): True, ("plot", "index", "radius", "linthresh"): 1e3, } # Backup the old config oldConfig = {} for key in newConfig.keys(): try: val = ytcfg[key] oldConfig[key] = val except KeyError: pass for key, val in newConfig.items(): ytcfg[key] = val self.oldConfig = oldConfig self.newConfig = newConfig fields = [("gas", "density"), ("gas", "temperature"), ("gas", "pressure")] units = ["g/cm**3", "K", "dyn/cm**2"] fields_to_plot = fields + [("index", "radius")] if self.ds is None: self.ds = fake_random_ds(16, fields=fields, units=units) self.slc = ProjectionPlot(self.ds, 0, fields_to_plot)
def test_scivis(): if not internet_on(): return ds = SDFDataset(scivis_data) yield assert_equal, str(ds), "ds14_scivis_0128_e4_dt04_1.0000" ad = ds.all_data() assert np.unique(ad['particle_position_x']).size > 1 ProjectionPlot(ds, "z", _fields)
def test_projection_plot_bs(self): test_ds = fake_random_ds(16) for bf in BUFF_SIZES: proj = ProjectionPlot(test_ds, 0, ("gas", "density"), buff_size=bf) image = proj.frb["gas", "density"] # note that image.shape is inverted relative to the passed in buff_size assert_equal(image.shape[::-1], bf)
def test_scivis(): if not internet_on(): return return # HOTFIX: See discussion in 2334 ds = SDFDataset(scivis_data) if scivis_data == slac_scivis_data: assert_equal(str(ds), "ds14_scivis_0128_e4_dt04_1.0000") else: assert_equal(str(ds), "744abba3") ad = ds.all_data() assert np.unique(ad["particle_position_x"]).size > 1 ProjectionPlot(ds, "z", _fields)
def test_creation_with_width(self): test_ds = fake_random_ds(16) for width in WIDTH_SPECS: xlim, ylim, pwidth, aun = WIDTH_SPECS[width] plot = ProjectionPlot(test_ds, 0, 'density', width=width) xlim = [plot.ds.quan(el[0], el[1]) for el in xlim] ylim = [plot.ds.quan(el[0], el[1]) for el in ylim] pwidth = [plot.ds.quan(el[0], el[1]) for el in pwidth] [assert_array_almost_equal(px, x, 14) for px, x in zip(plot.xlim, xlim)] [assert_array_almost_equal(py, y, 14) for py, y in zip(plot.ylim, ylim)] [assert_array_almost_equal(pw, w, 14) for pw, w in zip(plot.width, pwidth)] assert_true(aun == plot._axes_unit_names)
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() 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., 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", ), 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), (.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_magnetic_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields = ("density", "magnetic_field_x", "magnetic_field_y", "magnetic_field_z")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_magnetic_field() yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_magnetic_field() yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_magnetic_field(factor=8, scale=0.5, scale_units="inches", normalize = True) p.save(prefix)
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!') yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_text([0.5,0.5,0.5], 'dinosaurs!') yield assert_fname, p.save(prefix)[0] p = OffAxisSlicePlot(ds, vector, "density") p.annotate_text([0.5,0.5,0.5], 'dinosaurs!') yield 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)
def test_magnetic_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "magnetic_field_x", "magnetic_field_y", "magnetic_field_z")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_magnetic_field() assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_magnetic_field() assert_fname(p.save(prefix)[0]) # Test for OffAxis Slice p = SlicePlot(ds, [1, 1, 0], 'density', north_vector=[0, 0, 1]) p.annotate_magnetic_field(factor=40, normalize=True) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_magnetic_field(factor=8, scale=0.5, scale_units="inches", normalize=True) assert_fname(p.save(prefix)[0]) with _cleanup_fname() as prefix: ds = load(cyl_2d) slc = SlicePlot(ds, "theta", "magnetic_field_strength") slc.annotate_magnetic_field() assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = load(cyl_3d) for ax in ["r", "z", "theta"]: slc = SlicePlot(ds, ax, "magnetic_field_strength") slc.annotate_magnetic_field() assert_fname(slc.save(prefix)[0]) slc = ProjectionPlot(ds, ax, "magnetic_field_strength") slc.annotate_magnetic_field() assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "magnetic_field_r", "magnetic_field_theta", "magnetic_field_phi"), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_magnetic_field(factor=8, scale=0.5, scale_units="inches", normalize=True) assert_raises(YTDataTypeUnsupported, 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_streamline_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y", "magvel")) for ax in 'xyz': # Projection plot tests p = ProjectionPlot(ds, ax, "density") p.annotate_streamlines("velocity_x", "velocity_y") assert_fname(p.save(prefix)[0]) p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_streamlines("velocity_x", "velocity_y") assert_fname(p.save(prefix)[0]) # Slice plot test p = SlicePlot(ds, ax, "density") p.annotate_streamlines("velocity_x", "velocity_y") assert_fname(p.save(prefix)[0]) # Additional features p = SlicePlot(ds, ax, "density") p.annotate_streamlines("velocity_x", "velocity_y", factor=32, density=4) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_streamlines("velocity_x", "velocity_y", field_color="magvel") assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_streamlines("velocity_x", "velocity_y", field_color="magvel", display_threshold=0.5, plot_args={ 'cmap': ytcfg.get("yt", "default_colormap"), 'arrowstyle': '->' }) assert_fname(p.save(prefix)[0]) # Axisymmetric dataset with _cleanup_fname() as prefix: ds = load(cyl_2d) slc = SlicePlot(ds, "theta", "velocity_magnitude") slc.annotate_streamlines("velocity_r", "velocity_z") assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = load(cyl_3d) slc = SlicePlot(ds, "r", "velocity_magnitude") slc.annotate_streamlines("velocity_theta", "velocity_z") assert_fname(slc.save(prefix)[0]) slc = SlicePlot(ds, "z", "velocity_magnitude") slc.annotate_streamlines("velocity_cartesian_x", "velocity_cartesian_y") assert_fname(slc.save(prefix)[0]) slc = SlicePlot(ds, "theta", "velocity_magnitude") slc.annotate_streamlines("velocity_r", "velocity_z") assert_fname(slc.save(prefix)[0]) # Spherical dataset with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "velocity_r", "velocity_theta", "velocity_phi"), geometry="spherical") p = SlicePlot(ds, "r", "density") p.annotate_streamlines("velocity_theta", "velocity_phi") assert_raises(YTDataTypeUnsupported, p.save, prefix)
def test_particles_callback(): with _cleanup_fname() as prefix: ax = 'z' ds = fake_amr_ds(fields=("density", ), particles=1) p = ProjectionPlot(ds, ax, "density") p.annotate_particles((10, "Mpc")) assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_particles((10, "Mpc")) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") ad = ds.all_data() p.annotate_particles((10, "Mpc"), p_size=1.0, col="k", marker="o", stride=1, ptype="all", alpha=1.0, data_source=ad) p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", ), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_particles((10, "Mpc")) assert_raises(YTDataTypeUnsupported, p.save, prefix)
def test_contour_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "temperature")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_contour("temperature") assert_fname(p.save(prefix)[0]) p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_contour("temperature") assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_contour("temperature") # BREAKS WITH ndarray assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_contour("temperature", ncont=10, factor=8, take_log=False, clim=(0.4, 0.6), plot_args={'linewidths': 2.0}, label=True, text_args={'fontsize': 'x-large'}) p.save(prefix) p = SlicePlot(ds, "x", "density") s2 = ds.slice(0, 0.2) p.annotate_contour("temperature", ncont=10, factor=8, take_log=False, clim=(0.4, 0.6), plot_args={'linewidths': 2.0}, label=True, text_args={'fontsize': 'x-large'}, data_source=s2) p.save(prefix) with _cleanup_fname() as prefix: ds = load(cyl_2d) slc = SlicePlot(ds, "theta", "plasma_beta") slc.annotate_contour("plasma_beta", ncont=2, factor=7., take_log=False, clim=(1.e-1, 1.e1), label=True, plot_args={ "colors": ("c", "w"), "linewidths": 1 }, text_args={"fmt": "%1.1f"}) assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "temperature"), geometry="spherical") p = SlicePlot(ds, "r", "density") p.annotate_contour("temperature", ncont=10, factor=8, take_log=False, clim=(0.4, 0.6), plot_args={'linewidths': 2.0}, label=True, text_args={'fontsize': 'x-large'}) assert_raises(YTDataTypeUnsupported, p.save, prefix)
def test_cell_edges_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", )) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_cell_edges() assert_fname(p.save(prefix)[0]) p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_cell_edges() assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_cell_edges() assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_cell_edges(alpha=0.7, line_width=0.9, color=(0.0, 1.0, 1.0)) p.save(prefix) with _cleanup_fname() as prefix: ds = load(cyl_2d) slc = SlicePlot(ds, "theta", "density") slc.annotate_cell_edges() assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", ), geometry="spherical") p = SlicePlot(ds, "r", "density") p.annotate_cell_edges() assert_raises(YTDataTypeUnsupported, p.save, prefix)
def test_quiver_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields = ("density", "velocity_x", "velocity_y", "velocity_z")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_quiver("velocity_x", "velocity_y") yield assert_fname, p.save(prefix)[0] p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_quiver("velocity_x", "velocity_y") yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_quiver("velocity_x", "velocity_y") yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_quiver("velocity_x", "velocity_y", factor=8, scale=0.5, scale_units="inches", normalize = True, bv_x = 0.5 * u.cm / u.s, bv_y = 0.5 * u.cm / u.s) p.save(prefix)
def test_contour_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields = ("density", "temperature")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_contour("temperature") yield assert_fname, p.save(prefix)[0] p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_contour("temperature") yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_contour("temperature") # BREAKS WITH ndarray yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_contour("temperature", ncont=10, factor=8, take_log=False, clim=(0.4, 0.6), plot_args={'lw':2.0}, label=True, text_args={'text-size':'x-large'}) p.save(prefix) p = SlicePlot(ds, "x", "density") s2 = ds.slice(0, 0.2) p.annotate_contour("temperature", ncont=10, factor=8, take_log=False, clim=(0.4, 0.6), plot_args={'lw':2.0}, label=True, text_args={'text-size':'x-large'}, data_source=s2) p.save(prefix)
def test_grids_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields = ("density",)) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_grids() yield assert_fname, p.save(prefix)[0] p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_grids() yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_grids() yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_grids(alpha=0.7, min_pix=10, min_pix_ids=30, draw_ids=True, periodic=False, min_level=2, max_level=3, cmap="gist_stern") p.save(prefix)
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_projection_plot(self): test_ds = fake_random_ds(16) for dim in range(3): proj = ProjectionPlot(test_ds, dim, 'density') for fname in TEST_FLNMS: assert assert_fname(proj.save(fname)[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_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_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_velocity_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y", "velocity_z")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_velocity() assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_velocity() assert_fname(p.save(prefix)[0]) # Test for OffAxis Slice p = SlicePlot(ds, [1, 1, 0], 'density', north_vector=[0, 0, 1]) p.annotate_velocity(factor=40, normalize=True) assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_velocity(factor=8, scale=0.5, scale_units="inches", normalize=True) assert_fname(p.save(prefix)[0]) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "velocity_r", "velocity_theta", "velocity_phi"), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_velocity(factor=40, normalize=True) assert_raises(YTDataTypeUnsupported, p.save, prefix)
def test_quiver_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y", "velocity_z")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_quiver("velocity_x", "velocity_y") assert_fname(p.save(prefix)[0]) p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_quiver("velocity_x", "velocity_y") assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_quiver("velocity_x", "velocity_y") assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_quiver("velocity_x", "velocity_y", factor=8, scale=0.5, scale_units="inches", normalize=True, bv_x=0.5 * u.cm / u.s, bv_y=0.5 * u.cm / u.s) assert_fname(p.save(prefix)[0]) with _cleanup_fname() as prefix: ds = load(cyl_2d) slc = SlicePlot(ds, "theta", "density") slc.annotate_quiver("velocity_r", "velocity_z") assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = load(cyl_3d) slc = SlicePlot(ds, "r", "velocity_magnitude") slc.annotate_quiver("velocity_theta", "velocity_z") assert_fname(slc.save(prefix)[0]) slc = SlicePlot(ds, "z", "velocity_magnitude") slc.annotate_quiver("velocity_cartesian_x", "velocity_cartesian_y") assert_fname(slc.save(prefix)[0]) slc = SlicePlot(ds, "theta", "velocity_magnitude") slc.annotate_quiver("velocity_r", "velocity_z") assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_theta", "velocity_phi"), geometry="spherical") p = ProjectionPlot(ds, "r", "density") p.annotate_quiver("velocity_theta", "velocity_phi", factor=8, scale=0.5, scale_units="inches", normalize=True, bv_x=0.5 * u.cm / u.s, bv_y=0.5 * u.cm / u.s) assert_raises(YTDataTypeUnsupported, 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",)) 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_grids_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", )) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_grids() assert_fname(p.save(prefix)[0]) p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_grids() assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_grids() assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_grids(alpha=0.7, min_pix=10, min_pix_ids=30, draw_ids=True, id_loc="upper right", periodic=False, min_level=2, max_level=3, cmap="gist_stern") p.save(prefix) with _cleanup_fname() as prefix: ds = load(cyl_2d) slc = SlicePlot(ds, "theta", "density") slc.annotate_grids() assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", ), geometry="spherical") p = SlicePlot(ds, "r", "density") p.annotate_grids(alpha=0.7, min_pix=10, min_pix_ids=30, draw_ids=True, id_loc="upper right", periodic=False, min_level=2, max_level=3, cmap="gist_stern") assert_raises(YTDataTypeUnsupported, p.save, prefix)
def test_grids_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", )) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_grids() yield assert_fname, p.save(prefix)[0] p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_grids() yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_grids() yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_grids(alpha=0.7, min_pix=10, min_pix_ids=30, draw_ids=True, periodic=False, min_level=2, max_level=3, cmap="gist_stern") 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() 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_magnetic_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "magnetic_field_x", "magnetic_field_y", "magnetic_field_z")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_magnetic_field() yield assert_fname, p.save(prefix)[0] p = SlicePlot(ds, ax, "density") p.annotate_magnetic_field() yield assert_fname, p.save(prefix)[0] # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_magnetic_field(factor=8, scale=0.5, scale_units="inches", normalize=True) p.save(prefix)
def test_line_integral_convolution_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y", "velocity_z")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_line_integral_convolution("velocity_x", "velocity_y") assert_fname(p.save(prefix)[0]) p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_line_integral_convolution("velocity_x", "velocity_y") assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_line_integral_convolution("velocity_x", "velocity_y") assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_line_integral_convolution("velocity_x", "velocity_y", kernellen=100., lim=(0.4, 0.7), cmap=ytcfg.get( "yt", "default_colormap"), alpha=0.9, const_alpha=True) p.save(prefix) with _cleanup_fname() as prefix: ds = load(cyl_2d) slc = SlicePlot(ds, "theta", "magnetic_field_strength") slc.annotate_line_integral_convolution("magnetic_field_r", "magnetic_field_z") assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = load(cyl_3d) slc = SlicePlot(ds, "r", "magnetic_field_strength") slc.annotate_line_integral_convolution("magnetic_field_theta", "magnetic_field_z") assert_fname(slc.save(prefix)[0]) slc = SlicePlot(ds, "z", "magnetic_field_strength") slc.annotate_line_integral_convolution("magnetic_field_cartesian_x", "magnetic_field_cartesian_y") assert_fname(slc.save(prefix)[0]) slc = SlicePlot(ds, "theta", "magnetic_field_strength") slc.annotate_line_integral_convolution("magnetic_field_r", "magnetic_field_z") assert_fname(slc.save(prefix)[0]) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "velocity_r", "velocity_theta", "velocity_phi"), geometry="spherical") p = SlicePlot(ds, "r", "density") p.annotate_line_integral_convolution("velocity_theta", "velocity_phi") assert_raises(YTDataTypeUnsupported, p.save, prefix)
def test_contour_callback(): with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "temperature")) for ax in 'xyz': p = ProjectionPlot(ds, ax, "density") p.annotate_contour("temperature") assert_fname(p.save(prefix)[0]) p = ProjectionPlot(ds, ax, "density", weight_field="density") p.annotate_contour("temperature") assert_fname(p.save(prefix)[0]) p = SlicePlot(ds, ax, "density") p.annotate_contour("temperature") # BREAKS WITH ndarray assert_fname(p.save(prefix)[0]) # Now we'll check a few additional minor things p = SlicePlot(ds, "x", "density") p.annotate_contour("temperature", ncont=10, factor=8, take_log=False, clim=(0.4, 0.6), plot_args={'lw': 2.0}, label=True, text_args={'text-size': 'x-large'}) p.save(prefix) p = SlicePlot(ds, "x", "density") s2 = ds.slice(0, 0.2) p.annotate_contour("temperature", ncont=10, factor=8, take_log=False, clim=(0.4, 0.6), plot_args={'lw': 2.0}, label=True, text_args={'text-size': 'x-large'}, data_source=s2) p.save(prefix) with _cleanup_fname() as prefix: ds = fake_amr_ds(fields=("density", "temperature"), geometry="spherical") p = SlicePlot(ds, "r", "density") p.annotate_contour("temperature", ncont=10, factor=8, take_log=False, clim=(0.4, 0.6), plot_args={'lw': 2.0}, label=True, text_args={'text-size': 'x-large'}) 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_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)