[yt-users] adding a smoothed field

Desika Narayanan dnarayan at haverford.edu
Mon Nov 10 10:54:23 PST 2014


Hey Matt,

Thanks for this!  This definitely added a field though has a small hiccup
when trying to access the information in it.    I can't seem to access the
yt pastebin, so I'll copy the issue below.

#I define metaldens (metal density) as:
def _metaldens(field,data): return
(data["PartType0","Density"]*data["PartType0","Metallicity"])

add_field(("PartType0","MetalDens"),function=_metaldens,units="g/cm**3"]
ds = load(fname,unit_base=unit_base,bounding_box=bbox)
ds.index
ad = ds.all_data()

#then add the smoothed field
metal_fn = add_volume_weighted_smoothed_field("PartType0", "Coordinates",
"Masses",
                                              "SmoothingLength",
"Density","MetalDens",
                                              ds.field_info)

metal_fn = metal_fn[0]

#when trying to access this information, though, I get the error below:
print ad[metal_fn]



Traceback (most recent call last):

  File "gadget_load.py", line 32, in <module>

    print ad[metal_fn]

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 240, in __getitem__

    self.get_data(f)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 661, in get_data

    self._generate_fields(fields_to_generate)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 681, in _generate_fields

    fd = self._generate_field(field)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 277, in _generate_field

    tr = self._generate_fluid_field(field)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 295, in _generate_fluid_field

    rv = self._generate_spatial_fluid(field, ngt_exception.ghost_zones)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 311, in _generate_spatial_fluid

    ind += o.select(self.selector, self[field], rv, ind)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 240, in __getitem__

    self.get_data(f)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 661, in get_data

    self._generate_fields(fields_to_generate)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 681, in _generate_fields

    fd = self._generate_field(field)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 277, in _generate_field

    tr = self._generate_fluid_field(field)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 297, in _generate_fluid_field

    rv = finfo(gen_obj)

  File "/Users/desika/yt-x86_64/src/yt-hg/yt/fields/derived_field.py", line
184, in __call__

    dd = self._function(self, data)

  File "/Users/desika/yt-x86_64/src/yt-hg/yt/fields/particle_fields.py",
line 551, in _vol_weight

    quan = data[ptype, smoothed_field].in_units(field_units)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/octree_subset.py", line
76, in __getitem__

    tr = super(OctreeSubset, self).__getitem__(key)

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 233, in __getitem__

    f = self._determine_fields([key])[0]

  File
"/Users/desika/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 500, in _determine_fields

    raise YTFieldTypeNotFound(ftype)

yt.utilities.exceptions.YTFieldTypeNotFound: Could not find field
'PartType0'.




On Mon, Nov 10, 2014 at 11:49 AM, Matthew Turk <matthewturk at gmail.com>
wrote:

> Hi Desika,
>
> Looking over the code, if you have a *particle* quantity, you should be
> able to add a *smoothed* quantity using this type of construction:
>
> from yt.fields.particle_fields import add_volume_weighted_smoothed field
>
> The API for this function is:
>
> def add_volume_weighted_smoothed_field(ptype, coord_name, mass_name,
>         smoothing_length_name, density_name, smoothed_field, registry,
>         nneighbors = None)
>
> so you should be able to supply particle type, "particle_position",
> "particle_mass", "smoothing_length", the density name ("density" probably),
> the name of the field to smooth, and then the ds.field_info.  I believe
> this should do it, and it may require another step but I don't think so.
>
> -Matt
>
> On Mon Nov 10 2014 at 8:22:08 AM Desika Narayanan <dnarayan at haverford.edu>
> wrote:
>
>>
>> Hey All,
>>
>> I'm trying to figure out how to add a new smoothed field to a data set.
>> Specifically, I want to add a (particle) field, and then be able to access
>> the smoothed mesh quantities (the same way I would access the mesh
>> quantities of density as below, for example)
>>
>> ad = ds.all_data()
>>
>> ad["deposit","PartType0_smoothed_desnsity"]
>>
>> (in this case PartType0 is gas).   I'm adding a field prior to loading
>> the data set as described here:
>>
>> http://yt-project.org/doc/developing/creating_derived_
>> fields.html#defining-a-new-field
>>
>> thanks,
>>
>> desika
>>
>>
>> _______________________________________________
>> 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/20141110/49f55c40/attachment.htm>


More information about the yt-users mailing list