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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Sep 7 11:12:15 PDT 2016


8 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/03ab04e1c30e/
Changeset:   03ab04e1c30e
Branch:      yt
User:        WeiguangCui
Date:        2016-08-16 06:01:15+00:00
Summary:     Enabled Gadget Format 2 in _validate_header
Affected #:  1 file

diff -r c941aa457bc3c9e43f3ab0ecafa82d2924a8e204 -r 03ab04e1c30e43e0a1ba1d04dc85d3ec4fcad630 yt/frontends/gadget/data_structures.py
--- a/yt/frontends/gadget/data_structures.py
+++ b/yt/frontends/gadget/data_structures.py
@@ -281,10 +281,10 @@
     @staticmethod
     def _validate_header(filename):
         '''
-        This method automatically detects whether the Gadget file is big/little endian 
-        and is not corrupt/invalid using the first 4 bytes in the file.  It returns a 
-        tuple of (Valid, endianswap) where Valid is a boolean that is true if the file 
-        is a Gadget binary file, and endianswap is the endianness character '>' or '<'. 
+        This method automatically detects whether the Gadget file is big/little endian
+        and is not corrupt/invalid using the first 4 bytes in the file.  It returns a
+        tuple of (Valid, endianswap) where Valid is a boolean that is true if the file
+        is a Gadget binary file, and endianswap is the endianness character '>' or '<'.
         '''
         try:
             f = open(filename,'rb')
@@ -293,9 +293,9 @@
                 f = open(filename+".0")
             except IOError:
                 return False, 1
-        
+
         # First int32 is 256 for a Gadget2 binary file with SnapFormat=1,
-        # 8 for a Gadget2 binary file with SnapFormat=2 file, 
+        # 8 for a Gadget2 binary file with SnapFormat=2 file,
         # or the byte swapped equivalents (65536 and 134217728).
         # The int32 following the header (first 4+256 bytes) must equal this
         # number.
@@ -311,16 +311,17 @@
             endianswap = '>'
         # Disabled for now (does any one still use SnapFormat=2?)
         # If so, alternate read would be needed based on header.
-        # elif rhead == 8:
-        #     return True, '<'
-        # elif rhead == 134217728:
-        #     return True, '>'
+        # Eabled Format2 here
+        elif rhead == 8:
+            return True, '<'
+        elif rhead == 134217728:
+            return True, '>'
         else:
             f.close()
             return False, 1
         # Read in particle number from header
         np0 = sum(struct.unpack(endianswap+'IIIIII',f.read(6*4)))
-        # Read in size of position block. It should be 4 bytes per float, 
+        # Read in size of position block. It should be 4 bytes per float,
         # with 3 coordinates (x,y,z) per particle. (12 bytes per particle)
         f.seek(4+256+4,0)
         np1 = struct.unpack(endianswap+'I',f.read(4))[0]/(4*3)


https://bitbucket.org/yt_analysis/yt/commits/e0a07d979202/
Changeset:   e0a07d979202
Branch:      yt
User:        WeiguangCui
Date:        2016-08-29 07:02:58+00:00
Summary:     Changes in data_structures.py:
1. New function to determine the gadget format:
def _get_gadget_format(filename):
    # check and return gadget binary format
    f = open(filename, 'rb')
    (rhead,) = struct.unpack('<I',f.read(4))
    f.close()
    if (rhead == 134217728) | (rhead == 8):
        return 2
    elif (rhead == 65536) | (rhead == 256):
        return 1
    else:
        raise RuntimeError("Un correct Gadget format!")
2. class GadgetBinaryFile(ParticleFile): add skip for the GF2 header
            if _get_gadget_format(filename) == 2:
                f.seek(f.tell()+16)
3. Function _get_hvals in class GadgetDataset: add skip for the GF2 header

4. Function _validate_header in class GadgetDataset: add skip for the GF2 header
        elif rhead == 8:
            return True, '<'
        elif rhead == 134217728:
            return True, '>'

Changes in io.py:
1. from .data_structures import _get_gadget_format
2. in class IOHandlerGadgetBinary(BaseIOHandler) __init__(): self._format =  _get_gadget_format(ds.parameter_filename)#default gadget format 1
3. in _calculate_field_offsets:
            if self._format == 2:
                pos += 20 #skip block header
                #print("With Gadget format 2")
            elif self._format == 1:
                pos += 4
            else:
                raise RuntimeError("Un correct Gadget format!")
		.....
            if (file_size != pos) & (self._format == 1): #ignore the rest of format 2
Affected #:  2 files

diff -r 03ab04e1c30e43e0a1ba1d04dc85d3ec4fcad630 -r e0a07d97920272b6f27d84581f40cf4c679f3669 yt/frontends/gadget/data_structures.py
--- a/yt/frontends/gadget/data_structures.py
+++ b/yt/frontends/gadget/data_structures.py
@@ -46,10 +46,23 @@
     if isinstance(unit[0], string_types):
         unit = unit[1], unit[0]
     return unit
+def _get_gadget_format(filename):
+    # check and return gadget binary format
+    f = open(filename, 'rb')
+    (rhead,) = struct.unpack('<I',f.read(4))
+    f.close()
+    if (rhead == 134217728) | (rhead == 8):
+        return 2
+    elif (rhead == 65536) | (rhead == 256):
+        return 1
+    else:
+        raise RuntimeError("Un correct Gadget format!")
 
 class GadgetBinaryFile(ParticleFile):
     def __init__(self, ds, io, filename, file_id):
         with open(filename, "rb") as f:
+            if _get_gadget_format(filename) == 2:
+                f.seek(f.tell()+16)
             self.header = read_record(f, ds._header_spec)
             self._position_offset = f.tell()
             f.seek(0, os.SEEK_END)
@@ -135,6 +148,8 @@
         # in the GADGET-2 user guide.
 
         f = open(self.parameter_filename, 'rb')
+        if _get_gadget_format(self.parameter_filename) == 2:
+            f.seek(f.tell()+16)
         hvals = read_record(f, self._header_spec)
         for i in hvals:
             if len(hvals[i]) == 1:

diff -r 03ab04e1c30e43e0a1ba1d04dc85d3ec4fcad630 -r e0a07d97920272b6f27d84581f40cf4c679f3669 yt/frontends/gadget/io.py
--- a/yt/frontends/gadget/io.py
+++ b/yt/frontends/gadget/io.py
@@ -27,11 +27,13 @@
     compute_morton
 from yt.utilities.logger import ytLogger as mylog
 
+from .data_structures import _get_gadget_format
+
 class IOHandlerGadgetHDF5(IOHandlerOWLS):
     _dataset_type = "gadget_hdf5"
 
 ZeroMass = object()
-    
+
 class IOHandlerGadgetBinary(BaseIOHandler):
     _dataset_type = "gadget_binary"
     _vector_fields = (("Coordinates", 3),
@@ -61,6 +63,8 @@
         self._vector_fields = dict(self._vector_fields)
         self._fields = ds._field_spec
         self._ptypes = ds._ptype_spec
+        self.data_files = set([])
+        self._format =  _get_gadget_format(ds.parameter_filename)#default gadget format 1
         super(IOHandlerGadgetBinary, self).__init__(ds, *args, **kwargs)
 
     @property
@@ -173,7 +177,13 @@
             if not any( (ptype, field) in field_list
                         for ptype in self._ptypes):
                 continue
-            pos += 4
+            if self._format == 2:
+                pos += 20 #skip block header
+                #print("With Gadget format 2")
+            elif self._format == 1:
+                pos += 4
+            else:
+                raise RuntimeError("Un correct Gadget format!")
             any_ptypes = False
             for ptype in self._ptypes:
                 if field == "Mass" and ptype not in self.var_mass:
@@ -189,7 +199,7 @@
             pos += 4
             if not any_ptypes: pos -= 8
         if file_size is not None:
-            if file_size != pos:
+            if (file_size != pos) & (self._format == 1): #ignore the rest of format 2 
                 mylog.warning("Your Gadget-2 file may have extra " +
                               "columns or different precision!" +
                               " (%s file vs %s computed)",


https://bitbucket.org/yt_analysis/yt/commits/7020500b1e02/
Changeset:   7020500b1e02
Branch:      yt
User:        WeiguangCui
Date:        2016-08-30 13:05:36+00:00
Summary:     data_structures.py edited online with Bitbucket
Corrected under John's suggestion
Affected #:  1 file

diff -r e0a07d97920272b6f27d84581f40cf4c679f3669 -r 7020500b1e026beff2776e127dd574b1a1075c96 yt/frontends/gadget/data_structures.py
--- a/yt/frontends/gadget/data_structures.py
+++ b/yt/frontends/gadget/data_structures.py
@@ -46,14 +46,15 @@
     if isinstance(unit[0], string_types):
         unit = unit[1], unit[0]
     return unit
+    
 def _get_gadget_format(filename):
     # check and return gadget binary format
     f = open(filename, 'rb')
     (rhead,) = struct.unpack('<I',f.read(4))
     f.close()
-    if (rhead == 134217728) | (rhead == 8):
+    if (rhead == 134217728) or (rhead == 8):
         return 2
-    elif (rhead == 65536) | (rhead == 256):
+    elif (rhead == 65536) or (rhead == 256):
         return 1
     else:
         raise RuntimeError("Un correct Gadget format!")
@@ -149,7 +150,7 @@
 
         f = open(self.parameter_filename, 'rb')
         if _get_gadget_format(self.parameter_filename) == 2:
-            f.seek(f.tell()+16)
+            f.seek(f.tell()+16, os.SEEK_END)
         hvals = read_record(f, self._header_spec)
         for i in hvals:
             if len(hvals[i]) == 1:
@@ -326,7 +327,7 @@
             endianswap = '>'
         # Disabled for now (does any one still use SnapFormat=2?)
         # If so, alternate read would be needed based on header.
-        # Eabled Format2 here
+        # Enabled Format2 here
         elif rhead == 8:
             return True, '<'
         elif rhead == 134217728:


https://bitbucket.org/yt_analysis/yt/commits/bc84b20f3808/
Changeset:   bc84b20f3808
Branch:      yt
User:        WeiguangCui
Date:        2016-08-30 13:17:16+00:00
Summary:     io.py edited online with Bitbucket
Revised under John's suggestion
Affected #:  1 file

diff -r 7020500b1e026beff2776e127dd574b1a1075c96 -r bc84b20f38080c58c50285a58b33e2e7c4fb2233 yt/frontends/gadget/io.py
--- a/yt/frontends/gadget/io.py
+++ b/yt/frontends/gadget/io.py
@@ -179,11 +179,10 @@
                 continue
             if self._format == 2:
                 pos += 20 #skip block header
-                #print("With Gadget format 2")
             elif self._format == 1:
                 pos += 4
             else:
-                raise RuntimeError("Un correct Gadget format!")
+                raise RuntimeError("incorrect Gadget format %s!" % str(self._format))
             any_ptypes = False
             for ptype in self._ptypes:
                 if field == "Mass" and ptype not in self.var_mass:


https://bitbucket.org/yt_analysis/yt/commits/d6130c4030a1/
Changeset:   d6130c4030a1
Branch:      yt
User:        WeiguangCui
Date:        2016-08-30 13:19:34+00:00
Summary:     data_structures.py edited online with Bitbucket
Affected #:  1 file

diff -r bc84b20f38080c58c50285a58b33e2e7c4fb2233 -r d6130c4030a187c210756c1cafb499bce44be130 yt/frontends/gadget/data_structures.py
--- a/yt/frontends/gadget/data_structures.py
+++ b/yt/frontends/gadget/data_structures.py
@@ -52,12 +52,12 @@
     f = open(filename, 'rb')
     (rhead,) = struct.unpack('<I',f.read(4))
     f.close()
-    if (rhead == 134217728) or (rhead == 8):
+    if (rhead == 134217728) | (rhead == 8):
         return 2
-    elif (rhead == 65536) or (rhead == 256):
+    elif (rhead == 65536) | (rhead == 256):
         return 1
     else:
-        raise RuntimeError("Un correct Gadget format!")
+        raise RuntimeError("Incorrect Gadget format %s!" % str(rhead))
 
 class GadgetBinaryFile(ParticleFile):
     def __init__(self, ds, io, filename, file_id):


https://bitbucket.org/yt_analysis/yt/commits/de8fd19ea503/
Changeset:   de8fd19ea503
Branch:      yt
User:        WeiguangCui
Date:        2016-08-30 13:25:58+00:00
Summary:     data_structures.py edited online with Bitbucket
Affected #:  1 file

diff -r d6130c4030a187c210756c1cafb499bce44be130 -r de8fd19ea50345e6f869d2392f668cc048b25ae2 yt/frontends/gadget/data_structures.py
--- a/yt/frontends/gadget/data_structures.py
+++ b/yt/frontends/gadget/data_structures.py
@@ -150,7 +150,7 @@
 
         f = open(self.parameter_filename, 'rb')
         if _get_gadget_format(self.parameter_filename) == 2:
-            f.seek(f.tell()+16, os.SEEK_END)
+            f.seek(f.tell()+16)
         hvals = read_record(f, self._header_spec)
         for i in hvals:
             if len(hvals[i]) == 1:


https://bitbucket.org/yt_analysis/yt/commits/9d4256fa9c64/
Changeset:   9d4256fa9c64
Branch:      yt
User:        WeiguangCui
Date:        2016-09-05 06:28:11+00:00
Summary:     Merged yt_analysis/yt into yt
Affected #:  3 files

diff -r de8fd19ea50345e6f869d2392f668cc048b25ae2 -r 9d4256fa9c64fe73737776027358e8dafcb23a29 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -941,8 +941,12 @@
             if level < min_level:
                 self._update_level_state(ls)
                 continue
-            domain_dims = self.ds.domain_dimensions.astype("int64") \
-                        * self.ds.relative_refinement(0, ls.current_level)
+            nd = self.ds.dimensionality
+            refinement = np.zeros_like(ls.base_dx)
+            refinement += self.ds.relative_refinement(0, ls.current_level)
+            refinement[nd:] = 1
+            domain_dims = self.ds.domain_dimensions * refinement
+            domain_dims = domain_dims.astype("int64")
             tot = ls.current_dims.prod()
             for chunk in ls.data_source.chunks(fields, "io"):
                 chunk[fields[0]]
@@ -956,7 +960,8 @@
                 raise RuntimeError
             self._update_level_state(ls)
         for name, v in zip(fields, ls.fields):
-            if self.level > 0: v = v[1:-1,1:-1,1:-1]
+            if self.level > 0:
+                v = v[1:-1, 1:-1, 1:-1]
             fi = self.ds._get_field_info(*name)
             self[name] = self.ds.arr(v, fi.units)
 
@@ -1010,8 +1015,11 @@
         rf = float(self.ds.relative_refinement(
                     ls.current_level, ls.current_level + 1))
         ls.current_level += 1
-        ls.current_dx = ls.base_dx / \
-            self.ds.relative_refinement(0, ls.current_level)
+        nd = self.ds.dimensionality
+        refinement = np.zeros_like(ls.base_dx)
+        refinement += self.ds.relative_refinement(0, ls.current_level)
+        refinement[nd:] = 1
+        ls.current_dx = ls.base_dx / refinement
         ls.old_global_startindex = ls.global_startindex
         ls.global_startindex, end_index, ls.current_dims = \
             self._minimal_box(ls.current_dx)

diff -r de8fd19ea50345e6f869d2392f668cc048b25ae2 -r 9d4256fa9c64fe73737776027358e8dafcb23a29 yt/data_objects/tests/test_covering_grid.py
--- a/yt/data_objects/tests/test_covering_grid.py
+++ b/yt/data_objects/tests/test_covering_grid.py
@@ -131,3 +131,11 @@
     cgrid = ds.covering_grid(0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions)
     density_field = cgrid["density"]
     assert_equal((density_field == 0.0).sum(), 0)
+
+ekh = 'EnzoKelvinHelmholtz/DD0011/DD0011'
+ at requires_file(ekh)
+def test_smoothed_covering_grid_2d_dataset():
+    ds = load(ekh)
+    ds.periodicity = (True, True, True)
+    scg = ds.smoothed_covering_grid(1, [0, 0, 0], [128, 128, 1])
+    assert_equal(scg['density'].shape, [128, 128, 1])

diff -r de8fd19ea50345e6f869d2392f668cc048b25ae2 -r 9d4256fa9c64fe73737776027358e8dafcb23a29 yt/fields/derived_field.py
--- a/yt/fields/derived_field.py
+++ b/yt/fields/derived_field.py
@@ -144,12 +144,18 @@
         return dd
 
     def get_units(self):
-        u = Unit(self.units, registry=self.ds.unit_registry)
+        if self.ds is not None:
+            u = Unit(self.units, registry=self.ds.unit_registry)
+        else:
+            u = Unit(self.units)
         return u.latex_representation()
 
     def get_projected_units(self):
-        u = Unit(self.units, registry=self.ds.unit_registry)*Unit('cm')
-        return u.latex_representation()
+        if self.ds is not None:
+            u = Unit(self.units, registry=self.ds.unit_registry)
+        else:
+            u = Unit(self.units)
+        return (u*Unit('cm')).latex_representation()
 
     def check_available(self, data):
         """
@@ -222,7 +228,10 @@
         if projected:
             raise NotImplementedError
         else:
-            units = Unit(self.units, registry=self.ds.unit_registry)
+            if self.ds is not None:
+                units = Unit(self.units, registry=self.ds.unit_registry)
+            else:
+                units = Unit(self.units)
         # Add unit label
         if not units.is_dimensionless:
             data_label += r"\ \ (%s)" % (units.latex_representation())


https://bitbucket.org/yt_analysis/yt/commits/eaabc53f4933/
Changeset:   eaabc53f4933
Branch:      yt
User:        ngoldbaum
Date:        2016-09-07 18:11:48+00:00
Summary:     Merged in WeiguangCui/yt (pull request #2355)

Yt - enabled Gadget format 2
Affected #:  2 files

diff -r 7e7c3fdd9cc79e65a179d277ae64b345dc30411f -r eaabc53f4933c4f46b032631563f6b1af087bd95 yt/frontends/gadget/data_structures.py
--- a/yt/frontends/gadget/data_structures.py
+++ b/yt/frontends/gadget/data_structures.py
@@ -46,10 +46,24 @@
     if isinstance(unit[0], string_types):
         unit = unit[1], unit[0]
     return unit
+    
+def _get_gadget_format(filename):
+    # check and return gadget binary format
+    f = open(filename, 'rb')
+    (rhead,) = struct.unpack('<I',f.read(4))
+    f.close()
+    if (rhead == 134217728) | (rhead == 8):
+        return 2
+    elif (rhead == 65536) | (rhead == 256):
+        return 1
+    else:
+        raise RuntimeError("Incorrect Gadget format %s!" % str(rhead))
 
 class GadgetBinaryFile(ParticleFile):
     def __init__(self, ds, io, filename, file_id):
         with open(filename, "rb") as f:
+            if _get_gadget_format(filename) == 2:
+                f.seek(f.tell()+16)
             self.header = read_record(f, ds._header_spec)
             self._position_offset = f.tell()
             f.seek(0, os.SEEK_END)
@@ -135,6 +149,8 @@
         # in the GADGET-2 user guide.
 
         f = open(self.parameter_filename, 'rb')
+        if _get_gadget_format(self.parameter_filename) == 2:
+            f.seek(f.tell()+16)
         hvals = read_record(f, self._header_spec)
         for i in hvals:
             if len(hvals[i]) == 1:
@@ -281,10 +297,10 @@
     @staticmethod
     def _validate_header(filename):
         '''
-        This method automatically detects whether the Gadget file is big/little endian 
-        and is not corrupt/invalid using the first 4 bytes in the file.  It returns a 
-        tuple of (Valid, endianswap) where Valid is a boolean that is true if the file 
-        is a Gadget binary file, and endianswap is the endianness character '>' or '<'. 
+        This method automatically detects whether the Gadget file is big/little endian
+        and is not corrupt/invalid using the first 4 bytes in the file.  It returns a
+        tuple of (Valid, endianswap) where Valid is a boolean that is true if the file
+        is a Gadget binary file, and endianswap is the endianness character '>' or '<'.
         '''
         try:
             f = open(filename,'rb')
@@ -293,9 +309,9 @@
                 f = open(filename+".0")
             except IOError:
                 return False, 1
-        
+
         # First int32 is 256 for a Gadget2 binary file with SnapFormat=1,
-        # 8 for a Gadget2 binary file with SnapFormat=2 file, 
+        # 8 for a Gadget2 binary file with SnapFormat=2 file,
         # or the byte swapped equivalents (65536 and 134217728).
         # The int32 following the header (first 4+256 bytes) must equal this
         # number.
@@ -311,16 +327,17 @@
             endianswap = '>'
         # Disabled for now (does any one still use SnapFormat=2?)
         # If so, alternate read would be needed based on header.
-        # elif rhead == 8:
-        #     return True, '<'
-        # elif rhead == 134217728:
-        #     return True, '>'
+        # Enabled Format2 here
+        elif rhead == 8:
+            return True, '<'
+        elif rhead == 134217728:
+            return True, '>'
         else:
             f.close()
             return False, 1
         # Read in particle number from header
         np0 = sum(struct.unpack(endianswap+'IIIIII',f.read(6*4)))
-        # Read in size of position block. It should be 4 bytes per float, 
+        # Read in size of position block. It should be 4 bytes per float,
         # with 3 coordinates (x,y,z) per particle. (12 bytes per particle)
         f.seek(4+256+4,0)
         np1 = struct.unpack(endianswap+'I',f.read(4))[0]/(4*3)

diff -r 7e7c3fdd9cc79e65a179d277ae64b345dc30411f -r eaabc53f4933c4f46b032631563f6b1af087bd95 yt/frontends/gadget/io.py
--- a/yt/frontends/gadget/io.py
+++ b/yt/frontends/gadget/io.py
@@ -27,11 +27,13 @@
     compute_morton
 from yt.utilities.logger import ytLogger as mylog
 
+from .data_structures import _get_gadget_format
+
 class IOHandlerGadgetHDF5(IOHandlerOWLS):
     _dataset_type = "gadget_hdf5"
 
 ZeroMass = object()
-    
+
 class IOHandlerGadgetBinary(BaseIOHandler):
     _dataset_type = "gadget_binary"
     _vector_fields = (("Coordinates", 3),
@@ -61,6 +63,8 @@
         self._vector_fields = dict(self._vector_fields)
         self._fields = ds._field_spec
         self._ptypes = ds._ptype_spec
+        self.data_files = set([])
+        self._format =  _get_gadget_format(ds.parameter_filename)#default gadget format 1
         super(IOHandlerGadgetBinary, self).__init__(ds, *args, **kwargs)
 
     @property
@@ -173,7 +177,12 @@
             if not any( (ptype, field) in field_list
                         for ptype in self._ptypes):
                 continue
-            pos += 4
+            if self._format == 2:
+                pos += 20 #skip block header
+            elif self._format == 1:
+                pos += 4
+            else:
+                raise RuntimeError("incorrect Gadget format %s!" % str(self._format))
             any_ptypes = False
             for ptype in self._ptypes:
                 if field == "Mass" and ptype not in self.var_mass:
@@ -189,7 +198,7 @@
             pos += 4
             if not any_ptypes: pos -= 8
         if file_size is not None:
-            if file_size != pos:
+            if (file_size != pos) & (self._format == 1): #ignore the rest of format 2 
                 mylog.warning("Your Gadget-2 file may have extra " +
                               "columns or different precision!" +
                               " (%s file vs %s computed)",

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