Hi yt-users! I am trying to add a field that is radius/rvir. This is an idealized galaxy sim with static DM potential (no live halo), so I was planning on putting the virial radius in by hand. I am not totally sure what is causing yt to choke--does it not like that I am putting in a number? See below for details. Thanks in advance for any help! Best, Stephanie The lines of code: def rrvir(field,data): return data['radius'].in_units('kpc')/(218.,'kpc') i =0 while i < len(loop): ds = yt.load("blahblah/DD"+loop[i]+"/sb_"+loop[i]) ds.add_field(('gas','r_rvir'),function=rrvir) ....many unimportant lines.... I get this error message: yt : [INFO ] 2018-06-14 09:02:48,783 Gathering a field list (this may take a moment.) yt_slices_allouts_mli.py:19: UserWarning: Because 'sampling_type' not specified, yt will assume a cell 'sampl ing_type' ds.add_field(('gas','r_rvir'),function=rrvir) Traceback (most recent call last): File "yt_slices_allouts_mli.py", line 19, in <module> ds.add_field(('gas','r_rvir'),function=rrvir) File "/home/stonnesen/yt-conda/src/yt-git/yt/data_objects/static_output.py", line 1221, in add_field deps, _ = self.field_info.check_derived_fields([name]) File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/field_info_container.py", line 366, in check_derived_fi elds fd = fi.get_dependencies(ds = self.ds) File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/derived_field.py", line 210, in get_dependencies e[self.name] File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/field_detector.py", line 108, in __missing__ vv = finfo(self) File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/derived_field.py", line 250, in __call__ dd = self._function(self, data) File "yt_slices_allouts_mli.py", line 13, in rrvir return data['radius'].in_units('kpc')/(300.,'kpc') File "/home/stonnesen/yt-conda/src/yt-git/yt/units/yt_array.py", line 1372, in __array_ufunc__ out=out, **kwargs) TypeError: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' -- Dr. Stephanie Tonnesen Associate Research Scientist CCA, Flatiron Institute New York, NY stonnes@gmail.com
Hi Stephanie,
Instead of:
return data['radius'].in_units('kpc')/(300.,'kpc')
Say:
from yt.units import kpc
....
return data['radius'].in_units('kpc')/(300*kpc)
Or alternatively without the import:
return data['radius'].in_units('kpc')/data.ds.quan(300, 'kpc')
Hope that helps,
Nathan
On Thu, Jun 14, 2018 at 11:18 AM, Stephanie Tonnesen
Hi yt-users!
I am trying to add a field that is radius/rvir. This is an idealized galaxy sim with static DM potential (no live halo), so I was planning on putting the virial radius in by hand. I am not totally sure what is causing yt to choke--does it not like that I am putting in a number? See below for details.
Thanks in advance for any help!
Best, Stephanie
The lines of code:
def rrvir(field,data): return data['radius'].in_units('kpc')/(218.,'kpc')
i =0 while i < len(loop): ds = yt.load("blahblah/DD"+loop[i]+"/sb_"+loop[i])
ds.add_field(('gas','r_rvir'),function=rrvir)
....many unimportant lines....
I get this error message: yt : [INFO ] 2018-06-14 09:02:48,783 Gathering a field list (this may take a moment.) yt_slices_allouts_mli.py:19: UserWarning: Because 'sampling_type' not specified, yt will assume a cell 'sampl ing_type' ds.add_field(('gas','r_rvir'),function=rrvir) Traceback (most recent call last): File "yt_slices_allouts_mli.py", line 19, in <module> ds.add_field(('gas','r_rvir'),function=rrvir) File "/home/stonnesen/yt-conda/src/yt-git/yt/data_objects/static_output.py", line 1221, in add_field deps, _ = self.field_info.check_derived_fields([name]) File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/field_info_container.py", line 366, in check_derived_fi elds fd = fi.get_dependencies(ds = self.ds) File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/derived_field.py", line 210, in get_dependencies e[self.name] File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/field_detector.py", line 108, in __missing__ vv = finfo(self) File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/derived_field.py", line 250, in __call__ dd = self._function(self, data) File "yt_slices_allouts_mli.py", line 13, in rrvir return data['radius'].in_units('kpc')/(300.,'kpc') File "/home/stonnesen/yt-conda/src/yt-git/yt/units/yt_array.py", line 1372, in __array_ufunc__ out=out, **kwargs) TypeError: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
-- Dr. Stephanie Tonnesen Associate Research Scientist CCA, Flatiron Institute New York, NY
stonnes@gmail.com
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
Hi Stephanie, In your field definition you are trying to divide a YTArray by a tuple, but YTArray doesn’t know how to do that. We use (value, unit) tuples as inputs to things like spheres, etc but it always converts to at YTQuantity under the hood. And while I was typing this I saw Nathan’s response, so you should go with his, but I provided some background anyway. Best, John
On Jun 14, 2018, at 12:18 PM, Stephanie Tonnesen
wrote: Hi yt-users!
I am trying to add a field that is radius/rvir. This is an idealized galaxy sim with static DM potential (no live halo), so I was planning on putting the virial radius in by hand. I am not totally sure what is causing yt to choke--does it not like that I am putting in a number? See below for details.
Thanks in advance for any help!
Best, Stephanie
The lines of code:
def rrvir(field,data): return data['radius'].in_units('kpc')/(218.,'kpc')
i =0 while i < len(loop): ds = yt.load("blahblah/DD"+loop[i]+"/sb_"+loop[i])
ds.add_field(('gas','r_rvir'),function=rrvir)
....many unimportant lines....
I get this error message: yt : [INFO ] 2018-06-14 09:02:48,783 Gathering a field list (this may take a moment.) yt_slices_allouts_mli.py:19: UserWarning: Because 'sampling_type' not specified, yt will assume a cell 'sampl ing_type' ds.add_field(('gas','r_rvir'),function=rrvir) Traceback (most recent call last): File "yt_slices_allouts_mli.py", line 19, in <module> ds.add_field(('gas','r_rvir'),function=rrvir) File "/home/stonnesen/yt-conda/src/yt-git/yt/data_objects/static_output.py", line 1221, in add_field deps, _ = self.field_info.check_derived_fields([name]) File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/field_info_container.py", line 366, in check_derived_fi elds fd = fi.get_dependencies(ds = self.ds) File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/derived_field.py", line 210, in get_dependencies e[self.name http://self.name/] File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/field_detector.py", line 108, in __missing__ vv = finfo(self) File "/home/stonnesen/yt-conda/src/yt-git/yt/fields/derived_field.py", line 250, in __call__ dd = self._function(self, data) File "yt_slices_allouts_mli.py", line 13, in rrvir return data['radius'].in_units('kpc')/(300.,'kpc') File "/home/stonnesen/yt-conda/src/yt-git/yt/units/yt_array.py", line 1372, in __array_ufunc__ out=out, **kwargs) TypeError: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
-- Dr. Stephanie Tonnesen Associate Research Scientist CCA, Flatiron Institute New York, NY
stonnes@gmail.com mailto:stonnes@gmail.com _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
participants (3)
-
John Zuhone
-
Nathan Goldbaum
-
Stephanie Tonnesen