[yt-svn] commit/yt: ngoldbaum: Merged in MatthewTurk/yt/yt-3.0 (pull request #983)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sat Jun 28 09:55:28 PDT 2014


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/395cbbd74d04/
Changeset:   395cbbd74d04
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-06-28 18:55:17
Summary:     Merged in MatthewTurk/yt/yt-3.0 (pull request #983)

Fix cookbook recipes
Affected #:  10 files

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b doc/source/cookbook/profile_with_variance.py
--- a/doc/source/cookbook/profile_with_variance.py
+++ b/doc/source/cookbook/profile_with_variance.py
@@ -16,17 +16,15 @@
 
 # Create a 1D profile object for profiles over radius
 # and add a velocity profile.
-prof = yt.ProfilePlot(sp, 'radius', 'velocity_magnitude', 
-                      weight_field='cell_mass')
-prof.set_unit('radius', 'kpc')
-prof.set_xlim(0.1, 1000)
+prof = yt.create_profile(sp, 'radius', 'velocity_magnitude',
+                         units = {'radius': 'kpc'},
+                         extrema = {'radius': ((0.1, 'kpc'), (1000.0, 'kpc'))},
+                         weight_field='cell_mass')
 
 # Plot the average velocity magnitude.
-plt.loglog(prof['radius'], prof['velocity_magnitude'],
-              label='Mean')
+plt.loglog(prof.x, prof['velocity_magnitude'], label='Mean')
 # Plot the variance of the velocity madnitude.
-plt.loglog(prof['radius'], prof['velocity_magnitude_std'],
-              label='Standard Deviation')
+plt.loglog(prof.x, prof['velocity_magnitude_std'], label='Standard Deviation')
 plt.xlabel('r [kpc]')
 plt.ylabel('v [cm/s]')
 plt.legend()

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b doc/source/cookbook/rad_velocity.py
--- a/doc/source/cookbook/rad_velocity.py
+++ b/doc/source/cookbook/rad_velocity.py
@@ -21,18 +21,15 @@
 
 # Radial profile without correction
 
-rp0 = yt.ProfilePlot(sp0, 'radius', 'radial_velocity')
-rp0.set_unit('radius', 'kpc')
-rp0.set_log('radius', False)
+rp0 = yt.create_profile(sp0, 'radius', 'radial_velocity',
+        units = {'radius': 'kpc'},
+        logs = {'radius': False})
 
 # Radial profile with correction for bulk velocity
 
-rp1 = yt.ProfilePlot(sp1, 'radius', 'radial_velocity')
-rp1.set_unit('radius', 'kpc')
-rp1.set_log('radius', False)
-
-#rp0.save('radial_velocity_profile_uncorrected.png')
-#rp1.save('radial_velocity_profile_corrected.png')
+rp1 = yt.create_profile(sp1, 'radius', 'radial_velocity',
+        units = {'radius': 'kpc'},
+        logs = {'radius': False})
 
 # Make a plot using matplotlib
 
@@ -40,8 +37,8 @@
 ax = fig.add_subplot(111)
 
 # Here we scale the velocities by 1.0e5 to get into km/s
-ax.plot(rad_profile0["Radiuskpc"], rad_profile0["RadialVelocity"]/1.0e5,
-		rad_profile1["Radiuskpc"], rad_profile1["RadialVelocity"]/1.0e5)
+ax.plot(rp0.x, rp0["radial_velocity"].in_units("km/s"),
+		rp1.x, rp1["radial_velocity"].in_units("km/s"))
 
 ax.set_xlabel(r"$\mathrm{r\ (kpc)}$")
 ax.set_ylabel(r"$\mathrm{v_r\ (km/s)}$")

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b doc/source/cookbook/radial_profile_styles.py
--- a/doc/source/cookbook/radial_profile_styles.py
+++ b/doc/source/cookbook/radial_profile_styles.py
@@ -15,8 +15,9 @@
 #rp = BinnedProfile1D(sphere, 100, "Radiuskpc", 0.0, 500., log_space=False)
 #rp.add_fields("density","temperature")
 rp = yt.ProfilePlot(sp, 'radius', ['density', 'temperature'])
-rp.set_unit('radius', 'kpc')
-rp.set_log('radius', False)
+rp = yt.create_profile(sp, 'radius', ['density', 'temperature'],
+                       units = {'radius': 'kpc'},
+                       logs = {'radius': False})
 
 # Make plots using matplotlib
 
@@ -24,7 +25,7 @@
 ax = fig.add_subplot(111)
 
 # Plot the density as a log-log plot using the default settings
-dens_plot = ax.loglog(rp["Radiuskpc"], rp["density"])
+dens_plot = ax.loglog(rp.x, rp["density"])
 
 # Here we set the labels of the plot axes
 
@@ -52,15 +53,3 @@
 dens_plot[0].set_markersize(10)
 
 fig.savefig("density_profile_thick_with_xs.png")
-
-# Now get rid of the line on the axes plot
-
-ax.lines = []
-
-# Since the radial profile object also includes the standard deviation in each bin,
-# we'll use these as errorbars. We have to make a new plot for this:
-
-dens_err_plot = ax.errorbar(pr["Radiuskpc"], rp["density"],
-                            yerr=rp["Density_std"])
-                                                        
-fig.savefig("density_profile_with_errorbars.png")

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b doc/source/cookbook/save_profiles.py
--- a/doc/source/cookbook/save_profiles.py
+++ /dev/null
@@ -1,72 +0,0 @@
-### THIS RECIPE IS CURRENTLY BROKEN IN YT-3.0
-### DO NOT TRUST THIS RECIPE UNTIL THIS LINE IS REMOVED
-
-import yt
-import matplotlib.pyplot as plt
-import h5py as h5
-
-ds = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150")
-
-# Get a sphere
-
-sp = ds.sphere(ds.domain_center, (500., "kpc"))
-
-# Radial profile from the sphere
-
-prof = yt.BinnedProfile1D(sp, 100, "Radiuskpc", 0.0, 500., log_space=False)
-prof = yt.ProfilePlot(sp, 'radius', ['density', 'temperature'], weight_field="cell_mass")
-prof.set_unit('radius', 'kpc')
-prof.set_log('radius', False)
-prof.set_xlim(0, 500)
-
-# Write profiles to ASCII file
-
-prof.write_out("%s_profile.dat" % ds, bin_style="center")
-
-# Write profiles to HDF5 file
-
-prof.write_out_h5("%s_profile.h5" % ds, bin_style="center")
-
-# Now we will show how using NumPy, h5py, and Matplotlib the data in these
-# files may be plotted.
-
-# Plot density from ASCII file
-
-# Open the text file using NumPy's "loadtxt" method. In order to get the 
-# separate columns into separate NumPy arrays, it is essential to set unpack=True.
-
-r, dens, std_dens, temp, std_temp = \
-	np.loadtxt("sloshing_nomag2_hdf5_plt_cnt_0150_profile.dat", unpack=True)
-
-fig1 = plt.figure()
-
-ax = fig1.add_subplot(111)
-ax.plot(r, dens)
-ax.set_xlabel(r"$\mathrm{r\ (kpc)}$")
-ax.set_ylabel(r"$\mathrm{\rho\ (g\ cm^{-3})}$")
-ax.set_title("Density vs. Radius")
-fig1.savefig("%s_dens.png" % ds)
-
-# Plot temperature from HDF5 file
-
-# Get the file handle
-
-f = h5py.File("%s_profile.h5" % ds, "r")
-
-# Get the radius and temperature arrays from the file handle
-
-r = f["/Radiuskpc-1d"].attrs["x-axis-Radiuskpc"][:]
-temp = f["/Radiuskpc-1d/temperature"][:]
-
-# Close the file handle
-
-f.close()
-
-fig2 = plt.figure()
-
-ax = fig2.add_subplot(111)
-ax.plot(r, temp)
-ax.set_xlabel(r"$\mathrm{r\ (kpc)}$")
-ax.set_ylabel(r"$\mathrm{T\ (K)}$")
-ax.set_title("temperature vs. Radius")
-fig2.savefig("%s_temp.png" % ds)

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b doc/source/cookbook/simple_profile.py
--- a/doc/source/cookbook/simple_profile.py
+++ b/doc/source/cookbook/simple_profile.py
@@ -12,6 +12,7 @@
 sphere = ds.sphere("c", (100., "kpc"))
 plot = yt.ProfilePlot(sphere, "density", ["temperature", "velocity_x"],
                       weight_field="cell_mass")
+plot.set_log("velocity_x", False)
 
 # Save the image.
 # Optionally, give a string as an argument

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b doc/source/cookbook/simple_slice_with_multiple_fields.py
--- a/doc/source/cookbook/simple_slice_with_multiple_fields.py
+++ b/doc/source/cookbook/simple_slice_with_multiple_fields.py
@@ -7,5 +7,5 @@
 ds = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150")
 
 # Create density slices of several fields along the x axis
-yt.SlicePlot(ds, 'x', ['density','temperature','pressure','vorticity_squared'], 
+yt.SlicePlot(ds, 'x', ['density','temperature','pressure'], 
              width = (800.0, 'kpc')).save()

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -811,6 +811,8 @@
         blank = ~temp_storage.used
         self.used = temp_storage.used
         if self.weight_field is not None:
+            # This is unnecessary, but it will suppress division errors.
+            temp_storage.weight_values[blank] = 1e-30
             temp_storage.values /= temp_storage.weight_values[...,None]
             self.weight = temp_storage.weight_values[...,None]
             self.weight[blank] = 0.0

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b yt/fields/angular_momentum.py
--- a/yt/fields/angular_momentum.py
+++ b/yt/fields/angular_momentum.py
@@ -45,28 +45,25 @@
     def _specific_angular_momentum_x(field, data):
         xv, yv, zv = obtain_velocities(data, ftype)
         center = data.get_field_parameter('center')
-        v_vec = obtain_rvec(data)
-        v_vec = np.rollaxis(v_vec, 0, len(v_vec.shape))
-        v_vec = data.pf.arr(v_vec, input_units = data["index", "x"].units)
-        rv = v_vec - center
+        rv = obtain_rvec(data)
+        rv = np.rollaxis(rv, 0, len(rv.shape))
+        rv = data.pf.arr(rv, input_units = data["index", "x"].units)
         return yv * rv[...,2] - zv * rv[...,1]
 
     def _specific_angular_momentum_y(field, data):
         xv, yv, zv = obtain_velocities(data, ftype)
         center = data.get_field_parameter('center')
-        v_vec = obtain_rvec(data)
-        v_vec = np.rollaxis(v_vec, 0, len(v_vec.shape))
-        v_vec = data.pf.arr(v_vec, input_units = data["index", "x"].units)
-        rv = v_vec - center
+        rv = obtain_rvec(data)
+        rv = np.rollaxis(rv, 0, len(rv.shape))
+        rv = data.pf.arr(rv, input_units = data["index", "x"].units)
         return - (xv * rv[...,2] - zv * rv[...,0])
 
     def _specific_angular_momentum_z(field, data):
         xv, yv, zv = obtain_velocities(data, ftype)
         center = data.get_field_parameter('center')
-        v_vec = obtain_rvec(data)
-        v_vec = np.rollaxis(v_vec, 0, len(v_vec.shape))
-        v_vec = data.pf.arr(v_vec, input_units = data["index", "x"].units)
-        rv = v_vec - center
+        rv = obtain_rvec(data)
+        rv = np.rollaxis(rv, 0, len(rv.shape))
+        rv = data.pf.arr(rv, input_units = data["index", "x"].units)
         return xv * rv[...,1] - yv * rv[...,0]
 
     registry.add_field((ftype, "specific_angular_momentum_x"),

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b yt/visualization/profile_plotter.py
--- a/yt/visualization/profile_plotter.py
+++ b/yt/visualization/profile_plotter.py
@@ -317,10 +317,10 @@
         return ret
 
     def _setup_plots(self):
+        for f in self.axes:
+            self.axes[f].cla()
         for i, profile in enumerate(self.profiles):
             for field, field_data in profile.items():
-                if field in self.axes:
-                    self.axes[field].cla()
                 self.axes[field].plot(np.array(profile.x), np.array(field_data),
                                       label=self.label[i], **self.plot_spec[i])
         

diff -r 15bf4f304a0e8b46658a6a7a1b887e4cc60722bb -r 395cbbd74d0469288a679cc5fa559d4a8b8bad9b yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -581,7 +581,8 @@
         return image
 
     def _render(self, double_check, num_threads, image, sampler):
-        pbar = get_pbar("Ray casting", (self.volume.brick_dimensions + 1).prod(axis=-1).sum())
+        ncells = sum(b.source_mask.size for b in self.volume.bricks)
+        pbar = get_pbar("Ray casting", ncells)
         total_cells = 0
         if double_check:
             for brick in self.volume.bricks:
@@ -592,7 +593,7 @@
         view_pos = self.front_center + self.orienter.unit_vectors[2] * 1.0e6 * self.width[2]
         for brick in self.volume.traverse(view_pos):
             sampler(brick, num_threads=num_threads)
-            total_cells += np.prod(brick.my_data[0].shape)
+            total_cells += brick.source_mask.size
             pbar.update(total_cells)
 
         pbar.finish()

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