Hi, Everybody!
Does anyone out there have a technique for getting the variance out of
a profile object? A profile object is good at getting <X> vs. B, I'd
then like to get < (X - <X>)^2 > vs B. Matt and I had spittballed the
possibility some time ago, but I was wondering if anyone out there had
successfully done it.
Thanks,
d.
--
Sent from my computer.
Dear yt
Can current yt calculate 3-D Mass power spectra? I checked the website but
I didn't find any information. I think calculating 3-D Mass power
spectra is a very useful for cosmological simulations. So I guess maybe yt
supports this function now....?
Thanks in advance
I also have a follow-up question. My previous question was about the
build-in deposited fields. But when I try to do that myself, units seem
to be screwed up.
-----------------------
import yt
import numpy as np
def StellarMass2(field,data):
ms = data[('STAR','particle_mass')]
if('FieldDetector' in str(type(data))):
return ms
else:
return ms.in_units("Msun")
d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
d.add_field(("STAR","mass2"),function=StellarMass2,sampling_type="particle",units="Msun")
d.add_deposited_particle_field(("STAR","mass2"),"nearest",weight_field='particle_ones')
xcen = d.arr([5,5,5],"Mpccm/h")
s = d.sphere(xcen,(100,"kpc"))
sf = ('STAR','mass2')
df = ('deposit','STAR_nn_mass2')
print(np.amax(s[sf]),np.amax(s[df]))
----------------------------
>
1625.2196373326824 Msun 1625.2196373326824 Msun
I.e, the units of the deposited field are that of mass, rather than density.
Even worse, if I treat the deposited field as the mass per cell rather
than density, it does not add up:
print("sum=%9.3e
int=%9.3e"%(np.sum(s[sf].in_units("Msun")),np.sum(s[df].in_units("Msun"))))
> sum=3.252e+04 int=1.521e+05
So, I am totally lost about what add_deposited_particle_field() function
actually does.
n
Hi,
I run a code(Nyx) and it generates "AmrEx/BoxLib" (plotfile) files
The code I run to generate "AmrEx/BoxLib" (plotfile) files is here.
I have cloned these two code
https://github.com/AMReX-Codes/amrex
and
https://github.com/AMReX-Astro/Nyx
and follow the chapter 1 in Nyx User guide to run the most basic Lya example.
It generates the several plotfile directories and I want to use yt to read the plotfile and visualize it.
I have read these two links
https://amrex-codes.github.io/amrex/docs_html/Visualization.html#ythttp://yt-project.org/doc/examining/loading_data.html (Section of AMReX / BoxLib Data)
and follow the instruction to load the one of the plotfile directory.
The problem is here....
This is my python(yt) code to read the plotfile ("plt00302" is the plotfile directory)
import yt
print(yt.__version__)
ds = yt.load("plt00302")
print(ds.field_list)
The first three lines is ok and no error. This line,"ds = yt.load("plt00302")", even print some information which looks reasonable.
But the last line, "print(ds.field_list)" gives me the following error message.
Traceback (most recent call last):
File "boxlibTest.py", line 4, in <module>
print(ds.field_list)
File "/home/myUserName/anaconda3/lib/python3.6/site-packages/yt/data_objects/static_output.py", line 546, in field_list
return self.index.field_list
File "/home/myUserName/anaconda3/lib/python3.6/site-packages/yt/data_objects/static_output.py", line 504, in index
self, dataset_type=self.dataset_type)
File "/home/myUserName/anaconda3/lib/python3.6/site-packages/yt/frontends/boxlib/data_structures.py", line 1215, in __init__
super(NyxHierarchy, self).__init__(ds, dataset_type)
File "/home/myUserName/anaconda3/lib/python3.6/site-packages/yt/frontends/boxlib/data_structures.py", line 337, in __init__
self._cache_endianness(self.grids[-1])
File "/home/myUserName/anaconda3/lib/python3.6/site-packages/yt/frontends/boxlib/data_structures.py", line 467, in _cache_endianness
_header_pattern[self.dimensionality-1].search(header).groups()
AttributeError: 'NoneType' object has no attribute 'groups'
Any one has suggestion or solution about this?
Thanks
Guys,
What are the implicit units of the deposited field? In the following
script using implicit units returns an incorrect result, while setting
them explicitly gives the correct one.
import yt
import numpy as np
d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
xcen = d.arr([5,5,5],"Mpccm/h")
s = d.sphere(xcen,(100,"kpc"))
sf = ('STAR','particle_mass')
df = ('deposit','STAR_density')
print("sum=%9.3e
int=%9.3e"%(np.sum(s[sf]),np.sum(s[df]*s[('gas','cell_volume')])))
print("sum=%9.3e
int=%9.3e"%(np.sum(s[sf].in_units("Msun")),np.sum(s[df].in_units("Msun/kpc**3")*s[('gas','cell_volume')].in_units("kpc**3"))))
>
sum=6.894e-05 int=1.818e-31
sum=3.252e+04 int=3.252e+04
n
Nathan,
I think it was my bug - the field detector wants to see all the fields
accessed inside the call. If I do the following, then the code works:
def StellarLuminosity(field,data):
ts = data[('STAR','age')]
zs = data[('STAR','metallicity_snii')] +
data[('STAR','metallicity_snia')]
ms = data[('STAR','particle_mass')]
if('FieldDetector' in str(type(data))):
return ms
else:
#ts = data[('STAR','age')].in_units("yr").v
#zs =
(data[('STAR','metallicity_snii')]+data[('STAR','metallicity_snia')]).v
return ms.in_units("Msun")
# return sps.GetLnu(ts,zs)*data[('STAR','mass')].in_units("Msun")
Thank you so much for all the help, sorry for keeping pestering you.
n
On 5/27/2018 1:37 PM, Nathan Goldbaum wrote:
> So in this case you've written the field to behave one way during field
> detection and another way during the real field evaluation. This is
> confusing the field machinery.
>
> I think you're running into a bug in how the artio frontend handles some
> of its particle fields, see this pull request I just opened:
>
> https://github.com/yt-project/yt/pull/1802
> <https://github.com/yt-project/yt/pull/1802>
>
> After applying that patch I think you'll be able to avoid the check to
> see if you're in field detection.
>
> On Sun, May 27, 2018 at 1:20 PM, Nick Gnedin <ngnedin(a)gmail.com
> <mailto:ngnedin@gmail.com>> wrote:
>
>
> Nathan,
>
> I made progress with the real code, but then I hit another error
> that leaves me dumbfounded:
>
> ----------------------------
> import yt
>
> def StellarLuminosity(field,data):
> if(not 'FieldDetector' in str(type(data))):
> ts = data[('STAR','age')].in_units("yr").v
> zs =
> (data[('STAR','metallicity_snii')]+data[('STAR','metallicity_snia')]).v
> return data[('STAR','mass')].in_units("Msun")
> else:
> return data[('STAR','age')]
>
>
> d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
>
>
> d.add_field(("STAR","luminosity"),function=StellarLuminosity,units="Msun",sampling_type="particle")
> d.add_deposited_particle_field(("STAR","luminosity"),"nearest",weight_field='particle_ones')
>
> print(d.derived_field_list)
>
> print(d.all_data()[('STAR','metallicity_snii')])
> print(d.all_data()[("deposit","STAR_nn_luminosity")])
> --------------------------
>
> Below is the error I get. ('STAR','metallicity_snii') certainly
> exists, I can print it, but the deposited field seems to be unable
> to find it.
>
> yt : [INFO ] 2018-05-27 13:15:16,205 Created 256 chunks for ARTIO
> [ 5.39916630e-30 2.21650149e-22 2.95487393e-06 ...,
> 1.23813297e-05
> 1.28902484e-05 1.42594863e-05] dimensionless
> yt : [INFO ] 2018-05-27 13:15:16,396 Created 256 chunks for ARTIO
> Traceback (most recent call last):
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 335, in _generate_fluid_field
> finfo.check_available(gen_obj)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/fields/derived_field.py",
> line 199, in check_available
> validator(data)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/fields/derived_field.py",
> line 418, in __call__
> raise NeedsGridType(self.ghost_zones,self.fields)
> yt.fields.field_exceptions.NeedsGridType: (0, None)
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "debug.py", line 23, in <module>
> print(d.all_data()[("deposit","STAR_nn_luminosity")])
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 282, in __getitem__
> self.get_data(f)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 1337, in get_data
> self._generate_fields(fields_to_generate)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 1357, in _generate_fields
> fd = self._generate_field(field)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 319, in _generate_field
> tr = self._generate_fluid_field(field)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 337, in _generate_fluid_field
> rv = self._generate_spatial_fluid(field, ngt_exception.ghost_zones)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 357, in _generate_spatial_fluid
> ind += o.select(self.selector, self[field], rv, ind)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 282, in __getitem__
> self.get_data(f)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 1337, in get_data
> self._generate_fields(fields_to_generate)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 1357, in _generate_fields
> fd = self._generate_field(field)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 319, in _generate_field
> tr = self._generate_fluid_field(field)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 339, in _generate_fluid_field
> rv = finfo(gen_obj)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/fields/derived_field.py",
> line 237, in __call__
> dd = self._function(self, data)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/static_output.py",
> line 1274, in _deposit_field
> fields = [data[ptype, deposit_field]]
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/octree_subset.py",
> line 75, in __getitem__
> tr = super(OctreeSubset, self).__getitem__(key)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 282, in __getitem__
> self.get_data(f)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 1337, in get_data
> self._generate_fields(fields_to_generate)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 1357, in _generate_fields
> fd = self._generate_field(field)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 317, in _generate_field
> tr = self._generate_particle_field(field)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
> line 402, in _generate_particle_field
> rv = self.ds._get_field_info(*field)(gen_obj)
> File
> "/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/fields/derived_field.py",
> line 235, in __call__
> "for %s" % (self.name <http://self.name>,))
> RuntimeError: Something has gone terribly wrong, _function is
> NullFunc for ('STAR', 'METALLICITY_SNII')
>
>
> n
>
>
>
>
>
> On 5/27/2018 12:08 PM, Nathan Goldbaum wrote:
>
> Hi Nick,
>
> What you're seeing in those print statements is how yt's field
> detection system works. Before we actually select and return
> data, we pass your field function fake data to make sure it
> doesn't raise errors or it doesn't select fields that aren't
> available for your dataset.
>
> Here's a script I made based on yours that helps explain what's
> going on:
>
> https://gist.github.com/ngoldbaum/4d27987bda8ecbce5c9bd9b98bbbbf49
> <https://gist.github.com/ngoldbaum/4d27987bda8ecbce5c9bd9b98bbbbf49>
>
> And here's the output of that script:
>
> https://gist.github.com/ngoldbaum/475fcd827a53e4d02e76cb25711ff5ea
> <https://gist.github.com/ngoldbaum/475fcd827a53e4d02e76cb25711ff5ea>
>
> I made a couple modifications compared to your script. First, I
> added a line at the end that selects your new field from a data
> object, which causes real data to be fed into the field function
> after field detection completes. I also specified "units='auto'"
> in the call to add_field. The dimensions keyword is only used
> when "units='auto'" is set.
>
> You can see that your field function is called twice. First with
> a `FieldDetector` instance and then the second time with a real
> yt data object. In general the field function might be called
> several times before real data is supplied to it. One way I
> commonly deal with this is the following hack to only see output
> when the field definition is called with real data:
>
> def NewField(field, data):
> q = data[('STAR', 'age')]
> if 'FieldDetector' in str(type(data)):
> print("BBB",data)
> return q
>
> Although more often I use python's debugger via "import pdb;
> pdb.set_trace()" instead of print statements.
>
> Hope that helps,
>
> Nathan
>
> On Sun, May 27, 2018 at 10:51 AM, Nick Gnedin <ngnedin(a)gmail.com
> <mailto:ngnedin@gmail.com> <mailto:ngnedin@gmail.com
> <mailto:ngnedin@gmail.com>>> wrote:
>
>
> Guys,
>
> I am trying to add a new particle field, and apparently I
> am doing
> something wrong, but I could find the documentation for this:
>
> import yt
> def NewField(field,data):
> q = data[('STAR','age')]
> print("BBB",data)
> return q
> d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
> print('AAA',d.all_data()[("STAR","age")])
>
> d.add_field(("STAR","new-field"),function=NewField,dimensions="time",sampling_type="particle")
>
> The result is here:
>
> AAA [ 1.35689106e+08 1.29578798e+08 1.15241829e+08 ...,
> 2.97175878e+07
> 2.04648908e+07 1.35365980e+07] yr
> BBB defaultdict(<function
> FieldDetector.__init__.<locals>.<lambda>
> at 0x2b9e698e3598>, {('STAR', 'BIRTH_TIME'): YTArray([ 1.])
> (dimensionless), ('STAR', 'creation_time'): YTArray([ 1.])
> (dimensionless), ('STAR', 'age'): YTArray([ 1.])
> (dimensionless)})
>
> It appears that the data object sent to
> NewField(field,data) has all
> its fields set to dimensionless.
>
> I tried omitting sampling_type="particle", but it does not
> help,
> just generates an incomprehensible warning.
>
> n
> _______________________________________________
> yt-users mailing list -- yt-users(a)python.org
> <mailto:yt-users@python.org>
> <mailto:yt-users@python.org <mailto:yt-users@python.org>>
> To unsubscribe send an email to yt-users-leave(a)python.org
> <mailto:yt-users-leave@python.org>
> <mailto:yt-users-leave@python.org
> <mailto:yt-users-leave@python.org>>
>
>
>
Nathan,
I made progress with the real code, but then I hit another error that
leaves me dumbfounded:
----------------------------
import yt
def StellarLuminosity(field,data):
if(not 'FieldDetector' in str(type(data))):
ts = data[('STAR','age')].in_units("yr").v
zs =
(data[('STAR','metallicity_snii')]+data[('STAR','metallicity_snia')]).v
return data[('STAR','mass')].in_units("Msun")
else:
return data[('STAR','age')]
d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
d.add_field(("STAR","luminosity"),function=StellarLuminosity,units="Msun",sampling_type="particle")
d.add_deposited_particle_field(("STAR","luminosity"),"nearest",weight_field='particle_ones')
print(d.derived_field_list)
print(d.all_data()[('STAR','metallicity_snii')])
print(d.all_data()[("deposit","STAR_nn_luminosity")])
--------------------------
Below is the error I get. ('STAR','metallicity_snii') certainly exists,
I can print it, but the deposited field seems to be unable to find it.
yt : [INFO ] 2018-05-27 13:15:16,205 Created 256 chunks for ARTIO
[ 5.39916630e-30 2.21650149e-22 2.95487393e-06 ..., 1.23813297e-05
1.28902484e-05 1.42594863e-05] dimensionless
yt : [INFO ] 2018-05-27 13:15:16,396 Created 256 chunks for ARTIO
Traceback (most recent call last):
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 335, in _generate_fluid_field
finfo.check_available(gen_obj)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/fields/derived_field.py",
line 199, in check_available
validator(data)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/fields/derived_field.py",
line 418, in __call__
raise NeedsGridType(self.ghost_zones,self.fields)
yt.fields.field_exceptions.NeedsGridType: (0, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "debug.py", line 23, in <module>
print(d.all_data()[("deposit","STAR_nn_luminosity")])
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 282, in __getitem__
self.get_data(f)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 1337, in get_data
self._generate_fields(fields_to_generate)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 1357, in _generate_fields
fd = self._generate_field(field)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 319, in _generate_field
tr = self._generate_fluid_field(field)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 337, in _generate_fluid_field
rv = self._generate_spatial_fluid(field, ngt_exception.ghost_zones)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 357, in _generate_spatial_fluid
ind += o.select(self.selector, self[field], rv, ind)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 282, in __getitem__
self.get_data(f)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 1337, in get_data
self._generate_fields(fields_to_generate)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 1357, in _generate_fields
fd = self._generate_field(field)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 319, in _generate_field
tr = self._generate_fluid_field(field)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 339, in _generate_fluid_field
rv = finfo(gen_obj)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/fields/derived_field.py",
line 237, in __call__
dd = self._function(self, data)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/static_output.py",
line 1274, in _deposit_field
fields = [data[ptype, deposit_field]]
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/octree_subset.py",
line 75, in __getitem__
tr = super(OctreeSubset, self).__getitem__(key)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 282, in __getitem__
self.get_data(f)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 1337, in get_data
self._generate_fields(fields_to_generate)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 1357, in _generate_fields
fd = self._generate_field(field)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 317, in _generate_field
tr = self._generate_particle_field(field)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/data_objects/data_containers.py",
line 402, in _generate_particle_field
rv = self.ds._get_field_info(*field)(gen_obj)
File
"/data/gnedin/soft/anaconda3/lib/python3.6/site-packages/yt/fields/derived_field.py",
line 235, in __call__
"for %s" % (self.name,))
RuntimeError: Something has gone terribly wrong, _function is NullFunc
for ('STAR', 'METALLICITY_SNII')
n
On 5/27/2018 12:08 PM, Nathan Goldbaum wrote:
> Hi Nick,
>
> What you're seeing in those print statements is how yt's field detection
> system works. Before we actually select and return data, we pass your
> field function fake data to make sure it doesn't raise errors or it
> doesn't select fields that aren't available for your dataset.
>
> Here's a script I made based on yours that helps explain what's going on:
>
> https://gist.github.com/ngoldbaum/4d27987bda8ecbce5c9bd9b98bbbbf49
>
> And here's the output of that script:
>
> https://gist.github.com/ngoldbaum/475fcd827a53e4d02e76cb25711ff5ea
>
> I made a couple modifications compared to your script. First, I added a
> line at the end that selects your new field from a data object, which
> causes real data to be fed into the field function after field detection
> completes. I also specified "units='auto'" in the call to add_field. The
> dimensions keyword is only used when "units='auto'" is set.
>
> You can see that your field function is called twice. First with a
> `FieldDetector` instance and then the second time with a real yt data
> object. In general the field function might be called several times
> before real data is supplied to it. One way I commonly deal with this is
> the following hack to only see output when the field definition is
> called with real data:
>
> def NewField(field, data):
> q = data[('STAR', 'age')]
> if 'FieldDetector' in str(type(data)):
> print("BBB",data)
> return q
>
> Although more often I use python's debugger via "import pdb;
> pdb.set_trace()" instead of print statements.
>
> Hope that helps,
>
> Nathan
>
> On Sun, May 27, 2018 at 10:51 AM, Nick Gnedin <ngnedin(a)gmail.com
> <mailto:ngnedin@gmail.com>> wrote:
>
>
> Guys,
>
> I am trying to add a new particle field, and apparently I am doing
> something wrong, but I could find the documentation for this:
>
> import yt
> def NewField(field,data):
> q = data[('STAR','age')]
> print("BBB",data)
> return q
> d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
> print('AAA',d.all_data()[("STAR","age")])
> d.add_field(("STAR","new-field"),function=NewField,dimensions="time",sampling_type="particle")
>
> The result is here:
>
> AAA [ 1.35689106e+08 1.29578798e+08 1.15241829e+08 ...,
> 2.97175878e+07
> 2.04648908e+07 1.35365980e+07] yr
> BBB defaultdict(<function FieldDetector.__init__.<locals>.<lambda>
> at 0x2b9e698e3598>, {('STAR', 'BIRTH_TIME'): YTArray([ 1.])
> (dimensionless), ('STAR', 'creation_time'): YTArray([ 1.])
> (dimensionless), ('STAR', 'age'): YTArray([ 1.]) (dimensionless)})
>
> It appears that the data object sent to NewField(field,data) has all
> its fields set to dimensionless.
>
> I tried omitting sampling_type="particle", but it does not help,
> just generates an incomprehensible warning.
>
> n
> _______________________________________________
> yt-users mailing list -- yt-users(a)python.org
> <mailto:yt-users@python.org>
> To unsubscribe send an email to yt-users-leave(a)python.org
> <mailto:yt-users-leave@python.org>
>
>
Nathan,
Thank you. If you care for a comment, I do not think this is a good
idea. I sent you a snippet, my real field function looks like this:
def StellarLuminosity(field,data):
ts = data[('STAR','age')].in_units("yr").v
zs = (data[('STAR', 'METALLICITY_SNII')]+data[('STAR',
'METALLICITY_SNIa')]).v
return sps.GetLnu(ts,zs)*data[('STAR','mass')].in_units("Msun")
The fake data caused an error in the statement
ts = data[('STAR','age')].in_units("yr")
because dimensionless data cannot be converted into years, and that was
how I discovered that the incorrect data were sent to the field function.
I can add a check "if 'FieldDetector' in str(type(data))" to the
function, but think about what is going on in the actual calculation: a
string comparison is going to be taking place every time that function
is called, if it is called frequently, that will be a huge performance
penalty.
n
On 5/27/2018 12:08 PM, Nathan Goldbaum wrote:
> Hi Nick,
>
> What you're seeing in those print statements is how yt's field detection
> system works. Before we actually select and return data, we pass your
> field function fake data to make sure it doesn't raise errors or it
> doesn't select fields that aren't available for your dataset.
>
> Here's a script I made based on yours that helps explain what's going on:
>
> https://gist.github.com/ngoldbaum/4d27987bda8ecbce5c9bd9b98bbbbf49
>
> And here's the output of that script:
>
> https://gist.github.com/ngoldbaum/475fcd827a53e4d02e76cb25711ff5ea
>
> I made a couple modifications compared to your script. First, I added a
> line at the end that selects your new field from a data object, which
> causes real data to be fed into the field function after field detection
> completes. I also specified "units='auto'" in the call to add_field. The
> dimensions keyword is only used when "units='auto'" is set.
>
> You can see that your field function is called twice. First with a
> `FieldDetector` instance and then the second time with a real yt data
> object. In general the field function might be called several times
> before real data is supplied to it. One way I commonly deal with this is
> the following hack to only see output when the field definition is
> called with real data:
>
> def NewField(field, data):
> q = data[('STAR', 'age')]
> if 'FieldDetector' in str(type(data)):
> print("BBB",data)
> return q
>
> Although more often I use python's debugger via "import pdb;
> pdb.set_trace()" instead of print statements.
>
> Hope that helps,
>
> Nathan
>
> On Sun, May 27, 2018 at 10:51 AM, Nick Gnedin <ngnedin(a)gmail.com
> <mailto:ngnedin@gmail.com>> wrote:
>
>
> Guys,
>
> I am trying to add a new particle field, and apparently I am doing
> something wrong, but I could find the documentation for this:
>
> import yt
> def NewField(field,data):
> q = data[('STAR','age')]
> print("BBB",data)
> return q
> d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
> print('AAA',d.all_data()[("STAR","age")])
> d.add_field(("STAR","new-field"),function=NewField,dimensions="time",sampling_type="particle")
>
> The result is here:
>
> AAA [ 1.35689106e+08 1.29578798e+08 1.15241829e+08 ...,
> 2.97175878e+07
> 2.04648908e+07 1.35365980e+07] yr
> BBB defaultdict(<function FieldDetector.__init__.<locals>.<lambda>
> at 0x2b9e698e3598>, {('STAR', 'BIRTH_TIME'): YTArray([ 1.])
> (dimensionless), ('STAR', 'creation_time'): YTArray([ 1.])
> (dimensionless), ('STAR', 'age'): YTArray([ 1.]) (dimensionless)})
>
> It appears that the data object sent to NewField(field,data) has all
> its fields set to dimensionless.
>
> I tried omitting sampling_type="particle", but it does not help,
> just generates an incomprehensible warning.
>
> n
> _______________________________________________
> yt-users mailing list -- yt-users(a)python.org
> <mailto:yt-users@python.org>
> To unsubscribe send an email to yt-users-leave(a)python.org
> <mailto:yt-users-leave@python.org>
>
>
Guys,
I am trying to add a new particle field, and apparently I am doing
something wrong, but I could find the documentation for this:
import yt
def NewField(field,data):
q = data[('STAR','age')]
print("BBB",data)
return q
d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
print('AAA',d.all_data()[("STAR","age")])
d.add_field(("STAR","new-field"),function=NewField,dimensions="time",sampling_type="particle")
The result is here:
AAA [ 1.35689106e+08 1.29578798e+08 1.15241829e+08 ...,
2.97175878e+07
2.04648908e+07 1.35365980e+07] yr
BBB defaultdict(<function FieldDetector.__init__.<locals>.<lambda> at
0x2b9e698e3598>, {('STAR', 'BIRTH_TIME'): YTArray([ 1.])
(dimensionless), ('STAR', 'creation_time'): YTArray([ 1.])
(dimensionless), ('STAR', 'age'): YTArray([ 1.]) (dimensionless)})
It appears that the data object sent to NewField(field,data) has all its
fields set to dimensionless.
I tried omitting sampling_type="particle", but it does not help, just
generates an incomprehensible warning.
n
I am using 3.4.1.
I get the same problem with wrong units with the data set I uploaded:
d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
s = d.sphere([0,0,0],(10,'kpc'))
loc = s.quantities.max_location(('gas', 'density'))
print(loc)
> [7.042448094432284e-28 g/cm**3, 0.3125 cm, 0.0625 cm, 63.8125 cm]
On 05/25/2018 12:49 PM, Nathan Goldbaum wrote:
>
>
> On Fri, May 25, 2018 at 12:25 PM, Nick Gnedin <gnedin(a)fnal.gov
> <mailto:gnedin@fnal.gov>> wrote:
>
>
> Guys,
>
> Sorry for multiple question, here is another simple one.
>
> I have a dataset d for which I create a sphere:
>
> s = d.sphere([x0,y0,z0],r0)
> vcen = s.quantities.bulk_velocity()
> s.set_field_parameter("bulk_velocity",vcen)
>
> It is located somewhere in the box:
>
> print(x0,y0,z0)
> > 0.04789762673404803 Mpc 4.396788395087413 Mpc 0.9398923037682868 Mpc
>
> Now I would like to find the location of the max density for some
> field. When I try this:
>
> print(s.quantities.max_location(('deposit', 'STAR_density')))
> print(s.quantities.max_location(('gas', 'density')))
> print(s.quantities.max_location(('deposit', 'N-BODY_density')))
>
> I get non-nonsensical values:
>
> [1.1195988056992701e-21 g/cm**3, 1.3408203125 cm, 117.7998046875 cm,
> 25.3603515625 cm]
> [1.3058663046178781e-20 g/cm**3, 1.3408203125 cm, 117.8017578125 cm,
> 25.3603515625 cm]
> [1.73680472946578e-20 g/cm**3, 1.3896484375 cm, 117.7919921875 cm,
> 25.3271484375 cm]
>
> Density values are ok, but positions surely cannot be measured in a
> small number of cm. Given that in code units the box size is 128, it
> seems like locations are returned in code units but interpreted as cm.
>
>
> Hmm, I agree that's probably what's happening. That said, I can't seem
> to reproduce the issue on yt 3.4.1, with the following script:
>
> import yt
> ds =
> yt.load('sizmbhloz-clref04SNth-rs9_a0.9011/sizmbhloz-clref04SNth-rs9_a0.9011.art')
>
> c = [0.04789762673404803*Mpc, 4.396788395087413*Mpc,
> 0.9398923037682868*Mpc]
> s = ds.sphere(c, 50*Mpc)
> print(s.quantities.max_location(('gas', 'density')))
>
> I get:
>
> [3.4612530065401464e-22 g/cm**3, 63.9970703125 code_length,
> 63.9990234375 code_length, 63.9970703125 code_length]
>
> If you're not already using yt 3.4.1, can you try updating? You can see
> your current yt version with:
>
> $ python -c "import yt; print(yt.__version__)"
>
> If you're on yt 3.4.1 and are still seeing the issue, I guess it has
> something to do with the dataset you're using or the precise details of
> the code you're running. Is this the same dataset you sent me in the
> other thread?
>
> -Nathan
>
>
> n
> _______________________________________________
> yt-users mailing list -- yt-users(a)python.org
> <mailto:yt-users@python.org>
> To unsubscribe send an email to yt-users-leave(a)python.org
> <mailto:yt-users-leave@python.org>
>
>