Skip to content

Loading Captures#

The Data Framework loads captured data using the CaptureTarget class and the ProcedureManifest.

CaptureTarget#

Load a target directory:

import capturegraph.data as cg

target = cg.CaptureTarget("/path/to/MyPlant")

The CaptureTarget automatically:

  1. Reads the manifest.json to understand the data structure
  2. Recursively loads files and sessions
  3. Converts files to typed Python objects

Accessing Data#

Files#

Access files directly by name:

# Direct file access
reference = target.reference_image  # Returns loaded image
settings = target.settings          # Returns dict/string/etc.

Sessions#

Access session groups by prefix:

# Get all sessions with prefix "daily_capture"
sessions = target.sessions.daily_capture

# Iterate
for session in sessions:
    print(session.date, session.photo, session.notes)

# Vectorized access
all_photos = sessions.photo  # List of all photos
all_dates = sessions.date    # List of all dates

Nested Directories#

Access subdirectories:

# Access subdirectory
vitals = sessions.vitals

# Access files within
blood_pressure = sessions.vitals.bp
temperature = sessions.vitals.temp

Session Properties#

Each session has automatic metadata:

Property Type Description
date datetime Parsed from hex timestamp
id str Session folder name
path Path Absolute path to session
for session in sessions:
    print(f"Session {session.id} from {session.date}")
    print(f"  Located at: {session.path}")

The Manifest#

The ProcedureManifest describes the expected data structure:

{
  "files": {
    "photo": { "type": "PImage", "extension": "heic" },
    "notes": { "type": "PString", "extension": "json" }
  },
  "sessions": {
    "daily_capture": {
      "manifest": {
        "files": {
          "measurement": { "type": "PNumber", "extension": "json" }
        }
      }
    }
  }
}

The loader uses this to:

  • Know what files to expect
  • Convert each file to the correct type
  • Handle missing files gracefully

Handling Missing Data#

Missing data returns MissingType instead of raising errors:

import capturegraph.data as cg

for session in sessions:
    notes = session.notes
    if cg.is_missing(notes):
        print("No notes for this session")
    else:
        print(notes)

This prevents pipeline crashes from incomplete data.

Type Conversion#

Files are automatically converted based on their PType:

PType Python Type Notes
PImage PIL.Image Loaded image
PString str Text content
PNumber float Numeric value
PBool bool Boolean flag
PLocation Dict {latitude, longitude, altitude}
PWeather Dict Weather data

Complete Example#

import capturegraph.data as cg
import numpy as np

# Load target
target = cg.CaptureTarget("/path/to/MyPlant")

# Get sessions
sessions = target.sessions.daily

# Extract data
dates = sessions.date
temperatures = sessions.weather.temperature

# Filter valid temperatures
valid_temps = [t for t in temperatures if not cg.is_missing(t)]

# Analyze
print(f"Captured {len(sessions)} sessions")
print(f"Temperature range: {min(valid_temps):.1f}° - {max(valid_temps):.1f}°")

See Also#