Commits

Matthew Turk committed 6dee662

Making progress on derived fields talk.

Comments (0)

Files changed (5)

scripts/derived_fields.py

 def Dinosaurs(field, data):
     return (data["Density"]**(2./3) /
             data["Temperature"]**(0.5))
-
-pf = load("Enzo_64/DD0023/data0023")
-dd = pf.h.all_data()
-
-dinosaurs, = dd.quantities["TotalQuantity"](["Dinosaurs"])
-print "Total T-Rexes per Second: %0.3e" % (dinosaurs)

scripts/derived_fields_tq.py

+from yt.mods import *
+
+@derived_field(name = "Dinosaurs", units = "TRexPerS")
+def Dinosaurs(field, data):
+    return (data["Density"]**(2./3) /
+            data["Temperature"]**(0.5))
+
+pf = load("Enzo_64/DD0023/data0023")
+dd = pf.h.all_data()
+
+dinosaurs, = dd.quantities["TotalQuantity"](["Dinosaurs"])
+print "Total T-Rexes per Second: %0.3e" % (dinosaurs)

scripts/examine_field.py

+from yt.mods import *
+
+pf = load("Enzo_64/DD0030/data0030")
+pf.h
+print pf.field_info["Density"].get_units()
+print pf.field_info["MeanMolecularWeight"].get_source()

scripts/field_parameters.py

+from yt.mods import *
+
+@derived_field(name = "delta_Velocity",
+               validators = [ValidateParameter("bulk_velocity")])
+def delta_Velocity(field, data):
+    bv = data.get_field_parameter("bulk_velocity")
+    delta_v = ((data["x-velocity"] - bv[0])**2.0
+            +  (data["y-velocity"] - bv[1])**2.0
+            +  (data["z-velocity"] - bv[2])**2.0)**0.5
+    return delta_v
+
+pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+
+sp_small = pf.h.sphere("max", (0.01, 'mpc'))
+bv = sp_small.quantities["BulkVelocity"]()
+
+sp = pf.h.sphere("max", (1.0, 'mpc'))
+sp.set_field_parameter("bulk_velocity", bv)
+
+print sp["delta_Velocity"].min()
+print sp["delta_Velocity"].max()
-\documentclass[14pt]{beamer}
+\documentclass[13pt]{beamer}
 \newcommand{\bigsimple}[1]{
   \begin{frame}[c]{}
   \begin{center}
 \usepackage[latin1]{inputenc}
 % or whatever
 
-%\usepackage{times}
 \usepackage[T1]{fontenc}
 \usepackage{tgadventor}
+\newcommand\smfont{\fontsize{8}{6.4}\selectfont}
 
 \usepackage{graphicx}
 \usepackage{color}
 \usepackage{fancyvrb}
 \usepackage{../pastie}
 
-\title{\yt{}: A Deep Dive}
+\title{Fields and Quantities}
 
 \begin{document}
 
  \titlepage
 \end{frame}
 
+% How to create a new derived field
+% Where can I find information about derived fields?
+% How to use spatial information in that derived field
+%   Where does that spatial information come from?
+%   How do you efficiently slice?
+% How to pass parameters in to a derived field
+%   Walk through "Delta" function
+% What are derived quantities?
+% Which DQs are available?
+
+
+\mediumsimple{(start slow, end fast)}
+
 \mediumsimple{First a few pedantic exercises}
 
 \defslide{Fields}{Fluid or particle characteristics defined everywhere in the
 simulation where fluids or particles are also found.}
 
+\defslide{Known Fields}{Fields that are known to exist on-disk under some
+circumstances in a particular output type.}
+
+\defslide{Derived field}{A field defined by a function that transforms
+existing, on-disk fields.}
+
+
 \begin{frame}[t]{Common Fields}
 \begin{itemize}
 \item
 <<d['scripts/field_list.py|fn|py|pyg|l']>>
 \end{frame}
 
-\defslide{Derived field}{A field defined by a function that transforms
-existing, on-disk fields.}
+\mediumsimple{Auto-generated
+list:\\\texttt{http://yt-project.org/docs/2.3/reference/field\_list.html}}
 
 \begin{frame}[fragile,t]{}
 \tiny
 
 \defslide{Field Object}{An object describing how to obtain a field, which
 carries with it information about units, conversion factors, integration,
-labelling, and so on.}
+labeling, and so on.}
 
 \begin{frame}[fragile,t]{}
 \tiny
-<<d['scripts/derived_fields.py|fn|pyg|l']>>
+<<d['scripts/examine_field.py|fn|pyg|l']>>
 \hline
-<<d['scripts/derived_fields.py|fn|py|pyg|l']>>
+<<d['scripts/examine_field.py|fn|py|pyg|l']>>
 \end{frame}
 
+\begin{frame}[fragile,t]{Defining a Field}
+\hspace{1.0in}
+\tiny
+<<d['scripts/derived_fields.py|fn|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{Arguments to \texttt{derived\_field}}
+\begin{center}
+\smfont{}
+\begin{tabular}{l|p{2.5in}}
+\texttt{function} & The function that will define the field.  Accepts two
+arguments: \texttt{field} and \texttt{data}.  \texttt{data} will always be a
+data container, and \texttt{field} is the \texttt{DerivedField} object. \\[9pt]
+%\hline
+\texttt{convert\_function} & A function that accepts \texttt{data} and returns
+the conversion factor to CGS.  \\[9pt]
+%\hline
+\texttt{units} & A text field of units, suitable for \LaTeX processing. \\[9pt]
+%\hline
+\texttt{projected\_units} & The units after projection (i.e., line integral)
+\\[9pt]
+%\hline
+\texttt{projection\_conversion} & Units to multiply against after projecting
+through the domain.\\[9pt]
+%\hline
+\texttt{take\_log} & Should we tend to take the log of this field when we plot
+it? \\[9pt]
+%\hline
+\texttt{particle\_type} & Is this field shaped like particle data? \\[9pt]
+%\hline
+\texttt{display\_name} & What's a nice, \LaTeX-friendly display of this field?
+\\[9pt]
+%\hline
+\texttt{validators} & List of ``validators'' that govern the type of data
+passed in.
+\end{tabular}
+\end{center}
+\end{frame}
+
+\bigsimple{What's a validator?}
+
+\begin{frame}[t]{}
+\begin{center}
+\smfont{}
+\begin{tabular}{l|p{2.5in}}
+\texttt{ValidateParameter} & Ensure that a particular parameter is passed in
+via \texttt{field\_parameters}. \\[9pt]
+\texttt{ValidateDataField} & Ensure that a dataset has a particular data field.
+\\[9pt]
+\texttt{ValidateSpatial} & Ensure that we are passed 3D spatial data.  Accepts
+an argument of the number of extra zones in each direction. \\[9pt]
+\texttt{ValidateGridType} & Ensure we have an actual grid object.
+\end{tabular}
+\end{center}
+\end{frame}
+
+\begin{frame}[fragile, t]{Example: Field Parameters}
+\tiny
+<<d['scripts/field_parameters.py|fn|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{Example: Field Parameters}
+\tiny
+<<d['scripts/field_parameters.py|fn|py|pyg|l']>>
+\end{frame}
+
+
 \end{document}