1. Matthew Turk
  2. yt.workshop2012.advanced_visualization

Commits

J.S. Oishi  committed 06740c0

added a bunch of scripts; changed the cmap on frb

  • Participants
  • Parent commits a495c39
  • Branches default

Comments (0)

Files changed (6)

File advanced_visualization.tex

View file
 
 \fullimage{DD0001_Slice_y_Density.png}
 
-\mediumsimple{However, PlotCollections are the most \emph{feature rich} plotting tools in \yt{}.}
+\mediumsimple{However, PlotCollections are the most \emph{feature rich} plotting tools in \yt{}.\\\\ Think back to Stephen Skory \& John ZuHone's talk yesterday}
 
 \bigsimple{Plot Modifications (aka ``Callbacks'')}
 
 
 \fullimage{vel_Slice_y_Density.png}
 
-\mediumsimple{I want to tweak...everything.}
+\bigsimple{I want to tweak...everything.}
 
 \begin{frame}[fragile,t]{Example: Overlaying Profiles on Phase Plots}
   \tiny
 
 \fullimage{temp_density_phase.png}
 
+\mediumsimple{The Key to Ultimate Plot Flexibility is \emph{getting the components}.}
+
+\begin{frame}[fragile,t]{FixedResolutionBuffers}
+  \tiny
+  <<d['scripts/frb.py|fn|pyg|l']>>
+\end{frame}
+
+\fullimage{projection_frb.png}
+\bigsimple{This looks \emph{terrible}!}
+\bigsimple{But it's really awesome.}
+
+\begin{frame}[t]{\emph{Everything} is a unique object}
+  \begin{itemize}
+    \item the data is in the \texttt{proj} object
+    \item the pixels are in the \texttt{FixedResolutionBuffer} object
+    \item the figure itself is a matplotlib \texttt{Figure} object
+    \item and the pixels are drawn into the frame via the \texttt{imshow} method of the \texttt{axes}  \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile,t]{Let's try again}
+  \tiny
+  <<d['scripts/frb_2.py|fn|pyg|l']>>
+\end{frame}
+\fullimage{log_projection_frb.png}
 
 \end{document}

File scripts/frb.py

View file
 proj = pf.h.proj(direction,"Density", "Density")
 
 c = pf.h.find_max("Density")[1]
-width = ( 100, 'mpc')
+width = ( 10, 'mpc')
 xax, yax = x_dict[direction], y_dict[direction] # handy helper!
 LE = (c[xax] - 0.5*width[0]/pf[width[1].lower()], 
       c[yax] - 0.5*width[0]/pf[width[1].lower()])
 # 
 frb = FixedResolutionBuffer(proj, (LE[0],RE[0],LE[1],RE[1]), (512,512))
 
-P.imshow(frb['Density'])
+P.imshow(frb['Density'], cmap = 'bone')
 P.savefig('projection_frb.png')

File scripts/frb_2.py

View file
+from yt.mods import *
+import pylab as P
+from matplotlib.colors import LogNorm
+from matplotlib.colorbar import ColorbarBase
+import matplotlib.ticker as ticker 
+
+direction = 0
+pf  = load("data/enzo_tiny_cosmology/DD0042/DD0042")
+
+# get the projection *object*
+proj = pf.h.proj(direction,"Density", "Density")
+
+c = pf.h.find_max("Density")[1]
+width = ( 10, 'mpc')
+xax, yax = x_dict[direction], y_dict[direction] # handy helper!
+LE = (c[xax] - 0.5*width[0]/pf[width[1].lower()], 
+      c[yax] - 0.5*width[0]/pf[width[1].lower()])
+RE = (c[xax] + 0.5*width[0]/pf[width[1].lower()], 
+      c[yax] + 0.5*width[0]/pf[width[1].lower()])
+
+frb = FixedResolutionBuffer(proj, (LE[0],RE[0],LE[1],RE[1]), (512,512))
+# logging it the hard way
+cmap = 'bone'
+fig = P.figure()
+ax = fig.add_axes([0.1,0.1,0.85,0.85])
+norm = LogNorm()
+
+ax.imshow(frb['Density'], #the data
+          interpolation='nearest', #no lying!
+          origin='lower', 
+          norm = norm, # log it!
+          cmap = cmap)
+fig.savefig('log_projection_frb.png')

File scripts/pc_callback.py

View file
+from yt.mods import *
+pf = load("data/enzo_tiny_cosmology/DD0042/DD0042")
+pc = PlotCollection(pf)
+
+pc.add_slice("Density",1)
+
+# loop over all plots in the collection
+for p in pc.plots:
+    p.modify['grids']() # add a "callback" to modify the plot
+
+pc.save('grid')

File scripts/phase_overlay.py

View file
+from yt.mods import *
+import yt.visualization.profile_plotter as pp
+from yt.visualization._mpl_imports import \
+    FigureCanvasAgg
+
+pf  = load("data/enzo_tiny_cosmology/DD0042/DD0042")
+
+phase = pp.PhasePlotter(pf.h.sphere('max', (10.,'mpc')),
+                        "Density", "Temperature", "CellMassMsun").plot
+profile = pp.ProfilePlotter(pf.h.sphere('max', (10.,'mpc')),
+                            "Density", "Temperature",
+                            weight="CellMassMsun").plot
+
+# make a phase diagram
+figure, axes = phase.to_mpl()
+axes.collections[0].set_cmap('gist_heat')
+axes.hold(True)
+figure.colorbar(axes.collections[0]).set_label(r"$\mathrm{Cell\ Mass\ (M_\odot)}$", size="x-large")
+
+# over plot the profile
+axes.loglog(profile.x_values, profile.y_values, lw=3., color='k')
+
+# save it to a PNG 
+pname = "temp_density_phase"
+canvas = FigureCanvasAgg(figure)
+canvas.print_figure("%s.png" % (pname))

File scripts/yt_pc.py

View file
+from yt.mods import *
+pf = load("data/enzo_tiny_cosmology/DD0001/DD0001")
+pc = PlotCollection(pf)
+
+pc.add_slice("Density",1)
+
+pc.save()
+