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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Jul 18 05:20:28 PDT 2014


4 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/d8e6f1fa0e3e/
Changeset:   d8e6f1fa0e3e
Branch:      yt-3.0
User:        samskillman
Date:        2014-05-08 06:36:00
Summary:     Add a method to splat points with colors
Affected #:  2 files

diff -r b6bbd6601ea3f3fcdce2568d2383f52fb1876763 -r d8e6f1fa0e3e69d0082f6dc9549e9d4f88dd2dd2 yt/utilities/lib/image_utilities.pyx
--- a/yt/utilities/lib/image_utilities.pyx
+++ b/yt/utilities/lib/image_utilities.pyx
@@ -37,3 +37,24 @@
     #        for k in range(3):
     #            v = buffer[i, j, k]
     #            buffer[i, j, k] = iclip(v, 0, 255)
+def add_rgba_points_to_image(
+        np.ndarray[np.float64_t, ndim=3] buffer,
+        np.ndarray[np.float64_t, ndim=1] px,
+        np.ndarray[np.float64_t, ndim=1] py,
+        np.ndarray[np.float64_t, ndim=2] rgba,
+        ):
+    cdef int i, j, k, pi
+    cdef int np = px.shape[0]
+    cdef int xs = buffer.shape[0]
+    cdef int ys = buffer.shape[1]
+    cdef int v
+    #iv = iclip(<int>(pv * 255), 0, 255)
+    for pi in range(np):
+        j = <int> (xs * px[pi])
+        i = <int> (ys * py[pi])
+        if i < 0 or j < 0 or i >= xs or j >= ys:
+            continue
+        for k in range(4):
+            buffer[i, j, k] += rgba[pi, k]
+    return
+

diff -r b6bbd6601ea3f3fcdce2568d2383f52fb1876763 -r d8e6f1fa0e3e69d0082f6dc9549e9d4f88dd2dd2 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -18,6 +18,7 @@
 
 from yt.funcs import *
 from yt.utilities.exceptions import YTNotInsideNotebook
+from color_maps import mcm
 import _colormap_data as cmd
 import yt.utilities.lib.image_utilities as au
 import yt.utilities.png_writer as pw
@@ -153,7 +154,7 @@
     if transpose:
         bitmap_array = bitmap_array.swapaxes(0,1)
     if filename is not None:
-        pw.write_png(bitmap_array.copy(), filename)
+        pw.write_png(bitmap_array, filename)
     else:
         return pw.write_png_to_string(bitmap_array.copy())
     return bitmap_array
@@ -239,10 +240,18 @@
     return to_plot
 
 def map_to_colors(buff, cmap_name):
-    if cmap_name not in cmd.color_map_luts:
-        print ("Your color map was not found in the extracted colormap file.")
-        raise KeyError(cmap_name)
-    lut = cmd.color_map_luts[cmap_name]
+    try:
+        lut = cmd.color_map_luts[cmap_name]
+    except KeyError:
+        try:
+            cmap = mcm.get_cmap(cmap_name)
+            dummy = cmap(0.0)
+            lut = cmap._lut.T
+        except ValueError:
+            print "Your color map was not found in either the extracted" +\
+                " colormap file or matplotlib colormaps"
+            raise KeyError(cmap_name)
+
     x = np.mgrid[0.0:1.0:lut[0].shape[0]*1j]
     shape = buff.shape
     mapped = np.dstack(


https://bitbucket.org/yt_analysis/yt/commits/f514280f7d5f/
Changeset:   f514280f7d5f
Branch:      yt-3.0
User:        samskillman
Date:        2014-05-08 07:14:49
Summary:     np -> npart + a extra line
Affected #:  1 file

diff -r d8e6f1fa0e3e69d0082f6dc9549e9d4f88dd2dd2 -r f514280f7d5f148039d6ed60ff513f2ae9bb28cc yt/utilities/lib/image_utilities.pyx
--- a/yt/utilities/lib/image_utilities.pyx
+++ b/yt/utilities/lib/image_utilities.pyx
@@ -37,6 +37,7 @@
     #        for k in range(3):
     #            v = buffer[i, j, k]
     #            buffer[i, j, k] = iclip(v, 0, 255)
+
 def add_rgba_points_to_image(
         np.ndarray[np.float64_t, ndim=3] buffer,
         np.ndarray[np.float64_t, ndim=1] px,
@@ -44,12 +45,12 @@
         np.ndarray[np.float64_t, ndim=2] rgba,
         ):
     cdef int i, j, k, pi
-    cdef int np = px.shape[0]
+    cdef int npart = px.shape[0]
     cdef int xs = buffer.shape[0]
     cdef int ys = buffer.shape[1]
     cdef int v
     #iv = iclip(<int>(pv * 255), 0, 255)
-    for pi in range(np):
+    for pi in range(npart):
         j = <int> (xs * px[pi])
         i = <int> (ys * py[pi])
         if i < 0 or j < 0 or i >= xs or j >= ys:


https://bitbucket.org/yt_analysis/yt/commits/e43cce305c63/
Changeset:   e43cce305c63
Branch:      yt-3.0
User:        samskillman
Date:        2014-07-18 06:43:19
Summary:     Merging with tip, adding some docs
Affected #:  2 files

diff -r b58796ca19881fca5b1244e13152816ad2164200 -r e43cce305c630d03c4a75fe03ebe9465714a2b3d yt/utilities/lib/image_utilities.pyx
--- a/yt/utilities/lib/image_utilities.pyx
+++ b/yt/utilities/lib/image_utilities.pyx
@@ -43,7 +43,15 @@
         np.ndarray[np.float64_t, ndim=1] px, 
         np.ndarray[np.float64_t, ndim=1] py, 
         np.ndarray[np.float64_t, ndim=2] rgba,
-        ):  
+        ):
+    """
+    Splat rgba points onto an image
+
+    Given an image buffer, add colors to
+    pixels defined by fractional positions px and py,
+    with colors rgba.  px and py are one dimensional
+    arrays, and rgba is a an array of rgba values.
+    """
     cdef int i, j, k, pi
     cdef int npart = px.shape[0]
     cdef int xs = buffer.shape[0]
@@ -53,7 +61,7 @@
     for pi in range(npart):
         j = <int> (xs * px[pi])
         i = <int> (ys * py[pi])
-        if i < 0 or j < 0 or i >= xs or j >= ys: 
+        if i < 0 or j < 0 or i >= xs or j >= ys:
             continue
         for k in range(4):
             buffer[i, j, k] += rgba[pi, k]

diff -r b58796ca19881fca5b1244e13152816ad2164200 -r e43cce305c630d03c4a75fe03ebe9465714a2b3d yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -18,6 +18,7 @@
 
 from yt.funcs import *
 from yt.utilities.exceptions import YTNotInsideNotebook
+from color_maps import mcm
 import _colormap_data as cmd
 import yt.utilities.lib.image_utilities as au
 import yt.utilities.png_writer as pw
@@ -157,7 +158,7 @@
     if transpose:
         bitmap_array = bitmap_array.swapaxes(0,1)
     if filename is not None:
-        pw.write_png(bitmap_array.copy(), filename)
+        pw.write_png(bitmap_array, filename)
     else:
         return pw.write_png_to_string(bitmap_array.copy())
     return bitmap_array
@@ -243,10 +244,18 @@
     return to_plot
 
 def map_to_colors(buff, cmap_name):
-    if cmap_name not in cmd.color_map_luts:
-        print ("Your color map was not found in the extracted colormap file.")
-        raise KeyError(cmap_name)
-    lut = cmd.color_map_luts[cmap_name]
+    try:
+        lut = cmd.color_map_luts[cmap_name]
+    except KeyError:
+        try:
+            cmap = mcm.get_cmap(cmap_name)
+            dummy = cmap(0.0)
+            lut = cmap._lut.T
+        except ValueError:
+            print "Your color map was not found in either the extracted" +\
+                " colormap file or matplotlib colormaps"
+            raise KeyError(cmap_name)
+
     x = np.mgrid[0.0:1.0:lut[0].shape[0]*1j]
     shape = buff.shape
     mapped = np.dstack(


https://bitbucket.org/yt_analysis/yt/commits/a7017f15e008/
Changeset:   a7017f15e008
Branch:      yt-3.0
User:        samskillman
Date:        2014-07-18 07:06:51
Summary:     Adding test for splat code, and making sure that write_png doesn't modify the image.
Affected #:  1 file

diff -r e43cce305c630d03c4a75fe03ebe9465714a2b3d -r a7017f15e008ce7aa83f3cb3db9f16532d63fdd4 yt/visualization/tests/test_splat.py
--- /dev/null
+++ b/yt/visualization/tests/test_splat.py
@@ -0,0 +1,58 @@
+"""
+Test for write_bitmap and add_rgba_points
+
+
+
+"""
+
+#-----------------------------------------------------------------------------
+# Copyright (c) 2013, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+import os
+import os.path
+import tempfile
+import shutil
+import numpy as np
+import yt
+from yt.testing import \
+    assert_equal, expand_keywords
+from yt.utilities.lib.api import add_rgba_points_to_image
+
+
+def setup():
+    """Test specific setup."""
+    from yt.config import ytcfg
+    ytcfg["yt", "__withintesting"] = "True"
+
+
+def test_splat():
+    """Tests functionality of off_axis_projection and write_projection."""
+    # Perform I/O in safe place instead of yt main dir
+    tmpdir = tempfile.mkdtemp()
+    curdir = os.getcwd()
+    os.chdir(tmpdir)
+
+    N = 16 
+    Np = int(1e2)
+    image = np.zeros([N,N,4])
+    xs = np.random.random(Np)
+    ys = np.random.random(Np)
+
+    cbx = yt.visualization.color_maps.mcm.RdBu
+    cs = cbx(np.random.random(Np))
+    add_rgba_points_to_image(image, xs, ys, cs)
+
+    before_hash = image.copy()
+    fn = 'tmp.png'
+    yt.write_bitmap(image, fn)
+    yield assert_equal, os.path.exists(fn), True
+    os.remove(fn)
+    yield assert_equal, before_hash, image
+
+    os.chdir(curdir)
+    # clean up
+    shutil.rmtree(tmpdir)

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