# Authoring a Lambda

Spatial lambdas are typically composed of three main components:

**1. Input Definition**

Specify the dataset(s) and region of interest (bounding box or selection) to process.

**2. Compute Function**

Write code that iterates through voxels and applies your logic. For example, summing the ore\_grade property forvoxels above a grade threshold.

**3. Output**

Return a summary value (e.g., total\_volume) or create a new dataset (e.g., filtered voxels). Lambdas can alsoattach files or emit logs during execution.

**Sample Python Lambda**

Here's a basic example that sums the volume of high-grade voxels:

```python
def lambda_handler (context, voxel_reader, voxel_writer): 
  total_volume = 0.0
  for voxel in voxel_reader:
    if voxel.properties.get('grade',0.0) &gt;= 0.5: 
      total_volume += voxel.size
  return {'total_volume': total_volume}

```

**<span style="font-size: 11.5pt;">Code Explanation</span>**

<span style="font-size: 9.0pt; font-family: 'IBM Plex Mono'; mso-bidi-font-family: 'IBM Plex Mono';">voxel\_reader</span>**<span style="font-size: 10.5pt;">: </span>**<span style="font-size: 10.5pt;">Provides voxel objects with property dictionaries and geometry</span>

<span style="font-size: 9.0pt; font-family: 'IBM Plex Mono'; mso-bidi-font-family: 'IBM Plex Mono';">voxel.properties.get('grade', 0.0)</span>**<span style="font-size: 10.5pt;">: </span>**<span style="font-size: 10.5pt;">Safely retrieves the grade property with a default valueof 0.0</span>

<span style="font-size: 9.0pt; font-family: 'IBM Plex Mono'; mso-bidi-font-family: 'IBM Plex Mono';">voxel.size</span>**<span style="font-size: 10.5pt;">: </span>**<span style="font-size: 10.5pt;">Represents the volume of a voxel (e.g., 1 m³)</span>

**<span style="font-size: 10.5pt;">Return value: </span>**<span style="font-size: 10.5pt;">Dictionary with the computed total volume that will appear in reports</span>