Skip to main content

A Python implementation of the calculations and evaluations done by the Dew Point Calculator found at https://www.dpcalc.org/.

Project description

preservationeval

PyPI Python CI Coverage License

A Python implementation of the calculations and evaluations done by the Dew Point Calculator found at https://www.dpcalc.org/.

Details

This project is a Python implementation of the Dew Point Calculator created by the Image Permanence Institute. The original lookup tables from their published JavaScript are not redistributed. Instead, during installation, dp.js is downloaded, its integrity is verified via a pinned SHA-256 hash, and the table data is extracted by executing the JavaScript in an embedded V8 engine (PyMiniRacer) and converted into a Python module.

Installation

pip install preservationeval

Usage

Basic Examples

from preservationeval import pi, emc, mold

# Calculate Preservation Index
pi_value = pi(20, 50)  # temperature=20°C, RH=50%
print(f"Preservation Index: {pi_value}")

# Calculate EMC (Equilibrium Moisture Content)
emc_value = emc(20, 50)
print(f"EMC: {emc_value}%")

# Calculate Mold Risk
mold_risk = mold(20, 50)
print(f"Mold Risk: {mold_risk}")

Evaluating Conditions

The package also provides functions to rate environmental conditions:

from preservationeval import (
    pi, mold, rate_natural_aging, rate_mold_growth, EnvironmentalRating
)

# Rate preservation conditions (returns GOOD, OK, or RISK)
aging_risk = rate_natural_aging(pi(20, 50))
print(f"Natural aging: {aging_risk}")  # EnvironmentalRating.GOOD

mold_risk = rate_mold_growth(mold(20, 50))
print(f"Mold risk: {mold_risk}")  # EnvironmentalRating.GOOD

Interpreting Results

For details of how to use, see:

Development

Project Status Downloads Issues

Setup

# Clone the repository
git clone https://github.com/petter-b/preservationeval
cd preservationeval

# Install development dependencies
uv sync --extra dev

Development Tools

  • ruff: Code formatting, linting and code quality
  • mypy: Static type checking
  • pytest: Testing framework
  • pre-commit: Git hooks for code quality

Common Tasks

# Format code
uv run ruff format .

# Run linter
uv run ruff check .

# Type checking
uv run mypy .

# Run tests with coverage
uv run pytest --cov

Testing

CI Coverage CodeQL

Validation Testing

The package includes a validation framework that compares the Python implementation against the original JavaScript implementation from dpcalc.org.

Requirements
  • Node.js and npm must be installed (download)
  • Python test dependencies: uv sync --extra test
Test Data Setup

The test framework automatically:

  • Creates the tests/data directory (git-ignored)
  • Downloads the JavaScript reference implementation
  • Generates and saves test cases
  • Caches results for future test runs

You can manually trigger this setup:

# Download JavaScript reference implementation
# This happens automatically when running tests, or manually:
uv run python -m tests.validate_core

# Run all tests
uv run pytest

# Run only validation tests
uv run pytest tests/test_validation.py

# Run with verbose output
uv run pytest -v tests/test_validation.py

# Generate new test cases (ignore cached)
uv run pytest tests/test_validation.py --force-update

Code Quality

Ruff Ruff Mypy

Automation

Pre-commit Pre-commit CI Renovate dp.js Monitor

Releasing

Releases are triggered through the python-cicd.yml workflow. There are two methods:

  1. PR label — add one of these labels to a pull request: release-candidate, release-patch, release-minor, release-major
  2. Manual dispatch — trigger from the Actions tab and select a release type
Release type Version bump Target
release-candidate X.Y.ZrcN TestPyPI
release-patch X.Y.Z+1 PyPI
release-minor X.Y+1.0 PyPI
release-major X+1.0.0 PyPI

Production releases (patch/minor/major) require the [Unreleased] section in CHANGELOG.md to have entries. The workflow creates a git tag, publishes the sdist to PyPI, and creates a GitHub Release.

Development Notes

This project was developed with assistance from Claude AI (Anthropic) and to some extent Codeium and GitHub Copilot. All code has been validated and tested for accuracy.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See CHANGELOG.md for all changes and versioning details.

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

preservationeval-1.2.1.tar.gz (135.8 kB view details)

Uploaded Source

File details

Details for the file preservationeval-1.2.1.tar.gz.

File metadata

  • Download URL: preservationeval-1.2.1.tar.gz
  • Upload date:
  • Size: 135.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for preservationeval-1.2.1.tar.gz
Algorithm Hash digest
SHA256 a6b676a799e8db415d9e559eded3fd1f83df8f84fde00ca8b46edc1d09aac66b
MD5 75237c733c9e28b805e9a9c799df21b9
BLAKE2b-256 bc9428f914c10181252024ef3d826f9a646e2e98fee5686cd3a3f230b1463b9e

See more details on using hashes here.

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