<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Thank you very much Nathan and Sam.<br>
    The python always provides simple way to calculate.<br>
    <br>
    Junhwan<br>
    On 10/04/12 17:11, Sam Skillman wrote:
    <blockquote
cite="mid:CAB4=1s3CEpec0FXYjsgLYTLEGKL0aajjaTvSSDcacaJLvjo6eQ@mail.gmail.com"
      type="cite">I think you want to first copy the data, or else you
      may end up modifying the original Density data.
      <div><br>
      </div>
      <div>def _DensityCeiling(field, data):<br>
        <div>    Ceiling = 1e-22</div>
        <div>    new_dens = data["Density"].copy()</div>
        <div>    new_dens[new_dens > Ceiling] = Ceiling</div>
        <div>    return new_dens</div>
        <div><br>
        </div>
        <div>Cheers,</div>
        <div>Sam</div>
        <div><br>
        </div>
        <div class="gmail_quote">On Thu, Oct 4, 2012 at 3:06 PM, Nathan
          Goldbaum <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@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 style="word-wrap:break-word">
              <div>Hi Junhwan</div>
              <div><br>
              </div>
              <div>In fact, in general you'll get back a 1D array.
                 These are the collapsed values for the data in a single
                grid (i.e. flattened from 3D to 1D).</div>
              <div><br>
              </div>
              <div>Since your field does not explicitly depend on the 3D
                nature of the grid, this is an easy fix:</div>
              <div><br>
              </div>
              <div>def _DensityCeiling(field, data):</div>
              <div>
                <div bgcolor="#FFFFFF" text="#000000">
                  <font face="Monotype.com">    Ceiling = 1e-22</font></div>
                <div bgcolor="#FFFFFF" text="#000000"><font
                    face="Monotype.com">    wh =
                    np.where(data["Density"] < Ceiling)<br>
                        DensityCeiling = data["Density"]<br>
                  </font></div>
                <div bgcolor="#FFFFFF" text="#000000">   
                  DensityCeiling[wh] = Ceiling</div>
                <div bgcolor="#FFFFFF" text="#000000"><font
                    face="Monotype.com">    return DensityCeiling</font></div>
              </div>
              <div><br>
              </div>
              <div>Here np is how I've imported numpy locally.  There
                may be an even cleverer way of doing the array
                manipulation that someone else on the list may know of
                off-hand.</div>
              <div><br>
              </div>
              <div>Cheers,</div>
              <div><br>
              </div>
              <div>Nathan</div>
              <br>
              <div>
                <div>
                  <div>
                    <div>On Oct 4, 2012, at 2:00 PM, Jun-Hwan Choi
                      wrote:</div>
                    <br>
                  </div>
                </div>
                <blockquote type="cite">
                  <div>
                    <div>
                      <div bgcolor="#FFFFFF" text="#000000"> <font
                          face="Monotype.com">Hi yt-users,<br>
                          <br>
                          I try to make a density projection of my
                          simulation.<br>
                          I would like to make a small modification that
                          if the cell density higher than a given
                          density ceiling the density value becomes the
                          density ceiling.<br>
                          And, I made a following script:<br>
                          ############################################<br>
                          from yt.mods import *<br>
                          import matplotlib.pylab as pylab<br>
                          <br>
                          def _DensityCeiling(field, data):<br>
                              Ceiling = 1e-22<br>
                              nx, ny, nz = data["Density"].shape<br>
                              DensityCeiling = 
                          na.zeros(data["Density"].shape,
                          dtype='float64')<br>
                              DensityCeiling = data["Density"]<br>
                              for ix, in range(0,nx):<br>
                                  for iy, in range(0,ny):<br>
                                      for iz, in range(0,nz):<br>
                                         
                          if(data["DensityCeiling"][ix,iy,iz]  >
                          Ceiling):<br>
                                              DensityCeiling[ix,iy,iz] =
                          Ceiling<br>
                              return DensityCeiling<br>
                          add_field("DensityCeiling",
                          function=_DensityCeiling,
                          units=r"\rm{g}/\rm{cm^3}")<br>
                          <br>
                          <br>
                          # load up a dataset<br>
                          pf = load("DD0000/DD0000")<br>
                          all_center = [0.5, 0.5, 0.5]<br>
                          <br>
                          pc = PlotCollection(pf,center=all_center)<br>
                          pc.add_slice("DensityCeiling", 0)<br>
                          pc.add_slice("DensityCeiling", 2)<br>
                          pc.add_projection("DensityCeiling", 0)<br>
                          pc.add_projection("DensityCeiling", 2)<br>
                          <br>
                          pc.set_width(6, 'kpc')<br>
                          pc.save("cen_t%04.1f_L6K" % pf.current_time)<br>
                          pc.set_width(1, 'kpc')<br>
                          pc.save("cen_t%04.1f_L1K" % pf.current_time)<br>
#######################################################<br>
                          <br>
                          And then, I got a following error.<br>
                          File "DenViz.py", line 6, in _DensityCeiling<br>
                           nx, ny, nz = data["Density"].shape<br>
                          ValueError: need more than 1 value to unpack<br>
                          <br>
                          It turns out that the data</font><font
                          face="Monotype.com">["Density"] is not always
                          3d array but sometimes become 1d array.<br>
                          Is there any way to fix the derived field to
                          avoid this problem?<br>
                          <br>
                          Thank you in advance,<br>
                          Junhwan<br>
                        </font><font face="Monotype.com"><br>
                          <br>
                        </font>
                        <pre cols="72">-- 
--------------------------------------------------------------
Jun-Hwan Choi, Ph.D.
Department of Physics and Astronomy, University of Kentucky
Tel: <a moz-do-not-send="true" href="tel:%28859%29%20897-6737" value="+18598976737" target="_blank">(859) 897-6737</a>        Fax: <a moz-do-not-send="true" href="tel:%28859%29%20323-2846" value="+18593232846" target="_blank">(859) 323-2846</a>
Email: <a moz-do-not-send="true" href="mailto:jhchoi@pa.uky.edu" target="_blank">jhchoi@pa.uky.edu</a>   URL: <a moz-do-not-send="true" href="http://www.pa.uky.edu/%7Ejhchoi" target="_blank">http://www.pa.uky.edu/~jhchoi</a>
--------------------------------------------------------------
</pre>
                      </div>
                    </div>
                  </div>
                  _______________________________________________<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>
                </blockquote>
              </div>
              <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>
          </blockquote>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
yt-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a>
<a class="moz-txt-link-freetext" href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a>
</pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
--------------------------------------------------------------
Jun-Hwan Choi, Ph.D.
Department of Physics and Astronomy, University of Kentucky
Tel: (859) 897-6737        Fax: (859) 323-2846
Email: <a class="moz-txt-link-abbreviated" href="mailto:jhchoi@pa.uky.edu">jhchoi@pa.uky.edu</a>   URL: <a class="moz-txt-link-freetext" href="http://www.pa.uky.edu/~jhchoi">http://www.pa.uky.edu/~jhchoi</a>
--------------------------------------------------------------
</pre>
  </body>
</html>