[yt-svn] commit/yt: MatthewTurk: Merged in jzuhone/yt-3.x (pull request #1367)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sat Jan 3 20:26:55 PST 2015


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/f904451a2faa/
Changeset:   f904451a2faa
Branch:      yt
User:        MatthewTurk
Date:        2015-01-04 04:26:46+00:00
Summary:     Merged in jzuhone/yt-3.x (pull request #1367)

[bugfixish] PPVCube fixes
Affected #:  5 files

diff -r 6f2e8040d395c53810a66157cf804dc7dc9c1431 -r f904451a2faa7a2461dc85d651dc8ff32e30e2d6 doc/source/analyzing/analysis_modules/PPVCube.ipynb
--- a/doc/source/analyzing/analysis_modules/PPVCube.ipynb
+++ b/doc/source/analyzing/analysis_modules/PPVCube.ipynb
@@ -1,7 +1,7 @@
 {
  "metadata": {
   "name": "",
-  "signature": "sha256:7ba601e381023e5b7c00a585ccaa55996316d2dfe7f8c96284b4539e1ee5b846"
+  "signature": "sha256:794e861818b8a105bc91b537e8359801c8d28d5a13a32787fb386b0578109a66"
  },
  "nbformat": 3,
  "nbformat_minor": 0,
@@ -19,10 +19,13 @@
      "cell_type": "code",
      "collapsed": false,
      "input": [
+      "from yt.config import ytcfg\n",
+      "ytcfg[\"yt\",\"loglevel\"] = 30\n",
+      "\n",
       "import yt\n",
       "import numpy as np\n",
-      "\n",
-      "from yt.analysis_modules.ppv_cube.api import PPVCube"
+      "from yt.analysis_modules.ppv_cube.api import PPVCube\n",
+      "import yt.units as u"
      ],
      "language": "python",
      "metadata": {},
@@ -168,7 +171,7 @@
      "cell_type": "markdown",
      "metadata": {},
      "source": [
-      "Which shows a rotating disk with a specific density and velocity profile. Now, suppose we wanted to look at this disk galaxy from a certain orientation angle, and simulate a 3D FITS data cube where we can see the gas that is emitting at different velocities along the line of sight. We can do this using the `PPVCube` class. First, let's assume we rotate our viewing angle 60 degrees from face-on, from along the z-axis into the y-axis. We'll create a normal vector:"
+      "Which shows a rotating disk with a specific density and velocity profile. Now, suppose we wanted to look at this disk galaxy from a certain orientation angle, and simulate a 3D FITS data cube where we can see the gas that is emitting at different velocities along the line of sight. We can do this using the `PPVCube` class. First, let's assume we rotate our viewing angle 60 degrees from face-on, from along the z-axis into the x-axis. We'll create a normal vector:"
      ]
     },
     {
@@ -176,7 +179,7 @@
      "collapsed": false,
      "input": [
       "i = 60.*np.pi/180.\n",
-      "L = [0.0,np.sin(i),np.sin(i)]"
+      "L = [np.sin(i),0.0,np.cos(i)]"
      ],
      "language": "python",
      "metadata": {},
@@ -193,7 +196,7 @@
      "cell_type": "code",
      "collapsed": false,
      "input": [
-      "cube = PPVCube(ds, L, \"density\", dims=(200,100,50), velocity_bounds=(-150.,150.,\"km/s\"), method=\"sum\")"
+      "cube = PPVCube(ds, L, \"density\", dims=(200,50), velocity_bounds=(-150.,150.,\"km/s\"), method=\"sum\")"
      ],
      "language": "python",
      "metadata": {},
@@ -268,7 +271,6 @@
      "cell_type": "code",
      "collapsed": false,
      "input": [
-      "import yt.units as u\n",
       "# Picking different velocities for the slices\n",
       "new_center = ds_cube.domain_center\n",
       "new_center[2] = ds_cube.spec2pixel(-100.*u.km/u.s)\n",
@@ -334,7 +336,7 @@
      "cell_type": "code",
      "collapsed": false,
      "input": [
-      "cube2 = PPVCube(ds, L, \"density\", dims=(200,100,50), velocity_bounds=(-150,150,\"km/s\"), thermal_broad=True, \n",
+      "cube2 = PPVCube(ds, L, \"density\", dims=(200,50), velocity_bounds=(-150,150,\"km/s\"), thermal_broad=True, \n",
       "                atomic_weight=12.0, method=\"sum\")\n",
       "cube2.write_fits(\"cube2.fits\", clobber=True, length_unit=\"kpc\")"
      ],

diff -r 6f2e8040d395c53810a66157cf804dc7dc9c1431 -r f904451a2faa7a2461dc85d651dc8ff32e30e2d6 yt/analysis_modules/photon_simulator/photon_models.py
--- a/yt/analysis_modules/photon_simulator/photon_models.py
+++ b/yt/analysis_modules/photon_simulator/photon_models.py
@@ -217,7 +217,8 @@
             photons["dx"].append(chunk["dx"][idxs].in_units("kpc"))
 
         for key in photons:
-            photons[key] = uconcatenate(photons[key])
+            if len(photons[key]) > 0:
+                photons[key] = uconcatenate(photons[key])
 
         return photons
 

diff -r 6f2e8040d395c53810a66157cf804dc7dc9c1431 -r f904451a2faa7a2461dc85d651dc8ff32e30e2d6 yt/analysis_modules/ppv_cube/ppv_cube.py
--- a/yt/analysis_modules/ppv_cube/ppv_cube.py
+++ b/yt/analysis_modules/ppv_cube/ppv_cube.py
@@ -51,8 +51,9 @@
 
 class PPVCube(object):
     def __init__(self, ds, normal, field, center="c", width=(1.0,"unitary"),
-                 dims=(100,100,100), velocity_bounds=None, thermal_broad=False,
-                 atomic_weight=56., method="integrate", no_shifting=False):
+                 dims=(100,100), velocity_bounds=None, thermal_broad=False,
+                 atomic_weight=56., method="integrate", no_shifting=False,
+                 north_vector=None):
         r""" Initialize a PPVCube object.
 
         Parameters
@@ -62,7 +63,7 @@
         normal : array_like or string
             The normal vector along with to make the projections. If an array, it
             will be normalized. If a string, it will be assumed to be along one of the
-            principal axes of the domain ("x","y", or "z").
+            principal axes of the domain ("x", "y", or "z").
         field : string
             The field to project.
         center : A sequence of floats, a string, or a tuple.
@@ -78,9 +79,11 @@
         width : float, tuple, or YTQuantity.
             The width of the projection. A float will assume the width is in code units.
             A (value, unit) tuple or YTQuantity allows for the units of the width to be
-            specified.
+            specified. Implies width = height, e.g. the aspect ratio of the PPVCube's 
+            spatial dimensions is 1. 
         dims : tuple, optional
-            A 3-tuple of dimensions (nx,ny,nv) for the cube.
+            A 2-tuple of dimensions (nx,nv) for the cube. Implies nx = ny, e.g. the aspect
+            ratio of the PPVCube's spatial dimensions is 1. 
         velocity_bounds : tuple, optional
             A 3-tuple of (vmin, vmax, units) for the velocity bounds to
             integrate over. If None, the largest velocity of the
@@ -95,6 +98,10 @@
         no_shifting : boolean, optional
             If set, no shifting due to velocity will occur but only thermal broadening.
             Should not be set when *thermal_broad* is False, otherwise nothing happens!
+        north_vector : a sequence of floats
+            A vector defining the 'up' direction. This option sets the orientation of 
+            the plane of projection. If not set, an arbitrary grid-aligned north_vector 
+            is chosen. Ignored in the case of on-axis plots.
 
         Examples
         --------
@@ -117,8 +124,8 @@
         self.center = ds.coordinates.sanitize_center(center, normal)[0]
 
         self.nx = dims[0]
-        self.ny = dims[1]
-        self.nv = dims[2]
+        self.ny = dims[0]
+        self.nv = dims[1]
 
         if method not in ["integrate","sum"]:
             raise RuntimeError("Only the 'integrate' and 'sum' projection +"
@@ -167,7 +174,8 @@
             else:
                 buf = off_axis_projection(ds, self.center, normal, width,
                                           (self.nx, self.ny), "intensity",
-                                          no_ghost=True, method=method)[::-1]
+                                          north_vector=north_vector,
+                                          no_ghost=True, method=method).swapaxes(0,1)
             sto.result_id = i
             sto.result = buf
             pbar.update(i)
@@ -176,7 +184,7 @@
         self.data = ds.arr(np.zeros((self.nx,self.ny,self.nv)), self.proj_units)
         if is_root():
             for i, buf in sorted(storage.items()):
-                self.data[:,:,i] = buf[:,:]
+                self.data[:,:,i] = buf.transpose()
 
         self.axis_type = "velocity"
 
@@ -197,8 +205,8 @@
             T = data["temperature"].v
             w = ppv_utils.compute_weight(self.thermal_broad, self.dv_cgs,
                                          self.particle_mass, v.flatten(), T.flatten())
-            w[np.isnan(w)] = 0.0                                                                                                                        
-            return data[self.field]*w.reshape(v.shape)                                                                                                  
+            w[np.isnan(w)] = 0.0
+            return data[self.field]*w.reshape(v.shape)
         return _intensity
 
     def transform_spectral_axis(self, rest_value, units):
@@ -283,7 +291,7 @@
         if sky_scale is not None and sky_center is not None:
             w = create_sky_wcs(w, sky_center, sky_scale)
 
-        fib = FITSImageBuffer(self.data.transpose(2,0,1), fields=self.field, wcs=w)
+        fib = FITSImageBuffer(self.data.transpose(), fields=self.field, wcs=w)
         fib[0].header["bunit"] = re.sub('()', '', str(self.proj_units))
         fib[0].header["btype"] = self.field
 

diff -r 6f2e8040d395c53810a66157cf804dc7dc9c1431 -r f904451a2faa7a2461dc85d651dc8ff32e30e2d6 yt/analysis_modules/ppv_cube/tests/test_ppv.py
--- a/yt/analysis_modules/ppv_cube/tests/test_ppv.py
+++ b/yt/analysis_modules/ppv_cube/tests/test_ppv.py
@@ -38,7 +38,7 @@
 
     ds = load_uniform_grid(data, dims)
 
-    cube = PPVCube(ds, "z", "density", dims=dims,
+    cube = PPVCube(ds, "z", "density", dims=(8,1024),
                    velocity_bounds=(-300., 300., "km/s"),
                    thermal_broad=True)
 

diff -r 6f2e8040d395c53810a66157cf804dc7dc9c1431 -r f904451a2faa7a2461dc85d651dc8ff32e30e2d6 yt/utilities/fits_image.py
--- a/yt/utilities/fits_image.py
+++ b/yt/utilities/fits_image.py
@@ -337,8 +337,8 @@
         cunit = [str(ds.wcs.wcs.cunit[idx]) for idx in axis_wcs[axis]]
         ctype = [ds.wcs.wcs.ctype[idx] for idx in axis_wcs[axis]]
         cdelt = [ds.wcs.wcs.cdelt[idx] for idx in axis_wcs[axis]]
-        ctr_pix = center.in_units("code_length")[:self.dimensionality].v
-        crval = ds.wcs.wcs_pix2world(ctr_pix.reshape(1,self.dimensionality))[0]
+        ctr_pix = center.in_units("code_length")[:ds.dimensionality].v
+        crval = ds.wcs.wcs_pix2world(ctr_pix.reshape(1,ds.dimensionality))[0]
         crval = [crval[idx] for idx in axis_wcs[axis]]
     else:
         # This is some other kind of dataset

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