<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Nathan,<div class=""><br class=""></div><div class="">Thanks for the quick reply. I was able to just load it into a separate dataset as a NumPy array. </div><div class=""><br class=""></div><div class="">Will</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 16, 2016, at 8:33 AM, Nathan Goldbaum <<a href="mailto:nathan12343@gmail.com" class="">nathan12343@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Hi Will,<div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">That said, if you could make a 3D numpy<span class=""></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 class=""><br class=""></div><div class="">Hope that's helpful,</div><div class=""><br class=""></div><div class=""> Nathan Goldbaum</div><div class=""><br class="">On Saturday, October 15, 2016, Will Barnes <<a href="mailto:Will_Barnes@alumni.baylor.edu" class="">Will_Barnes@alumni.baylor.edu</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi yt users,<br class="">
<br class="">
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 class="">
<br class="">
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 class="">
<br class="">
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 class="">
<br class="">
Thanks!<br class="">
<br class="">
Will Barnes<br class="">
<br class="">
```<br class="">
# create 3d numpy array<br class="">
arr = np.random.random(size=(64,64,<wbr class="">64))<br class="">
<br class="">
# load generic data into a dataset<br class="">
data = dict(density = (arr, "g/cm**3"))<br class="">
bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [-1.5, 1.5]])<br class="">
ds = yt.load_uniform_grid(data, arr.shape, length_unit="Mpc", bbox=bbox, nprocs=64)<br class="">
<br class="">
# set seed points<br class="">
c = ds.domain_center<br class="">
N = 100<br class="">
scale = ds.domain_width[0]<br class="">
pos_dx = np.random.random((N,3))*scale-<wbr class="">scale/2.<br class="">
pos = c+pos_dx<br class="">
<br class="">
# Create streamlines<br class="">
streamlines = Streamlines(ds, pos, 'velocity_x', 'velocity_y', 'velocity_z',length=1.0*Mpc, get_magnitude=True)<br class="">
streamlines.integrate_through_<wbr class="">volume()<br class="">
<br class="">
# create a density field in ds initialized as 0 everywhere<br class="">
# for each streamline in streamlines, find coordinates from streamline and add the appropriate density value to the coordinates<br class="">
```<br class="">
______________________________<wbr class="">_________________<br class="">
yt-users mailing list<br class="">
<a href="javascript:;" onclick="_e(event, 'cvml', 'yt-users@lists.spacepope.org')" class="">yt-users@lists.spacepope.org</a><br class="">
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" target="_blank" class="">http://lists.spacepope.org/<wbr class="">listinfo.cgi/yt-users-<wbr class="">spacepope.org</a><br class="">
</blockquote></div>
_______________________________________________<br class="">yt-users mailing list<br class=""><a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org<br class=""></div></blockquote></div><br class=""></div></body></html>