[yt-users] Plotting differences of two datasets

Geoffrey So gsiisg at gmail.com
Wed Mar 12 11:19:02 PDT 2014


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)
------------------------------------------------------------------------------------------------------
from yt.mods import *

def pf_compare(pf1, pf2):
  def _NewField(field, data):
       data2 = pf2.h.grids[data.id - data._id_offset]
       return data["HI_Density"]/(data["HI_Density"]+data2["HII_Density"])
  pf1.field_info.add_field("CompareIonization", function = _NewField,
validators = [ValidateGridType()])

pf1 = load('DD0273/DD0273')
pf2 = load('DD0273/DD0273')
pf1.h
pf2.h
pf_compare(pf1, pf2)
# Now you can
do:

dd = pf1.h.all_data()
dd["CompareIonization"]
-----------------------------------------------------------------------------------------------------

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.
Hope this helps.

From
G.S.


On Tue, Mar 11, 2014 at 2:27 PM, Aaron Lee <a.t.lee at berkeley.edu> wrote:

> All,
>
> Hopefully this is a simple question and is giving me trouble only because
> of my ignorance of how data is stored in YT structures.
>
> 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.
>
> So what I have tried is this:
>
> (1) Load the files:
> pf1 = load("file1")
> pf2 = load("file2")
>
> (2) Following some YT cookbook pages, I extract the data :
> cube1 =
> pf1.h.covering_grid(1,left_edge=[0,0,0],dims=[128,128,128],fields=["Density"])
> cube2 =
> pf2.h.covering_grid(1,left_edge=[0,0,0],dims=[128,128,128],fields=["Density"])
>
> If I then type something like
>         cube1["Density"]
> the output is a 3d array of data. Similarly for cube2["Density"]. OK.
>
> (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):
> test = cube1
> test["Density"] = cube1["Density"]-cube2["Density"]
>
> If I then type
>         test["Density"]
> the outputted array is an array of the differences, which is what I want
> to plot.
>
> However, when I then plot the data by doing:
>
> pc=PlotCollection(test,center=[0.5,0.5,0.5])
> p=pc.add_slice("Density",'y')
> p.save_to_pdf('Test.pdf')
>
> 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.
>
> 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.
>
> Thanks in advance for any notes and tips,
> Aaron
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20140312/9c3844d4/attachment.htm>


More information about the yt-users mailing list