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

Bitbucket commits-noreply at bitbucket.org
Wed Dec 14 09:58:23 PST 2011


4 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/8406fbc010dc/
changeset:   8406fbc010dc
branch:      yt
user:        chummels
date:        2011-12-14 05:43:55
summary:     Added "write_projection" function to image_writer.py.  This function is a helper function to generate a matplotlib figure with a possible title, colorbar, etc.  It is to be used after you generate a projection image array from either a volume render or an offaxis projection.
affected #:  3 files

diff -r 4e4544676353d5163c5ef8314aeaf223a920b00e -r 8406fbc010dca55b97e5ff3f9f12288e8df278bd yt/mods.py
--- a/yt/mods.py
+++ b/yt/mods.py
@@ -108,7 +108,7 @@
     PlotCollection, PlotCollectionInteractive, \
     get_multi_plot, FixedResolutionBuffer, ObliqueFixedResolutionBuffer, \
     callback_registry, write_bitmap, write_image, annotate_image, \
-    apply_colormap, scale_image
+    apply_colormap, scale_image, write_projection
 
 from yt.visualization.volume_rendering.api import \
     ColorTransferFunction, PlanckTransferFunction, ProjectionTransferFunction, \


diff -r 4e4544676353d5163c5ef8314aeaf223a920b00e -r 8406fbc010dca55b97e5ff3f9f12288e8df278bd yt/visualization/api.py
--- a/yt/visualization/api.py
+++ b/yt/visualization/api.py
@@ -49,7 +49,8 @@
     splat_points, \
     annotate_image, \
     apply_colormap, \
-    scale_image
+    scale_image, \
+    write_projection
 
 from plot_modifications import \
     PlotCallback, \


diff -r 4e4544676353d5163c5ef8314aeaf223a920b00e -r 8406fbc010dca55b97e5ff3f9f12288e8df278bd yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -24,6 +24,7 @@
 import imp
 import os
 import numpy as na
+import pylab as pl
 
 from yt.funcs import *
 import _colormap_data as cmd
@@ -327,3 +328,77 @@
     im = image.copy()
     au.add_points_to_image(im, points_x, points_y, val)
     return im
+
+def write_projection(data, filename, colorbar=True, colorbar_label=None, 
+                    title=None, limits=None, take_log=True):
+    r"""Write a projection or volume rendering to disk with a variety of 
+    pretty parameters such as limits, title, colorbar, etc.  write_projection
+    uses the standard matplotlib interface to create the figure.  N.B. This code
+    only works *after* you have created the projection using the standard 
+    framework (i.e. the Camera interface or off_axis_projection).
+
+    Accepts an NxM sized array representing the projection itself as well
+    as the filename to which you will save this figure.  
+
+    Parameters
+    ----------
+    data : array_like 
+        image array as output by off_axis_projection or camera.snapshot()
+    filename : string 
+        the filename where the data will be saved
+    colorbar : boolean
+        do you want a colorbar generated to the right of the image?
+    colorbar_label : string
+        the label associated with your colorbar
+    title : string
+        the label at the top of the figure
+    limits : 2-element array_like
+        the lower limit and the upper limit to be plotted in the figure 
+        of the data array
+    take_log : boolean
+        plot the log of the data array (and take the log of the limits if set)?
+
+    Examples
+    --------
+
+    >>> image = off_axis_projection(pf, c, L, W, N, "Density", no_ghost=False)
+    >>> write_projection(image, 'test.png', 
+                         colorbar_label="Column Density (cm$^{-2}$)", 
+                         title="Offaxis Projection", limits=(1e-3,1e-5), 
+                         take_log=True)
+    """
+
+    # If there are limits, then clip the data before plotting
+    if limits is not None:
+        data = na.clip(data, limits[0], limits[1])
+
+    # If this is rendered as log, then apply now.
+    if take_log:
+        data = na.log10(data)
+        if limits is not None:
+            limits = na.log10(limits)
+
+    # Create the figure and paint the data on
+    fig = pl.figure()
+    ax = fig.add_subplot(111)
+    cax = ax.imshow(data)
+
+    # If there are limits, apply them to the colormap
+    if limits is not None:
+        cax.set_clim=limits
+    if title:
+        ax.set_title(title)
+
+    # Suppress the x and y pixel counts
+    ax.set_xticks(())
+    ax.set_yticks(())
+
+    # Add a color bar and label if requested
+    if colorbar:
+        cbar = fig.colorbar(cax)
+        if colorbar_label:
+            cbar.ax.set_ylabel(colorbar_label)
+
+    pl.savefig(filename)
+    pl.clf()
+    pl.close()



https://bitbucket.org/yt_analysis/yt/changeset/28670b75dba9/
changeset:   28670b75dba9
branch:      yt
user:        chummels
date:        2011-12-14 05:46:20
summary:     Merging.
affected #:  3 files

diff -r f3e76b71172ac873f7322b3e1ca7959a788055dd -r 28670b75dba9e08f7f8085c0ffc1ea4a1a394e5a yt/mods.py
--- a/yt/mods.py
+++ b/yt/mods.py
@@ -108,7 +108,7 @@
     PlotCollection, PlotCollectionInteractive, \
     get_multi_plot, FixedResolutionBuffer, ObliqueFixedResolutionBuffer, \
     callback_registry, write_bitmap, write_image, annotate_image, \
-    apply_colormap, scale_image
+    apply_colormap, scale_image, write_projection
 
 from yt.visualization.volume_rendering.api import \
     ColorTransferFunction, PlanckTransferFunction, ProjectionTransferFunction, \


diff -r f3e76b71172ac873f7322b3e1ca7959a788055dd -r 28670b75dba9e08f7f8085c0ffc1ea4a1a394e5a yt/visualization/api.py
--- a/yt/visualization/api.py
+++ b/yt/visualization/api.py
@@ -49,7 +49,8 @@
     splat_points, \
     annotate_image, \
     apply_colormap, \
-    scale_image
+    scale_image, \
+    write_projection
 
 from plot_modifications import \
     PlotCallback, \


diff -r f3e76b71172ac873f7322b3e1ca7959a788055dd -r 28670b75dba9e08f7f8085c0ffc1ea4a1a394e5a yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -24,6 +24,7 @@
 import imp
 import os
 import numpy as na
+import pylab as pl
 
 from yt.funcs import *
 import _colormap_data as cmd
@@ -327,3 +328,77 @@
     im = image.copy()
     au.add_points_to_image(im, points_x, points_y, val)
     return im
+
+def write_projection(data, filename, colorbar=True, colorbar_label=None, 
+                    title=None, limits=None, take_log=True):
+    r"""Write a projection or volume rendering to disk with a variety of 
+    pretty parameters such as limits, title, colorbar, etc.  write_projection
+    uses the standard matplotlib interface to create the figure.  N.B. This code
+    only works *after* you have created the projection using the standard 
+    framework (i.e. the Camera interface or off_axis_projection).
+
+    Accepts an NxM sized array representing the projection itself as well
+    as the filename to which you will save this figure.  
+
+    Parameters
+    ----------
+    data : array_like 
+        image array as output by off_axis_projection or camera.snapshot()
+    filename : string 
+        the filename where the data will be saved
+    colorbar : boolean
+        do you want a colorbar generated to the right of the image?
+    colorbar_label : string
+        the label associated with your colorbar
+    title : string
+        the label at the top of the figure
+    limits : 2-element array_like
+        the lower limit and the upper limit to be plotted in the figure 
+        of the data array
+    take_log : boolean
+        plot the log of the data array (and take the log of the limits if set)?
+
+    Examples
+    --------
+
+    >>> image = off_axis_projection(pf, c, L, W, N, "Density", no_ghost=False)
+    >>> write_projection(image, 'test.png', 
+                         colorbar_label="Column Density (cm$^{-2}$)", 
+                         title="Offaxis Projection", limits=(1e-3,1e-5), 
+                         take_log=True)
+    """
+
+    # If there are limits, then clip the data before plotting
+    if limits is not None:
+        data = na.clip(data, limits[0], limits[1])
+
+    # If this is rendered as log, then apply now.
+    if take_log:
+        data = na.log10(data)
+        if limits is not None:
+            limits = na.log10(limits)
+
+    # Create the figure and paint the data on
+    fig = pl.figure()
+    ax = fig.add_subplot(111)
+    cax = ax.imshow(data)
+
+    # If there are limits, apply them to the colormap
+    if limits is not None:
+        cax.set_clim=limits
+    if title:
+        ax.set_title(title)
+
+    # Suppress the x and y pixel counts
+    ax.set_xticks(())
+    ax.set_yticks(())
+
+    # Add a color bar and label if requested
+    if colorbar:
+        cbar = fig.colorbar(cax)
+        if colorbar_label:
+            cbar.ax.set_ylabel(colorbar_label)
+
+    pl.savefig(filename)
+    pl.clf()
+    pl.close()



https://bitbucket.org/yt_analysis/yt/changeset/87d682adcf17/
changeset:   87d682adcf17
branch:      yt
user:        chummels
date:        2011-12-14 18:51:36
summary:     Modified the write_projection function call to include the ability to scale the size of the image with the resolution of the image array.  (Previously, it always output an 800x600 image regardless of the resolution of the underlying projection data).  Also moved the pylab call into the function and out of the top level of image_writer.py.
affected #:  1 file

diff -r 28670b75dba9e08f7f8085c0ffc1ea4a1a394e5a -r 87d682adcf1771330b11ca2332cde14fb9bf0812 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -24,7 +24,6 @@
 import imp
 import os
 import numpy as na
-import pylab as pl
 
 from yt.funcs import *
 import _colormap_data as cmd
@@ -330,7 +329,7 @@
     return im
 
 def write_projection(data, filename, colorbar=True, colorbar_label=None, 
-                    title=None, limits=None, take_log=True):
+                    title=None, limits=None, take_log=True, var_fig_size=False):
     r"""Write a projection or volume rendering to disk with a variety of 
     pretty parameters such as limits, title, colorbar, etc.  write_projection
     uses the standard matplotlib interface to create the figure.  N.B. This code
@@ -357,6 +356,9 @@
         of the data array
     take_log : boolean
         plot the log of the data array (and take the log of the limits if set)?
+    var_fig_size : boolean
+        If we want the resolution (and size) of the output image to scale 
+        with the resolution of the image array.  
 
     Examples
     --------
@@ -367,6 +369,7 @@
                          title="Offaxis Projection", limits=(1e-3,1e-5), 
                          take_log=True)
     """
+    import pylab as pl
 
     # If there are limits, then clip the data before plotting
     if limits is not None:
@@ -378,6 +381,7 @@
         if limits is not None:
             limits = na.log10(limits)
 
+
     # Create the figure and paint the data on
     fig = pl.figure()
     ax = fig.add_subplot(111)
@@ -399,6 +403,14 @@
         if colorbar_label:
             cbar.ax.set_ylabel(colorbar_label)
 
-    pl.savefig(filename)
+    # If we want the resolution of the image to scale with the resolution
+    # of the image array. we increase the dpi value accordingly
+    if var_fig_size:
+        N = data.shape[0]
+        mag_factor = N/480.
+        pl.savefig(filename, dpi=100*mag_factor)
+    else:
+        pl.savefig(filename)
+
     pl.clf()
     pl.close()



https://bitbucket.org/yt_analysis/yt/changeset/0ac521e9ac07/
changeset:   0ac521e9ac07
branch:      yt
user:        chummels
date:        2011-12-14 18:55:49
summary:     Merging.
affected #:  3 files

diff -r cce024601183277b73f32feada172a5a7a05a077 -r 0ac521e9ac07be8f66be6f7eb40e7d16a9e20fb8 yt/mods.py
--- a/yt/mods.py
+++ b/yt/mods.py
@@ -108,7 +108,7 @@
     PlotCollection, PlotCollectionInteractive, \
     get_multi_plot, FixedResolutionBuffer, ObliqueFixedResolutionBuffer, \
     callback_registry, write_bitmap, write_image, annotate_image, \
-    apply_colormap, scale_image
+    apply_colormap, scale_image, write_projection
 
 from yt.visualization.volume_rendering.api import \
     ColorTransferFunction, PlanckTransferFunction, ProjectionTransferFunction, \


diff -r cce024601183277b73f32feada172a5a7a05a077 -r 0ac521e9ac07be8f66be6f7eb40e7d16a9e20fb8 yt/visualization/api.py
--- a/yt/visualization/api.py
+++ b/yt/visualization/api.py
@@ -49,7 +49,8 @@
     splat_points, \
     annotate_image, \
     apply_colormap, \
-    scale_image
+    scale_image, \
+    write_projection
 
 from plot_modifications import \
     PlotCallback, \


diff -r cce024601183277b73f32feada172a5a7a05a077 -r 0ac521e9ac07be8f66be6f7eb40e7d16a9e20fb8 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -327,3 +327,90 @@
     im = image.copy()
     au.add_points_to_image(im, points_x, points_y, val)
     return im
+
+def write_projection(data, filename, colorbar=True, colorbar_label=None, 
+                    title=None, limits=None, take_log=True, var_fig_size=False):
+    r"""Write a projection or volume rendering to disk with a variety of 
+    pretty parameters such as limits, title, colorbar, etc.  write_projection
+    uses the standard matplotlib interface to create the figure.  N.B. This code
+    only works *after* you have created the projection using the standard 
+    framework (i.e. the Camera interface or off_axis_projection).
+
+    Accepts an NxM sized array representing the projection itself as well
+    as the filename to which you will save this figure.  
+
+    Parameters
+    ----------
+    data : array_like 
+        image array as output by off_axis_projection or camera.snapshot()
+    filename : string 
+        the filename where the data will be saved
+    colorbar : boolean
+        do you want a colorbar generated to the right of the image?
+    colorbar_label : string
+        the label associated with your colorbar
+    title : string
+        the label at the top of the figure
+    limits : 2-element array_like
+        the lower limit and the upper limit to be plotted in the figure 
+        of the data array
+    take_log : boolean
+        plot the log of the data array (and take the log of the limits if set)?
+    var_fig_size : boolean
+        If we want the resolution (and size) of the output image to scale 
+        with the resolution of the image array.  
+
+    Examples
+    --------
+
+    >>> image = off_axis_projection(pf, c, L, W, N, "Density", no_ghost=False)
+    >>> write_projection(image, 'test.png', 
+                         colorbar_label="Column Density (cm$^{-2}$)", 
+                         title="Offaxis Projection", limits=(1e-3,1e-5), 
+                         take_log=True)
+    """
+    import pylab as pl
+
+    # If there are limits, then clip the data before plotting
+    if limits is not None:
+        data = na.clip(data, limits[0], limits[1])
+
+    # If this is rendered as log, then apply now.
+    if take_log:
+        data = na.log10(data)
+        if limits is not None:
+            limits = na.log10(limits)
+
+
+    # Create the figure and paint the data on
+    fig = pl.figure()
+    ax = fig.add_subplot(111)
+    cax = ax.imshow(data)
+
+    # If there are limits, apply them to the colormap
+    if limits is not None:
+        cax.set_clim=limits
+    if title:
+        ax.set_title(title)
+
+    # Suppress the x and y pixel counts
+    ax.set_xticks(())
+    ax.set_yticks(())
+
+    # Add a color bar and label if requested
+    if colorbar:
+        cbar = fig.colorbar(cax)
+        if colorbar_label:
+            cbar.ax.set_ylabel(colorbar_label)
+
+    # If we want the resolution of the image to scale with the resolution
+    # of the image array. we increase the dpi value accordingly
+    if var_fig_size:
+        N = data.shape[0]
+        mag_factor = N/480.
+        pl.savefig(filename, dpi=100*mag_factor)
+    else:
+        pl.savefig(filename)
+
+    pl.clf()
+    pl.close()

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