yt.utilities.amr_utils
Hi, I am trying to compute gridded density of some subset of particles. So I tried to import some modules first in the python script as follows: from yt.data_objects.field_info_container import \ FieldInfoContainer, \ NullFunc, \ TranslationFunc, \ FieldInfo, \ ValidateParameter, \ ValidateDataField, \ ValidateProperty, \ ValidateSpatial, \ ValidateGridType import yt.data_objects.universal_fields from yt.utilities.physical_constants import mh from yt.funcs import * import yt.utilities.amr_utils as amr_utils But I got this error message: Traceback (most recent call last): File "SFR.py", line 28, in <module> import yt.utilities.amr_utils as amr_utils ImportError: No module named amr_utils Am I doing something wrong? Thanks, Renyue
Hi Renyue, The module amr_utils became lib a while back. But my guess is that you probably don't need to import it anyway, unless you are explicitly using one of the routines it provides. -Matt On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi,
I am trying to compute gridded density of some subset of particles. So I tried to import some modules first in the python script as follows:
from yt.data_objects.field_info_container import \ FieldInfoContainer, \ NullFunc, \ TranslationFunc, \ FieldInfo, \ ValidateParameter, \ ValidateDataField, \ ValidateProperty, \ ValidateSpatial, \ ValidateGridType import yt.data_objects.universal_fields from yt.utilities.physical_constants import mh from yt.funcs import * import yt.utilities.amr_utils as amr_utils
But I got this error message:
Traceback (most recent call last): File "SFR.py", line 28, in <module> import yt.utilities.amr_utils as amr_utils ImportError: No module named amr_utils
Am I doing something wrong?
Thanks, Renyue
Hi Matt, Thanks very much for your prompt help. Ok, I switched to lib now. I am trying to do volume rendering of young stars (those formed in the last 100 Myrs, say), so I did (by emulating some routines I found): from yt.utilities.lib import CICDeposit_3 def _convertDensity(data): return data.convert("Density") def _spdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 if not filter.any(): return blank amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), data["particle_position_y"][filter].astype(na.float64), data["particle_position_z"][filter].astype(na.float64), data["particle_mass"][filter].astype(na.float32), na.int64(na.where(filter)[0].size), blank, na.array(data.LeftEdge).astype(na.float64), na.array(data.ActiveDimensions).astype(na.int32), na.float64(data['dx'])) return blank add_field("star_density", function=_spdensity, validators=[ValidateSpatial(0)], convert_function=_convertDensity) this new "star_density" of my own is actually for young stars only (I initially named things like SFR_density instead of the already defined star_density in the above, but AMRKDTree does not seem to recognize it, so I am re-using the already defined variable "star_density" to see if that works). Could I do better in this case? Best, Renyue On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
Hi Renyue,
The module amr_utils became lib a while back. But my guess is that you probably don't need to import it anyway, unless you are explicitly using one of the routines it provides.
-Matt
On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi,
I am trying to compute gridded density of some subset of particles. So I tried to import some modules first in the python script as follows:
from yt.data_objects.field_info_container import \ FieldInfoContainer, \ NullFunc, \ TranslationFunc, \ FieldInfo, \ ValidateParameter, \ ValidateDataField, \ ValidateProperty, \ ValidateSpatial, \ ValidateGridType import yt.data_objects.universal_fields from yt.utilities.physical_constants import mh from yt.funcs import * import yt.utilities.amr_utils as amr_utils
But I got this error message:
Traceback (most recent call last): File "SFR.py", line 28, in <module> import yt.utilities.amr_utils as amr_utils ImportError: No module named amr_utils
Am I doing something wrong?
Thanks, Renyue
Hi Matt, It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did: def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), data["particle_position_y"][filter].astype(na.float64), data["particle_position_z"][filter].astype(na.float64), data["particle_mass"][filter].astype(na.float32), na.int64(na.where(filter)[0].size), blank, na.array(data.LeftEdge).astype(na.float64), na.array(data.ActiveDimensions).astype(na.int32), na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)], convert_function=_convertDensity) volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None ,north_vector=dir) with the following error message: Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", line 316, in __init__ for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 70, in __missing__ raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity' So I must be doing something wrong with defining the SFRdensity field. Thanks very much, Renyue On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
Hi Renyue,
The module amr_utils became lib a while back. But my guess is that you probably don't need to import it anyway, unless you are explicitly using one of the routines it provides.
-Matt
On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi,
I am trying to compute gridded density of some subset of particles. So I tried to import some modules first in the python script as follows:
from yt.data_objects.field_info_container import \ FieldInfoContainer, \ NullFunc, \ TranslationFunc, \ FieldInfo, \ ValidateParameter, \ ValidateDataField, \ ValidateProperty, \ ValidateSpatial, \ ValidateGridType import yt.data_objects.universal_fields from yt.utilities.physical_constants import mh from yt.funcs import * import yt.utilities.amr_utils as amr_utils
But I got this error message:
Traceback (most recent call last): File "SFR.py", line 28, in <module> import yt.utilities.amr_utils as amr_utils ImportError: No module named amr_utils
Am I doing something wrong?
Thanks, Renyue
Hi Renyue, One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do: add_field( ... ) pf = ... because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies. -Matt On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did:
def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), data["particle_position_y"][filter].astype(na.float64), data["particle_position_z"][filter].astype(na.float64), data["particle_mass"][filter].astype(na.float32), na.int64(na.where(filter)[0].size), blank, na.array(data.LeftEdge).astype(na.float64), na.array(data.ActiveDimensions).astype(na.int32), na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)], convert_function=_convertDensity)
volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None ,north_vector=dir)
with the following error message:
Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", line 316, in __init__ for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 70, in __missing__ raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity'
So I must be doing something wrong with defining the SFRdensity field.
Thanks very much, Renyue
On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
Hi Renyue,
The module amr_utils became lib a while back. But my guess is that you probably don't need to import it anyway, unless you are explicitly using one of the routines it provides.
-Matt
On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi,
I am trying to compute gridded density of some subset of particles. So I tried to import some modules first in the python script as follows:
from yt.data_objects.field_info_container import \ FieldInfoContainer, \ NullFunc, \ TranslationFunc, \ FieldInfo, \ ValidateParameter, \ ValidateDataField, \ ValidateProperty, \ ValidateSpatial, \ ValidateGridType import yt.data_objects.universal_fields from yt.utilities.physical_constants import mh from yt.funcs import * import yt.utilities.amr_utils as amr_utils
But I got this error message:
Traceback (most recent call last): File "SFR.py", line 28, in <module> import yt.utilities.amr_utils as amr_utils ImportError: No module named amr_utils
Am I doing something wrong?
Thanks, Renyue
Hi Matt, This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables that did not require CIC and seem to work. Was I using the wrong syntax or something? Renyue On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
Hi Renyue,
One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do:
add_field( ... ) pf = ...
because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies.
-Matt
On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did:
def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), data["particle_position_y"][filter].astype(na.float64), data["particle_position_z"][filter].astype(na.float64), data["particle_mass"][filter].astype(na.float32), na.int64(na.where(filter)[0].size), blank, na.array(data.LeftEdge).astype(na.float64), na.array(data.ActiveDimensions).astype(na.int32), na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)], convert_function=_convertDensity)
volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None ,north_vector=dir)
with the following error message:
Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", line 316, in __init__ for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 70, in __missing__ raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity'
So I must be doing something wrong with defining the SFRdensity field.
Thanks very much, Renyue
On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
Hi Renyue,
The module amr_utils became lib a while back. But my guess is that you probably don't need to import it anyway, unless you are explicitly using one of the routines it provides.
-Matt
On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi,
I am trying to compute gridded density of some subset of particles. So I tried to import some modules first in the python script as follows:
from yt.data_objects.field_info_container import \ FieldInfoContainer, \ NullFunc, \ TranslationFunc, \ FieldInfo, \ ValidateParameter, \ ValidateDataField, \ ValidateProperty, \ ValidateSpatial, \ ValidateGridType import yt.data_objects.universal_fields from yt.utilities.physical_constants import mh from yt.funcs import * import yt.utilities.amr_utils as amr_utils
But I got this error message:
Traceback (most recent call last): File "SFR.py", line 28, in <module> import yt.utilities.amr_utils as amr_utils ImportError: No module named amr_utils
Am I doing something wrong?
Thanks, Renyue
Hi Renyue, No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the CICDeposit_3. The exception from the NameError is probably killing its availability. So here's what to do: 1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with: from yt.utilities.lib import CICDeposit_3 2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3 And try again? -Matt On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables that did not require CIC and seem to work.
Was I using the wrong syntax or something?
Renyue
On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
Hi Renyue,
One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do:
add_field( ... ) pf = ...
because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies.
-Matt
On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did:
def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), data["particle_position_y"][filter].astype(na.float64), data["particle_position_z"][filter].astype(na.float64), data["particle_mass"][filter].astype(na.float32), na.int64(na.where(filter)[0].size), blank, na.array(data.LeftEdge).astype(na.float64), na.array(data.ActiveDimensions).astype(na.int32), na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)], convert_function=_convertDensity)
volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None ,north_vector=dir)
with the following error message:
Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", line 316, in __init__ for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 70, in __missing__ raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity'
So I must be doing something wrong with defining the SFRdensity field.
Thanks very much, Renyue
On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
Hi Renyue,
The module amr_utils became lib a while back. But my guess is that you probably don't need to import it anyway, unless you are explicitly using one of the routines it provides.
-Matt
On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi,
I am trying to compute gridded density of some subset of particles. So I tried to import some modules first in the python script as follows:
from yt.data_objects.field_info_container import \ FieldInfoContainer, \ NullFunc, \ TranslationFunc, \ FieldInfo, \ ValidateParameter, \ ValidateDataField, \ ValidateProperty, \ ValidateSpatial, \ ValidateGridType import yt.data_objects.universal_fields from yt.utilities.physical_constants import mh from yt.funcs import * import yt.utilities.amr_utils as amr_utils
But I got this error message:
Traceback (most recent call last): File "SFR.py", line 28, in <module> import yt.utilities.amr_utils as amr_utils ImportError: No module named amr_utils
Am I doing something wrong?
Thanks, Renyue
HI Matt, That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3": #from yt.utilities.cosmology import Cosmology #from field_info_container import \ # add_field, \ # ValidateDataField, \ # ValidateGridType, \ # ValidateParameter, \ # ValidateSpatial, \ # NeedsGridType, \ # NeedsOriginalGrid, \ # NeedsDataField, \ # NeedsProperty, \ # NeedsParameter which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before. Thanks very much, Renyue On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:
Hi Renyue,
No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the CICDeposit_3. The exception from the NameError is probably killing its availability.
So here's what to do:
1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with:
from yt.utilities.lib import CICDeposit_3
2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
And try again?
-Matt
On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables that did not require CIC and seem to work.
Was I using the wrong syntax or something?
Renyue
On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
Hi Renyue,
One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do:
add_field( ... ) pf = ...
because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies.
-Matt
On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did:
def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), data["particle_position_y"][filter].astype(na.float64), data["particle_position_z"][filter].astype(na.float64), data["particle_mass"][filter].astype(na.float32), na.int64(na.where(filter)[0].size), blank, na.array(data.LeftEdge).astype(na.float64), na.array(data.ActiveDimensions).astype(na.int32), na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)], convert_function=_convertDensity)
volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None ,north_vector=dir)
with the following error message:
Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", line 316, in __init__ for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 70, in __missing__ raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity'
So I must be doing something wrong with defining the SFRdensity field.
Thanks very much, Renyue
On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
Hi Renyue,
The module amr_utils became lib a while back. But my guess is that you probably don't need to import it anyway, unless you are explicitly using one of the routines it provides.
-Matt
On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi,
I am trying to compute gridded density of some subset of particles. So I tried to import some modules first in the python script as follows:
from yt.data_objects.field_info_container import \ FieldInfoContainer, \ NullFunc, \ TranslationFunc, \ FieldInfo, \ ValidateParameter, \ ValidateDataField, \ ValidateProperty, \ ValidateSpatial, \ ValidateGridType import yt.data_objects.universal_fields from yt.utilities.physical_constants import mh from yt.funcs import * import yt.utilities.amr_utils as amr_utils
But I got this error message:
Traceback (most recent call last): File "SFR.py", line 28, in <module> import yt.utilities.amr_utils as amr_utils ImportError: No module named amr_utils
Am I doing something wrong?
Thanks, Renyue
Sorry to revive this old(ish) thread, but I've been experiencing similar troubles to Renyue's. Mine, however, were not completely fixed by switching from yt.utilities.amr_utils to yt.utilities.lib. I was still getting this error: AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute 'NumberOfParticles' The solution for me was to switch from validators=[ValidateSpatial(0)] to validators=[ValidateGridType()] in the add_field() call. Since many of the fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm getting the same NumberOfParticles AttributeError when I try to do volume renderings of "built-in" fields like dm_density. Cheers, Mike On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
HI Matt,
That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3": #from yt.utilities.cosmology import Cosmology #from field_info_container import \ # add_field, \ # ValidateDataField, \ # ValidateGridType, \ # ValidateParameter, \ # ValidateSpatial, \ # NeedsGridType, \ # NeedsOriginalGrid, \ # NeedsDataField, \ # NeedsProperty, \ # NeedsParameter
which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.
Thanks very much, Renyue
On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:
Hi Renyue,
No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the CICDeposit_3. The exception from the NameError is probably killing its availability.
So here's what to do:
1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with:
from yt.utilities.lib import CICDeposit_3
2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
And try again?
-Matt
Hi Matt,
This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables
and seem to work.
Was I using the wrong syntax or something?
Renyue
On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
Hi Renyue,
One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do:
add_field( ... ) pf = ...
because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies.
-Matt
On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did:
def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank
amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64),
data["particle_position_y"][filter].astype(na.float64),
data["particle_position_z"][filter].astype(na.float64),
data["particle_mass"][filter].astype(na.float32),
na.int64(na.where(filter)[0].size), blank,
na.array(data.LeftEdge).astype(na.float64),
na.array(data.ActiveDimensions).astype(na.int32),
na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)],
convert_function=_convertDensity)
volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3,
no_ghost=False,log_fields=None
,north_vector=dir)
with the following error message:
Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File
"/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py",
for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py",
return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py",
return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py",
On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu> wrote: that did not require CIC line 316, in __init__ line 71, in __missing__ line 71, in __missing__ line 70, in __missing__
raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity'
So I must be doing something wrong with defining the SFRdensity field.
Thanks very much, Renyue
On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
Hi Renyue,
The module amr_utils became lib a while back. But my guess is that you probably don't need to import it anyway, unless you are explicitly using one of the routines it provides.
-Matt
On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen < cen@astro.princeton.edu> wrote: > Hi, > > I am trying to compute gridded density of some subset of particles. > So I tried to import some modules first in the python script as follows: > > from yt.data_objects.field_info_container import \ > FieldInfoContainer, \ > NullFunc, \ > TranslationFunc, \ > FieldInfo, \ > ValidateParameter, \ > ValidateDataField, \ > ValidateProperty, \ > ValidateSpatial, \ > ValidateGridType > import yt.data_objects.universal_fields > from yt.utilities.physical_constants import mh > from yt.funcs import * > import yt.utilities.amr_utils as amr_utils > > > But I got this error message: > > Traceback (most recent call last): > File "SFR.py", line 28, in <module> > import yt.utilities.amr_utils as amr_utils > ImportError: No module named amr_utils > > > Am I doing something wrong? > > Thanks, > Renyue
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
Hi Mike, I think that the checks for .NumberOfParticles may be unnecessary in the dm_density calls. Removing those, and simply returning an empty deposition field if there are no particles, will likely give the same results as what it currently does. Switching between ValidateGridType and ValidateSpatial will turn on/off fields in ways I think we may want to avoid. For particle density fields specifically it would likely result in estimates for particle density that are generated at a coarser level then interpolated to a finer level. -Matt On Tue, Jan 22, 2013 at 1:38 AM, Michael Kuhlen <mqk@astro.berkeley.edu> wrote:
Sorry to revive this old(ish) thread, but I've been experiencing similar troubles to Renyue's. Mine, however, were not completely fixed by switching from yt.utilities.amr_utils to yt.utilities.lib. I was still getting this error:
AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute 'NumberOfParticles'
The solution for me was to switch from validators=[ValidateSpatial(0)] to validators=[ValidateGridType()] in the add_field() call. Since many of the fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm getting the same NumberOfParticles AttributeError when I try to do volume renderings of "built-in" fields like dm_density.
Cheers, Mike
On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
HI Matt,
That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3": #from yt.utilities.cosmology import Cosmology #from field_info_container import \ # add_field, \ # ValidateDataField, \ # ValidateGridType, \ # ValidateParameter, \ # ValidateSpatial, \ # NeedsGridType, \ # NeedsOriginalGrid, \ # NeedsDataField, \ # NeedsProperty, \ # NeedsParameter
which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.
Thanks very much, Renyue
On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:
Hi Renyue,
No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the CICDeposit_3. The exception from the NameError is probably killing its availability.
So here's what to do:
1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with:
from yt.utilities.lib import CICDeposit_3
2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
And try again?
-Matt
On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables that did not require CIC and seem to work.
Was I using the wrong syntax or something?
Renyue
On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
Hi Renyue,
One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do:
add_field( ... ) pf = ...
because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies.
-Matt
On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did:
def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank
amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64),
data["particle_position_y"][filter].astype(na.float64),
data["particle_position_z"][filter].astype(na.float64),
data["particle_mass"][filter].astype(na.float32), na.int64(na.where(filter)[0].size), blank, na.array(data.LeftEdge).astype(na.float64),
na.array(data.ActiveDimensions).astype(na.int32), na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)], convert_function=_convertDensity)
volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None ,north_vector=dir)
with the following error message:
Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", line 316, in __init__ for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 70, in __missing__ raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity'
So I must be doing something wrong with defining the SFRdensity field.
Thanks very much, Renyue
On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
> Hi Renyue, > > The module amr_utils became lib a while back. But my guess is that > you probably don't need to import it anyway, unless you are > explicitly > using one of the routines it provides. > > -Matt > > On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen > <cen@astro.princeton.edu> wrote: >> Hi, >> >> I am trying to compute gridded density of some subset of particles. >> So I tried to import some modules first in the python script as >> follows: >> >> from yt.data_objects.field_info_container import \ >> FieldInfoContainer, \ >> NullFunc, \ >> TranslationFunc, \ >> FieldInfo, \ >> ValidateParameter, \ >> ValidateDataField, \ >> ValidateProperty, \ >> ValidateSpatial, \ >> ValidateGridType >> import yt.data_objects.universal_fields >> from yt.utilities.physical_constants import mh >> from yt.funcs import * >> import yt.utilities.amr_utils as amr_utils >> >> >> But I got this error message: >> >> Traceback (most recent call last): >> File "SFR.py", line 28, in <module> >> import yt.utilities.amr_utils as amr_utils >> ImportError: No module named amr_utils >> >> >> Am I doing something wrong? >> >> Thanks, >> Renyue
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
Hi Matt First, I got the idea for ValidateGridType from the definition of the field "particle_density" in yt/data_objects/universal_fields.py, which uses data.NumerOfParticles and does not result in an error with AMRSmoothedCoveringGrid. So I guess that field also returns interpolated particle density? Secondly, simply commenting out the test for NumberOfParticles == 0 doesn't work, "DataCubeError: CombineGrids: Three dimensions required for g_data[0]." Let me know if you want the full traceback. Btw, here's an example script with which you should be able to reproduce the error: http://paste.yt-project.org/show/3069/ Mike On Tue, Jan 22, 2013 at 2:10 AM, Matthew Turk <matthewturk@gmail.com> wrote:
Hi Mike,
I think that the checks for .NumberOfParticles may be unnecessary in the dm_density calls. Removing those, and simply returning an empty deposition field if there are no particles, will likely give the same results as what it currently does. Switching between ValidateGridType and ValidateSpatial will turn on/off fields in ways I think we may want to avoid. For particle density fields specifically it would likely result in estimates for particle density that are generated at a coarser level then interpolated to a finer level.
-Matt
Sorry to revive this old(ish) thread, but I've been experiencing similar troubles to Renyue's. Mine, however, were not completely fixed by switching from yt.utilities.amr_utils to yt.utilities.lib. I was still getting this error:
AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute 'NumberOfParticles'
The solution for me was to switch from validators=[ValidateSpatial(0)] to validators=[ValidateGridType()] in the add_field() call. Since many of
fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm getting the same NumberOfParticles AttributeError when I try to do volume renderings of "built-in" fields like dm_density.
Cheers, Mike
On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
HI Matt,
That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3": #from yt.utilities.cosmology import Cosmology #from field_info_container import \ # add_field, \ # ValidateDataField, \ # ValidateGridType, \ # ValidateParameter, \ # ValidateSpatial, \ # NeedsGridType, \ # NeedsOriginalGrid, \ # NeedsDataField, \ # NeedsProperty, \ # NeedsParameter
which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.
Thanks very much, Renyue
On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:
Hi Renyue,
No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the CICDeposit_3. The exception from the NameError is probably killing its availability.
So here's what to do:
1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with:
from yt.utilities.lib import CICDeposit_3
2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
And try again?
-Matt
On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables that did not require CIC and seem to work.
Was I using the wrong syntax or something?
Renyue
On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
Hi Renyue,
One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do:
add_field( ... ) pf = ...
because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies.
-Matt
On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <
cen@astro.princeton.edu>
wrote: > Hi Matt, > > It seems that my attempt to reuse "star_density" for a subset of > stars does not work: > "star_density" remains the density of all stars when plotted. > But I also failed to redefine a new density that is called > "SFRdensity" and feed it to AMRKDTree which is in turn > fed to camera to volume render. Here is what I did: > > def _convertDensity(data): > return data.convert("Density") > def _SFRdensity(field, data): > blank = na.zeros(data.ActiveDimensions, dtype='float32') > if data.NumberOfParticles == 0: return blank > # filter = data.pf.time_units['years']*(data.pf.current_time - > data['creation_time']) < 1.e8 > filter = data.pf.time_units['years']*(data.pf.current_time - > data['creation_time']) < 1.e6 > if not filter.any(): return blank > > amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), > > data["particle_position_y"][filter].astype(na.float64), > > data["particle_position_z"][filter].astype(na.float64), > > data["particle_mass"][filter].astype(na.float32), > na.int64(na.where(filter)[0].size), > blank, > na.array(data.LeftEdge).astype(na.float64), > > na.array(data.ActiveDimensions).astype(na.int32), > na.float64(data['dx'])) > return blank > add_field("SFRdensity", function=_SFRdensity, > validators=[ValidateSpatial(0)], > convert_function=_convertDensity) > > volume3 = AMRKDTree(pf, fields=["SFRdensity"] > ,no_ghost=False, tree_type="domain" > ,le=c-0.5*WW, re=c+0.5*WW) > cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, > no_ghost=False,log_fields=None > ,north_vector=dir) > > > with the following error message: > > Traceback (most recent call last): > File "SFR.py", line 393, in <module> > ,le=c-0.5*WW, re=c+0.5*WW) > File > "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", > line 316, in __init__ > for field in self.fields] > File > "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", > line 71, in __missing__ > return self.fallback[key] > File > "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", > line 71, in __missing__ > return self.fallback[key] > File > "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", > line 70, in __missing__ > raise KeyError("No field named %s" % key) > KeyError: 'No field named SFRdensity' > > > So I must be doing something wrong with defining the SFRdensity > field. > > Thanks very much, > Renyue > > > On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote: > >> Hi Renyue, >> >> The module amr_utils became lib a while back. But my guess is
>> you probably don't need to import it anyway, unless you are >> explicitly >> using one of the routines it provides. >> >> -Matt >> >> On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen >> <cen@astro.princeton.edu> wrote: >>> Hi, >>> >>> I am trying to compute gridded density of some subset of
On Tue, Jan 22, 2013 at 1:38 AM, Michael Kuhlen <mqk@astro.berkeley.edu> wrote: the that particles.
>>> So I tried to import some modules first in the python script as >>> follows: >>> >>> from yt.data_objects.field_info_container import \ >>> FieldInfoContainer, \ >>> NullFunc, \ >>> TranslationFunc, \ >>> FieldInfo, \ >>> ValidateParameter, \ >>> ValidateDataField, \ >>> ValidateProperty, \ >>> ValidateSpatial, \ >>> ValidateGridType >>> import yt.data_objects.universal_fields >>> from yt.utilities.physical_constants import mh >>> from yt.funcs import * >>> import yt.utilities.amr_utils as amr_utils >>> >>> >>> But I got this error message: >>> >>> Traceback (most recent call last): >>> File "SFR.py", line 28, in <module> >>> import yt.utilities.amr_utils as amr_utils >>> ImportError: No module named amr_utils >>> >>> >>> Am I doing something wrong? >>> >>> Thanks, >>> Renyue >
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
One more thing. Adding try: data.NumberOfParticles except AttributeError: return blank before "if data.NumberOfParticles == 0: return blank" allows the projection to complete without errors even with ValidateSpatial(0). This might work as a stopgap. On Tue, Jan 22, 2013 at 9:57 AM, Michael Kuhlen <mqk@astro.berkeley.edu>wrote:
Hi Matt
First, I got the idea for ValidateGridType from the definition of the field "particle_density" in yt/data_objects/universal_fields.py, which uses data.NumerOfParticles and does not result in an error with AMRSmoothedCoveringGrid. So I guess that field also returns interpolated particle density?
Secondly, simply commenting out the test for NumberOfParticles == 0 doesn't work, "DataCubeError: CombineGrids: Three dimensions required for g_data[0]." Let me know if you want the full traceback.
Btw, here's an example script with which you should be able to reproduce the error: http://paste.yt-project.org/show/3069/
Mike
On Tue, Jan 22, 2013 at 2:10 AM, Matthew Turk <matthewturk@gmail.com>wrote:
Hi Mike,
I think that the checks for .NumberOfParticles may be unnecessary in the dm_density calls. Removing those, and simply returning an empty deposition field if there are no particles, will likely give the same results as what it currently does. Switching between ValidateGridType and ValidateSpatial will turn on/off fields in ways I think we may want to avoid. For particle density fields specifically it would likely result in estimates for particle density that are generated at a coarser level then interpolated to a finer level.
-Matt
Sorry to revive this old(ish) thread, but I've been experiencing similar troubles to Renyue's. Mine, however, were not completely fixed by switching from yt.utilities.amr_utils to yt.utilities.lib. I was still getting
error:
AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute 'NumberOfParticles'
The solution for me was to switch from validators=[ValidateSpatial(0)] to validators=[ValidateGridType()] in the add_field() call. Since many of
fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm getting the same NumberOfParticles AttributeError when I try to do volume renderings of "built-in" fields like dm_density.
Cheers, Mike
On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
HI Matt,
That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3": #from yt.utilities.cosmology import Cosmology #from field_info_container import \ # add_field, \ # ValidateDataField, \ # ValidateGridType, \ # ValidateParameter, \ # ValidateSpatial, \ # NeedsGridType, \ # NeedsOriginalGrid, \ # NeedsDataField, \ # NeedsProperty, \ # NeedsParameter
which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.
Thanks very much, Renyue
On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:
Hi Renyue,
No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the
CICDeposit_3.
The exception from the NameError is probably killing its availability.
So here's what to do:
1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with:
from yt.utilities.lib import CICDeposit_3
2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
And try again?
-Matt
On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu
wrote:
Hi Matt,
This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables that did not require CIC and seem to work.
Was I using the wrong syntax or something?
Renyue
On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
> Hi Renyue, > > One important thing to note is that the field has to be added before > you instantiate the parameter file; i.e., you must do: > > add_field( ... ) > pf = ... > > because the parameter file, upon creation of the hierarchy,
> an auto-detection step. This auto-detection step determines which > fields are available based on their dependencies. > > -Matt > > On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen < cen@astro.princeton.edu> > wrote: >> Hi Matt, >> >> It seems that my attempt to reuse "star_density" for a subset of >> stars does not work: >> "star_density" remains the density of all stars when plotted. >> But I also failed to redefine a new density that is called >> "SFRdensity" and feed it to AMRKDTree which is in turn >> fed to camera to volume render. Here is what I did: >> >> def _convertDensity(data): >> return data.convert("Density") >> def _SFRdensity(field, data): >> blank = na.zeros(data.ActiveDimensions, dtype='float32') >> if data.NumberOfParticles == 0: return blank >> # filter = data.pf.time_units['years']*(data.pf.current_time - >> data['creation_time']) < 1.e8 >> filter = data.pf.time_units['years']*(data.pf.current_time - >> data['creation_time']) < 1.e6 >> if not filter.any(): return blank >> >> amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), >> >> data["particle_position_y"][filter].astype(na.float64), >> >> data["particle_position_z"][filter].astype(na.float64), >> >> data["particle_mass"][filter].astype(na.float32), >> na.int64(na.where(filter)[0].size), >> blank, >> na.array(data.LeftEdge).astype(na.float64), >> >> na.array(data.ActiveDimensions).astype(na.int32), >> na.float64(data['dx'])) >> return blank >> add_field("SFRdensity", function=_SFRdensity, >> validators=[ValidateSpatial(0)], >> convert_function=_convertDensity) >> >> volume3 = AMRKDTree(pf, fields=["SFRdensity"] >> ,no_ghost=False, tree_type="domain" >> ,le=c-0.5*WW, re=c+0.5*WW) >> cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, >> no_ghost=False,log_fields=None >> ,north_vector=dir) >> >> >> with the following error message: >> >> Traceback (most recent call last): >> File "SFR.py", line 393, in <module> >> ,le=c-0.5*WW, re=c+0.5*WW) >> File >> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", >> line 316, in __init__ >> for field in self.fields] >> File >> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", >> line 71, in __missing__ >> return self.fallback[key] >> File >> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", >> line 71, in __missing__ >> return self.fallback[key] >> File >> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", >> line 70, in __missing__ >> raise KeyError("No field named %s" % key) >> KeyError: 'No field named SFRdensity' >> >> >> So I must be doing something wrong with defining the SFRdensity >> field. >> >> Thanks very much, >> Renyue >> >> >> On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote: >> >>> Hi Renyue, >>> >>> The module amr_utils became lib a while back. But my guess is
>>> you probably don't need to import it anyway, unless you are >>> explicitly >>> using one of the routines it provides. >>> >>> -Matt >>> >>> On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen >>> <cen@astro.princeton.edu> wrote: >>>> Hi, >>>> >>>> I am trying to compute gridded density of some subset of
On Tue, Jan 22, 2013 at 1:38 AM, Michael Kuhlen <mqk@astro.berkeley.edu> wrote: this the performs that particles.
>>>> So I tried to import some modules first in the python script as >>>> follows: >>>> >>>> from yt.data_objects.field_info_container import \ >>>> FieldInfoContainer, \ >>>> NullFunc, \ >>>> TranslationFunc, \ >>>> FieldInfo, \ >>>> ValidateParameter, \ >>>> ValidateDataField, \ >>>> ValidateProperty, \ >>>> ValidateSpatial, \ >>>> ValidateGridType >>>> import yt.data_objects.universal_fields >>>> from yt.utilities.physical_constants import mh >>>> from yt.funcs import * >>>> import yt.utilities.amr_utils as amr_utils >>>> >>>> >>>> But I got this error message: >>>> >>>> Traceback (most recent call last): >>>> File "SFR.py", line 28, in <module> >>>> import yt.utilities.amr_utils as amr_utils >>>> ImportError: No module named amr_utils >>>> >>>> >>>> Am I doing something wrong? >>>> >>>> Thanks, >>>> Renyue >>
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
Hi Mike, I've created a pull request: https://bitbucket.org/yt_analysis/yt/pull-request/407/adding-ability-to-get-... -Matt On Tue, Jan 22, 2013 at 1:10 PM, Michael Kuhlen <mqk@astro.berkeley.edu> wrote:
One more thing. Adding
try: data.NumberOfParticles except AttributeError: return blank
before "if data.NumberOfParticles == 0: return blank" allows the projection to complete without errors even with ValidateSpatial(0). This might work as a stopgap.
On Tue, Jan 22, 2013 at 9:57 AM, Michael Kuhlen <mqk@astro.berkeley.edu> wrote:
Hi Matt
First, I got the idea for ValidateGridType from the definition of the field "particle_density" in yt/data_objects/universal_fields.py, which uses data.NumerOfParticles and does not result in an error with AMRSmoothedCoveringGrid. So I guess that field also returns interpolated particle density?
Secondly, simply commenting out the test for NumberOfParticles == 0 doesn't work, "DataCubeError: CombineGrids: Three dimensions required for g_data[0]." Let me know if you want the full traceback.
Btw, here's an example script with which you should be able to reproduce the error: http://paste.yt-project.org/show/3069/
Mike
On Tue, Jan 22, 2013 at 2:10 AM, Matthew Turk <matthewturk@gmail.com> wrote:
Hi Mike,
I think that the checks for .NumberOfParticles may be unnecessary in the dm_density calls. Removing those, and simply returning an empty deposition field if there are no particles, will likely give the same results as what it currently does. Switching between ValidateGridType and ValidateSpatial will turn on/off fields in ways I think we may want to avoid. For particle density fields specifically it would likely result in estimates for particle density that are generated at a coarser level then interpolated to a finer level.
-Matt
On Tue, Jan 22, 2013 at 1:38 AM, Michael Kuhlen <mqk@astro.berkeley.edu> wrote:
Sorry to revive this old(ish) thread, but I've been experiencing similar troubles to Renyue's. Mine, however, were not completely fixed by switching from yt.utilities.amr_utils to yt.utilities.lib. I was still getting this error:
AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute 'NumberOfParticles'
The solution for me was to switch from validators=[ValidateSpatial(0)] to validators=[ValidateGridType()] in the add_field() call. Since many of the fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm getting the same NumberOfParticles AttributeError when I try to do volume renderings of "built-in" fields like dm_density.
Cheers, Mike
On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
HI Matt,
That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3": #from yt.utilities.cosmology import Cosmology #from field_info_container import \ # add_field, \ # ValidateDataField, \ # ValidateGridType, \ # ValidateParameter, \ # ValidateSpatial, \ # NeedsGridType, \ # NeedsOriginalGrid, \ # NeedsDataField, \ # NeedsProperty, \ # NeedsParameter
which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.
Thanks very much, Renyue
On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:
Hi Renyue,
No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the CICDeposit_3. The exception from the NameError is probably killing its availability.
So here's what to do:
1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with:
from yt.utilities.lib import CICDeposit_3
2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
And try again?
-Matt
On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu> wrote: > Hi Matt, > > This field (SFRdensity) was defined before the > pf = ... > statement, along with some other simpler definitions of gas > variables > that did not require CIC > and seem to work. > > Was I using the wrong syntax or something? > > Renyue > > On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote: > >> Hi Renyue, >> >> One important thing to note is that the field has to be added >> before >> you instantiate the parameter file; i.e., you must do: >> >> add_field( ... ) >> pf = ... >> >> because the parameter file, upon creation of the hierarchy, >> performs >> an auto-detection step. This auto-detection step determines which >> fields are available based on their dependencies. >> >> -Matt >> >> On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen >> <cen@astro.princeton.edu> >> wrote: >>> Hi Matt, >>> >>> It seems that my attempt to reuse "star_density" for a subset of >>> stars does not work: >>> "star_density" remains the density of all stars when plotted. >>> But I also failed to redefine a new density that is called >>> "SFRdensity" and feed it to AMRKDTree which is in turn >>> fed to camera to volume render. Here is what I did: >>> >>> def _convertDensity(data): >>> return data.convert("Density") >>> def _SFRdensity(field, data): >>> blank = na.zeros(data.ActiveDimensions, dtype='float32') >>> if data.NumberOfParticles == 0: return blank >>> # filter = data.pf.time_units['years']*(data.pf.current_time - >>> data['creation_time']) < 1.e8 >>> filter = data.pf.time_units['years']*(data.pf.current_time - >>> data['creation_time']) < 1.e6 >>> if not filter.any(): return blank >>> >>> >>> amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), >>> >>> data["particle_position_y"][filter].astype(na.float64), >>> >>> data["particle_position_z"][filter].astype(na.float64), >>> >>> data["particle_mass"][filter].astype(na.float32), >>> na.int64(na.where(filter)[0].size), >>> blank, >>> na.array(data.LeftEdge).astype(na.float64), >>> >>> na.array(data.ActiveDimensions).astype(na.int32), >>> na.float64(data['dx'])) >>> return blank >>> add_field("SFRdensity", function=_SFRdensity, >>> validators=[ValidateSpatial(0)], >>> convert_function=_convertDensity) >>> >>> volume3 = AMRKDTree(pf, fields=["SFRdensity"] >>> ,no_ghost=False, tree_type="domain" >>> ,le=c-0.5*WW, re=c+0.5*WW) >>> cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, >>> no_ghost=False,log_fields=None >>> ,north_vector=dir) >>> >>> >>> with the following error message: >>> >>> Traceback (most recent call last): >>> File "SFR.py", line 393, in <module> >>> ,le=c-0.5*WW, re=c+0.5*WW) >>> File >>> >>> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", >>> line 316, in __init__ >>> for field in self.fields] >>> File >>> >>> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", >>> line 71, in __missing__ >>> return self.fallback[key] >>> File >>> >>> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", >>> line 71, in __missing__ >>> return self.fallback[key] >>> File >>> >>> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", >>> line 70, in __missing__ >>> raise KeyError("No field named %s" % key) >>> KeyError: 'No field named SFRdensity' >>> >>> >>> So I must be doing something wrong with defining the SFRdensity >>> field. >>> >>> Thanks very much, >>> Renyue >>> >>> >>> On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote: >>> >>>> Hi Renyue, >>>> >>>> The module amr_utils became lib a while back. But my guess is >>>> that >>>> you probably don't need to import it anyway, unless you are >>>> explicitly >>>> using one of the routines it provides. >>>> >>>> -Matt >>>> >>>> On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen >>>> <cen@astro.princeton.edu> wrote: >>>>> Hi, >>>>> >>>>> I am trying to compute gridded density of some subset of >>>>> particles. >>>>> So I tried to import some modules first in the python script as >>>>> follows: >>>>> >>>>> from yt.data_objects.field_info_container import \ >>>>> FieldInfoContainer, \ >>>>> NullFunc, \ >>>>> TranslationFunc, \ >>>>> FieldInfo, \ >>>>> ValidateParameter, \ >>>>> ValidateDataField, \ >>>>> ValidateProperty, \ >>>>> ValidateSpatial, \ >>>>> ValidateGridType >>>>> import yt.data_objects.universal_fields >>>>> from yt.utilities.physical_constants import mh >>>>> from yt.funcs import * >>>>> import yt.utilities.amr_utils as amr_utils >>>>> >>>>> >>>>> But I got this error message: >>>>> >>>>> Traceback (most recent call last): >>>>> File "SFR.py", line 28, in <module> >>>>> import yt.utilities.amr_utils as amr_utils >>>>> ImportError: No module named amr_utils >>>>> >>>>> >>>>> Am I doing something wrong? >>>>> >>>>> Thanks, >>>>> Renyue >>> >
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
Michael, This happens to me occasionally and I was told that it might be due to some subregions in your region that got no particles or something like that. It seems due to AMRKDTree construction, as I understand it. Renyue On Jan 22, 2013, at 1:38 AM, Michael Kuhlen wrote:
Sorry to revive this old(ish) thread, but I've been experiencing similar troubles to Renyue's. Mine, however, were not completely fixed by switching from yt.utilities.amr_utils to yt.utilities.lib. I was still getting this error:
AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute 'NumberOfParticles'
The solution for me was to switch from validators=[ValidateSpatial(0)] to validators=[ValidateGridType()] in the add_field() call. Since many of the fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm getting the same NumberOfParticles AttributeError when I try to do volume renderings of "built-in" fields like dm_density.
Cheers, Mike
On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <cen@astro.princeton.edu> wrote: HI Matt,
That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3": #from yt.utilities.cosmology import Cosmology #from field_info_container import \ # add_field, \ # ValidateDataField, \ # ValidateGridType, \ # ValidateParameter, \ # ValidateSpatial, \ # NeedsGridType, \ # NeedsOriginalGrid, \ # NeedsDataField, \ # NeedsProperty, \ # NeedsParameter
which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.
Thanks very much, Renyue
On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:
Hi Renyue,
No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the CICDeposit_3. The exception from the NameError is probably killing its availability.
So here's what to do:
1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with:
from yt.utilities.lib import CICDeposit_3
2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
And try again?
-Matt
On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables that did not require CIC and seem to work.
Was I using the wrong syntax or something?
Renyue
On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
Hi Renyue,
One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do:
add_field( ... ) pf = ...
because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies.
-Matt
On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did:
def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), data["particle_position_y"][filter].astype(na.float64), data["particle_position_z"][filter].astype(na.float64), data["particle_mass"][filter].astype(na.float32), na.int64(na.where(filter)[0].size), blank, na.array(data.LeftEdge).astype(na.float64), na.array(data.ActiveDimensions).astype(na.int32), na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)], convert_function=_convertDensity)
volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None ,north_vector=dir)
with the following error message:
Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", line 316, in __init__ for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 70, in __missing__ raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity'
So I must be doing something wrong with defining the SFRdensity field.
Thanks very much, Renyue
On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
Hi Renyue,
The module amr_utils became lib a while back. But my guess is that you probably don't need to import it anyway, unless you are explicitly using one of the routines it provides.
-Matt
On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen@astro.princeton.edu> wrote: > Hi, > > I am trying to compute gridded density of some subset of particles. > So I tried to import some modules first in the python script as follows: > > from yt.data_objects.field_info_container import \ > FieldInfoContainer, \ > NullFunc, \ > TranslationFunc, \ > FieldInfo, \ > ValidateParameter, \ > ValidateDataField, \ > ValidateProperty, \ > ValidateSpatial, \ > ValidateGridType > import yt.data_objects.universal_fields > from yt.utilities.physical_constants import mh > from yt.funcs import * > import yt.utilities.amr_utils as amr_utils > > > But I got this error message: > > Traceback (most recent call last): > File "SFR.py", line 28, in <module> > import yt.utilities.amr_utils as amr_utils > ImportError: No module named amr_utils > > > Am I doing something wrong? > > Thanks, > Renyue
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
Hi Renyue It's possible that this is what's going on, but the region as a whole definitely has plenty of particles in it. Did you figure out a way around this error? Mike On Tue, Jan 22, 2013 at 5:28 AM, Renyue Cen <cen@astro.princeton.edu> wrote:
Michael,
This happens to me occasionally and I was told that it might be due to some subregions in your region that got no particles or something like that. It seems due to AMRKDTree construction, as I understand it.
Renyue
On Jan 22, 2013, at 1:38 AM, Michael Kuhlen wrote:
Sorry to revive this old(ish) thread, but I've been experiencing similar troubles to Renyue's. Mine, however, were not completely fixed by switching from yt.utilities.amr_utils to yt.utilities.lib. I was still getting this error:
AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute 'NumberOfParticles'
The solution for me was to switch from validators=[ValidateSpatial(0)] to validators=[ValidateGridType()] in the add_field() call. Since many of the fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm getting the same NumberOfParticles AttributeError when I try to do volume renderings of "built-in" fields like dm_density.
Cheers, Mike
On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <cen@astro.princeton.edu>wrote:
HI Matt,
That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3": #from yt.utilities.cosmology import Cosmology #from field_info_container import \ # add_field, \ # ValidateDataField, \ # ValidateGridType, \ # ValidateParameter, \ # ValidateSpatial, \ # NeedsGridType, \ # NeedsOriginalGrid, \ # NeedsDataField, \ # NeedsProperty, \ # NeedsParameter
which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.
Thanks very much, Renyue
On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:
Hi Renyue,
No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the CICDeposit_3. The exception from the NameError is probably killing its availability.
So here's what to do:
1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with:
from yt.utilities.lib import CICDeposit_3
2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
And try again?
-Matt
Hi Matt,
This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables
and seem to work.
Was I using the wrong syntax or something?
Renyue
On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
Hi Renyue,
One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do:
add_field( ... ) pf = ...
because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies.
-Matt
On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did:
def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank
amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64),
data["particle_position_y"][filter].astype(na.float64),
data["particle_position_z"][filter].astype(na.float64),
data["particle_mass"][filter].astype(na.float32),
na.int64(na.where(filter)[0].size), blank,
na.array(data.LeftEdge).astype(na.float64),
na.array(data.ActiveDimensions).astype(na.int32),
na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)],
convert_function=_convertDensity)
volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3,
no_ghost=False,log_fields=None
,north_vector=dir)
with the following error message:
Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File
"/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py",
for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py",
return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py",
return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py",
On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu> wrote: that did not require CIC line 316, in __init__ line 71, in __missing__ line 71, in __missing__ line 70, in __missing__
raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity'
So I must be doing something wrong with defining the SFRdensity field.
Thanks very much, Renyue
On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
> Hi Renyue, > > The module amr_utils became lib a while back. But my guess is that > you probably don't need to import it anyway, unless you are explicitly > using one of the routines it provides. > > -Matt > > On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen < cen@astro.princeton.edu> wrote: >> Hi, >> >> I am trying to compute gridded density of some subset of particles. >> So I tried to import some modules first in the python script as follows: >> >> from yt.data_objects.field_info_container import \ >> FieldInfoContainer, \ >> NullFunc, \ >> TranslationFunc, \ >> FieldInfo, \ >> ValidateParameter, \ >> ValidateDataField, \ >> ValidateProperty, \ >> ValidateSpatial, \ >> ValidateGridType >> import yt.data_objects.universal_fields >> from yt.utilities.physical_constants import mh >> from yt.funcs import * >> import yt.utilities.amr_utils as amr_utils >> >> >> But I got this error message: >> >> Traceback (most recent call last): >> File "SFR.py", line 28, in <module> >> import yt.utilities.amr_utils as amr_utils >> ImportError: No module named amr_utils >> >> >> Am I doing something wrong? >> >> Thanks, >> Renyue
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
Hi Michael, Yes, the cutout region as a whole got plenty of particles in it so it must be some subregions with it that is causing issues. I have not figured out a way around it as yet but hope that Sam will take a look at it when he gets time. Best, Renyue On Jan 22, 2013, at 1:02 PM, Michael Kuhlen wrote:
Hi Renyue
It's possible that this is what's going on, but the region as a whole definitely has plenty of particles in it. Did you figure out a way around this error?
Mike
On Tue, Jan 22, 2013 at 5:28 AM, Renyue Cen <cen@astro.princeton.edu> wrote: Michael,
This happens to me occasionally and I was told that it might be due to some subregions in your region that got no particles or something like that. It seems due to AMRKDTree construction, as I understand it.
Renyue
On Jan 22, 2013, at 1:38 AM, Michael Kuhlen wrote:
Sorry to revive this old(ish) thread, but I've been experiencing similar troubles to Renyue's. Mine, however, were not completely fixed by switching from yt.utilities.amr_utils to yt.utilities.lib. I was still getting this error:
AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute 'NumberOfParticles'
The solution for me was to switch from validators=[ValidateSpatial(0)] to validators=[ValidateGridType()] in the add_field() call. Since many of the fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm getting the same NumberOfParticles AttributeError when I try to do volume renderings of "built-in" fields like dm_density.
Cheers, Mike
On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <cen@astro.princeton.edu> wrote: HI Matt,
That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3": #from yt.utilities.cosmology import Cosmology #from field_info_container import \ # add_field, \ # ValidateDataField, \ # ValidateGridType, \ # ValidateParameter, \ # ValidateSpatial, \ # NeedsGridType, \ # NeedsOriginalGrid, \ # NeedsDataField, \ # NeedsProperty, \ # NeedsParameter
which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.
Thanks very much, Renyue
On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:
Hi Renyue,
No, that should work. What I'm actually seeing now is that you do in fact use amr_utils -- I missed this before -- to get the CICDeposit_3. The exception from the NameError is probably killing its availability.
So here's what to do:
1) Replace your previous import, which I suggested you remove, of yt.utilities.amr_utils with:
from yt.utilities.lib import CICDeposit_3
2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
And try again?
-Matt
On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
This field (SFRdensity) was defined before the pf = ... statement, along with some other simpler definitions of gas variables that did not require CIC and seem to work.
Was I using the wrong syntax or something?
Renyue
On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
Hi Renyue,
One important thing to note is that the field has to be added before you instantiate the parameter file; i.e., you must do:
add_field( ... ) pf = ...
because the parameter file, upon creation of the hierarchy, performs an auto-detection step. This auto-detection step determines which fields are available based on their dependencies.
-Matt
On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen@astro.princeton.edu> wrote:
Hi Matt,
It seems that my attempt to reuse "star_density" for a subset of stars does not work: "star_density" remains the density of all stars when plotted. But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn fed to camera to volume render. Here is what I did:
def _convertDensity(data): return data.convert("Density") def _SFRdensity(field, data): blank = na.zeros(data.ActiveDimensions, dtype='float32') if data.NumberOfParticles == 0: return blank # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8 filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6 if not filter.any(): return blank amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), data["particle_position_y"][filter].astype(na.float64), data["particle_position_z"][filter].astype(na.float64), data["particle_mass"][filter].astype(na.float32), na.int64(na.where(filter)[0].size), blank, na.array(data.LeftEdge).astype(na.float64), na.array(data.ActiveDimensions).astype(na.int32), na.float64(data['dx'])) return blank add_field("SFRdensity", function=_SFRdensity, validators=[ValidateSpatial(0)], convert_function=_convertDensity)
volume3 = AMRKDTree(pf, fields=["SFRdensity"] ,no_ghost=False, tree_type="domain" ,le=c-0.5*WW, re=c+0.5*WW) cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None ,north_vector=dir)
with the following error message:
Traceback (most recent call last): File "SFR.py", line 393, in <module> ,le=c-0.5*WW, re=c+0.5*WW) File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", line 316, in __init__ for field in self.fields] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__ return self.fallback[key] File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 70, in __missing__ raise KeyError("No field named %s" % key) KeyError: 'No field named SFRdensity'
So I must be doing something wrong with defining the SFRdensity field.
Thanks very much, Renyue
On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
> Hi Renyue, > > The module amr_utils became lib a while back. But my guess is that > you probably don't need to import it anyway, unless you are explicitly > using one of the routines it provides. > > -Matt > > On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen@astro.princeton.edu> wrote: >> Hi, >> >> I am trying to compute gridded density of some subset of particles. >> So I tried to import some modules first in the python script as follows: >> >> from yt.data_objects.field_info_container import \ >> FieldInfoContainer, \ >> NullFunc, \ >> TranslationFunc, \ >> FieldInfo, \ >> ValidateParameter, \ >> ValidateDataField, \ >> ValidateProperty, \ >> ValidateSpatial, \ >> ValidateGridType >> import yt.data_objects.universal_fields >> from yt.utilities.physical_constants import mh >> from yt.funcs import * >> import yt.utilities.amr_utils as amr_utils >> >> >> But I got this error message: >> >> Traceback (most recent call last): >> File "SFR.py", line 28, in <module> >> import yt.utilities.amr_utils as amr_utils >> ImportError: No module named amr_utils >> >> >> Am I doing something wrong? >> >> Thanks, >> Renyue
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
-- ********************************************************************* * * * Dr. Michael Kuhlen Theoretical Astrophysics Center * * email: mqk@astro.berkeley.edu UC Berkeley * * cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 * * skype username: mikekuhlen Berkeley, CA 94720 * * * *********************************************************************
participants (3)
-
Matthew Turk
-
Michael Kuhlen
-
Renyue Cen