Hi,
I tried to set a particle filter with EAGLE and got an error. Here is a simple example, which uses the EAGLE dataset from yt sample data.
import yt
from yt.data_objects.particle_filters import add_particle_filter
eagle_fpath = './data/snapshot_028_z000p000/snap_028_z000p000.0.hdf5'
unit_base = {'UnitLength_in_cm' : 3.085678e+24,
'UnitMass_in_g' : 1.989e+43,
'UnitVelocity_in_cm_per_s' : 100000.0}
ds = yt.load(eagle_fpath,unit_base=unit_base)
ad = ds.all_data()
def cold_gas(pfilter, data):
temperature = data[pfilter.filtered_type, "Temperature"]
filter = (temperature.in_units('K') <= 1e5)
return filter
add_particle_filter("gas_cold", function=cold_gas, filtered_type='PartType0', requires=["Temperature"])
ds.add_particle_filter('gas_cold')
Below shows the error.
UnboundLocalError Traceback (most recent call last)
/Users/stephaniehho/EAGLE_sim/sho/test_with_yt/test_ z000p000/particle_filter_ simple.py in <module>()
20
21 add_particle_filter("gas_cold", function=cold_gas, filtered_type='PartType0', requires=["Temperature"])
---> 22 ds.add_particle_filter('gas_cold')
/Users/stephaniehho/yt-git/yt/data_objects/static_output.pyc in add_particle_filter(self, filter)
673 if f is None:
674 return False
--> 675 used = self._setup_filtered_type(f)
676 if used:
677 filter = f
/Users/stephaniehho/yt-git/yt/data_objects/static_output.pyc in _setup_filtered_type(self, filter)
714 if filter.name not in self.filtered_particle_types:
715 self.filtered_particle_types.append(filter.name)
--> 716 new_fields = self._setup_particle_types([filter.name ])
717 deps, _ = self.field_info.check_derived_fields(new_fields)
718 self.field_dependencies.update(deps)
/Users/stephaniehho/yt-git/yt/data_objects/static_output.pyc in _setup_particle_types(self, ptypes)
723 if ptypes is None: ptypes = self.ds.particle_types_raw
724 for ptype in set(ptypes):
--> 725 df += self._setup_particle_type(ptype)
726 return df
727
/Users/stephaniehho/yt-git/yt/data_objects/static_output.pyc in _setup_particle_type(self, ptype)
889 def _setup_particle_type(self, ptype):
890 orig = set(self.field_info.items())
--> 891 self.field_info.setup_particle_fields(ptype)
892 return [n for n, v in set(self.field_info.items()).difference(orig)]
893
/Users/stephaniehho/yt-git/yt/frontends/owls/fields.pyc in setup_particle_fields(self, ptype)
111
112 super(OWLSFieldInfo,self).setup_particle_fields(
--> 113 ptype, num_neighbors=self._num_neighbors, ftype=ftype)
114
115
UnboundLocalError: local variable 'ftype' referenced before assignment
What I find is that, this problem seems to be temporarily solved if I add en else case at line 111 of the code: https://github.com/yt-project/yt/blob/master/yt/frontends/ ,owls/fields.py
else:
ftype=ptype
But this will raise the questions of, what are ftype and ptype designed for at the first place, or will this temporary fix cause other errors that I have not yet encountered.
Thanks,
Stephanie
_______________________________________________
yt-users mailing list -- yt-users@python.org
To unsubscribe send an email to yt-users-leave@python.org