<div dir="ltr"><div><div><div>Hi Aaron, I'm pasting a sample script which Matt Turk shared with me a while back, so it might need some update, but I think it does what you're trying to do by creating a derived field from two different pf's. (so change pf2= to some other pf)<br>
------------------------------------------------------------------------------------------------------<br>from yt.mods import *<br><br>def pf_compare(pf1, pf2):<br>  def _NewField(field, data):<br>       data2 = pf2.h.grids[<a href="http://data.id">data.id</a> - data._id_offset]<br>
       return data["HI_Density"]/(data["HI_Density"]+data2["HII_Density"])<br>  pf1.field_info.add_field("CompareIonization", function = _NewField, validators = [ValidateGridType()])<br>
<br>pf1 = load('DD0273/DD0273')<br>pf2 = load('DD0273/DD0273')<br>pf1.h<br>pf2.h<br>pf_compare(pf1, pf2)<br># Now you can do:                                                               <br><br>dd = pf1.h.all_data()<br>
dd["CompareIonization"]<br>-----------------------------------------------------------------------------------------------------<br><br></div>I think this requires that your two data sets have the same dimensions so I've only used this on unigrid data and not AMR.<br>
</div>Hope this helps.<br><br></div>From<br>G.S.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 11, 2014 at 2:27 PM, Aaron Lee <span dir="ltr"><<a href="mailto:a.t.lee@berkeley.edu" target="_blank">a.t.lee@berkeley.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">All,<br>
<br>
Hopefully this is a simple question and is giving me trouble only because of my ignorance of how data is stored in YT structures.<br>
<br>
I have two data files of data tabulated over the same unigrid. Each side of the domain ranges from 0 to 1. I am interested in plotting a cell by cell difference of some quantity. For simplicity, let’s just say it’s the density.<br>

<br>
So what I have tried is this:<br>
<br>
(1) Load the files:<br>
pf1 = load(“file1”)<br>
pf2 = load(“file2")<br>
<br>
(2) Following some YT cookbook pages, I extract the data :<br>
cube1 = pf1.h.covering_grid(1,left_edge=[0,0,0],dims=[128,128,128],fields=["Density”])<br>
cube2 = pf2.h.covering_grid(1,left_edge=[0,0,0],dims=[128,128,128],fields=["Density”])<br>
<br>
If I then type something like<br>
        cube1[“Density”]<br>
the output is a 3d array of data. Similarly for cube2[“Density”]. OK.<br>
<br>
(3) Now the part I’m more iffy on. To create a new data cube, I first instigate it as a copy of cube1 and then manipulate the data (at least, I thought I was… see below):<br>
test = cube1<br>
test[“Density”] = cube1[“Density”]-cube2[“Density”]<br>
<br>
If I then type<br>
        test[“Density”]<br>
the outputted array is an array of the differences, which is what I want to plot.<br>
<br>
However, when I then plot the data by doing:<br>
<br>
pc=PlotCollection(test,center=[0.5,0.5,0.5])<br>
p=pc.add_slice(“Density",'y')<br>
p.save_to_pdf('Test.pdf’)<br>
<br>
The Test.pdf is a plot of just the cube1 density. So the data does not appear to be manipulated at all. If I do not instigate ‘test' first as a copy of cube1, yt complains because cube1[“Density”]-cube2[“Density”] is only an array of data.<br>

<br>
Another idea could be to create a new user-defined field that within the field definition loads another data file and does the difference for me. It would probably be clunky, but seems possible in theory. But you would know better than I.<br>

<br>
Thanks in advance for any notes and tips,<br>
Aaron<br>
<br>
_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto: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/listinfo.cgi/yt-users-spacepope.org</a><br>
</blockquote></div><br></div>