[yt-svn] commit/yt: MatthewTurk: Fix ordering of FITS files, allow masking of NaNs, and enable odd units.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Dec 4 14:09:05 PST 2013


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/8ed709644790/
Changeset:   8ed709644790
Branch:      yt-3.0
User:        MatthewTurk
Date:        2013-12-04 22:46:30
Summary:     Fix ordering of FITS files, allow masking of NaNs, and enable odd units.
Affected #:  3 files

diff -r 424f1dcfd229055851cb113b23742362f98f2885 -r 8ed70964479018aa2ca1ecff614547033068383b yt/frontends/fits/data_structures.py
--- a/yt/frontends/fits/data_structures.py
+++ b/yt/frontends/fits/data_structures.py
@@ -35,6 +35,8 @@
 from yt.utilities.io_handler import \
     io_registry
 from yt.utilities.physical_constants import cm_per_mpc
+from yt.utilities.exceptions import \
+    YTFITSHeaderNotUnderstood
 from .fields import FITSFieldInfo, add_fits_field, KnownFITSFields
 from yt.data_objects.field_info_container import FieldInfoContainer, NullFunc, \
      ValidateDataField, TranslationFunc
@@ -129,11 +131,14 @@
     _handle = None
     
     def __init__(self, filename, data_style='fits',
+                 ignore_unit_names = False,
                  primary_header = None,
                  sky_conversion = None,
                  storage_filename = None,
-                 conversion_override = None):
+                 conversion_override = None,
+                 mask_nans = True):
 
+        self.mask_nans = mask_nans
         if isinstance(filename, pyfits.HDUList):
             self._handle = filename
             fname = filename.filename()
@@ -155,7 +160,10 @@
 
         self.wcs = pywcs.WCS(self.primary_header)
 
-        if self.wcs.wcs.cunit[0].name in ["deg","arcsec","arcmin","mas"]:
+        name = getattr(self.wcs.wcs.cunit[0], "name", None)
+        if name is None and ignore_unit_names == False:
+            raise YTFITSHeaderNotUnderstood
+        if name in ["deg","arcsec","arcmin","mas"]:
             self.sky_wcs = self.wcs.deepcopy()
             if sky_conversion is None:
                 self._set_minimalist_wcs()
@@ -186,7 +194,7 @@
         dims = np.array(self.shape)
         ndims = len(dims)
         self.wcs.wcs.crpix = 0.5*(dims+1)
-        self.wcs.wcs.cdelt = [1.,1.]
+        self.wcs.wcs.cdelt = [1.0]*ndims
         self.wcs.wcs.crval = 0.5*(dims+1)
         self.wcs.wcs.cunit = ["pixel"]*ndims
         self.wcs.wcs.ctype = ["LINEAR"]*ndims
@@ -239,7 +247,8 @@
         self.dimensionality = self.primary_header["naxis"]
         self.geometry = "cartesian"
 
-        self.domain_dimensions = np.array(self._handle[self.first_image].shape)
+        dims = self._handle[self.first_image].shape[::-1]
+        self.domain_dimensions = np.array(dims)
         if self.dimensionality == 2:
             self.domain_dimensions = np.append(self.domain_dimensions,
                                                [int(1)])

diff -r 424f1dcfd229055851cb113b23742362f98f2885 -r 8ed70964479018aa2ca1ecff614547033068383b yt/frontends/fits/io.py
--- a/yt/frontends/fits/io.py
+++ b/yt/frontends/fits/io.py
@@ -35,26 +35,6 @@
             count_list, conv_factors):
         pass
 
-    def _read_data_set(self, grid, field):
-        f = self._handle
-        if self.pf.dimensionality == 2:
-            nx,ny = f[field].data.tranpose().shape
-            tr = f[field].data.transpose().reshape(nx,ny,1)
-        elif self.pf.dimensionality == 3:
-            tr = f[field].data.transpose()
-        return tr.astype("float64")
-
-    def _read_data_slice(self, grid, field, axis, coord):
-        sl = [slice(None), slice(None), slice(None)]
-        sl[axis] = slice(coord, coord + 1)
-        f = self._handle
-        if self.pf.dimensionality == 2:
-            nx,ny = f[field].data.transpose().shape
-            tr = f[field].data.transpose().reshape(nx,ny,1)[sl]
-        elif self.pf.dimensionality == 3:
-            tr = f[field].data.transpose()[sl]
-        return tr.astype("float64")
-
     def _read_fluid_selection(self, chunks, selector, fields, size):
         chunks = list(chunks)
         if any((ftype != "gas" for ftype, fname in fields)):
@@ -69,14 +49,13 @@
                     size, [f2 for f1, f2 in fields], ng)
         for field in fields:
             ftype, fname = field
-            ds = f[fname].data.astype("float64")
+            ds = f[fname].data.astype("float64").transpose()
+            if self.pf.mask_nans:
+                ds[np.isnan(ds)] = 0.0
             ind = 0
             for chunk in chunks:
                 for g in chunk.objs:
                     if self.pf.dimensionality == 2:
-                        nx,ny = ds.transpose().shape
-                        data = ds.transpose().reshape(nx,ny,1)
-                    elif self.pf.dimensionality == 3:
-                        data = ds.transpose()
-                    ind += g.select(selector, data, rv[field], ind) # caches
+                        ds.shape = ds.shape + (1,)
+                    ind += g.select(selector, ds, rv[field], ind) # caches
         return rv

diff -r 424f1dcfd229055851cb113b23742362f98f2885 -r 8ed70964479018aa2ca1ecff614547033068383b yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -311,3 +311,9 @@
         v += "mass %0.3e.  Multi-mass particles are not currently supported." % (
             self.ma)
         return v
+
+class YTFITSHeaderNotUnderstood(YTException):
+    def __str__(self):
+        return "This FITS header is not recognizable in its current form.\n" + \
+                "If you would like to force loading, specify: \n" + \
+                "ignore_unit_names = True"

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