Skip to main content

Python library for working with Leapfrog calculation sets (.lfcalc files)

Project description

Automating Leapfrog Workflows with Pollywog – An Independent Open-Source Tool

DOI-badge docs-badge lite-badge

Pollywog is a Python library for building, manipulating, and automating Leapfrog calculation sets programmatically.

Table of Contents

Why Pollywog?

If you work with Leapfrog for geological modeling and resource estimation, you know that building calculation sets (.lfcalc files) manually can be:

  • Time-consuming – Repetitive point-and-click operations
  • Error-prone – Easy to make mistakes in complex formulas
  • Hard to maintain – Difficult to update across multiple projects
  • Not version-controlled – Changes are hard to track and review
  • Not automatable – Can't script or integrate with other tools

Pollywog solves these problems by letting you define calculations in Python code that is:

  • Programmatic and automatable
  • Version-controlled (Git-friendly)
  • Testable and reproducible
  • Easy to refactor and maintain
  • Integrated with ML pipelines (scikit-learn)

Key Features

Core Functionality

  • Read and write .lfcalc files programmatically
  • Create calculations with Python classes (Number, Category, If, etc.)
  • Query and filter calculation sets like pandas DataFrames
  • Topological sorting for automatic dependency resolution
  • Rich display in Jupyter notebooks with interactive trees

Helper Functions

  • Mathematical operations: Sum, Product, Average, WeightedAverage
  • Transformations: Scale, Normalize
  • Classification: CategoryFromThresholds
  • Dual mode: Return complete calculations (with name) or expressions (without name) for composition

Machine Learning Integration

  • Convert scikit-learn decision trees to Leapfrog calculations
  • Convert random forests to ensemble calculations
  • Convert linear models to equations
  • Support for both regression and classification

Domain-Based Calculations

  • Multi-domain resource modeling
  • Weighted averages by domain proportions
  • Conditional logic for different geological units

Quick Start

from pollywog.core import CalcSet, Number
from pollywog.helpers import WeightedAverage

# Create a calculation set
calcset = CalcSet([
    # Clean data
    Number("Au_clean", "clamp([Au], 0)",
           comment_equation="Remove negative values"),
    
    # Domain-weighted grade
    WeightedAverage(
        variables=["Au_oxide", "Au_sulfide", "Au_transition"],
        weights=["prop_oxide", "prop_sulfide", "prop_transition"],
        name="Au_composite",
        comment="Domain-weighted gold grade"
    ),
    
    # Apply recovery
    Number("Au_recovered", "[Au_composite] * 0.88",
           comment_equation="88% metallurgical recovery"),
])

# Export to Leapfrog
calcset.to_lfcalc("my_calculations.lfcalc")

Then import my_calculations.lfcalc into Leapfrog and you're done! ✨

⚠️ Note: Pollywog is in active development. Always backup your Leapfrog projects before testing. Report issues on GitHub.

Legal Disclaimer

Pollywog is an independent open-source tool developed to support the automation of workflows involving .lfcalc files used in Leapfrog software by Seequent. This tool does not perform reverse engineering, does not modify Leapfrog, and does not access its source code or proprietary libraries. Pollywog operates exclusively on user-generated files and is designed to complement Leapfrog through external automation.

Important:

  • Pollywog is not affiliated with, endorsed by, or sponsored by Seequent or any company associated with Leapfrog
  • Use of this tool does not violate Leapfrog’s license terms or Seequent’s policies
  • Users are encouraged to review Leapfrog’s terms of use before integrating Pollywog into commercial or corporate environments
  • The author is not responsible for any misuse of the tool that may breach Seequent’s licensing terms

Installation

From PyPI (Recommended)

pip install lf_pollywog

From GitHub (Latest Development Version)

pip install git+https://github.com/endarthur/pollywog.git

Try in Your Browser (No Installation)

Try Pollywog without installing anything using JupyterLite: https://endarthur.github.io/pollyweb

Note: JupyterLite runs in your browser and has limitations (no file system access, limited libraries). Files are stored in browser memory and won't persist if you clear your cache. Download your work regularly! For production use, preferably install locally.

Usage Examples

1. Reading and Writing .lfcalc Files

from pollywog.core import CalcSet, Number

# Read existing file
calcset = CalcSet.read_lfcalc("path/to/file.lfcalc")

# Modify calculations
calcset.items.append(Number("new_calc", "[Au] * 2"))

# Export modified version
calcset.to_lfcalc("output.lfcalc")

2. Creating Calculations from Scratch

from pollywog.core import Number, CalcSet

calcset = CalcSet([
    Number("Au_clean", "clamp([Au], 0)",
           comment_equation="Remove negative values"),
    Number("Au_log", "log([Au_clean] + 1e-6)",
           comment_equation="Log transform for kriging"),
])

calcset.to_lfcalc("drillhole_preprocessing.lfcalc")

3. Using Helper Functions

Helpers can return either complete calculations or just expressions for composition:

from pollywog.helpers import WeightedAverage, Product, CategoryFromThresholds
from pollywog.core import CalcSet, Number

calcset = CalcSet([
    # With name: Returns complete Number object
    WeightedAverage(
        variables=["Au_oxide", "Au_sulfide", "Au_transition"],
        weights=["prop_oxide", "prop_sulfide", "prop_transition"],
        name="Au_composite",
        comment="Domain-weighted gold grade"
    ),
    
    # Calculate gold equivalent (Ag and Cu converted to Au)
    Number("AuEq",
        "[Au_composite] + ([Ag_composite] * 0.011) + ([Cu_composite] * 1.5)",
        comment_equation="Gold equivalent grade (Ag/91, Cu*1.5 for price ratio)"
    ),
    
    # Without name: Returns expression for composition
    # Calculate net smelter return (NSR) per tonne
    Number("NSR_per_tonne",
        f"{Product(['Au_composite', '1800', '0.88'])} + "  # Au: price $1800/oz, 88% recovery
        f"{Product(['Ag_composite', '22', '0.75'])} + "    # Ag: price $22/oz, 75% recovery  
        f"{Product(['Cu_composite', '3.5', '0.85'])}"      # Cu: price $3.5/lb, 85% recovery
    ),
    
    # Classify by gold equivalent grade
    CategoryFromThresholds(
        variable="AuEq",
        thresholds=[0.5, 2.0],
        categories=["waste", "low_grade", "high_grade"],
        name="ore_class"
    ),
])

calcset.to_lfcalc("resource_model.lfcalc")

4. Machine Learning Model Conversion

Deploy machine learning models directly in Leapfrog:

from pollywog.conversion.sklearn import convert_tree, convert_forest
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor
from pollywog.core import CalcSet
import numpy as np

# Training data: Au grade, Cu grade, grind size (P80)
X = np.array([[1.2, 0.3, 75], [0.8, 0.5, 100], [2.0, 0.2, 75]])
y = np.array([0.88, 0.82, 0.91])  # Recovery values

# Train and convert decision tree
model = DecisionTreeRegressor(max_depth=3, random_state=42)
model.fit(X, y)

recovery_calc = convert_tree(
    model, 
    ["Au_composite", "Cu_composite", "P80"], 
    "Au_recovery_predicted"
)

# Export to Leapfrog
CalcSet([recovery_calc]).to_lfcalc("ml_recovery_model.lfcalc")

5. Domain-Based Calculations

from pollywog.core import CalcSet, Number, If
from pollywog.helpers import WeightedAverage

domains = ["oxide", "transition", "sulfide"]
metals = ["Au", "Ag", "Cu"]

# Domain-weighted grades for all metals
calcset = CalcSet([
    WeightedAverage(
        variables=[f"{metal}_{domain}" for domain in domains],
        weights=[f"prop_{domain}" for domain in domains],
        name=f"{metal}_composite",
        comment=f"Domain-weighted {metal} grade"
    )
    for metal in metals
])

# Apply domain-specific recovery
# Note: If objects require a list since they are separate structures
calcset.items.append(
    Number("Au_recovered", [
        If([
            ("[domain] = 'oxide'", "[Au_composite] * 0.92"),
            ("[domain] = 'transition'", "[Au_composite] * 0.85"),
            ("[domain] = 'sulfide'", "[Au_composite] * 0.78"),
        ], otherwise=["[Au_composite] * 0.75"])
    ])
)

calcset.to_lfcalc("multi_domain_workflow.lfcalc")

6. Querying CalcSets

Filter calculations like pandas DataFrames:

# Select items by name pattern
au_calcs = calcset.query('name.startswith("Au")')

# Use external variables
metals_of_interest = ["Au", "Ag"]
selected = calcset.query('any(name.startswith(m) for m in @metals_of_interest)')

# Complex queries
filtered = calcset.query('len(expression) > 1 and "log" in name')
  • Use item attributes (e.g., name, item_type) in expressions.
  • Reference external variables using @var syntax (e.g., name.startswith(@prefix)).
  • Supported helpers: len, any, all, min, max, sorted, re, str.

Documentation

📚 Full documentation: https://pollywog.readthedocs.io

License

MIT License – See LICENSE file for details.

Contributions

Contributions are very welcome! If you'd like to collaborate on Pollywog, whether through bug fixes, feature enhancements, new use cases, or documentation, please follow these steps:

  • Fork the repository
  • Create a feature branch (git checkout -b feature-name)
  • Make your changes and commit (git commit -m 'Add new feature')
  • Submit a pull request with a clear explanation of your changes

Before contributing, please:

  • Ensure your changes align with the project’s goals
  • Maintain consistent code style
  • Test your modifications whenever possible
  • Though It's ok to use LLMs to help write code or documentation, please review and understand all contributions to ensure quality and accuracy.

Feel free to open an issue if you have questions or suggestions.

Acknowledgements

Thanks to Debora Roldão for helping with organization of the project, documentation and design, Eduardo Takafuji for the initial discussion of the feasability of this all those years ago and Jessica da Matta for support and sanity checks along the way.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lf_pollywog-0.2.0.tar.gz (42.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lf_pollywog-0.2.0-py3-none-any.whl (48.5 kB view details)

Uploaded Python 3

File details

Details for the file lf_pollywog-0.2.0.tar.gz.

File metadata

  • Download URL: lf_pollywog-0.2.0.tar.gz
  • Upload date:
  • Size: 42.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lf_pollywog-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3db166ca67c89672c786ea4afc5600dbd33424a35caf0fe4d43bbbde97bd11cb
MD5 6b006b5f5004dbba1898170c59d2ee25
BLAKE2b-256 96d225e3b66053e7e68af7f474296b0ac412f91f388cf1c422f252e32e03ecc1

See more details on using hashes here.

Provenance

The following attestation bundles were made for lf_pollywog-0.2.0.tar.gz:

Publisher: publish-to-pypi.yml on endarthur/pollywog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lf_pollywog-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: lf_pollywog-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 48.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lf_pollywog-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a6a2aa88e1fae338768d4a57b7b51060ad6c6eea3ab1a0d54d11ff52502cb91
MD5 7b1f49c76151662dcf47f2b10a4ac0ee
BLAKE2b-256 a6e51788f2d2b53800264d5780facba3aa2b6835d7031c883b3e15c3b29f680f

See more details on using hashes here.

Provenance

The following attestation bundles were made for lf_pollywog-0.2.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on endarthur/pollywog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page