[yt-users] Error in visualization with new derived field

Sam Skillman samskillman at gmail.com
Thu Oct 4 14:11:42 PDT 2012


I think you want to first copy the data, or else you may end up modifying
the original Density data.

def _DensityCeiling(field, data):
    Ceiling = 1e-22
    new_dens = data["Density"].copy()
    new_dens[new_dens > Ceiling] = Ceiling
    return new_dens

Cheers,
Sam

On Thu, Oct 4, 2012 at 3:06 PM, Nathan Goldbaum <nathan12343 at gmail.com>wrote:

> Hi Junhwan
>
> 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).
>
> Since your field does not explicitly depend on the 3D nature of the grid,
> this is an easy fix:
>
> def _DensityCeiling(field, data):
>     Ceiling = 1e-22
>     wh = np.where(data["Density"] < Ceiling)
>     DensityCeiling = data["Density"]
>     DensityCeiling[wh] = Ceiling
>     return DensityCeiling
>
> 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.
>
> Cheers,
>
> Nathan
>
> On Oct 4, 2012, at 2:00 PM, Jun-Hwan Choi wrote:
>
>  Hi yt-users,
>
> I try to make a density projection of my simulation.
> 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.
> And, I made a following script:
> ############################################
> from yt.mods import *
> import matplotlib.pylab as pylab
>
> def _DensityCeiling(field, data):
>     Ceiling = 1e-22
>     nx, ny, nz = data["Density"].shape
>     DensityCeiling =  na.zeros(data["Density"].shape, dtype='float64')
>     DensityCeiling = data["Density"]
>     for ix, in range(0,nx):
>         for iy, in range(0,ny):
>             for iz, in range(0,nz):
>                 if(data["DensityCeiling"][ix,iy,iz]  > Ceiling):
>                     DensityCeiling[ix,iy,iz] = Ceiling
>     return DensityCeiling
> add_field("DensityCeiling", function=_DensityCeiling,
> units=r"\rm{g}/\rm{cm^3}")
>
>
> # load up a dataset
> pf = load("DD0000/DD0000")
> all_center = [0.5, 0.5, 0.5]
>
> pc = PlotCollection(pf,center=all_center)
> pc.add_slice("DensityCeiling", 0)
> pc.add_slice("DensityCeiling", 2)
> pc.add_projection("DensityCeiling", 0)
> pc.add_projection("DensityCeiling", 2)
>
> pc.set_width(6, 'kpc')
> pc.save("cen_t%04.1f_L6K" % pf.current_time)
> pc.set_width(1, 'kpc')
> pc.save("cen_t%04.1f_L1K" % pf.current_time)
> #######################################################
>
> And then, I got a following error.
> File "DenViz.py", line 6, in _DensityCeiling
>  nx, ny, nz = data["Density"].shape
> ValueError: need more than 1 value to unpack
>
> It turns out that the data["Density"] is not always 3d array but
> sometimes become 1d array.
> Is there any way to fix the derived field to avoid this problem?
>
> Thank you in advance,
> Junhwan
>
>
>  --
> --------------------------------------------------------------
> Jun-Hwan Choi, Ph.D.
> Department of Physics and Astronomy, University of Kentucky
> Tel: (859) 897-6737        Fax: (859) 323-2846
> Email: jhchoi at pa.uky.edu   URL: http://www.pa.uky.edu/~jhchoi
> --------------------------------------------------------------
>
>  _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
>
> _______________________________________________
> 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/20121004/ad984819/attachment.html>


More information about the yt-users mailing list