[yt-users] Problem trying to define a new field

k.grisdale at surrey.ac.uk k.grisdale at surrey.ac.uk
Mon Nov 4 06:49:58 PST 2013


Hi yt-users

I’m attempting to plot some profiles as a function of radius/radiusSH, where radiusSh is the radius of a shock. However I am not sure what the simplest way of getting yt to plot this. I have been using the following commands to produce the profiles.
:

pc = PlotCollection(p6, center = cen)
pc.add_profile_sphere(0.5, "cm", ["Radius", "Density"], weight = "Denin”)

I have also tried to define a new field:


@derived_field(name = "RRsh", take_log = False, validators = [ValidateParameter("rsh")])
def RRshunits(field, data):
    value, rsh = p6.h.find_max("Density")
    return(data["Radius"]/rsh)

but this leads to the following error:

Traceback (most recent call last):
  File "profiles.py", line 21, in <module>
    pc.add_profile_sphere(0.5, "cm", ["RRsh", "Denin"], weight = "Denin")
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/visualization/plot_collection.py", line 1058, in add_profile_sphere
    figure=figure, axes=axes)
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/visualization/plot_collection.py", line 961, in add_profile_object
    lazy_reader=lazy_reader)[0]
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 92, in __call__
    return self._call_func_lazy(args, kwargs)
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 99, in _call_func_lazy
    rv = self.func(GridChildMaskWrapper(g, self._data_source), *args, **kwargs)
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 615, in _Extrema
    if data[field].size < 1:
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 60, in __getitem__
    data = self.data_source._get_data_from_grid(self.grid, item)
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 95, in save_state
    tr = func(self, grid, field, *args, **kwargs)
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 2645, in _get_data_from_grid
    tr = grid[field]
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.py", line 157, in __getitem__
    self.get_data(key)
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.py", line 200, in get_data
    self._generate_field(field)
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.py", line 132, in _generate_field
    self.pf.field_info[field].check_available(self)
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/field_info_container.py", line 366, in check_available
    validator(data)
  File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/field_info_container.py", line 442, in __call__
    raise NeedsParameter(doesnt_have)
yt.data_objects.field_info_container.NeedsParameter: (['rsh’])

Am I missing something in my field definition or is their a simpler way to go about this?

Thanks

Kearn



More information about the yt-users mailing list