Drawing and Highlighting

[1]:


# Determines where configuration file is located # file contains directory info and model input settings # config_file = os.environ[ # "CANOPYHYDRO_CONFIG" # ] = f"{os.getcwd()}/canopyhydro_config.toml" # log_config = os.environ["CANOPYHYDRO_LOG_CONFIG"] = f"{os.getcwd()}/logging_config.yml"
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[1], line 10
      4 logger.setLevel(logging.CRITICAL)
      6 # Determines where configuration file is located
      7 # file contains directory info and model input settings
      8 config_file = os.environ[
      9     "CANOPYHYDRO_CONFIG"
---> 10 ] = f"{os.getcwd()}/canopyhydro_config.toml"
     11 log_config = os.environ["CANOPYHYDRO_LOG_CONFIG"] = f"{os.getcwd()}/logging_config.yml"

NameError: name 'os' is not defined
Let’s first discuss our low code approach to figure creation
Examine the output produced by the following two cells. Note that their outputs are the same,but the former uses quite a bit more code.
[1]:

from canopyhydro.CylinderCollection import CylinderCollection # Initializing a CylinderCollection object myCollection = CylinderCollection() # Converting a specified file to a CylinderCollection object myCollection.from_csv('example_tree.csv') # Requesting an plot of the tree projected onto the XZ plane ('fromt' view) myCollection.project_cylinders('XZ') myCollection.draw('XZ') # Requesting an plot of the tree projected onto the YZ plane ('side' view) myCollection.project_cylinders('YZ') myCollection.draw('YZ') # Requesting an plot of the tree projected onto the XY plane (Birds eye view) myCollection.project_cylinders('XY') myCollection.draw('XY')
2024.10.14 21:20:00.045 |MainThread   | INFO    | CylinderCollection.py:291 -             from_csv() | model - Processing <_io.TextIOWrapper name='./data/input/example_tree.csv' mode='r' encoding='UTF-8'>
2024.10.14 21:20:00.734 |MainThread   | INFO    | CylinderCollection.py:320 -             from_csv() | model - ./data/input/example_tree.csv initialized with 9998 cylinders
2024.10.14 21:20:00.737 |MainThread   | INFO    | CylinderCollection.py:335 -    project_cylinders() | model - Projection into XZ axis begun for file example_tree.csv
2024.10.14 21:20:16.357 |MainThread   | INFO    | utils.py:190 -      intermitent_log() | model - Cylinder projection: 44.3
Cylinder projection: 44.3
2024.10.14 21:20:35.224 |MainThread   | INFO    | CylinderCollection.py:344 -    project_cylinders() | model - Projection into XZ axis complete for file example_tree.csv
2024.10.14 21:20:35.333 |MainThread   | INFO    | CylinderCollection.py:400 -                 draw() | model - 9998 cylinders matched criteria
2024.10.14 21:20:35.339 |MainThread   | INFO    | geometry.py:563 -            draw_cyls() | model - Plotting cylinder collection
2024.10.14 21:20:38.549 |MainThread   | INFO    | CylinderCollection.py:335 -    project_cylinders() | model - Projection into YZ axis begun for file example_tree.csv
2024.10.14 21:21:18.265 |MainThread   | INFO    | CylinderCollection.py:344 -    project_cylinders() | model - Projection into YZ axis complete for file example_tree.csv
2024.10.14 21:21:18.302 |MainThread   | INFO    | CylinderCollection.py:400 -                 draw() | model - 9998 cylinders matched criteria
2024.10.14 21:21:18.308 |MainThread   | INFO    | geometry.py:563 -            draw_cyls() | model - Plotting cylinder collection
2024.10.14 21:21:22.928 |MainThread   | INFO    | CylinderCollection.py:335 -    project_cylinders() | model - Projection into XY axis begun for file example_tree.csv
2024.10.14 21:21:57.637 |MainThread   | INFO    | CylinderCollection.py:344 -    project_cylinders() | model - Projection into XY axis complete for file example_tree.csv
2024.10.14 21:21:57.666 |MainThread   | INFO    | CylinderCollection.py:400 -                 draw() | model - 9998 cylinders matched criteria
2024.10.14 21:21:57.671 |MainThread   | INFO    | geometry.py:563 -            draw_cyls() | model - Plotting cylinder collection
[1]:
<Axes: >
../_images/examples_tree_drawing_highlighting_4_17.png
../_images/examples_tree_drawing_highlighting_4_18.png
../_images/examples_tree_drawing_highlighting_4_19.png
[2]:
# Below We can see the minimal code needed to plot a tree
from canopyhydro.CylinderCollection import CylinderCollection
from matplotlib import pyplot as plt

# Requesting an plot of the tree projected onto the XZ plane ('fromt' view)
myCollection.draw('XZ')

# Requesting an plot of the tree projected onto the YZ plane ('side' view)
myCollection.draw('YZ')

# Requesting an plot of the tree projected onto the XY plane (Birds eye view)
myCollection.draw('XY')



2024.10.14 21:22:04.682 |MainThread   | INFO    | CylinderCollection.py:400 -                 draw() | model - 9998 cylinders matched criteria
2024.10.14 21:22:04.688 |MainThread   | INFO    | geometry.py:563 -            draw_cyls() | model - Plotting cylinder collection
2024.10.14 21:22:08.202 |MainThread   | INFO    | CylinderCollection.py:400 -                 draw() | model - 9998 cylinders matched criteria
2024.10.14 21:22:08.213 |MainThread   | INFO    | geometry.py:563 -            draw_cyls() | model - Plotting cylinder collection
2024.10.14 21:22:11.427 |MainThread   | INFO    | CylinderCollection.py:400 -                 draw() | model - 9998 cylinders matched criteria
2024.10.14 21:22:11.433 |MainThread   | INFO    | geometry.py:563 -            draw_cyls() | model - Plotting cylinder collection
[2]:
<Axes: >
../_images/examples_tree_drawing_highlighting_5_7.png
../_images/examples_tree_drawing_highlighting_5_8.png
../_images/examples_tree_drawing_highlighting_5_9.png
The latter, more succinct option is applicable for all plotted shapes, cylinder projections.
This includes watershed boundaries (e.g. convex hull), drip points as well as their ‘XY,’ ‘XZ’ and ‘ZY’ projections.
This is to say, if a requested object is not available when the draw function is called, then the object will be calculated with the default attributes and drawn
[3]:
# Plotting a trees cylinders, and the watershed boundary together

# Calling draw directly, we get a default hull:
#   created to encompass the branch tips, with curvature_alpha=1.8
myCollection.draw(
    "XY",
    include_alpha_shape=True
)

# if we define a custom hull first, the
# custom hull will be plotted instead

myCollection.watershed_boundary(
    plane="XY",
    curvature_alpha=0.15,
    filter_lambda=lambda: cyl_id > 100,
    draw=False,
)

myCollection.draw(
    "XY",
    include_alpha_shape=True
)
2024.10.14 21:23:19.995 |MainThread   | INFO    | CylinderCollection.py:400 -                 draw() | model - 9998 cylinders matched criteria
2024.10.14 21:23:20.001 |MainThread   | WARNING | CylinderCollection.py:422 -                 draw() | model - No XY plane alpha shape found. Running watershed_boundary
2024.10.14 21:23:20.005 |MainThread   | WARNING | CylinderCollection.py:493 -        get_end_nodes() | model - Graph not initialized, running initialize_graph_from with default values
2024.10.14 21:23:25.943 |MainThread   | INFO    | geometry.py:563 -            draw_cyls() | model - Plotting cylinder collection
2024.10.14 21:23:29.227 |MainThread   | ERROR   | geometry.py:591 -            draw_cyls() | model - Overlay must be a Polygon, a list of Polygons or coordinate list
2024.10.14 21:23:30.936 |MainThread   | INFO    | CylinderCollection.py:400 -                 draw() | model - 9998 cylinders matched criteria
2024.10.14 21:23:30.943 |MainThread   | INFO    | geometry.py:563 -            draw_cyls() | model - Plotting cylinder collection
2024.10.14 21:23:34.099 |MainThread   | ERROR   | geometry.py:591 -            draw_cyls() | model - Overlay must be a Polygon, a list of Polygons or coordinate list
[3]:
<Axes: >
../_images/examples_tree_drawing_highlighting_7_9.png
../_images/examples_tree_drawing_highlighting_7_10.png
[ ]:
# Highlighting the stem flow component
from canopyhydro.CylinderCollection import CylinderCollection
from matplotlib import pyplot as plt

# Initializing a CylinderCollection object
myCollection = CylinderCollection()

# Converting a specified file to a CylinderCollection object
myCollection.from_csv('example_tree.csv')

# Requesting an plot of the tree projected onto the XZ plane ('fromt' view)
myCollection.project_cylinders('XY')


myCollection.initialize_digraph_from()
myCollection.find_flow_components()
myCollection.calculate_flows()


myCollection.draw('XY',
                    highlight_lambda=lambda:is_stem,
                    #save = False, file_name_ext="docs_ex"  # disabled for tutorial
                    )
myCollection.draw('XZ',
                    highlight_lambda=lambda:is_stem,
                    #save = False, file_name_ext="docs_ex"  # disabled for tutorial
                    )
[ ]:
# Drawing various branch orders
myCollection.draw('XZ', filter_lambda=lambda:branch_order<=1, highlight_lambda=lambda:branch_order==1, save = True, file_name_ext="docs_ex")
myCollection.draw('XZ', filter_lambda=lambda:branch_order<=2, highlight_lambda=lambda:branch_order==2, save = True, file_name_ext="docs_ex")
myCollection.draw('XZ', filter_lambda=lambda:branch_order<=3, highlight_lambda=lambda:branch_order==3, save = True, file_name_ext="docs_ex")
myCollection.draw('XZ', filter_lambda=lambda:branch_order<=4, highlight_lambda=lambda:branch_order==4, save = True, file_name_ext="docs_ex")