[yt-users] error on plotting particle_density
Matthew Turk
matthewturk at gmail.com
Wed Jul 10 12:58:11 PDT 2013
Hi Mohammad,
Sorry you're having trouble. In my version of cde0a641f1bf , the line
numebrs don't match up with yours. In particular, my _pdensity
function starts on line 1010, and looks like this:
def _pdensity(field, data):
blank = np.zeros(data.ActiveDimensions, dtype='float64')
if data["particle_position_x"].size == 0: return blank
CICDeposit_3(data["particle_position_x"].astype(np.float64),
data["particle_position_y"].astype(np.float64),
data["particle_position_z"].astype(np.float64),
data["ParticleMass"],
data["particle_position_x"].size,
blank, np.array(data.LeftEdge).astype(np.float64),
np.array(data.ActiveDimensions).astype(np.int32),
np.float64(data['dx']))
np.divide(blank, data["CellVolume"], blank)
return blank
add_field("particle_density", function=_pdensity,
validators=[ValidateGridType()],
display_name=r"\mathrm{Particle}\/\mathrm{Density}")
The only buffer there that's not cast to float64 is
data["ParticleMass"]. I don't know why your line numbers and mine do
not match up, since you don't have a + in your source file, however if
your function matches mine please try adding the appropriate
.astype(np.float64). In 3.0 we have abstracted some of this out to
use a deposit function that handles types better.
-Matt
On Wed, Jul 10, 2013 at 3:38 PM, mohammad safarzadeh
<mtsafarzadeh at gmail.com> wrote:
> Hi,
> I get this error when trying to do a projection plot:
> ----> 9 p = ProjectionPlot(pf, "x", "particle_density",[ 0.5808,0.5398,
> 0.4504 ],(4.0,'mpc'))
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/visualization/plot_window.pyc in
> __init__(self, pf, axis, fields, center, width, axes_unit, weight_field,
> max_level, origin, fontsize, field_parameters, data_source)
> 1347 if field_parameters is None: field_parameters = {}
> 1348 proj = pf.h.proj(axis, fields, weight_field=weight_field,
> max_level=max_level,
> -> 1349 center=center, source=data_source,
> **field_parameters)
> 1350 PWViewerMPL.__init__(self, proj, bounds, origin=origin,
> fontsize=fontsize)
> 1351 self.set_axes_unit(axes_unit)
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.pyc in
> __init__(self, axis, field, weight_field, max_level, center, pf, source,
> node_name, field_cuts, preload_style, serialize, style, **kwargs)
> 1758 self.preload_style = preload_style
> 1759 self._deserialize(node_name)
> -> 1760 self._refresh_data()
> 1761 if self._okay_to_serialize and self.serialize:
> self._serialize(node_name=self._node_name)
> 1762
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.pyc in
> _refresh_data(self)
> 318 """
> 319 self.clear_data()
> --> 320 self.get_data()
> 321
> 322 def keys(self):
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.pyc in
> get_data(self, fields)
> 1859 if g.Level == level],
> 1860 self.get_dependencies(fields),
> self.hierarchy.io)
> -> 1861 self._add_level_to_tree(tree, level, fields)
> 1862 mylog.debug("End of projecting level level %s, memory
> usage %0.3e",
> 1863 level, get_memory_usage()/1024.)
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.pyc in
> _add_level_to_tree(self, tree, level, fields)
> 1981 % (level, self._max_level),
> len(grids_to_project))
> 1982 for pi, grid in enumerate(grids_to_project):
> -> 1983 self._add_grid_to_tree(tree, grid, fields, zero_out,
> dls)
> 1984 pbar.update(pi)
> 1985 grid.clear_data()
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.pyc in
> _add_grid_to_tree(self, tree, grid, fields, zero_out, dls)
> 1925 if zero_out: weight_data[grid.child_indices] = 0
> 1926 masked_data = [fd.astype('float64') * weight_data
> -> 1927 for fd in self._get_data_from_grid(grid,
> fields)]
> 1928 wdl = 1.0
> 1929 else:
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.pyc in
> save_state(self, grid, field, *args, **kwargs)
> 93 old_keys = grid.field_data.keys()
> 94 grid.field_parameters = self.field_parameters
> ---> 95 tr = func(self, grid, field, *args, **kwargs)
> 96 grid.field_parameters = old_params
> 97 grid.field_data = YTFieldData( [(k, grid.field_data[k]) for
> k in old_keys] )
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.pyc in
> _get_data_from_grid(self, grid, fields)
> 2003 else:
> 2004 bad_points = 1.0
> -> 2005 return [grid[field] * bad_points for field in fields]
> 2006
> 2007 def _gen_node_name(self):
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.pyc in
> __getitem__(self, key)
> 155 """
> 156 if key not in self.field_data:
> --> 157 self.get_data(key)
> 158 return self.field_data[key]
> 159
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.pyc in
> get_data(self, field, convert)
> 198 else: raise
> 199 else:
> --> 200 self._generate_field(field)
> 201 return self.field_data[field]
> 202
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.pyc in
> _generate_field(self, field)
> 143 self[field] = temp_array[sl]
> 144 else:
> --> 145 self[field] = self.pf.field_info[field](self)
> 146 else: # Can't find the field, try as it might
> 147 raise exceptions.KeyError(field)
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/field_info_container.pyc
> in __call__(self, data)
> 393 ii = self.check_available(data)
> 394 original_fields = data.keys() # Copy
> --> 395 dd = self._function(self, data)
> 396 dd *= self._convert_function(data)
> 397 for field_name in data.keys():
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/data_objects/universal_fields.pyc in
> _pdensity(field, data)
> 982 blank, np.array(data.LeftEdge).astype(np.float64),
> 983 np.array(data.ActiveDimensions).astype(np.int32),
> --> 984 np.float64(data['dx']))
> 985 return blank
> 986 add_field("particle_density", function=_pdensity,
>
> /home/safarzadeh/yt-x86_64/src/yt-hg/yt/utilities/lib/CICDeposit.so in
> yt.utilities.lib.CICDeposit.CICDeposit_3
> (yt/utilities/lib/CICDeposit.c:1485)()
>
> ValueError: Buffer dtype mismatch, expected 'float64_t' but got 'float'
>
> are there alternative ways around it?
>
> (yt-x86_64)[safarzadeh at hecate yt-x86_64]$ yt instinfo
>
> yt module located at:
> /home/safarzadeh/yt-x86_64/src/yt-hg
> The supplemental repositories are located at:
> /home/safarzadeh/yt-x86_64/src/yt-supplemental
>
> The current version of the code is:
>
> ---
> cde0a641f1bf
> ---
>
> This installation CAN be automatically updated.
> Could not determine when yt stack was last updated.
>
>
>
> Regards,
> Mohammad
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
More information about the yt-users
mailing list