Commits

Britton Smith committed 1e7af99

Adding files for clump finding talk.

Comments (0)

Files changed (13)

clump_finding.tex

+\documentclass[14pt]{beamer}
+\newcommand{\bigsimple}[1]{
+  \begin{frame}[c]{}
+  \begin{center}
+    {\huge \textbf{#1} }
+  \end{center}
+  \end{frame}
+}
+\newcommand{\mediumsimple}[1]{
+  \begin{frame}[c]{}
+  \begin{center}
+    \textbf{#1}
+  \end{center}
+  \end{frame}
+}
+\newcommand{\fullimage}[1]{
+  {
+    \usebackgroundtemplate{\includegraphics[width=\paperwidth,height=\paperheight]{#1}}
+    \begin{frame}[plain]{}
+    \end{frame}
+  }
+}
+\newcommand{\defslide}[2]{
+  \begin{frame}[t]{}
+  \begin{center}
+  ``#1''
+  \end{center}
+  \\
+  \vspace{1in}
+  \\
+  #2
+  \end{frame}
+}
+
+\setbeamercolor{normal text}{bg=black,fg=white}
+\setbeamertemplate{navigation symbols}{}
+\usecolortheme[named=white]{structure}
+\usetheme{default}
+\usepackage{relsize}
+\newcommand{\yt}{{\larger\texttt{yt}}}
+
+\usepackage[english]{babel}
+% or whatever
+
+\usepackage[latin1]{inputenc}
+% or whatever
+
+%\usepackage{times}
+\usepackage[T1]{fontenc}
+\usepackage{tgadventor}
+
+\usepackage{graphicx}
+\usepackage{color}
+\usepackage{fancyvrb}
+\usepackage{../pastie}
+\usepackage{verbatim}
+
+\title{Clump Finding}
+
+\begin{document}
+
+\begin{frame}
+ \titlepage
+\end{frame}
+
+\defslide{Clump}{The largest disconnected contour satisfying a certain
+  criterion, such as being gravitationally bound.}
+
+\fullimage{galaxy0030_Projection_x_Density_Density.png}
+
+\fullimage{galaxy0030_Projection_z_Density_Density.png}
+
+\begin{frame}[fragile, t]{{\small \texttt{find\_clumps.py}}}
+  \tiny
+  <<d['scripts/find_clumps.py|fn|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{{\small \texttt{find\_clumps.py}}}
+  \tiny
+  <<d['scripts/find_clumps.py|fn|py|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{{\small Clump Hierarchy}}
+{\small \texttt{galaxy0030\_clump\_hierarchy.txt}}
+\tiny
+\verbatiminput{galaxy0030_clump_hierarchy.txt}
+\end{frame}
+
+\begin{frame}[fragile, t]{{\small Top Level Clumps}}
+{\small \texttt{galaxy0030\_clumps.txt}}
+\tiny
+\verbatiminput{galaxy0030_clumps.txt}
+\end{frame}
+
+\mediumsimple{Use \texttt{pf.h.save\_object} to store objects for later
+  use.  The object is stored in the .yt file.}
+
+\begin{frame}[fragile, t]{{\small \texttt{find\_clumps\_and\_save.py}}}
+  \tiny
+  <<d['scripts/find_clumps_and_save.py|fn|pyg|l']>>
+\end{frame}
+
+\mediumsimple{Use \texttt{pf.h.load\_object} to load saved objects.}
+
+\begin{frame}[fragile, t]{{\small \texttt{load\_clumps.py}}}
+  \tiny
+  <<d['scripts/load_clumps.py|fn|pyg|l']>>
+\end{frame}
+
+\mediumsimple{\texttt{Clump} objects are data containers, mostly.
+  {\color{yellow} Clump objects cannot access particles.}}
+
+\begin{frame}[fragile, t]{{\small \texttt{clumps\_as\_data\_containers.py}}}
+  \tiny
+  <<d['scripts/clumps_as_data_containers.py|fn|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{{\small \texttt{clumps\_as\_data\_containers.py}}}
+  \tiny
+  <<d['scripts/clumps_as_data_containers.py|fn|py|pyg|l']>>
+\end{frame}
+
+\mediumsimple{Control how clumps are determined to be valid with the
+  \texttt{function} keyword when instantiating the master clump.}
+
+\begin{frame}[fragile, t]{}
+  The \texttt{function} keyword is a string evaluated with eval.
+ \tiny
+  <<d['scripts/eval_example.py|fn|pyg|l']>>
+  \hline
+  <<d['scripts/eval_example.py|fn|py|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{Example validity functions}
+  {\small \texttt{validity\_functions.py}}
+  \tiny
+  <<d['scripts/validity_functions.py|fn|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{Plotting Clumps}
+  {\small \texttt{project\_disk\_with\_clumps.py}}
+  \tiny
+  <<d['scripts/project_disk_with_clumps.py|fn|pyg|l']>>
+\end{frame}
+
+\fullimage{Clumps_Projection_z_Density_Density.png}
+
+\mediumsimple{Use \texttt{Clump.add\_info\_item} to write out more
+  information about each clump.}
+
+\begin{frame}[fragile, t]{Adding Clump Information}
+  {\small \texttt{more\_clump\_information.py}}
+  \tiny
+  <<d['scripts/more_clump_information.py|fn|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{}
+\tiny
+\verbatiminput{galaxy0030_clumps_new.txt}
+\end{frame}
+
+\end{document}

clump_finding_full.pdf

Binary file added.

output/clump_finding.pdf

Binary file added.

scripts/clumps_as_data_containers.py

+from yt.config import ytcfg 
+ytcfg['yt','suppressStreamLogging'] = 'True'
+
+from yt.mods import *
+from yt.analysis_modules.level_sets.api import *
+
+pf = load("data/IsolatedGalaxy/galaxy0030/galaxy0030")
+
+# Reload the clumps we found.
+master_clump = pf.h.load_object('My_Clumps')
+
+# Clump objects are data containers, so we can do this
+print "Master clump temperatures:"
+print master_clump['Temperature']
+
+# Clump objects have children
+print "Master clump has", len(master_clump.children), "children."
+print master_clump.children
+
+# The children are data objects, too
+print "Density of the first child:"
+print master_clump.children[0]['Density']
+
+# Clump objects cannot access particles! :-(

scripts/eval_example.py

+# eval accepts a string and evaluates it in the context 
+# of the existing variables.
+
+x = 'y > 5'
+
+y = 4
+print "y = ", y
+print x, eval(x)
+
+y = 6
+print "y = ", y
+print x, eval(x)

scripts/find_clumps.py

+from yt.mods import *
+from yt.analysis_modules.level_sets.api import *
+
+pf = load("data/IsolatedGalaxy/galaxy0030/galaxy0030")
+
+# The field over which contouring is done.
+field = "Density"
+
+# The multiplicative interval between contours.
+step = 2.0
+
+data_source = pf.h.disk([0.5, 0.5, 0.5], [0., 0., 1.], 
+                        8./pf.units['kpc'], 1./pf.units['kpc'])
+
+# Set min and max contours
+c_min = 10**na.floor(na.log10(data_source[field]).min()  )
+c_max = 10**na.floor(na.log10(data_source[field]).max()+1)
+
+# keep only clumps with at least 20 cells
+function = 'self.data["Density"].size > 20'
+
+# Create the base clump.
+master_clump = Clump(data_source, None, field,
+                     function=function)
+
+# Find the clumps!
+find_clumps(master_clump, c_min, c_max, step)
+
+# Write out the clump hierarchy.
+f = open('%s_clump_hierarchy.txt' % pf,'w')
+write_clump_hierarchy(master_clump, 0, f)
+f.close()
+
+# Write out the list of clumps.
+f = open('%s_clumps.txt' % pf,'w')
+write_clumps(master_clump, 0, f)
+f.close()

scripts/find_clumps_and_save.py

+from yt.mods import *
+from yt.analysis_modules.level_sets.api import *
+
+pf = load("data/IsolatedGalaxy/galaxy0030/galaxy0030")
+
+field = "Density"
+step = 2.0
+
+data_source = pf.h.disk([0.5, 0.5, 0.5], [0., 0., 1.], 
+                        8./pf.units['kpc'], 1./pf.units['kpc'])
+
+c_min = 10**na.floor(na.log10(data_source[field]).min()  )
+c_max = 10**na.floor(na.log10(data_source[field]).max()+1)
+
+function = 'self.data["Density"].size > 20'
+master_clump = Clump(data_source, None, field,
+                     function=function)
+find_clumps(master_clump, c_min, c_max, step)
+
+# Save the clump object for later use.
+pf.h.save_object(master_clump, 'My_Clumps')

scripts/load_clumps.py

+from yt.mods import *
+from yt.analysis_modules.level_sets.api import *
+
+pf = load("data/IsolatedGalaxy/galaxy0030/galaxy0030")
+
+# Reload the clumps we found.
+master_clump = pf.h.load_object('My_Clumps')

scripts/more_clump_information.py

+from yt.mods import *
+from yt.analysis_modules.level_sets.api import *
+from yt.analysis_modules.level_sets.clump_handling import recipes as clump_recipes
+
+pf = load("data/IsolatedGalaxy/galaxy0030/galaxy0030")
+
+# Reload the clumps we found.
+master_clump = pf.h.load_object('My_Clumps')
+
+# clear the list of info items to be printed
+master_clump.clear_clump_info()
+
+# Number of cells.
+master_clump.add_info_item('self.data["CellMassMsun"].size',
+                           '"Cells: %d" % value')
+# Gas mass in solar masses.
+master_clump.add_info_item('self.data["CellMassMsun"].sum()',
+                           '"Mass: %e Msolar" % value')
+# Volume-weighted Jeans mass.
+master_clump.add_info_item('self.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellVolume")',
+                           '"Jeans Mass (vol-weighted): %.6e Msolar" % value')
+
+# Add distance to center of mass of main clump
+# see YT_DEST/yt/analysis_modules/level_sets/clump_handling.py
+clump_recipes['DistanceToMainClump'](master_clump, units='kpc')
+
+# Mass-weighted Jeans mass.
+master_clump.add_info_item('self.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellMassMsun")',
+                           '"Jeans Mass (mass-weighted): %.6e Msolar" % value')
+# Max level.
+master_clump.add_info_item('self.data["GridLevel"].max()',
+                           '"Max grid level: %d" % value')
+# Minimum number density.
+master_clump.add_info_item('self.data["NumberDensity"].min()',
+                           '"Min number density: %.6e cm^-3" % value')
+# Maximum number density.
+master_clump.add_info_item('self.data["NumberDensity"].max()',
+                           '"Max number density: %.6e cm^-3" % value')
+
+
+# Write out the clump hierarchy.
+f = open('%s_clump_hierarchy_new.txt' % pf,'w')
+write_clump_hierarchy(master_clump, 0, f)
+f.close()
+
+# Write out the list of clumps.
+f = open('%s_clumps_new.txt' % pf,'w')
+write_clumps(master_clump, 0, f)
+f.close()

scripts/project_disk.py

+from yt.mods import *
+
+pf = load("data/IsolatedGalaxy/galaxy0030/galaxy0030")
+
+pc = PlotCollection(pf, center=[0.5, 0.5, 0.5])
+
+pc.add_projection('Density', 0, weight_field='Density')
+pc.add_projection('Density', 2, weight_field='Density')
+
+pc.set_width(15., 'kpc')
+
+pc.save()

scripts/project_disk_with_clumps.py

+from yt.mods import *
+from yt.analysis_modules.level_sets.api import *
+
+pf = load("data/IsolatedGalaxy/galaxy0030/galaxy0030")
+
+master_clump = pf.h.load_object('My_Clumps')
+
+# get all of the lowest level clumps
+all_clumps = get_lowest_clumps(master_clump)
+
+pc = PlotCollection(pf, center=[0.5, 0.5, 0.5])
+
+pc.add_projection('Density', 2, weight_field='Density')
+
+pc.set_width(15., 'kpc')
+
+# Overlay the clumps on the projection.
+pc.plots[0].modify['clumps'](all_clumps)
+
+pc.save('Clumps')

scripts/validity_functions.py

+# This is the default validity function.
+# This returns True if the clump is gravitationally bound.
+function = 'self.data.quantities["IsBound"](truncate=True,include_thermal_energy=True) > 1.0'
+
+# Keep clumps with a minimum number of cells.
+function = 'self.data["Density"].size > 20'
+
+# Keep clumps with a minimum mass.
+function = 'self.data["CellMassMsun"].sum() > 10.0'
+
+# Keep clumps above a threshold number density.
+function = '(self.data["NumberDensity"] > 1e6).any()'
+
+# Keep everything!
+function = 'True'

yt_clump_finding_algorithm.pdf

Binary file added.