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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon May 1 07:56:03 PDT 2017


2 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/f4c5c13c67e5/
Changeset:   f4c5c13c67e5
Branch:      yt
User:        ngoldbaum
Date:        2017-03-04 07:08:00+00:00
Summary:     Add the ability to detect and read double precision Gadget data
Affected #:  2 files

diff -r 3eca2ae80ab14a48b643d3055d7d3c0933fa77ae -r f4c5c13c67e51d2ea6546c1e155e145570103fec yt/frontends/gadget/data_structures.py
--- a/yt/frontends/gadget/data_structures.py
+++ b/yt/frontends/gadget/data_structures.py
@@ -327,13 +327,13 @@
             endianswap = '<'
         elif rhead == 65536:
             endianswap = '>'
-        # Disabled for now (does any one still use SnapFormat=2?)
-        # If so, alternate read would be needed based on header.
         # Enabled Format2 here
         elif rhead == 8:
-            return True, '<'
+            f.close()
+            return True, 'float32'
         elif rhead == 134217728:
-            return True, '>'
+            f.close()
+            return True, 'float32'
         else:
             f.close()
             return False, 1
@@ -346,7 +346,9 @@
         f.close()
         # Compare
         if np0 == np1:
-            return True, endianswap
+            return True, 'float32'
+        elif np1 == 2*np0:
+            return True, 'float64'
         else:
             return False, 1
 

diff -r 3eca2ae80ab14a48b643d3055d7d3c0933fa77ae -r f4c5c13c67e51d2ea6546c1e155e145570103fec yt/frontends/gadget/io.py
--- a/yt/frontends/gadget/io.py
+++ b/yt/frontends/gadget/io.py
@@ -306,7 +306,7 @@
         if name == "ParticleIDs":
             dt = "uint32"
         else:
-            dt = "float32"
+            dt = self._float_type
         if name in self._vector_fields:
             count *= self._vector_fields[name]
         arr = np.fromfile(f, dtype=dt, count = count)
@@ -319,11 +319,13 @@
         count = sum(data_file.total_particles.values())
         DLE = data_file.ds.domain_left_edge
         DRE = data_file.ds.domain_right_edge
+        self._float_type = data_file.ds._validate_header(data_file.filename)[1]
+        self._field_size = np.dtype(self._float_type).itemsize
         with open(data_file.filename, "rb") as f:
             # We add on an additionally 4 for the first record.
             f.seek(data_file._position_offset + 4)
             # The first total_particles * 3 values are positions
-            pp = np.fromfile(f, dtype = 'float32', count = count*3)
+            pp = np.fromfile(f, dtype=self._float_type, count=count*3)
             pp.shape = (count, 3)
         regions.add_data_file(pp, data_file.file_id, data_file.ds.filter_bbox)
         morton = compute_morton(pp[:,0], pp[:,1], pp[:,2], DLE, DRE,
@@ -336,7 +338,6 @@
         return npart
 
     # header is 256, but we have 4 at beginning and end for ints
-    _field_size = 4
     def _calculate_field_offsets(self, field_list, pcount,
                                  offset, file_size = None):
         # field_list is (ftype, fname) but the blocks are ordered


https://bitbucket.org/yt_analysis/yt/commits/c8eac6c2ed9d/
Changeset:   c8eac6c2ed9d
Branch:      yt
User:        xarthisius
Date:        2017-05-01 14:55:59+00:00
Summary:     Merged in ngoldbaum/yt (pull request #2537)

Add the ability to detect and read double precision Gadget data

Approved-by: John ZuHone <jzuhone at gmail.com>
Approved-by: Matt Turk <matthewturk at gmail.com>
Approved-by: Kacper Kowalik <xarthisius.kk at gmail.com>
Affected #:  2 files

diff -r aad9958444e0d2671cf9983f8fae48a12fac23d7 -r c8eac6c2ed9d64f40c75c56bac3568b22f7d9bce yt/frontends/gadget/data_structures.py
--- a/yt/frontends/gadget/data_structures.py
+++ b/yt/frontends/gadget/data_structures.py
@@ -336,13 +336,13 @@
             endianswap = '<'
         elif rhead == 65536:
             endianswap = '>'
-        # Disabled for now (does any one still use SnapFormat=2?)
-        # If so, alternate read would be needed based on header.
         # Enabled Format2 here
         elif rhead == 8:
-            return True, '<'
+            f.close()
+            return True, 'float32'
         elif rhead == 134217728:
-            return True, '>'
+            f.close()
+            return True, 'float32'
         else:
             f.close()
             return False, 1
@@ -355,7 +355,9 @@
         f.close()
         # Compare
         if np0 == np1:
-            return True, endianswap
+            return True, 'float32'
+        elif np1 == 2*np0:
+            return True, 'float64'
         else:
             return False, 1
 

diff -r aad9958444e0d2671cf9983f8fae48a12fac23d7 -r c8eac6c2ed9d64f40c75c56bac3568b22f7d9bce yt/frontends/gadget/io.py
--- a/yt/frontends/gadget/io.py
+++ b/yt/frontends/gadget/io.py
@@ -306,7 +306,7 @@
         if name == "ParticleIDs":
             dt = "uint32"
         else:
-            dt = "float32"
+            dt = self._float_type
         if name in self._vector_fields:
             count *= self._vector_fields[name]
         arr = np.fromfile(f, dtype=dt, count = count)
@@ -319,11 +319,13 @@
         count = sum(data_file.total_particles.values())
         DLE = data_file.ds.domain_left_edge
         DRE = data_file.ds.domain_right_edge
+        self._float_type = data_file.ds._validate_header(data_file.filename)[1]
+        self._field_size = np.dtype(self._float_type).itemsize
         with open(data_file.filename, "rb") as f:
             # We add on an additionally 4 for the first record.
             f.seek(data_file._position_offset + 4)
             # The first total_particles * 3 values are positions
-            pp = np.fromfile(f, dtype = 'float32', count = count*3)
+            pp = np.fromfile(f, dtype=self._float_type, count=count*3)
             pp.shape = (count, 3)
         regions.add_data_file(pp, data_file.file_id, data_file.ds.filter_bbox)
         morton = compute_morton(pp[:,0], pp[:,1], pp[:,2], DLE, DRE,
@@ -336,7 +338,6 @@
         return npart
 
     # header is 256, but we have 4 at beginning and end for ints
-    _field_size = 4
     def _calculate_field_offsets(self, field_list, pcount,
                                  offset, file_size = None):
         # field_list is (ftype, fname) but the blocks are ordered

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