Hi, I am trying to create a filter for the field and apply it to a data in the following way: def density_threshold(field, data):
dens=data["gas", "density"].in_units('H/cm**3')
dens[dens < 50] = 0
return dens
ds.add_field(name=("gas", "density_threshold"), function=density_threshold, units="H/cm**3")
dd_1_c=ds.r[((com_x_1.value-1), "kpc"):((com_x_1.value+1),
"kpc"),((com_y_1.value-1), "kpc"):((com_y_1.value+1), "kpc"),:]
m_1_c=dd_1_c[("density_threshold", "cell_mass")].in_units(
'Msun')
But cannot find the field: Traceback (most recent call last): File "inflows-dense.py", line 68, in <module> m_1_c=dd_1_c[("density_threshold", "cell_mass")].in_units('Msun') File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 274, in __getitem__ f = self._determine_fields([key])[0] File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1121, in _determine_fields finfo = self.ds._get_field_info(ftype, fname) File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/static_output.py", line 753, in _get_field_info raise YTFieldNotFound((ftype, fname), self)
yt.utilities.exceptions.YTFieldNotFound: Could not find field '('density_threshold', 'cell_mass')' in info_00019.
Is this not how the field data is to be accessed? Thanks in advance
The field you added is (“gas”, “density_threshold”) but you asked for (“density_threshold”, “cell_mass”). yt is telling you that the field you asked for isn’t available. I’m guessing it will work fine if you ask for the correct field name, assuming your field definition doesn’t have any errors. Also I’m pretty sure the unit for your field isn’t correct, unless you’ve separately defined the “H” unit somewhere else. On Sun, Dec 9, 2018 at 3:56 AM Vadlamani Samhitha < vadlamani.samhitha@gmail.com> wrote:
Hi,
I am trying to create a filter for the field and apply it to a data in the following way:
def density_threshold(field, data):
dens=data["gas", "density"].in_units('H/cm**3')
dens[dens < 50] = 0
return dens
ds.add_field(name=("gas", "density_threshold"), function=density_threshold, units="H/cm**3")
dd_1_c=ds.r[((com_x_1.value-1), "kpc"):((com_x_1.value+1),
"kpc"),((com_y_1.value-1), "kpc"):((com_y_1.value+1), "kpc"),:]
m_1_c=dd_1_c[("density_threshold", "cell_mass"
)].in_units('Msun')
But cannot find the field:
Traceback (most recent call last):
File "inflows-dense.py", line 68, in <module>
m_1_c=dd_1_c[("density_threshold", "cell_mass")].in_units('Msun')
File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 274, in __getitem__
f = self._determine_fields([key])[0]
File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1121, in _determine_fields
finfo = self.ds._get_field_info(ftype, fname)
File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/static_output.py", line 753, in _get_field_info
raise YTFieldNotFound((ftype, fname), self)
yt.utilities.exceptions.YTFieldNotFound: Could not find field '('density_threshold', 'cell_mass')' in info_00019.
Is this not how the field data is to be accessed? Thanks in advance
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
Thanks, I do have 'H' defined in advance but I am confused about how to apply a filter created with a specific field ("density" in this case) to another field in data ("cell_mass")? If the following is supposed to be the right way, I also tried accessing the field through: m_1_c=dd_1_c[("gas","density_threshold"), "cell_mass"].in_units('Msun') but still in vain.
ds.add_field(name=("gas", "density_threshold"), function=density_threshold, units="H/cm**3") Traceback (most recent call last): File "inflows-dense.py", line 68, in <module> m_1_c=dd_1_c[("gas","density_threshold"), "cell_mass"].in_units('Msun') File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 274, in __getitem__ f = self._determine_fields([key])[0] File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1119, in _determine_fields raise YTFieldNotParseable(field) yt.utilities.exceptions.YTFieldNotParseable: Cannot identify field (('gas', 'density_threshold'), 'cell_mass')
On Sun, Dec 9, 2018 at 3:58 PM Nathan Goldbaum
The field you added is (“gas”, “density_threshold”) but you asked for (“density_threshold”, “cell_mass”). yt is telling you that the field you asked for isn’t available. I’m guessing it will work fine if you ask for the correct field name, assuming your field definition doesn’t have any errors.
Also I’m pretty sure the unit for your field isn’t correct, unless you’ve separately defined the “H” unit somewhere else.
On Sun, Dec 9, 2018 at 3:56 AM Vadlamani Samhitha < vadlamani.samhitha@gmail.com> wrote:
Hi,
I am trying to create a filter for the field and apply it to a data in the following way:
def density_threshold(field, data):
dens=data["gas", "density"].in_units('H/cm**3')
dens[dens < 50] = 0
return dens
ds.add_field(name=("gas", "density_threshold"), function=density_threshold, units="H/cm**3")
dd_1_c=ds.r[((com_x_1.value-1), "kpc"):((com_x_1.value+1),
"kpc"),((com_y_1.value-1), "kpc"):((com_y_1.value+1), "kpc"),:]
m_1_c=dd_1_c[("density_threshold", "cell_mass"
)].in_units('Msun')
But cannot find the field:
Traceback (most recent call last):
File "inflows-dense.py", line 68, in <module>
m_1_c=dd_1_c[("density_threshold", "cell_mass")].in_units('Msun')
File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 274, in __getitem__
f = self._determine_fields([key])[0]
File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1121, in _determine_fields
finfo = self.ds._get_field_info(ftype, fname)
File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/static_output.py", line 753, in _get_field_info
raise YTFieldNotFound((ftype, fname), self)
yt.utilities.exceptions.YTFieldNotFound: Could not find field '('density_threshold', 'cell_mass')' in info_00019.
Is this not how the field data is to be accessed? Thanks in advance
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
So what you ultimately want is the masses of zones with densities above some threshold? In that case there are two ways of doing what you want, first using numpy advanced indexing: data = dd['gas', 'density_threshold] wh = data > 0 masses = dd['gas', 'cell_mass'][wh] You could also use a cut_region data object, which creates a new data object based on a field cut criterion, like your density threshold. cr = ds.cut_region(ds.all_data(), ["obj['density'] > 1e-25"]) masses = cr['gas', 'cell_mass'] See this section of the docs for more details: http://yt-project.org/doc/analyzing/filtering.html#filtering-mesh-fields Hope that helps! -Nathan On Sun, Dec 9, 2018 at 12:12 PM Vadlamani Samhitha < vadlamani.samhitha@gmail.com> wrote:
Thanks, I do have 'H' defined in advance but I am confused about how to apply a filter created with a specific field ("density" in this case) to another field in data ("cell_mass")?
If the following is supposed to be the right way, I also tried accessing the field through:
m_1_c=dd_1_c[("gas","density_threshold"), "cell_mass"].in_units('Msun')
but still in vain.
ds.add_field(name=("gas", "density_threshold"), function=density_threshold, units="H/cm**3") Traceback (most recent call last): File "inflows-dense.py", line 68, in <module> m_1_c=dd_1_c[("gas","density_threshold"), "cell_mass"].in_units('Msun') File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 274, in __getitem__ f = self._determine_fields([key])[0] File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1119, in _determine_fields raise YTFieldNotParseable(field) yt.utilities.exceptions.YTFieldNotParseable: Cannot identify field (('gas', 'density_threshold'), 'cell_mass')
On Sun, Dec 9, 2018 at 3:58 PM Nathan Goldbaum
wrote: The field you added is (“gas”, “density_threshold”) but you asked for (“density_threshold”, “cell_mass”). yt is telling you that the field you asked for isn’t available. I’m guessing it will work fine if you ask for the correct field name, assuming your field definition doesn’t have any errors.
Also I’m pretty sure the unit for your field isn’t correct, unless you’ve separately defined the “H” unit somewhere else.
On Sun, Dec 9, 2018 at 3:56 AM Vadlamani Samhitha < vadlamani.samhitha@gmail.com> wrote:
Hi,
I am trying to create a filter for the field and apply it to a data in the following way:
def density_threshold(field, data):
dens=data["gas", "density"].in_units('H/cm**3')
dens[dens < 50] = 0
return dens
ds.add_field(name=("gas", "density_threshold"), function=density_threshold, units="H/cm**3")
dd_1_c=ds.r[((com_x_1.value-1), "kpc"):((com_x_1.value+
1), "kpc"),((com_y_1.value-1), "kpc"):((com_y_1.value+1), "kpc"),:]
m_1_c=dd_1_c[("density_threshold", "cell_mass"
)].in_units('Msun')
But cannot find the field:
Traceback (most recent call last):
File "inflows-dense.py", line 68, in <module>
m_1_c=dd_1_c[("density_threshold", "cell_mass")].in_units('Msun')
File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 274, in __getitem__
f = self._determine_fields([key])[0]
File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1121, in _determine_fields
finfo = self.ds._get_field_info(ftype, fname)
File "/home/samvad/yt-conda/lib/python3.6/site-packages/yt/data_objects/static_output.py", line 753, in _get_field_info
raise YTFieldNotFound((ftype, fname), self)
yt.utilities.exceptions.YTFieldNotFound: Could not find field '('density_threshold', 'cell_mass')' in info_00019.
Is this not how the field data is to be accessed? Thanks in advance
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
participants (2)
-
Nathan Goldbaum
-
Vadlamani Samhitha