[yt-svn] commit/yt: 7 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Sep 23 12:12:14 PDT 2014


7 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/f8d563291e43/
Changeset:   f8d563291e43
Branch:      yt
User:        galtay
Date:        2014-09-16 20:21:58+00:00
Summary:     update to Gadget/OWLS/Eagle frontends
Affected #:  1 file

diff -r 66bbf028d950fca7b523c06712c4f155bfbc15a4 -r f8d563291e435e34ebdf77dde9ee0d8eccaee16d yt/frontends/sph/data_structures.py
--- a/yt/frontends/sph/data_structures.py
+++ b/yt/frontends/sph/data_structures.py
@@ -204,11 +204,11 @@
         self.file_count = hvals["NumFiles"]
 
     def _set_code_unit_attributes(self):
-        # Set a sane default for cosmological simulations.
+        # Set a sane default for cosmological simulations (Gadget-2 users guide).
         if self._unit_base is None and self.cosmological_simulation == 1:
-            mylog.info("Assuming length units are in Mpc/h (comoving)")
-            self._unit_base = dict(length = (1.0, "Mpccm/h"))
-        # The other same defaults we will use from the standard Gadget
+            mylog.info("Assuming length units are in kpc/h (comoving)")
+            self._unit_base = dict(length = (1.0, "kpccm/h"))
+        # The other sane defaults we will use from the standard Gadget
         # defaults.
         unit_base = self._unit_base or {}
         if "length" in unit_base:
@@ -343,21 +343,126 @@
 
         handle.close()
 
+
+    def _set_code_unit_attributes(self):
+
+        # note the contents of the HDF5 Units group are in _unit_base 
+        # note the velocity stored on disk is sqrt(a) dx/dt 
+        self.length_unit = self.quan( self._unit_base["UnitLength_in_cm"], 'cmcm/h' )
+        self.mass_unit = self.quan( self._unit_base["UnitMass_in_g"], 'g/h' )
+        self.velocity_unit = self.quan( self._unit_base["UnitVelocity_in_cm_per_s"], 'cm/s' )
+        self.time_unit = self.quan( self._unit_base["UnitTime_in_s"], 's/h' )
+
     @classmethod
     def _is_valid(self, *args, **kwargs):
+        need_groups = ['Constants', 'Header', 'Parameters', 'Units']
+        veto_groups = ['SUBFIND',
+                       'PartType0/ChemistryAbundances', 
+                       'PartType0/ChemicalAbundances',
+                       'RuntimePars', 'HashTable']
+        valid = True
         try:
             fileh = h5py.File(args[0], mode='r')
-            if "Constants" in fileh["/"].keys() and \
-               "Header" in fileh["/"].keys() and \
-               "SUBFIND" not in fileh["/"].keys() and not\
-               ("ChemistryAbundances" in fileh["PartType0"].keys()
-                or "ChemicalAbundances" in fileh["PartType0"].keys()):
-                fileh.close()
-                return True
+            for ng in need_groups:
+                if ng not in fileh["/"]:
+                    valid = False
+            for vg in veto_groups:
+                if vg in fileh["/"]:
+                    valid = False                    
             fileh.close()
         except:
+            valid = False
             pass
-        return False
+        return valid
+
+
+class EagleDataset(GadgetHDF5Dataset):
+    _particle_mass_name = "Mass"
+    _field_info_class = OWLSFieldInfo
+    _time_readin_ = 'Time'
+
+    def _parse_parameter_file(self):
+        handle = h5py.File(self.parameter_filename, mode="r")
+        hvals = {}
+        hvals.update((str(k), v) for k, v in handle["/Header"].attrs.items())
+        hvals["NumFiles"] = hvals["NumFilesPerSnapshot"]
+        hvals["Massarr"] = hvals["MassTable"]
+
+        self.dimensionality = 3
+        self.refine_by = 2
+        self.parameters["HydroMethod"] = "sph"
+        self.unique_identifier = \
+            int(os.stat(self.parameter_filename)[stat.ST_CTIME])
+
+        # Set standard values
+        if self.domain_left_edge is None:
+            self.domain_left_edge = np.zeros(3, "float64")
+            self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"]
+        nz = 1 << self.over_refine_factor
+        self.domain_dimensions = np.ones(3, "int32") * nz
+        self.cosmological_simulation = 1
+        self.periodicity = (True, True, True)
+        self.current_redshift = hvals["Redshift"]
+        self.omega_lambda = hvals["OmegaLambda"]
+        self.omega_matter = hvals["Omega0"]
+        self.hubble_constant = hvals["HubbleParam"]
+
+        # this is an analytic solution in a flat LCDM universe
+        # as the time is not explicitly written out as it was 
+        # for the OWLS snapshots. 
+        a = hvals['ExpansionFactor']
+        H0 = hvals['H(z)'] / hvals['E(z)']
+        a_eq = ( self.omega_matter / self.omega_lambda )**(1./3)
+        t1 = 2.0 / ( 3.0 * np.sqrt( self.omega_lambda ) )
+        t2 = (a/a_eq)**(3./2)
+        t3 = np.sqrt( 1.0 + (a/a_eq)**3 )
+        t = t1 * np.log( t2 + t3 ) / H0
+        self.current_time = t * yt.units.s
+
+        self.parameters = hvals
+
+        prefix = os.path.abspath(self.parameter_filename.split(".", 1)[0])
+        suffix = self.parameter_filename.rsplit(".", 1)[-1]
+        self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix)
+        self.file_count = hvals["NumFilesPerSnapshot"]
+
+        # To avoid having to open files twice
+        self._unit_base = {}
+        self._unit_base.update(
+            (str(k), v) for k, v in handle["/Units"].attrs.items())
+
+        handle.close()
+
+    def _set_code_unit_attributes(self):
+
+        # note the contents of the HDF5 Units group are in _unit_base 
+        # note the velocity stored on disk is sqrt(a) dx/dt 
+        self.length_unit = self.quan( self._unit_base["UnitLength_in_cm"], 'cmcm/h' )
+        self.mass_unit = self.quan( self._unit_base["UnitMass_in_g"], 'g/h' )
+        self.velocity_unit = self.quan( self._unit_base["UnitVelocity_in_cm_per_s"], 'cm/s' )
+        self.time_unit = self.quan( self._unit_base["UnitTime_in_s"], 's/h' )
+
+    @classmethod
+    def _is_valid(self, *args, **kwargs):
+        need_groups = ['Config', 'Constants', 'HashTable', 'Header', 
+                       'Parameters', 'RuntimePars', 'Units']
+        veto_groups = ['SUBFIND',
+                       'PartType0/ChemistryAbundances', 
+                       'PartType0/ChemicalAbundances']
+        valid = True
+        try:
+            fileh = h5py.File(args[0], mode='r')
+            for ng in need_groups:
+                if ng not in fileh["/"]:
+                    valid = False
+            for vg in veto_groups:
+                if vg in fileh["/"]:
+                    valid = False                    
+            fileh.close()
+        except:
+            valid = False
+            pass
+        return valid
 
 class EagleNetworkDataset(OWLSDataset):
     _particle_mass_name = "Mass"


https://bitbucket.org/yt_analysis/yt/commits/1afe6d0f0d71/
Changeset:   1afe6d0f0d71
Branch:      yt
User:        galtay
Date:        2014-09-16 20:59:27+00:00
Summary:     removed a few redundant lines from OWLS/Eagle/EagleNetwork Datasets
Affected #:  1 file

diff -r f8d563291e435e34ebdf77dde9ee0d8eccaee16d -r 1afe6d0f0d716b3fc29d43d7745be93b8dafa538 yt/frontends/sph/data_structures.py
--- a/yt/frontends/sph/data_structures.py
+++ b/yt/frontends/sph/data_structures.py
@@ -307,12 +307,6 @@
         hvals["NumFiles"] = hvals["NumFilesPerSnapshot"]
         hvals["Massarr"] = hvals["MassTable"]
 
-        self.dimensionality = 3
-        self.refine_by = 2
-        self.parameters["HydroMethod"] = "sph"
-        self.unique_identifier = \
-            int(os.stat(self.parameter_filename)[stat.ST_CTIME])
-
         # Set standard values
         self.current_time = hvals[self._time_readin] * \
                             sec_conversion["Gyr"] * yt.units.s
@@ -388,11 +382,6 @@
         hvals["NumFiles"] = hvals["NumFilesPerSnapshot"]
         hvals["Massarr"] = hvals["MassTable"]
 
-        self.dimensionality = 3
-        self.refine_by = 2
-        self.parameters["HydroMethod"] = "sph"
-        self.unique_identifier = \
-            int(os.stat(self.parameter_filename)[stat.ST_CTIME])
 
         # Set standard values
         if self.domain_left_edge is None:


https://bitbucket.org/yt_analysis/yt/commits/40255620be9e/
Changeset:   40255620be9e
Branch:      yt
User:        galtay
Date:        2014-09-16 21:10:35+00:00
Summary:     consolidated the header reading for OWLS/Eagle into GadgetHDF5 Datasets.
Affected #:  1 file

diff -r 1afe6d0f0d716b3fc29d43d7745be93b8dafa538 -r 40255620be9e7bcf1e4a49bd134d44258eea39ec yt/frontends/sph/data_structures.py
--- a/yt/frontends/sph/data_structures.py
+++ b/yt/frontends/sph/data_structures.py
@@ -301,11 +301,7 @@
 
 
     def _parse_parameter_file(self):
-        handle = h5py.File(self.parameter_filename, mode="r")
-        hvals = {}
-        hvals.update((str(k), v) for k, v in handle["/Header"].attrs.items())
-        hvals["NumFiles"] = hvals["NumFilesPerSnapshot"]
-        hvals["Massarr"] = hvals["MassTable"]
+        hvals = self._get_hvals()
 
         # Set standard values
         self.current_time = hvals[self._time_readin] * \
@@ -376,12 +372,7 @@
     _time_readin_ = 'Time'
 
     def _parse_parameter_file(self):
-        handle = h5py.File(self.parameter_filename, mode="r")
-        hvals = {}
-        hvals.update((str(k), v) for k, v in handle["/Header"].attrs.items())
-        hvals["NumFiles"] = hvals["NumFilesPerSnapshot"]
-        hvals["Massarr"] = hvals["MassTable"]
-
+        hvals = self._get_hvals()
 
         # Set standard values
         if self.domain_left_edge is None:


https://bitbucket.org/yt_analysis/yt/commits/5f3db5feb086/
Changeset:   5f3db5feb086
Branch:      yt
User:        galtay
Date:        2014-09-16 21:23:26+00:00
Summary:     update check for cosmology in gadget i/o
Affected #:  1 file

diff -r 40255620be9e7bcf1e4a49bd134d44258eea39ec -r 5f3db5feb086acfe8390188dff1625f3f8006ff7 yt/frontends/sph/data_structures.py
--- a/yt/frontends/sph/data_structures.py
+++ b/yt/frontends/sph/data_structures.py
@@ -204,12 +204,17 @@
         self.file_count = hvals["NumFiles"]
 
     def _set_code_unit_attributes(self):
-        # Set a sane default for cosmological simulations (Gadget-2 users guide).
-        if self._unit_base is None and self.cosmological_simulation == 1:
-            mylog.info("Assuming length units are in kpc/h (comoving)")
-            self._unit_base = dict(length = (1.0, "kpccm/h"))
-        # The other sane defaults we will use from the standard Gadget
-        # defaults.
+        # If no units passed in by user, set a sane default (Gadget-2 users guide).
+        if self._unit_base is None:
+            if self.cosmological_simulation == 1:
+                mylog.info("Assuming length units are in kpc/h (comoving)")
+                self._unit_base = dict(length = (1.0, "kpccm/h"))
+            else:
+                mylog.info("Assuming length units are in kpc (physical)")
+                self._unit_base = dict(length = (1.0, "kpc"))
+                
+        # If units passed in by user, decide what to do about
+        # co-moving and factors of h
         unit_base = self._unit_base or {}
         if "length" in unit_base:
             length_unit = unit_base["length"]
@@ -232,6 +237,7 @@
             velocity_unit = (1e5, "cm/s")
         velocity_unit = _fix_unit_ordering(velocity_unit)
         self.velocity_unit = self.quan(velocity_unit[0], velocity_unit[1])
+
         # We set hubble_constant = 1.0 for non-cosmology, so this is safe.
         # Default to 1e10 Msun/h if mass is not specified.
         if "mass" in unit_base:


https://bitbucket.org/yt_analysis/yt/commits/1051e58cc735/
Changeset:   1051e58cc735
Branch:      yt
User:        galtay
Date:        2014-09-16 22:38:36+00:00
Summary:     consolidated as much as possible into GadgetHDF5Class from OWLS and Eagle Datasets
Affected #:  1 file

diff -r 5f3db5feb086acfe8390188dff1625f3f8006ff7 -r 1051e58cc7359fdffb8b323a60f19ebd8c5abab8 yt/frontends/sph/data_structures.py
--- a/yt/frontends/sph/data_structures.py
+++ b/yt/frontends/sph/data_structures.py
@@ -284,8 +284,61 @@
         # Compat reasons.
         hvals["NumFiles"] = hvals["NumFilesPerSnapshot"]
         hvals["Massarr"] = hvals["MassTable"]
+        handle.close()
         return hvals
 
+    def _get_uvals(self):
+        handle = h5py.File(self.parameter_filename, mode="r")
+        uvals = {}
+        uvals.update((str(k), v) for k, v in handle["/Units"].attrs.items())
+        handle.close()
+        return uvals
+
+
+
+    def _set_owls_eagle(self):
+
+        self.dimensionality = 3
+        self.refine_by = 2
+        self.parameters["HydroMethod"] = "sph"
+        self.unique_identifier = \
+            int(os.stat(self.parameter_filename)[stat.ST_CTIME])
+
+        self._unit_base = self._get_uvals()
+        self._unit_base['cmcm'] = 1.0 / self._unit_base["UnitLength_in_cm"]
+
+        self.current_redshift = self.parameters["Redshift"]
+        self.omega_lambda = self.parameters["OmegaLambda"]
+        self.omega_matter = self.parameters["Omega0"]
+        self.hubble_constant = self.parameters["HubbleParam"]
+
+        if self.domain_left_edge is None:
+            self.domain_left_edge = np.zeros(3, "float64")
+            self.domain_right_edge = np.ones(3, "float64") * self.parameters["BoxSize"]
+
+        nz = 1 << self.over_refine_factor
+        self.domain_dimensions = np.ones(3, "int32") * nz
+
+        self.cosmological_simulation = 1
+        self.periodicity = (True, True, True)
+
+        prefix = os.path.abspath(self.parameter_filename.split(".", 1)[0])
+        suffix = self.parameter_filename.rsplit(".", 1)[-1]
+        self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix)
+        self.file_count = self.parameters["NumFilesPerSnapshot"]
+
+
+    def _set_owls_eagle_units(self):
+
+        # note the contents of the HDF5 Units group are in _unit_base 
+        # note the velocity stored on disk is sqrt(a) dx/dt 
+        self.length_unit = self.quan( self._unit_base["UnitLength_in_cm"], 'cmcm/h' )
+        self.mass_unit = self.quan( self._unit_base["UnitMass_in_g"], 'g/h' )
+        self.velocity_unit = self.quan( self._unit_base["UnitVelocity_in_cm_per_s"], 'cm/s' )
+        self.time_unit = self.quan( self._unit_base["UnitTime_in_s"], 's/h' )
+
+        
+
     @classmethod
     def _is_valid(self, *args, **kwargs):
         try:
@@ -305,49 +358,23 @@
     _time_readin = "Time_GYR"
 
 
+    def _parse_parameter_file(self):
 
-    def _parse_parameter_file(self):
+        # read values from header
         hvals = self._get_hvals()
+        self.parameters = hvals
 
-        # Set standard values
+        # set features common to OWLS and Eagle
+        self._set_owls_eagle()
+
+        # Set time from value in header
         self.current_time = hvals[self._time_readin] * \
                             sec_conversion["Gyr"] * yt.units.s
-        if self.domain_left_edge is None:
-            self.domain_left_edge = np.zeros(3, "float64")
-            self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"]
-        nz = 1 << self.over_refine_factor
-        self.domain_dimensions = np.ones(3, "int32") * nz
-        self.cosmological_simulation = 1
-        self.periodicity = (True, True, True)
-        self.current_redshift = hvals["Redshift"]
-        self.omega_lambda = hvals["OmegaLambda"]
-        self.omega_matter = hvals["Omega0"]
-        self.hubble_constant = hvals["HubbleParam"]
-        self.parameters = hvals
-
-        prefix = os.path.abspath(self.parameter_filename.split(".", 1)[0])
-        suffix = self.parameter_filename.rsplit(".", 1)[-1]
-        self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix)
-        self.file_count = hvals["NumFilesPerSnapshot"]
-
-        # To avoid having to open files twice
-        self._unit_base = {}
-        self._unit_base.update(
-            (str(k), v) for k, v in handle["/Units"].attrs.items())
-        # Comoving cm is given in the Units
-        self._unit_base['cmcm'] = 1.0 / self._unit_base["UnitLength_in_cm"]
-
-        handle.close()
 
 
     def _set_code_unit_attributes(self):
+        self._set_owls_eagle_units()
 
-        # note the contents of the HDF5 Units group are in _unit_base 
-        # note the velocity stored on disk is sqrt(a) dx/dt 
-        self.length_unit = self.quan( self._unit_base["UnitLength_in_cm"], 'cmcm/h' )
-        self.mass_unit = self.quan( self._unit_base["UnitMass_in_g"], 'g/h' )
-        self.velocity_unit = self.quan( self._unit_base["UnitVelocity_in_cm_per_s"], 'cm/s' )
-        self.time_unit = self.quan( self._unit_base["UnitTime_in_s"], 's/h' )
 
     @classmethod
     def _is_valid(self, *args, **kwargs):
@@ -378,24 +405,15 @@
     _time_readin_ = 'Time'
 
     def _parse_parameter_file(self):
+
+        # read values from header
         hvals = self._get_hvals()
+        self.parameters = hvals
 
-        # Set standard values
-        if self.domain_left_edge is None:
-            self.domain_left_edge = np.zeros(3, "float64")
-            self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"]
-        nz = 1 << self.over_refine_factor
-        self.domain_dimensions = np.ones(3, "int32") * nz
-        self.cosmological_simulation = 1
-        self.periodicity = (True, True, True)
-        self.current_redshift = hvals["Redshift"]
-        self.omega_lambda = hvals["OmegaLambda"]
-        self.omega_matter = hvals["Omega0"]
-        self.hubble_constant = hvals["HubbleParam"]
+        # set features common to OWLS and Eagle
+        self._set_owls_eagle()
 
-        # this is an analytic solution in a flat LCDM universe
-        # as the time is not explicitly written out as it was 
-        # for the OWLS snapshots. 
+        # Set time from analytic solution for flat LCDM universe
         a = hvals['ExpansionFactor']
         H0 = hvals['H(z)'] / hvals['E(z)']
         a_eq = ( self.omega_matter / self.omega_lambda )**(1./3)
@@ -405,28 +423,10 @@
         t = t1 * np.log( t2 + t3 ) / H0
         self.current_time = t * yt.units.s
 
-        self.parameters = hvals
-
-        prefix = os.path.abspath(self.parameter_filename.split(".", 1)[0])
-        suffix = self.parameter_filename.rsplit(".", 1)[-1]
-        self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix)
-        self.file_count = hvals["NumFilesPerSnapshot"]
-
-        # To avoid having to open files twice
-        self._unit_base = {}
-        self._unit_base.update(
-            (str(k), v) for k, v in handle["/Units"].attrs.items())
-
-        handle.close()
 
     def _set_code_unit_attributes(self):
+        self._set_owls_eagle_units()
 
-        # note the contents of the HDF5 Units group are in _unit_base 
-        # note the velocity stored on disk is sqrt(a) dx/dt 
-        self.length_unit = self.quan( self._unit_base["UnitLength_in_cm"], 'cmcm/h' )
-        self.mass_unit = self.quan( self._unit_base["UnitMass_in_g"], 'g/h' )
-        self.velocity_unit = self.quan( self._unit_base["UnitVelocity_in_cm_per_s"], 'cm/s' )
-        self.time_unit = self.quan( self._unit_base["UnitTime_in_s"], 's/h' )
 
     @classmethod
     def _is_valid(self, *args, **kwargs):
@@ -450,6 +450,7 @@
             pass
         return valid
 
+
 class EagleNetworkDataset(OWLSDataset):
     _particle_mass_name = "Mass"
     _field_info_class = EagleNetworkFieldInfo


https://bitbucket.org/yt_analysis/yt/commits/d259725ff3a8/
Changeset:   d259725ff3a8
Branch:      yt
User:        galtay
Date:        2014-09-17 17:28:51+00:00
Summary:     updated api.py to include EagleDataset and made EagleNetworkDataset a subclass of EagleDataset.
Affected #:  2 files

diff -r 1051e58cc7359fdffb8b323a60f19ebd8c5abab8 -r d259725ff3a807075717a0505b678ce9c7390633 yt/frontends/sph/api.py
--- a/yt/frontends/sph/api.py
+++ b/yt/frontends/sph/api.py
@@ -19,7 +19,8 @@
       GadgetDataset, \
       GadgetHDF5Dataset, \
       TipsyDataset,\
-      EagleNetworkDataset
+      EagleNetworkDataset, \
+      EagleDataset
 
 from .io import \
       IOHandlerOWLS, \

diff -r 1051e58cc7359fdffb8b323a60f19ebd8c5abab8 -r d259725ff3a807075717a0505b678ce9c7390633 yt/frontends/sph/data_structures.py
--- a/yt/frontends/sph/data_structures.py
+++ b/yt/frontends/sph/data_structures.py
@@ -451,7 +451,7 @@
         return valid
 
 
-class EagleNetworkDataset(OWLSDataset):
+class EagleNetworkDataset(EagleDataset):
     _particle_mass_name = "Mass"
     _field_info_class = EagleNetworkFieldInfo
     _time_readin = 'Time'


https://bitbucket.org/yt_analysis/yt/commits/030d707551f6/
Changeset:   030d707551f6
Branch:      yt
User:        ngoldbaum
Date:        2014-09-23 19:12:06+00:00
Summary:     Merged in galtay/yt-bugfix1 (pull request #1211)

update to Gadget/OWLS/Eagle frontends
Affected #:  2 files

diff -r 5ad64a6cc689da8686018c5d10d68a9ca67f10d2 -r 030d707551f658a9af158a949356aad11c3a8988 yt/frontends/sph/api.py
--- a/yt/frontends/sph/api.py
+++ b/yt/frontends/sph/api.py
@@ -19,7 +19,8 @@
       GadgetDataset, \
       GadgetHDF5Dataset, \
       TipsyDataset,\
-      EagleNetworkDataset
+      EagleNetworkDataset, \
+      EagleDataset
 
 from .io import \
       IOHandlerOWLS, \

diff -r 5ad64a6cc689da8686018c5d10d68a9ca67f10d2 -r 030d707551f658a9af158a949356aad11c3a8988 yt/frontends/sph/data_structures.py
--- a/yt/frontends/sph/data_structures.py
+++ b/yt/frontends/sph/data_structures.py
@@ -204,12 +204,17 @@
         self.file_count = hvals["NumFiles"]
 
     def _set_code_unit_attributes(self):
-        # Set a sane default for cosmological simulations.
-        if self._unit_base is None and self.cosmological_simulation == 1:
-            mylog.info("Assuming length units are in Mpc/h (comoving)")
-            self._unit_base = dict(length = (1.0, "Mpccm/h"))
-        # The other same defaults we will use from the standard Gadget
-        # defaults.
+        # If no units passed in by user, set a sane default (Gadget-2 users guide).
+        if self._unit_base is None:
+            if self.cosmological_simulation == 1:
+                mylog.info("Assuming length units are in kpc/h (comoving)")
+                self._unit_base = dict(length = (1.0, "kpccm/h"))
+            else:
+                mylog.info("Assuming length units are in kpc (physical)")
+                self._unit_base = dict(length = (1.0, "kpc"))
+                
+        # If units passed in by user, decide what to do about
+        # co-moving and factors of h
         unit_base = self._unit_base or {}
         if "length" in unit_base:
             length_unit = unit_base["length"]
@@ -232,6 +237,7 @@
             velocity_unit = (1e5, "cm/s")
         velocity_unit = _fix_unit_ordering(velocity_unit)
         self.velocity_unit = self.quan(velocity_unit[0], velocity_unit[1])
+
         # We set hubble_constant = 1.0 for non-cosmology, so this is safe.
         # Default to 1e10 Msun/h if mass is not specified.
         if "mass" in unit_base:
@@ -278,8 +284,61 @@
         # Compat reasons.
         hvals["NumFiles"] = hvals["NumFilesPerSnapshot"]
         hvals["Massarr"] = hvals["MassTable"]
+        handle.close()
         return hvals
 
+    def _get_uvals(self):
+        handle = h5py.File(self.parameter_filename, mode="r")
+        uvals = {}
+        uvals.update((str(k), v) for k, v in handle["/Units"].attrs.items())
+        handle.close()
+        return uvals
+
+
+
+    def _set_owls_eagle(self):
+
+        self.dimensionality = 3
+        self.refine_by = 2
+        self.parameters["HydroMethod"] = "sph"
+        self.unique_identifier = \
+            int(os.stat(self.parameter_filename)[stat.ST_CTIME])
+
+        self._unit_base = self._get_uvals()
+        self._unit_base['cmcm'] = 1.0 / self._unit_base["UnitLength_in_cm"]
+
+        self.current_redshift = self.parameters["Redshift"]
+        self.omega_lambda = self.parameters["OmegaLambda"]
+        self.omega_matter = self.parameters["Omega0"]
+        self.hubble_constant = self.parameters["HubbleParam"]
+
+        if self.domain_left_edge is None:
+            self.domain_left_edge = np.zeros(3, "float64")
+            self.domain_right_edge = np.ones(3, "float64") * self.parameters["BoxSize"]
+
+        nz = 1 << self.over_refine_factor
+        self.domain_dimensions = np.ones(3, "int32") * nz
+
+        self.cosmological_simulation = 1
+        self.periodicity = (True, True, True)
+
+        prefix = os.path.abspath(self.parameter_filename.split(".", 1)[0])
+        suffix = self.parameter_filename.rsplit(".", 1)[-1]
+        self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix)
+        self.file_count = self.parameters["NumFilesPerSnapshot"]
+
+
+    def _set_owls_eagle_units(self):
+
+        # note the contents of the HDF5 Units group are in _unit_base 
+        # note the velocity stored on disk is sqrt(a) dx/dt 
+        self.length_unit = self.quan( self._unit_base["UnitLength_in_cm"], 'cmcm/h' )
+        self.mass_unit = self.quan( self._unit_base["UnitMass_in_g"], 'g/h' )
+        self.velocity_unit = self.quan( self._unit_base["UnitVelocity_in_cm_per_s"], 'cm/s' )
+        self.time_unit = self.quan( self._unit_base["UnitTime_in_s"], 's/h' )
+
+        
+
     @classmethod
     def _is_valid(self, *args, **kwargs):
         try:
@@ -299,67 +358,100 @@
     _time_readin = "Time_GYR"
 
 
+    def _parse_parameter_file(self):
 
-    def _parse_parameter_file(self):
-        handle = h5py.File(self.parameter_filename, mode="r")
-        hvals = {}
-        hvals.update((str(k), v) for k, v in handle["/Header"].attrs.items())
-        hvals["NumFiles"] = hvals["NumFilesPerSnapshot"]
-        hvals["Massarr"] = hvals["MassTable"]
+        # read values from header
+        hvals = self._get_hvals()
+        self.parameters = hvals
 
-        self.dimensionality = 3
-        self.refine_by = 2
-        self.parameters["HydroMethod"] = "sph"
-        self.unique_identifier = \
-            int(os.stat(self.parameter_filename)[stat.ST_CTIME])
+        # set features common to OWLS and Eagle
+        self._set_owls_eagle()
 
-        # Set standard values
+        # Set time from value in header
         self.current_time = hvals[self._time_readin] * \
                             sec_conversion["Gyr"] * yt.units.s
-        if self.domain_left_edge is None:
-            self.domain_left_edge = np.zeros(3, "float64")
-            self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"]
-        nz = 1 << self.over_refine_factor
-        self.domain_dimensions = np.ones(3, "int32") * nz
-        self.cosmological_simulation = 1
-        self.periodicity = (True, True, True)
-        self.current_redshift = hvals["Redshift"]
-        self.omega_lambda = hvals["OmegaLambda"]
-        self.omega_matter = hvals["Omega0"]
-        self.hubble_constant = hvals["HubbleParam"]
-        self.parameters = hvals
 
-        prefix = os.path.abspath(self.parameter_filename.split(".", 1)[0])
-        suffix = self.parameter_filename.rsplit(".", 1)[-1]
-        self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix)
-        self.file_count = hvals["NumFilesPerSnapshot"]
 
-        # To avoid having to open files twice
-        self._unit_base = {}
-        self._unit_base.update(
-            (str(k), v) for k, v in handle["/Units"].attrs.items())
-        # Comoving cm is given in the Units
-        self._unit_base['cmcm'] = 1.0 / self._unit_base["UnitLength_in_cm"]
+    def _set_code_unit_attributes(self):
+        self._set_owls_eagle_units()
 
-        handle.close()
 
     @classmethod
     def _is_valid(self, *args, **kwargs):
+        need_groups = ['Constants', 'Header', 'Parameters', 'Units']
+        veto_groups = ['SUBFIND',
+                       'PartType0/ChemistryAbundances', 
+                       'PartType0/ChemicalAbundances',
+                       'RuntimePars', 'HashTable']
+        valid = True
         try:
             fileh = h5py.File(args[0], mode='r')
-            if "Constants" in fileh["/"].keys() and \
-               "Header" in fileh["/"].keys() and \
-               "SUBFIND" not in fileh["/"].keys() and not\
-               ("ChemistryAbundances" in fileh["PartType0"].keys()
-                or "ChemicalAbundances" in fileh["PartType0"].keys()):
-                fileh.close()
-                return True
+            for ng in need_groups:
+                if ng not in fileh["/"]:
+                    valid = False
+            for vg in veto_groups:
+                if vg in fileh["/"]:
+                    valid = False                    
             fileh.close()
         except:
+            valid = False
             pass
-        return False
+        return valid
 
-class EagleNetworkDataset(OWLSDataset):
+
+class EagleDataset(GadgetHDF5Dataset):
+    _particle_mass_name = "Mass"
+    _field_info_class = OWLSFieldInfo
+    _time_readin_ = 'Time'
+
+    def _parse_parameter_file(self):
+
+        # read values from header
+        hvals = self._get_hvals()
+        self.parameters = hvals
+
+        # set features common to OWLS and Eagle
+        self._set_owls_eagle()
+
+        # Set time from analytic solution for flat LCDM universe
+        a = hvals['ExpansionFactor']
+        H0 = hvals['H(z)'] / hvals['E(z)']
+        a_eq = ( self.omega_matter / self.omega_lambda )**(1./3)
+        t1 = 2.0 / ( 3.0 * np.sqrt( self.omega_lambda ) )
+        t2 = (a/a_eq)**(3./2)
+        t3 = np.sqrt( 1.0 + (a/a_eq)**3 )
+        t = t1 * np.log( t2 + t3 ) / H0
+        self.current_time = t * yt.units.s
+
+
+    def _set_code_unit_attributes(self):
+        self._set_owls_eagle_units()
+
+
+    @classmethod
+    def _is_valid(self, *args, **kwargs):
+        need_groups = ['Config', 'Constants', 'HashTable', 'Header', 
+                       'Parameters', 'RuntimePars', 'Units']
+        veto_groups = ['SUBFIND',
+                       'PartType0/ChemistryAbundances', 
+                       'PartType0/ChemicalAbundances']
+        valid = True
+        try:
+            fileh = h5py.File(args[0], mode='r')
+            for ng in need_groups:
+                if ng not in fileh["/"]:
+                    valid = False
+            for vg in veto_groups:
+                if vg in fileh["/"]:
+                    valid = False                    
+            fileh.close()
+        except:
+            valid = False
+            pass
+        return valid
+
+
+class EagleNetworkDataset(EagleDataset):
     _particle_mass_name = "Mass"
     _field_info_class = EagleNetworkFieldInfo
     _time_readin = 'Time'

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list