Hi Will,<div><br></div><div>There isn't a way to do what you're describing in yt right now because fields are defined locally in terms of the values of other fields. We have long-term plans to make it possible to define a field in terms of women non-local property of other fields (e.g. a field defined in terms of streamlines) but this functionality does not exist yet.</div><div><br></div><div>That said, if you could make a 3D numpy<span></span> array of the same shape as your other fields, you could load *another* dataset using load_uniform_grid and pass it the original fields along with the new interpolated density field.</div><div><br></div><div>Hope that's helpful,</div><div><br></div><div> Nathan Goldbaum</div><div><br>On Saturday, October 15, 2016, Will Barnes <<a href="mailto:Will_Barnes@alumni.baylor.edu">Will_Barnes@alumni.baylor.edu</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi yt users,<br>
<br>
I have a question about derived fields in a dataset loaded from generic array data. I’ve created a dataset from a three dimensional Numpy array and traced some streamlines (say N of them) through the volume (this is a 3D magnetic field) such that I now have a set of N fieldlines. External to the dataset, I then have N Numpy arrays corresponding to each of the N streamlines, each the same length of the corresponding streamline, that represent the density as a function of the position along the streamline.<br>
<br>
What I’d like to do is create a new derived field (“density”) where the values from each of my external numpy arrays are mapped to the corresponding coordinate (as determined by the streamlines) and then “density” is zero everywhere else. I’ve read the documentation about creating derived fields and adding fields to a dataset, but it is not clear to me how to use external information (e.g. my set of N arrays) to create a new or derived field as all the examples show only how to use already existing fields in the dataset to create a new field.<br>
<br>
This seems like a relatively simple thing so perhaps I am just missing something or not quite understanding how a new field is added to a dataset? Since my explanation above is a bit confusing, I’ve included a code snippet below that hopefully illustrates a bit better what I’d like to do.<br>
<br>
Thanks!<br>
<br>
Will Barnes<br>
<br>
```<br>
# create 3d numpy array<br>
arr = np.random.random(size=(64,64,<wbr>64))<br>
<br>
# load generic data into a dataset<br>
data = dict(density = (arr, "g/cm**3"))<br>
bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [-1.5, 1.5]])<br>
ds = yt.load_uniform_grid(data, arr.shape, length_unit="Mpc", bbox=bbox, nprocs=64)<br>
<br>
# set seed points<br>
c = ds.domain_center<br>
N = 100<br>
scale = ds.domain_width[0]<br>
pos_dx = np.random.random((N,3))*scale-<wbr>scale/2.<br>
pos = c+pos_dx<br>
<br>
# Create streamlines<br>
streamlines = Streamlines(ds, pos, 'velocity_x', 'velocity_y', 'velocity_z',length=1.0*Mpc, get_magnitude=True)<br>
streamlines.integrate_through_<wbr>volume()<br>
<br>
# create a density field in ds initialized as 0 everywhere<br>
# for each streamline in streamlines, find coordinates from streamline and add the appropriate density value to the coordinates<br>
```<br>
______________________________<wbr>_________________<br>
yt-users mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'yt-users@lists.spacepope.org')">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
</blockquote></div>