def test_covering_grid(): return # We decompose in different ways cs = np.mgrid[0.47:0.53:2j, 0.47:0.53:2j, 0.47:0.53:2j] cs = np.array([a.ravel() for a in cs]).T length = (1.0 / 128) * 16 # 16 half-widths of a cell for nprocs in [1, 2, 4, 8]: ds = fake_random_ds(64, nprocs=nprocs, fields=_fields) streams = Streamlines(ds, cs, length=length) streams.integrate_through_volume() for path in (streams.path(i) for i in range(8)): yield assert_rel_equal, path['dts'].sum(), 1.0, 14 yield assert_equal, np.all(path['t'] <= (1.0 + 1e-10)), True path["density"]
def test_covering_grid(): return # We decompose in different ways cs = np.mgrid[0.47:0.53:2j,0.47:0.53:2j,0.47:0.53:2j] cs = np.array([a.ravel() for a in cs]).T length = (1.0/128) * 16 # 16 half-widths of a cell for nprocs in [1, 2, 4, 8]: ds = fake_random_ds(64, nprocs = nprocs, fields = _fields) streams = Streamlines(ds, cs, length=length) streams.integrate_through_volume() for path in (streams.path(i) for i in range(8)): yield assert_rel_equal, path['dts'].sum(), 1.0, 14 yield assert_equal, np.all(path['t'] <= (1.0 + 1e-10)), True path["density"]
def _integrate(self): #inbound streamlines = Streamlines(self.ds, self.init_coords.T, 'magnetic_field_x', 'magnetic_field_y', 'magnetic_field_z', length=self.ds.quan(10, 'code_length'), get_magnitude=True, direction=1) streamlines.integrate_through_volume() self.streamlines_in = streamlines #outbound streamlines = Streamlines(self.ds, self.init_coords.T, 'magnetic_field_x', 'magnetic_field_y', 'magnetic_field_z', length=self.ds.quan(10, 'code_length'), get_magnitude=True, direction=-1) streamlines.integrate_through_volume() self.streamlines_out = streamlines
from yt.visualization.api import Streamlines import random fname = '/Users/jillnaiman1/data/IsolatedGalaxy/galaxy0030/galaxy0030' # home # now, get stream line ds = yt.load(fname) c = np.array([0.5]*3) N = 10 # number of stream lines scale = 1.0 pos_dx = np.random.random((N,3))*scale-scale/2. pos = c+pos_dx streamlines = Streamlines(ds,pos,'velocity_x', 'velocity_y', 'velocity_z', length=1.0) streamlines.integrate_through_volume() # select out 1 stream... for now stream = streamlines.streamlines[1] stream = stream[np.all(stream != 0.0, axis=1)] # doen something fancy # units stream = stream*ds.length_unit # into cm # now, scale down to what we want stream = stream/yt.units.cm stream = stream/3.1e18 # pc # for this case
# Define c: the center of the box, N: the number of streamlines, # scale: the spatial scale of the streamlines relative to the boxsize, # and then pos: the random positions of the streamlines. c = ds.domain_center N = 100 scale = ds.domain_width[0] pos_dx = np.random.random((N, 3)) * scale - scale / 2.0 pos = c + pos_dx # Create streamlines of the 3D vector velocity and integrate them through # the box defined above streamlines = Streamlines( ds, pos, ("gas", "velocity_x"), ("gas", "velocity_y"), ("gas", "velocity_z"), length=1.0 * Mpc, get_magnitude=True, ) streamlines.integrate_through_volume() # Create a 3D plot, trace the streamlines through the 3D volume of the plot fig = plt.figure() ax = Axes3D(fig, auto_add_to_figure=False) fig.add_axes(ax) for stream in streamlines.streamlines: stream = stream[np.all(stream != 0.0, axis=1)] ax.plot3D(stream[:, 0], stream[:, 1], stream[:, 2], alpha=0.1)
# Define c: the center of the box, N: the number of streamlines, # scale: the spatial scale of the streamlines relative to the boxsize, # and then pos: the random positions of the streamlines. c = ds.domain_center N = 100 scale = ds.domain_width[0] pos_dx = np.random.random((N, 3)) * scale - scale / 2. pos = c + pos_dx # Create streamlines of the 3D vector velocity and integrate them through # the box defined above streamlines = Streamlines(ds, pos, 'velocity_x', 'velocity_y', 'velocity_z', length=1.0 * Mpc, get_magnitude=True) streamlines.integrate_through_volume() # Create a 3D plot, trace the streamlines through the 3D volume of the plot fig = pl.figure() ax = Axes3D(fig) for stream in streamlines.streamlines: stream = stream[np.all(stream != 0.0, axis=1)] ax.plot3D(stream[:, 0], stream[:, 1], stream[:, 2], alpha=0.1) # Save the plot to disk. pl.savefig('streamlines.png')
# Load the dataset ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") # Define c: the center of the box, N: the number of streamlines, # scale: the spatial scale of the streamlines relative to the boxsize, # and then pos: the random positions of the streamlines. c = ds.arr([0.5]*3, 'code_length') N = 30 scale = ds.quan(15, 'kpc').in_units('code_length') # 15 kpc in code units pos_dx = np.random.random((N,3))*scale-scale/2. pos = c+pos_dx # Create the streamlines from these positions with the velocity fields as the # fields to be traced streamlines = Streamlines(ds, pos, 'velocity_x', 'velocity_y', 'velocity_z', length=1.0) streamlines.integrate_through_volume() # Create a 3D matplotlib figure for visualizing the streamlines fig=pl.figure() ax = Axes3D(fig) # Trace the streamlines through the volume of the 3D figure for stream in streamlines.streamlines: stream = stream[np.all(stream != 0.0, axis=1)] # Make the colors of each stream vary continuously from blue to red # from low-x to high-x of the stream start position (each color is R, G, B) # can omit and just set streamline colors to a fixed color x_start_pos = ds.arr(stream[0,0], 'code_length') x_start_pos -= ds.arr(0.5, 'code_length')
from yt.visualization.api import Streamlines from yt.units import cm from mpl_toolkits.mplot3d import Axes3D # Load the dataset ds = yt.load('wd_512_rhoc4-5_plt64636') # Define c: the center of the box, N: the number of streamlines, # scale: the spatial scale of the streamlines relative to the boxsize, # and then pos: the random positions of the streamlines. c = ds.domain_center N = 100 scale = ds.domain_width[0] pos_dx = np.random.random((N,3))*scale pos = pos_dx # Create streamlines of the 3D vector velocity and integrate them through # the box defined above streamlines = Streamlines(ds, pos, ('boxlib', 'x_vel'), ('boxlib', 'y_vel'), ('boxlib', 'z_vel'), get_magnitude=True, volume=ds.all_data()) streamlines.integrate_through_volume() # Create a 3D plot, trace the streamlines throught the 3D volume of the plot fig=pl.figure() ax = Axes3D(fig) for stream in streamlines.streamlines: stream = stream[np.all(stream != 0.0, axis=1)] ax.plot3D(stream[:,0], stream[:,1], stream[:,2], alpha=0.1) # Save the plot to disk. pl.savefig('vel_streamlines.png')
# Define c: the center of the box, N: the number of streamlines, # scale: the spatial scale of the streamlines relative to the boxsize, # and then pos: the random positions of the streamlines. c = ds.arr([0.5] * 3, "code_length") N = 30 scale = ds.quan(15, "kpc").in_units("code_length") # 15 kpc in code units pos_dx = np.random.random((N, 3)) * scale - scale / 2.0 pos = c + pos_dx # Create the streamlines from these positions with the velocity fields as the # fields to be traced streamlines = Streamlines( ds, pos, ("gas", "velocity_x"), ("gas", "velocity_y"), ("gas", "velocity_z"), length=1.0, ) streamlines.integrate_through_volume() # Create a 3D matplotlib figure for visualizing the streamlines fig = plt.figure() ax = Axes3D(fig) # Trace the streamlines through the volume of the 3D figure for stream in streamlines.streamlines: stream = stream[np.all(stream != 0.0, axis=1)] # Make the colors of each stream vary continuously from blue to red # from low-x to high-x of the stream start position (each color is R, G, B)
def get_streamlines(ds): from yt.visualization.api import Streamlines streamlines = Streamlines(ds, ds.domain_center) streamlines.integrate_through_volume() stream = streamlines.path(0) matplotlib.pylab.semilogy(stream['t'], stream['Density'], '-x')
def streamLines(xc1, xc2, xc3, Bc1, Bc2, Bc3, N): ''' Computes streamlines. Automatically calls the streamSeeds function. ''' #bottom, top = streamSeeds(xc1, xc2, xc3, N) bottom, top = streamSeeds(xc1, xc2, xc3, Bc3, N) #top = [] #print(bottom) #print(top) bottom = np.array(bottom) top = np.array(top) #print(bottom) #return #bottom = [[.5,.5,.5],[.5,8.4999,.5]] ds = makeYtDS(xc1, xc2, xc3, Bc1, Bc2, Bc3) streamlines = Streamlines(ds, bottom, 'B_x', 'B_y', 'B_z', direction=1.0, length=3. * (xc3[-1] - xc3[0])) streamlines.integrate_through_volume() bottomstreamlines = streamlines.streamlines if len(top) > 0: streamlines = Streamlines(ds, top, 'B_x', 'B_y', 'B_z', direction=-1.0, length=3. * (xc3[-1] - xc3[0])) streamlines.integrate_through_volume() topstreamlines = streamlines.streamlines else: topstreamlines = [] streamlines = [] for stream in bottomstreamlines: stream = stream[np.all(stream != 0.0, axis=1)] streamlines.append(stream) for stream in topstreamlines: stream = stream[np.all(stream != 0.0, axis=1)] streamlines.append(stream) return np.array(streamlines)
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") # Define c: the center of the box, N: the number of streamlines, # scale: the spatial scale of the streamlines relative to the boxsize, # and then pos: the random positions of the streamlines. c = ds.arr([0.5] * 3, "code_length") N = 30 scale = ds.quan(15, "kpc").in_units("code_length") # 15 kpc in code units pos_dx = np.random.random((N, 3)) * scale - scale / 2.0 pos = c + pos_dx # Create the streamlines from these positions with the velocity fields as the # fields to be traced streamlines = Streamlines(ds, pos, "velocity_x", "velocity_y", "velocity_z", length=1.0) streamlines.integrate_through_volume() # Create a 3D matplotlib figure for visualizing the streamlines fig = pl.figure() ax = Axes3D(fig) # Trace the streamlines through the volume of the 3D figure for stream in streamlines.streamlines: stream = stream[np.all(stream != 0.0, axis=1)] # Make the colors of each stream vary continuously from blue to red # from low-x to high-x of the stream start position (each color is R, G, B) # can omit and just set streamline colors to a fixed color
import yt import numpy as np from yt.visualization.api import Streamlines import random fname = '/Users/jillnaiman1/data/IsolatedGalaxy/galaxy0030/galaxy0030' # home # now, get stream line ds = yt.load(fname) c = np.array([0.5] * 3) N = 10 # number of stream lines scale = 1.0 pos_dx = np.random.random((N, 3)) * scale - scale / 2. pos = c + pos_dx streamlines = Streamlines(ds, pos, 'velocity_x', 'velocity_y', 'velocity_z', length=1.0)