Chapter 20: Guardian Tools Architecture and Implementation

Building standardized calculation tools using Guardian's extractDataBlock and customLogicBlock mini-policy pattern

This chapter details how to build Guardian Tools - think of them as mini policies that implement standardized calculation methodologies like CDM AR Tools. Using AR Tool 14 as our example, you'll learn the complete architecture for creating reusable calculation tools that can be integrated into any environmental methodology.

Learning Objectives

After completing this chapter, you will be able to:

  • Understand Guardian's Tools architecture as re-usable mini policies with data extraction and calculation blocks

  • Analyze AR Tool 14's production implementation in Guardian format

  • Build extractDataBlock workflows for schema input/output operations

  • Implement standardized calculation logic using customLogicBlock

  • Create modular, reusable tools for integration across multiple methodologies

  • Test and validate tool calculations against methodology test artifacts

Prerequisites

  • Completed Chapter 18: Custom Logic Block Development

  • Understanding of Guardian workflow blocks from Part IV

  • Access to AR Tool 14 artifacts: AR-Tool-14.json and ar-am-tool-14-v4.1.pdf

  • Familiarity with extractDataBlock documentation

What is AR Tool 14?

AR Tool 14 is a CDM (Clean Development Mechanism) methodological tool for "Estimation of carbon stocks and change in carbon stocks of trees and shrubs in A/R CDM project activities." It provides standardized methods for:

Primary Purpose

  • Tree biomass estimation using allometric equations, sampling plots, or proportionate crown cover

  • Shrub biomass estimation based on crown cover measurements

  • Carbon stock changes calculated between two points in time or as annual changes

  • Uncertainty management with discount factors for conservative estimates

Key Calculation Methods

From the AR Tool 14 PDF, the tool supports multiple approaches:

  1. Measurement of sample plots - Stratified random sampling and double sampling

  2. Modelling approaches - Tree growth and stand development models

  3. Proportionate crown cover - For sparse vegetation scenarios

  4. Direct change estimation - Re-measurement of permanent plots

Guardian Tools Architecture

AR Tool 14 within policy editor

Mini-Policy Pattern

Guardian Tools usually follow a three-block pattern:

Block Flow Architecture

The Tool workflow follows this pattern:

  1. Input Event β†’ get_ar_tool_14 (extractDataBlock)

  2. Data Processing β†’ calc_ar_tool_14 (customLogicBlock)

  3. Output Event β†’ set_ar_tool_14 (extractDataBlock)

extractDataBlock: Data Input/Output Engine

Understanding extractDataBlock

The extractDataBlock is Guardian's mechanism for working with embedded schema data. From the documentation:

"This block is used for VC documents which are based on (or 'conform to') a schema which contains embedded schemas, extractDataBlock provides means to extract a data set which corresponds to any of these embedded schemas (at any depth level), and if required after processing to return the updated values back into the VC dataset to their original 'place'."

AR Tool 14 Schema Integration

In our AR Tool 14 implementation, the extractDataBlock references schema #632fd070-d788-49ae-889b-cd281c6c7194&1.0.0 which is published version of Tool 14 schema. You can see schema excel within PDD-schema.xlsx:

This extracts the AR Tool 14 input data structure from the parent document, containing parameters like:

  • Tree measurements - DBH, height, species data

  • Plot information - Area, sampling design, stratum details

  • Calculation methods - Selected approaches for biomass estimation

  • Uncertainty parameters - Confidence levels and discount factors

Data Extraction Process

When a policy workflow calls the AR Tool 14, the extraction process works as follows:

customLogicBlock: AR Tool 14 Calculation Engine

Production JavaScript Implementation

The AR Tool 14 customLogicBlock contains the actual calculation engine. From our AR-Tool-14.json artifact, here's the implementation structure:

Stratified Random Sampling Implementation

Code for stratified random sampling from AR Tool 14:

Uncertainty Management System

AR Tool 14 also implements a sophisticated uncertainty discount system:

Building Your Own Tool

Step 1: Define Tool Schema

First, create a schema that captures all the input parameters for your calculation methodology:

Step 2: Implement Tool Policy Structure

Create the three-block tool structure:

Step 3: Implement Calculation Logic

Build your customLogicBlock calculation function following the Guardian pattern:

Tool Integration in Parent Policies

Calling Tools from Methodologies

Guardian Tools are designed to be called from parent methodology policies. Here's how VM0033 would integrate AR Tool 14:

Tool integration in new project submission flow

Tool Event Configuration

Tools communicate with parent policies through Guardian's event system:

Testing and Validation Framework

Unit Testing Tool Calculations

Test individual calculation functions against methodology test cases:

Best Practices for Guardian Tools

Design Principles

  1. Single Responsibility: Each tool should implement exactly one methodology or calculation standard

  2. Schema Clarity: Design clear, well-documented input/output schemas

  3. Modular Architecture: Break complex calculations into testable functions

  4. Error Resilience: Handle edge cases and invalid inputs gracefully

  5. Performance: Optimize for large dataset processing

  6. Validation: Include comprehensive uncertainty and validation logic

Chapter Summary

Guardian Tools provide a powerful architecture for implementing standardized calculation methodologies as reusable mini policies. Key concepts:

  • Tools are like mini policies that follow the extractDataBlock β†’ customLogicBlock β†’ extractDataBlock pattern

  • AR Tool 14 demonstrates complete implementation of complex biomass calculations with uncertainty management

  • extractDataBlock handles schema-based data input and output operations automatically

  • customLogicBlock contains the actual methodology calculation logic in JavaScript

  • Production examples from AR Tool 14 show real implementation patterns for stratified sampling, uncertainty discounts, and error handling

  • Integration patterns enable tools to be called from parent methodology policies

  • Testing frameworks ensure calculation accuracy against methodology test artifacts

Next Steps

Chapter 21 will demonstrate comprehensive testing and validation frameworks for custom logic blocks for individual tools and complete policy.

References and Further Reading


Last updated