On Mon, Jun 27, 2016 at 11:59 AM, Hansheng Chen <jasonhs1221@gmail.com> wrote:
Hello yt users,
I have a question about projection. I used ds.proj() and to_frb() to get an image array of the projected 'Electron_Density' of an entire dataset. I multiplied the mean of projected 'Electron_Density' by the entire area of x-y plane and got a sum of total mass of electrons. Then, I used ds.all_data() and mean() to get the mean of 'Electron_Density' in 3-dimensional. I multiplied the mean by the volume of the entire box of the dataset and got another sum of total mass of electrons. However, this sum did not match the sum I got from the projected 'Electron_Density' previously. Here are the codes I used:
import yt import numpy as np ds = yt.load("redshift0100/redshift0100") print("Redshift =", ds.current_redshift)
p = yt.ProjectionPlot(ds, 2, 'Electron_Density') density_image = p.frb['Electron_Density'] ed = density_image['Electron_Density'].convert_to_cgs()
Are you sure this code would run? I'm pretty sure this line would produce an IndexError, since you can't use a string to index into an array.
ed_ndarr = ed.to_ndarray() sum1 = ed_ndarr.mean() * ((105.82 * 3.085677581e+24)**2) print(sum1)
dd = ds.all_data() ed_3d = dd['Electron_Density'].convert_to_cgs() sum2 = ed_3d.mean() * ((105.82 * 3.085677581e+24)**3) print(sum2)
You're not comparing apples and oranges here. In particular, in this section, you've found the mean density of cells in your simulation. If you have an AMR simulation, each cell is not necessarily the same size, so they do not contribute equally if you want to find the true, volume or mass-weighted mean density in your simulation. It would be a closer comparison to use a covering grid, or you could ask for a volume-weighted mean: In [18]: dd.quantities.weighted_average_quantity('El_density', weight='cell_volume ...: ') Out[18]: 5.54459040433e-34 g/cm**3 This script makes use of a public test dataset from yt-project.org/data and illustrates the point I'm making: https://bpaste.net/show/2eab176d8128 On my machine, both operations print out the same result to machine precision.
(105.82 * 3.085677581e+24) is the width of entire box in cm. I think sum1 and sum2 should be close to each other, but the result was that the two values did not match with each other. Is there any problem in the codes I used to get the values of sum1 and sum2? Could some one give me some help?
Thank you very much!
Sincerely, Hansheng
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org