ytree.analysis.analysis_pipeline.AnalysisPipeline
- class ytree.analysis.analysis_pipeline.AnalysisPipeline(output_dir=None)[source]
Initialize an AnalysisPipeline.
An AnalysisPipeline allows one to create a workflow of analysis to be performed on a node/halo in a tree. This is done by creating functions that minimally accept a node as the first argument and providing these to the AnalysisPipeline in the order they are meant to be run. This makes it straightforward to organize an analysis workflow into a series of distinct, reusable functions.
- Parameters:
output_dir (optional, str) – Path to a directory into which any files will be saved. The directory will be created if it does not already exist.
Examples
>>> import ytree >>> >>> def my_analysis(node): ... node["test_field"] = 2 * node["mass"] >>> >>> def minimum_mass(node, value): ... return node["mass"] > value >>> >>> def my_recipe(pipeline): ... pipeline.add_operation(my_analysis) >>> >>> def do_cleanup(node): ... print (f"End of analysis for {node}.") >>> >>> a = ytree.load("arbor/arbor.h5") >>> >>> ap = AnalysisPipeline() >>> # don't analyze halos below 3e11 Msun >>> ap.add_operation(minimum_mass, 3e11) >>> ap.add_recipe(my_recipe) >>> ap.add_recipe(do_cleanup, always_do=True) >>> >>> trees = list(a[:]) >>> for tree in trees: ... for node in tree["forest"]: ... ap.process_target(node) >>> >>> a.save_arbor(trees=trees)
Methods
__init__([output_dir])add_operation(function, *args[, always_do, ...])Add an operation to the AnalysisPipeline.
add_recipe(function, *args, **kwargs)Add a recipe to the AnalysisPipeline.
process_target(target[, handoff_attrs])Process a node through the AnalysisPipeline.