コード例 #1
0
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"]
コード例 #2
0
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"]
コード例 #3
0
    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)
コード例 #4
0
    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
コード例 #5
0
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
stream = stream/1e5
コード例 #6
0
# 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')
    x_start_pos /= scale 
コード例 #7
0
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')
コード例 #8
0
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')