<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Thanks Britton, it works perfectly.<br>
    <br>
    Cheers,<br>
    <br>
    JC<br>
    <br>
    On 5/1/12 1:04 PM, Britton Smith wrote:
    <blockquote
cite="mid:CABfs61kCPv=j=kq9-Dyq1TNA6V8VGYmtXYwHGMBuFAT+QnbvZA@mail.gmail.com"
      type="cite">Hi JC,
      <div><br>
      </div>
      <div>This is happening because the generation of the field happens
        grid by grid, so you're comparing the field for the entire
        region to the field for just one grid.</div>
      <div><br>
      </div>
      <div>A very similar question was posed on yt-dev about a week ago,
        but for some reason I can't find a record of it in the archive.
         I've found it in my email so I'll paste it here.  Sorry for it
        being in reverse order and a bit difficult to read.</div>
      <div><br>
      </div>
      <div>Britton</div>
      <div><br>
      </div>
      <div><br>
        <br>
        <div class="gmail_quote">---------- Forwarded message ----------<br>
          From: <b class="gmail_sendername">Geoffrey So</b> <span
            dir="ltr"><<a moz-do-not-send="true"
              href="mailto:gsiisg@gmail.com">gsiisg@gmail.com</a>></span><br>
          Date: Thu, Apr 26, 2012 at 4:11 PM<br>
          Subject: Re: [yt-dev] derived field from two datasets<br>
          To: <a moz-do-not-send="true"
            href="mailto:yt-dev@lists.spacepope.org">yt-dev@lists.spacepope.org</a><br>
          <br>
          <br>
          <div class="gmail_extra">ok changing the line to</div>
          <div class="gmail_extra">
            <div class="im">
              <div class="gmail_extra">       data2 = pf2.h.grids[<a
                  moz-do-not-send="true" href="http://data.id/"
                  target="_blank">data.id</a> - data._id_offset]</div>
            </div>
            <div>worked</div>
            <div><br>
            </div>
            <div>Thanks so much:-)</div>
            <div><br>
            </div>
            <div>From</div>
            <span class="HOEnZb"><font color="#888888">G.S.</font></span>
            <div>
              <div class="h5"><br>
                <div class="gmail_quote">On Thu, Apr 26, 2012 at 1:04
                  PM, Matthew Turk <span dir="ltr"><<a
                      moz-do-not-send="true"
                      href="mailto:matthewturk@gmail.com"
                      target="_blank">matthewturk@gmail.com</a>></span> wrote:<br>
                  <blockquote class="gmail_quote"
style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Ah,
                    don't ask for [field], just get .grids[ ... ].<br>
                    <br>
                    -Matt<br>
                    <div><br>
                      On Thu, Apr 26, 2012 at 4:02 PM, Geoffrey So <<a
                        moz-do-not-send="true"
                        href="mailto:gsiisg@gmail.com" target="_blank">gsiisg@gmail.com</a>>
                      wrote:<br>
                      > The new add field line<br>
                      >  
                      pf1.field_info.add_field("CompareIonization",
                      function = _NewField,<br>
                      > validators = [ValidateGridType()])<br>
                      > but that got me a new set of errors<br>
                      > KeyError:
                      <yt.data_objects.field_info_container.DerivedField
                      object at<br>
                      > 0x1065cbb90><br>
                      ><br>
                      > full trace<br>
                      > Traceback pasted to <a moz-do-not-send="true"
href="http://paste.yt-project.org/show/sIW43mg7AdRaKJELo0U1"
                        target="_blank">http://paste.yt-project.org/show/sIW43mg7AdRaKJELo0U1</a><br>
                      ><br>
                      > From<br>
                      > G.S.<br>
                      ><br>
                      > On Thu, Apr 26, 2012 at 12:54 PM, Matthew
                      Turk <<a moz-do-not-send="true"
                        href="mailto:matthewturk@gmail.com"
                        target="_blank">matthewturk@gmail.com</a>><br>
                      > wrote:<br>
                      >><br>
                      >> Hi Geoffrey,<br>
                      >><br>
                      >> AH!  Rats.  I forgot one thing.  In the
                      call to add_field, include a<br>
                      >> validator to ensure you're getting grids,
                      not regions:<br>
                      >><br>
                      >> validators = [ValidateGridType()]<br>
                      >><br>
                      >> This script, by the way, will *only* work
                      with unigrid where the grid<br>
                      >> IDs match between the two datasets.
                       (Doing it with AMR is possible<br>
                      >> but will be a hassle.)  What that line
                      does is cross-correlate grids<br>
                      >> between the two parameter files.<br>
                      >><br>
                      >> -Matt<br>
                      >><br>
                      >> On Thu, Apr 26, 2012 at 3:50 PM, Geoffrey
                      So <<a moz-do-not-send="true"
                        href="mailto:gsiisg@gmail.com" target="_blank">gsiisg@gmail.com</a>>
                      wrote:<br>
                      >> > Yeah I think that should do exactly
                      what I want.<br>
                      >> ><br>
                      >> > The script is at<br>
                      >> > <a moz-do-not-send="true"
                        href="http://paste.yt-project.org/show/2324/"
                        target="_blank">http://paste.yt-project.org/show/2324/</a><br>
                      >> ><br>
                      >> > gave me these error:<br>
                      >> > <a moz-do-not-send="true"
                        href="http://paste.yt-project.org/show/5XFq1xU2iVxiA9MTtT3v"
                        target="_blank">http://paste.yt-project.org/show/5XFq1xU2iVxiA9MTtT3v</a><br>
                      >> ><br>
                      >> > pf_compare was ran without error,
                      the error occurs when I tried to call<br>
                      >> > on dd["CompareIonization"]<br>
                      >> ><br>
                      >> > Can you also explain what this line
                      does with the <a moz-do-not-send="true"
                        href="http://data.id/" target="_blank">data.id</a> and<br>
                      >> > _id_offset?<br>
                      >> >        data2 = pf2.h.grids[<a
                        moz-do-not-send="true" href="http://data.id/"
                        target="_blank">data.id</a> -
                      data._id_offset][field]<br>
                      >> ><br>
                      >> > From<br>
                      >> > G.S.<br>
                      >> ><br>
                      >> > On Thu, Apr 26, 2012 at 12:15 PM,
                      Matthew Turk <<a moz-do-not-send="true"
                        href="mailto:matthewturk@gmail.com"
                        target="_blank">matthewturk@gmail.com</a>><br>
                      >> > wrote:<br>
                      >> >><br>
                      >> >> Hi Geoffrey,<br>
                      >> >><br>
                      >> >> On Thu, Apr 26, 2012 at 3:09 PM,
                      Geoffrey So <<a moz-do-not-send="true"
                        href="mailto:gsiisg@gmail.com" target="_blank">gsiisg@gmail.com</a>>
                      wrote:<br>
                      >> >> > This is very close to what
                      I was trying to do, except I wanted<br>
                      >> >> > something<br>
                      >> >> > slightly more general where
                      I can compare two distinct fields from<br>
                      >> >> > two<br>
                      >> >> > datasets.  (what I am
                      trying to do is to use<br>
                      >> >> >
                      HI_Density/(HI_Density+HII_Density)) where the HI
                      and HII are stored<br>
                      >> >> > separately, so I'll need
                      pf1 with field1 and pf2 with field2.)<br>
                      >> >> ><br>
                      >> >> > Rick recently showed me a
                      rendering where people at Argonne made a<br>
                      >> >> > rendering<br>
                      >> >> > of the fractional
                      difference in HI or HII from two simulations, one<br>
                      >> >> > with<br>
                      >> >> > radiation transport one
                      without, to compare the effects.  The ability<br>
                      >> >> > to<br>
                      >> >> > call two different fields
                      from two different simulation parameters in<br>
                      >> >> > creating a derived field
                      would be essential to doing something like<br>
                      >> >> > that.<br>
                      >> >><br>
                      >> >> Here's a video of it, for
                      everyone curious:<br>
                      >> >><br>
                      >> >> <a moz-do-not-send="true"
                        href="http://www.youtube.com/watch?v=hDh4NB31e2s"
                        target="_blank">http://www.youtube.com/watch?v=hDh4NB31e2s</a><br>
                      >> >><br>
                      >> >> ><br>
                      >> >> > Forgive my yt skills.  I
                      tried to first use the script you provided<br>
                      >> >> > as<br>
                      >> >> > an<br>
                      >> >> > example, but I wasn't sure
                      how to get values from pf_compare, I tried<br>
                      >> >> ><br>
                      >> >> > dd1=pf1.h.all_data()<br>
                      >> >> > dd1['NewField']<br>
                      >> >> ><br>
                      >> >> > but it gives:<br>
                      >> >> ><br>
                      >> >> > TypeError: _NewField()
                      takes exactly 4 arguments (2 given)<br>
                      >> >><br>
                      >> >> Okay, I should have been more
                      clear.  What you want to do is call:<br>
                      >> >><br>
                      >> >> pf_compare(pf1, pf2, some_field)<br>
                      >> >><br>
                      >> >> And then pf1 should have the
                      field accessible.  It doesn't return the<br>
                      >> >> field; what it does is make the
                      field accessible to yt functionality.<br>
                      >> >><br>
                      >> >> Here's a closer example, based
                      on what you have asked for:<br>
                      >> >><br>
                      >> >> def pf_compare(pf1, pf2):<br>
                      >> >>   def _NewField(field, data):<br>
                      >> >>        data2 = pf2.h.grids[<a
                        moz-do-not-send="true" href="http://data.id/"
                        target="_blank">data.id</a> -
                      data._id_offset][field]<br>
                      >> >>       return<br>
                      >> >>
                      data["HI_Density"]/(data2["HI_Density"]+data2["HII_Density"]))<br>
                      >> >>  
                      pf1.field_info.add_field("CompareIonization",
                      function = _NewField)<br>
                      >> >><br>
                      >> >> pf1 = load( ... )<br>
                      >> >> pf2 = load( ... )<br>
                      >> >> pf1.h<br>
                      >> >> pf_compare(pf1, pf2)<br>
                      >> >><br>
                      >> >> # Now you can do:<br>
                      >> >><br>
                      >> >> dd = pf1.h.all_data()<br>
                      >> >> dd["CompareIonization"]<br>
                      >> >><br>
                      >> >><br>
                      >> >> -Matt<br>
                      >> >><br>
                      >> >> ><br>
                      >> >> ><br>
                      >> >> ><br>
                      >> >> >
--------------------------------------------------------------------------------------<br>
                      >> >> ><br>
                      >> >> > What I was hoping to be
                      able to do is something like:<br>
                      >> >> ><br>
                      >> >> > def pf_compare(pf1, field1,
                      pf2, field2):<br>
                      >> >> >    def _NewField(field1,
                      data1, field2, data2):<br>
                      >> >> >        return data1[field1]
                      / data2[field2]     # or any calculation<br>
                      >> >> > involving data1,2 and
                      field1,2<br>
                      >> >> >  
                       pf1.field_info.add_field("NewField", function =
                      _NewField)<br>
                      >> >> ><br>
                      >> >> > pf1 = load('DD###1')<br>
                      >> >> > pf2 = load('DD###2')<br>
                      >> >> ><br>
                      >> >> > and call<br>
                      >> >> ><br>
                      >> >> >
                      pf1.h.all_data()['NewField']<br>
                      >> >> ><br>
                      >> >> > Where "NewField" involves
                      two different fields from two different<br>
                      >> >> > dataset<br>
                      >> >> ><br>
                      >> >> > This seems very possible
                      from the example you wrote Matt, but I guess<br>
                      >> >> > I'm<br>
                      >> >> > stuck on how to call the
                      values or make a plot of "NewField" once it<br>
                      >> >> > is<br>
                      >> >> > defined.<br>
                      >> >> ><br>
                      >> >> > From<br>
                      >> >> > G.S.<br>
                      >> >> ><br>
                      >> >> ><br>
                      >> >> > On Thu, Apr 26, 2012 at
                      5:02 AM, Matthew Turk <<a
                        moz-do-not-send="true"
                        href="mailto:matthewturk@gmail.com"
                        target="_blank">matthewturk@gmail.com</a>><br>
                      >> >> > wrote:<br>
                      >> >> >><br>
                      >> >> >> Hi Geoffrey,<br>
                      >> >> >><br>
                      >> >> >> There's no example per
                      se, but I'll try to give you one.  This<br>
                      >> >> >> sketch<br>
                      >> >> >> should give you an
                      idea.  There's a way to do this for AMR grids<br>
                      >> >> >> which<br>
                      >> >> >> would be similar (you'd
                      use a covering grid) but I think you're<br>
                      >> >> >> using<br>
                      >> >> >> static refinement so
                      that makes it a bit easier.  We want to wrap<br>
                      >> >> >> this<br>
                      >> >> >> in a function:<br>
                      >> >> >><br>
                      >> >> >> def pf_compare(pf1,
                      pf2, field):<br>
                      >> >> >>    def _NewField(field,
                      data):<br>
                      >> >> >>        return
                      data[field] / pf2.h.grids[<a
                        moz-do-not-send="true" href="http://data.id/"
                        target="_blank">data.id</a> -<br>
                      >> >> >> data._id_offset][field]<br>
                      >> >> >>  
                       pf1.field_info.add_field("Compare%s" % field,
                      function =<br>
                      >> >> >> _NewField)<br>
                      >> >> >><br>
                      >> >> >> pf1 = load( ... )<br>
                      >> >> >> pf2 = load( ... )<br>
                      >> >> >> pf1.h<br>
                      >> >> >> pf_compare(pf1, pf2,
                      "Density")<br>
                      >> >> >><br>
                      >> >> >> Now you should have
                      CompareDensity.<br>
                      >> >> >><br>
                      >> >> >> Let me know if that
                      works.  In the discussion document for yt 3.0<br>
                      >> >> >> Britton brought up that
                      we should have a grammar for this type of<br>
                      >> >> >> situation.<br>
                      >> >> >><br>
                      >> >> >> -Matt<br>
                      >> >> >><br>
                      >> >> >> On Wed, Apr 25, 2012 at
                      3:39 PM, Geoffrey So <<a moz-do-not-send="true"
                        href="mailto:gsiisg@gmail.com" target="_blank">gsiisg@gmail.com</a>><br>
                      >> >> >> wrote:<br>
                      >> >> >> > Hi, I was
                      wondering if there's an example of how to create a<br>
                      >> >> >> > derived<br>
                      >> >> >> > field<br>
                      >> >> >> > from two different
                      datasets.<br>
                      >> >> >> ><br>
                      >> >> >> > From<br>
                      >> >> >> > G.S.<br>
                      >> >> >> ><br>
                      >> >> >> >
                      _______________________________________________<br>
                      >> >> >> > yt-dev mailing
                      list<br>
                      >> >> >> > <a
                        moz-do-not-send="true"
                        href="mailto:yt-dev@lists.spacepope.org"
                        target="_blank">yt-dev@lists.spacepope.org</a><br>
                      >> >> >> > <a
                        moz-do-not-send="true"
                        href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org"
                        target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
                      >> >> >> ><br>
                      >> >> >>
                      _______________________________________________<br>
                      >> >> >> yt-dev mailing list<br>
                      >> >> >> <a
                        moz-do-not-send="true"
                        href="mailto:yt-dev@lists.spacepope.org"
                        target="_blank">yt-dev@lists.spacepope.org</a><br>
                      >> >> >> <a
                        moz-do-not-send="true"
                        href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org"
                        target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
                      >> >> ><br>
                      >> >> ><br>
                      >> >> ><br>
                      >> >> >
                      _______________________________________________<br>
                      >> >> > yt-dev mailing list<br>
                      >> >> > <a moz-do-not-send="true"
                        href="mailto:yt-dev@lists.spacepope.org"
                        target="_blank">yt-dev@lists.spacepope.org</a><br>
                      >> >> > <a moz-do-not-send="true"
                        href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org"
                        target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
                      >> >> ><br>
                      >> >>
                      _______________________________________________<br>
                      >> >> yt-dev mailing list<br>
                      >> >> <a moz-do-not-send="true"
                        href="mailto:yt-dev@lists.spacepope.org"
                        target="_blank">yt-dev@lists.spacepope.org</a><br>
                      >> >> <a moz-do-not-send="true"
                        href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org"
                        target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
                      >> ><br>
                      >> ><br>
                      >> ><br>
                      >> >
                      _______________________________________________<br>
                      >> > yt-dev mailing list<br>
                      >> > <a moz-do-not-send="true"
                        href="mailto:yt-dev@lists.spacepope.org"
                        target="_blank">yt-dev@lists.spacepope.org</a><br>
                      >> > <a moz-do-not-send="true"
                        href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org"
                        target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
                      >> ><br>
                      >>
                      _______________________________________________<br>
                      >> yt-dev mailing list<br>
                      >> <a moz-do-not-send="true"
                        href="mailto:yt-dev@lists.spacepope.org"
                        target="_blank">yt-dev@lists.spacepope.org</a><br>
                      >> <a moz-do-not-send="true"
                        href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org"
                        target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
                      ><br>
                      ><br>
                      ><br>
                      >
                      _______________________________________________<br>
                      > yt-dev mailing list<br>
                      > <a moz-do-not-send="true"
                        href="mailto:yt-dev@lists.spacepope.org"
                        target="_blank">yt-dev@lists.spacepope.org</a><br>
                      > <a moz-do-not-send="true"
                        href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org"
                        target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
                      ><br>
                      _______________________________________________<br>
                      yt-dev mailing list<br>
                      <a moz-do-not-send="true"
                        href="mailto:yt-dev@lists.spacepope.org"
                        target="_blank">yt-dev@lists.spacepope.org</a><br>
                      <a moz-do-not-send="true"
                        href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org"
                        target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
                    </div>
                  </blockquote>
                </div>
                <br>
              </div>
            </div>
          </div>
          <br>
          _______________________________________________<br>
          yt-dev mailing list<br>
          <a moz-do-not-send="true"
            href="mailto:yt-dev@lists.spacepope.org">yt-dev@lists.spacepope.org</a><br>
          <a moz-do-not-send="true"
            href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org"
            target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
          <br>
        </div>
        <br>
        <div class="gmail_quote">On Tue, May 1, 2012 at 12:27 PM,
          Jean-Claude Passy <span dir="ltr"><<a
              moz-do-not-send="true" href="mailto:jcpassy@gmail.com"
              target="_blank">jcpassy@gmail.com</a>></span> wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000"> Hi all,<br>
              <br>
              I am trying to compare the energy between two datasets. I
              execute the following script that uses the derived field
              'RelativeEnergy':<br>
              <br>
              <address>--------------------------------------------------------------------------------------------------------------------------------------------------</address>
              <address>def _RelativeEnergy(field, data):</address>
              <address>    return
(data["TotalEnergy"]-data.pf.parameters["TotalEnergy_ref"])/data.pf.parameters["TotalEnergy_ref"]</address>
              <address>add_field("RelativeEnergy",
                function=_RelativeEnergy)</address>
              <address><br>
                filen1 = 'helix/DD0000/CE0000'</address>
              <address>pf1 = load(filen1)</address>
              <address>region1 = pf1.h.region([0.5, 0.5, 0.5], [0.0,
                0.0, 0.0], [1.0, 1.0, 1.0])</address>
              <address>energy1 = region1["TotalEnergy"]</address>
              <address><br>
                filen2 = 'parallel/DD0000/CE0000'</address>
              <address>pf2 = load(filen2)</address>
              <address>region2 = pf2.h.region([0.5, 0.5, 0.5], [0.0,
                0.0, 0.0], [1.0, 1.0, 1.0])</address>
              <address>energy2 = region2["TotalEnergy"]</address>
              <address><br>
                # Adding reference energy into
                pf2                                                            
              </address>
              <address>pf2.parameters["TotalEnergy_ref"] = energy1</address>
              <address><br>
                delta_energy = region2["RelativeEnergy"]</address>
              <address><br>
                pc = PlotCollection(pf2)</address>
              <address>pc.add_slice("RelativeEnergy",2,center=[0.5, 0.5,
                0.5])</address>
              <address>pc.set_lim((0.4, 0.6, 0.4, 0.6))</address>
              <address>pc.save('DeltaEnergy')</address>
              <address>
--------------------------------------------------------------------------------------------------------------------------------------------------</address>
              <br>
              I get the error pasted here: <a moz-do-not-send="true"
                href="http://paste.yt-project.org/show/DPgMjV44JktpXExCljUj/"
                target="_blank">http://paste.yt-project.org/show/DPgMjV44JktpXExCljUj/</a><br>
              The variable delta_energy looks good (same type and size
              and energy1), but the problem arises when I try to take a
              slice of it.<br>
              <br>
              Any help much appreciated.<br>
              Thanks a lot,<br>
              <br>
              JC<br>
            </div>
            <br>
            _______________________________________________<br>
            yt-users mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
            <a moz-do-not-send="true"
              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>
            <br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
  </body>
</html>