1\documentclass[10pt,landscape]{article}
2\usepackage{multicol}
3\usepackage{calc}
4\usepackage{ifthen}
5\usepackage[landscape]{geometry}
6\usepackage[hyphens]{url}
7
8% To make this come out properly in landscape mode, do one of the following
9% 1.
10%  pdflatex cheatsheet.tex
11%
12% 2.
13%  latex cheatsheet.tex
14%  dvips -P pdf  -t landscape cheatsheet.dvi
15%  ps2pdf cheatsheet.ps
16
17
18% If you're reading this, be prepared for confusion.  Making this was
19% a learning experience for me, and it shows.  Much of the placement
20% was hacked in; if you make it better, let me know...
21
22
23% 2008-04
24% Changed page margin code to use the geometry package. Also added code for
25% conditional page margins, depending on paper size. Thanks to Uwe Ziegenhagen
26% for the suggestions.
27
28% 2006-08
29% Made changes based on suggestions from Gene Cooperman. <gene at ccs.neu.edu>
30
31% 2012-11 - Stephen Skory
32% Converted the latex cheat sheet to a yt cheat sheet, taken from
33% http://www.stdout.org/~winston/latex/
34
35
36% This sets page margins to .5 inch if using letter paper, and to 1cm
37% if using A4 paper. (This probably isn't strictly necessary.)
38% If using another size paper, use default 1cm margins.
39\ifthenelse{\lengthtest { \paperwidth = 11in}}
40	{ \geometry{top=.5in,left=.5in,right=.5in,bottom=0.85in} }
41	{\ifthenelse{ \lengthtest{ \paperwidth = 297mm}}
42		{\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
43		{\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
44	}
45
46% Turn off header and footer
47\pagestyle{empty}
48
49
50% Redefine section commands to use less space
51\makeatletter
52\renewcommand{\section}{\@startsection{section}{1}{0mm}%
53                                {-1ex plus -.5ex minus -.2ex}%
54                                {0.5ex plus .2ex}%x
55                                {\normalfont\large\bfseries}}
56\renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
57                                {-1explus -.5ex minus -.2ex}%
58                                {0.5ex plus .2ex}%
59                                {\normalfont\normalsize\bfseries}}
60\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
61                                {-1ex plus -.5ex minus -.2ex}%
62                                {1ex plus .2ex}%
63                                {\normalfont\small\bfseries}}
64\makeatother
65
66% Define BibTeX command
67\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
68    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
69
70% Don't print section numbers
71\setcounter{secnumdepth}{0}
72
73
74\setlength{\parindent}{0pt}
75\setlength{\parskip}{0pt plus 0.5ex}
76
77
78% -----------------------------------------------------------------------
79
80\begin{document}
81
82\raggedright
83\fontsize{3mm}{3mm}\selectfont
84\begin{multicols}{3}
85
86
87% multicol parameters
88% These lengths are set only within the two main columns
89%\setlength{\columnseprule}{0.25pt}
90\setlength{\premulticols}{1pt}
91\setlength{\postmulticols}{1pt}
92\setlength{\multicolsep}{1pt}
93\setlength{\columnsep}{2pt}
94
95\begin{center}
96     \Large{\textbf{yt Cheat Sheet}} \\
97\end{center}
98
99\subsection{General Info}
100For everything yt please see \url{http://yt-project.org}.
101Documentation \url{http://yt-project.org/doc/index.html}.
102Need help? Start here \url{http://yt-project.org/doc/help/} and then
103try the IRC chat room \url{http://yt-project.org/irc.html},
104or the mailing list \url{https://mail.python.org/archives/list/yt-users@python.org/}. \\
105
106\subsection{Installing yt} The easiest way to install yt is to use the
107installation script found on the yt homepage or the docs linked above.  If you
108already have python set up with \texttt{numpy}, \texttt{scipy},
109\texttt{matplotlib}, \texttt{h5py}, and \texttt{cython}, you can also use
110\texttt{pip install yt}
111
112\subsection{Command Line yt}
113yt, and its convenience functions, are launched from a command line prompt.
114Many commands have flags to control behavior.
115Commands can be followed by
116{\bf {-}{-}help} (e.g. {\bf yt render {-}{-}help}) for detailed help for that command
117including a list of the available flags.
118
119\texttt{iyt}\textemdash\ Load yt and IPython. \\
120\texttt{yt load} \textit{dataset}   \textemdash\ Load a single dataset.  \\
121\texttt{yt help} \textemdash\ Print yt help information. \\
122\texttt{yt stats} \textit{dataset} \textemdash\ Print stats of a dataset. \\
123\texttt{yt update} \textemdash\ Update yt to most recent version.\\
124\texttt{yt update --all} \textemdash\ Update yt and dependencies to most recent version. \\
125\texttt{yt version} \textemdash\ yt installation information. \\
126\texttt{yt notebook} \textemdash\ Run the IPython notebook server. \\
127\texttt{yt upload\_image} \textit{image.png} \textemdash\ Upload PNG image to imgur.com. \\
128\texttt{yt upload\_notebook} \textit{notebook.nb} \textemdash\ Upload IPython notebook to \url{https://girder.hub.yt}.\\
129\texttt{yt plot} \textit{dataset} \textemdash\ Create a set of images.\\
130\texttt{yt render} \textit{dataset} \textemdash\ Create a simple
131 volume rendering. \\
132\texttt{yt mapserver} \textit{dataset} \textemdash\ View a plot/projection in a Gmaps-like
133 interface. \\
134\texttt{yt pastebin} \textit{text.out} \textemdash\ Post text to the pastebin at
135 paste.yt-project.org. \\
136\texttt{yt pastebin\_grab} \textit{identifier} \textemdash\ Print content of pastebin to
137 STDOUT. \\
138\texttt{yt bugreport} \textemdash\ Report a yt bug. \\
139\texttt{yt hop} \textit{dataset} \textemdash\  Run hop on a dataset. \\
140
141\subsection{yt Imports}
142In order to use yt, Python must load the relevant yt modules into memory.
143The import commands are entered in the Python/IPython shell or
144used as part of a script.
145\newlength{\MyLen}
146\settowidth{\MyLen}{\texttt{letterpaper}/\texttt{a4paper} \ }
147\texttt{import yt}  \textemdash\
148Load yt. \\
149\texttt{from yt.config import ytcfg}  \textemdash\
150Used to set yt configuration options.
151If used, must be called before importing any other module.\\
152\texttt{from yt.analysis\_modules.\emph{halo\_finding}.api import \textasteriskcentered}  \textemdash\
153Load halo finding modules. Other modules
154are loaded in a similar way by swapping the
155\emph{emphasized} text.
156See the \textbf{Analysis Modules} section for a listing and short descriptions of each.
157
158\subsection{YTArray}
159Simulation data in yt is returned as a YTArray.  YTArray is a numpy array that
160has unit data attached to it and can automatically handle unit conversions and
161detect unit errors. Just like a numpy array, YTArray provides a wealth of
162built-in functions to calculate properties of the data in the array. Here is a
163very brief list of some useful ones.
164\settowidth{\MyLen}{\texttt{multicol} }\\
165\texttt{v = a.in\_cgs()} \textemdash\ Return the array in CGS units \\
166\texttt{v = a.in\_units('Msun/pc**3')} \textemdash\ Return the array in solar masses per cubic parsec \\
167\texttt{v = a.max(), a.min()} \textemdash\ Return maximum, minimum of \texttt{a}. \\
168\texttt{index = a.argmax(), a.argmin()} \textemdash\ Return index of max,
169min value of \texttt{a}.\\
170\texttt{v = a[}\textit{index}\texttt{]} \textemdash\ Select a single value from \texttt{a} at location \textit{index}.\\
171\texttt{b = a[}\textit{i:j}\texttt{]} \textemdash\ Select the slice of values from
172\texttt{a} between
173locations \textit{i} to \textit{j-1} saved to a new Numpy array \texttt{b} with length \textit{j-i}. \\
174\texttt{sel = (a > const)} \textemdash\ Create a new boolean Numpy array
175\texttt{sel}, of the same shape as \texttt{a},
176that marks which values of \texttt{a > const}. Other operators (e.g. \textless, !=, \%) work as well.\\
177\texttt{b = a[sel]} \textemdash\ Create a new Numpy array \texttt{b} made up of
178elements from \texttt{a} that correspond to elements of \texttt{sel}
179that are \textit{True}. In the above example \texttt{b} would be all elements of \texttt{a} that are greater than \texttt{const}.\\
180\texttt{a.write\_hdf5(\textit{filename.h5})} \textemdash\ Save \texttt{a} to the hdf5 file \textit{filename.h5}.\\
181
182\subsection{IPython Tips}
183\settowidth{\MyLen}{\texttt{multicol} }
184These tips work if IPython has been loaded, typically either by invoking
185\texttt{iyt} or \texttt{yt load} on the command line, or using the IPython notebook (\texttt{yt notebook}).
186\texttt{Tab complete} \textemdash\ IPython will attempt to auto-complete a
187variable or function name when the \texttt{Tab} key is pressed, e.g. \textit{HaloFi}\textendash\texttt{Tab} would auto-complete
188to \textit{HaloFinder}. This also works with imports, e.g. \textit{from numpy.random.}\textendash\texttt{Tab}
189would give you a list of random functions (note the trailing period before hitting \texttt{Tab}).\\
190\texttt{?, ??} \textemdash\ Appending one or two question marks at the end of any object gives you
191detailed information about it, e.g. \textit{variable\_name}?.\\
192Below a few IPython ``magics'' are listed, which are IPython-specific shortcut commands.\\
193\texttt{\%paste} \textemdash\ Paste content from the system clipboard into the IPython shell.\\
194\texttt{\%hist} \textemdash\ Print recent command history.\\
195\texttt{\%quickref} \textemdash\ Print IPython quick reference.\\
196\texttt{\%pdb} \textemdash\ Automatically enter the Python debugger at an exception.\\
197\texttt{\%debug} \textemdash\ Drop into a debugger at the location of the last unhandled exception. \\
198\texttt{\%time, \%timeit} \textemdash\ Find running time of expressions for benchmarking.\\
199\texttt{\%lsmagic} \textemdash\ List all available IPython magics. Hint: \texttt{?} works with magics.\\
200
201
202Please see \url{http://ipython.org/documentation.html} for the full
203IPython documentation.
204
205\subsection{Load and Access Data}
206The first step in using yt is to reference a simulation snapshot.
207After that, simulation data is generally accessed in yt using \textit{Data Containers} which are Python objects
208that define a region of simulation space from which data should be selected.
209\settowidth{\MyLen}{\texttt{multicol} }
210\texttt{ds = yt.load(}\textit{dataset}\texttt{)} \textemdash\   Reference a single snapshot.\\
211\texttt{dd = ds.all\_data()} \textemdash\ Select the entire volume.\\
212\texttt{a = dd[}\textit{field\_name}\texttt{]} \textemdash\ Copies the contents of \textit{field} into the
213YTArray \texttt{a}. Similarly for other data containers.\\
214\texttt{ds.field\_list} \textemdash\ A list of available fields in the snapshot. \\
215\texttt{ds.derived\_field\_list} \textemdash\ A list of available derived fields
216in the snapshot. \\
217\texttt{val, loc = ds.find\_max("Density")} \textemdash\ Find the \texttt{val}ue of
218the maximum of the field \texttt{Density} and its \texttt{loc}ation. \\
219\texttt{sp = ds.sphere(}\textit{cen}\texttt{,}\textit{radius}\texttt{)} \textemdash\   Create a spherical data
220container. \textit{cen} may be a coordinate, or ``max'' which
221centers on the max density point. \textit{radius} may be a float in
222code units or a tuple of (\textit{length, unit}).\\
223
224\texttt{re = ds.region(\textit{cen}, \textit{left edge}, \textit{right edge})} \textemdash\ Create a
225rectilinear data container. \textit{cen} is required but not used.
226\textit{left} and \textit{right edge} are coordinate values that define the region.
227
228\texttt{di = ds.disk(\textit{cen}, \textit{normal}, \textit{radius}, \textit{height})} \textemdash\
229Create a cylindrical data container centered at \textit{cen} along the
230direction set by \textit{normal},with total length
231 2$\times$\textit{height} and with radius \textit{radius}. \\
232
233\texttt{ds.save\_object(sp, \textit{``sp\_for\_later''})} \textemdash\ Save an object (\texttt{sp}) for later use.\\
234\texttt{sp = ds.load\_object(\textit{``sp\_for\_later''})} \textemdash\ Recover a saved object.\\
235
236
237\subsection{Defining New Fields}
238\texttt{yt} expects on-disk fields, fields generated on-demand and in-memory.
239Field can either be created before a dataset is loaded using \texttt{add\_field}:
240\texttt{def \_metal\_mass(\textit{field},\textit{data})}\\
241\texttt{\hspace{4 mm} return data["metallicity"]*data["cell\_mass"]}\\
242\texttt{add\_field("metal\_mass", units='g', function=\_metal\_mass)}\\
243Or added to an existing dataset using \texttt{ds.add\_field}:
244\texttt{ds.add\_field("metal\_mass", units='g', function=\_metal\_mass)}\\
245
246\subsection{Slices and Projections}
247\settowidth{\MyLen}{\texttt{multicol} }
248\texttt{slc = yt.SlicePlot(ds, \textit{axis or normal vector}, \textit{field}, \textit{center=}, \textit{width=}, \textit{weight\_field=}, \textit{additional parameters})} \textemdash\ Make a slice plot
249perpendicular to \textit{axis} (specified via 'x', 'y', or 'z') or a normal vector for an off-axis slice of \textit{field} weighted by \textit{weight\_field} at (code-units) \textit{center} with
250\textit{width} in code units or a (value, unit) tuple. Hint: try \textit{yt.SlicePlot?} in IPython to see additional parameters.\\
251\texttt{slc.save(\textit{file\_prefix})} \textemdash\ Save the slice to a png with name prefix \textit{file\_prefix}.
252\texttt{.save()} works similarly for the commands below.\\
253
254\texttt{prj = yt.ProjectionPlot(ds, \textit{axis}, \textit{field}, \textit{additional params})} \textemdash\ Make a projection. \\
255\texttt{prj = yt.OffAxisProjectionPlot(ds, \textit{normal}, \textit{fields}, \textit{center=}, \textit{width=}, \textit{depth=},\textit{north\_vector=},\textit{weight\_field=})} \textemdash Make an off axis projection. Note this takes an array of fields. \\
256
257\subsection{Plot Annotations}
258\settowidth{\MyLen}{\texttt{multicol} }
259Plot callbacks are functions itemized in a registry that is attached to every plot object. They can be accessed and then called like \texttt{ prj.annotate\_velocity(factor=16, normalize=False)}. Most callbacks also accept a \textit{plot\_args} dict that is fed to matplotlib annotator. \\
260\texttt{velocity(\textit{factor=},\textit{scale=},\textit{scale\_units=}, \textit{normalize=})} \textemdash\ Uses field "x-velocity" to draw quivers\\
261\texttt{magnetic\_field(\textit{factor=},\textit{scale=},\textit{scale\_units=}, \textit{normalize=})} \textemdash\ Uses field "Bx" to draw quivers\\
262\texttt{quiver(\textit{field\_x},\textit{field\_y},\textit{factor=},\textit{scale=},\textit{scale\_units=}, \textit{normalize=})} \\
263\texttt{contour(\textit{field=},\textit{ncont=},\textit{factor=},\textit{clim=},\textit{take\_log=}, \textit{additional parameters})} \textemdash Plots a number of contours \textit{ncont} to interpolate \textit{field} optionally using \textit{take\_log}, upper and lower \textit{c}ontour\textit{lim}its and \textit{factor} number of points in the interpolation.\\
264\texttt{grids(\textit{alpha=}, \textit{draw\_ids=}, \textit{periodic=}, \textit{min\_level=}, \textit{max\_level=})} \textemdash Add grid boundaries. \\
265\texttt{streamlines(\textit{field\_x},\textit{field\_y},\textit{factor=},\textit{density=})}\\
266\texttt{clumps(\textit{clumplist})} \textemdash\ Generate \textit{clumplist} using the clump finder and plot. \\
267\texttt{arrow(\textit{pos}, \textit{code\_size})} Add an arrow at a \textit{pos}ition. \\
268\texttt{point(\textit{pos}, \textit{text})} \textemdash\ Add text at a \textit{pos}ition. \\
269\texttt{marker(\textit{pos}, \textit{marker=})} \textemdash\ Add a matplotlib-defined marker at a \textit{pos}ition. \\
270\texttt{sphere(\textit{center}, \textit{radius}, \textit{text=})} \textemdash\ Draw a circle and append \textit{text}.\\
271\texttt{hop\_circles(\textit{hop\_output}, \textit{max\_number=}, \textit{annotate=}, \textit{min\_size=}, \textit{max\_size=}, \textit{font\_size=}, \textit{print\_halo\_size=}, \textit{fixed\_radius=}, \textit{min\_mass=}, \textit{print\_halo\_mass=}, \textit{width=})} \textemdash\ Draw a halo, printing it's ID, mass, clipping halos depending on number of particles (\textit{size}) and optionally fixing the drawn circle radius to be constant for all halos.\\
272\texttt{hop\_particles(\textit{hop\_output},\textit{max\_number=},\textit{p\_size=},\\
273\textit{min\_size},\textit{alpha=})} \textemdash\ Draw particle positions for member halos with a certain number of pixels per particle.\\
274\texttt{particles(\textit{width},\textit{p\_size=},\textit{col=}, \textit{marker=}, \textit{stride=}, \textit{ptype=}, \textit{stars\_only=}, \textit{dm\_only=}, \textit{minimum\_mass=}, \textit{alpha=})}  \textemdash\  Draw particles of \textit{p\_size} pixels in a slab of \textit{width} with \textit{col}or using a matplotlib \textit{marker} plotting only every \textit{stride} number of particles.\\
275\texttt{title(\textit{text})}\\
276
277\subsection{The $\sim$/.yt/ Directory}
278\settowidth{\MyLen}{\texttt{multicol} }
279yt will automatically check for configuration files in a special directory (\texttt{\$HOME/.yt/}) in the user's home directory.
280
281The \texttt{config} file \textemdash\ Settings that control runtime behavior. \\
282The \texttt{my\_plugins.py} file \textemdash\ Add functions, derived fields, constants, or other commonly-used Python code to yt.
283
284
285\subsection{Analysis Modules}
286\settowidth{\MyLen}{\texttt{multicol}}
287The import name for each module is listed at the end of each description (see \textbf{yt Imports}).
288
289\texttt{Absorption Spectrum} \textemdash\ (\texttt{absorption\_spectrum}). \\
290\texttt{Clump Finder} \textemdash\ Find clumps defined by density thresholds (\texttt{level\_sets}). \\
291\texttt{Halo Finding} \textemdash\ Locate halos of dark matter particles (\texttt{halo\_finding}). \\
292\texttt{Light Cone Generator} \textemdash\ Stitch datasets together to perform analysis over cosmological volumes. \\
293\texttt{Light Ray Generator} \textemdash\ Analyze the path of light rays.\\
294\texttt{Rockstar Halo Finding} \textemdash\ Locate halos of dark matter using the Rockstar halo finder (\texttt{halo\_finding.rockstar}). \\
295\texttt{Star Particle Analysis} \textemdash\ Analyze star formation history and assemble spectra (\texttt{star\_analysis}). \\
296\texttt{Sunrise Exporter} \textemdash\ Export data to the sunrise visualization format (\texttt{sunrise\_export}). \\
297
298
299\subsection{Parallel Analysis}
300\settowidth{\MyLen}{\texttt{multicol}}
301Nearly all of yt is parallelized using
302MPI\@.  The \textit{mpi4py} package must be installed for parallelism in yt.  To
303install \textit{pip install mpi4py} on the command line usually works.
304Execute python in parallel similar to this:\\
305\textit{mpirun -n 12 python script.py}\\
306The file \texttt{script.py} must call the \texttt{yt.enable\_parallelism()} to
307turn on yt's parallelism.  If this doesn't happen, all cores will execute the
308same serial yt script.  This command may differ for each system on which you use
309yt; please consult the system documentation for details on how to run parallel
310applications.
311
312\texttt{parallel\_objects()} \textemdash\ A way to parallelize analysis over objects
313(such as halos or clumps).\\
314
315
316\subsection{Git}
317\settowidth{\MyLen}{\texttt{multicol}}
318Please see \url{https://git-scm.com/} for the latest Git documentation.
319
320\texttt{git clone https://github.com/yt-project/yt} \textemdash\ Clone the yt
321repository. \\
322\texttt{git status} \textemdash\ Show status of working tree.\\
323\texttt{git diff} \textemdash\ Show changed files in the working tree. \\
324\texttt{git log} \textemdash\ Show a log of changes in reverse chronological
325oder.\\
326\texttt{git revert <commit>} \textemdash\ Revert the changes in an existing
327commit and create a new commit with reverted changes. \\
328\texttt{git add <pathspec>} \textemdash\ Stage changes in the working tree to
329the index. \\
330\texttt{git commit} \textemdash\ Commit staged changes to the repository. \\
331\texttt{git merge <branch>} Merge the revisions from the specified branch on
332top of the current branch.\\
333\texttt{git push <remote>} \textemdash\ Push changes to remote repository. \\
334\texttt{git push <remote> <branch>} \textemdash\ Push changes in specified
335branch to remote repository. \\
336\texttt{git pull <remote> <branch>} \textemdash\ Pull changes from the
337specified branch of the remote repository. This is equivalent to \texttt{git
338fetch <remote>} and then \texttt{git merge <remote>/<branch>}.\\
339
340\subsection{FAQ}
341\settowidth{\MyLen}{\texttt{multicol}}
342
343\texttt{slc.set\_log('field', False)} \textemdash\ When plotting \texttt{field}, use linear scaling instead of log scaling.
344
345
346%\rule{0.3\linewidth}{0.25pt}
347%\scriptsize
348
349% Can put some final stuff here like copyright etc...
350
351\end{multicols}
352
353\end{document}
354