Skip to main content

Calculate binomial efficiencies and their uncertainties

Project description

pycalceff

A Python project for calculating (binomial) efficiencies and their uncertainties. The mathematical theory and derivation of the formulas can be found in Fermilab Technical Memo 2286-cd. If you use this software for published work, please cite this note.

The default algorithm for finding the shortest interval is based on Hyndman, R. J. (1996). Computing and graphing highest density regions, The American Statistician, 50(2), 120-126.

Installation

pip install pycalceff

Usage

# Show help
pycalceff --help

# Show version
pycalceff --version

# Calculate efficiencies from data file with 95% confidence intervals
# Displays results in a formatted table
pycalceff data.txt 0.95

# Save results to a tab-separated values (TSV) file
pycalceff --out results.tsv data.txt 0.95

# Save results to a comma-separated values (CSV) file
pycalceff --out results.csv --use-csv data.txt 0.95

# Error: --use-csv requires --out
pycalceff --use-csv data.txt 0.95  # This will show an error

Output Formats

  • Console (default): Results are displayed in a nicely formatted table using Rich.
  • TSV File: Tab-separated values with full precision scientific notation. Includes header row with columns: k, n, mode, low, high.
  • CSV File: Comma-separated values with full precision scientific notation. Includes header row with columns: k, n, mode, low, high.

Data File Format

The input file should contain lines with two integers each: number of successes (k) and number of trials (n). Lines beginning with '#' are treated as comments and ignored.

Example input file:

# Example efficiency data
# Format: k n (successes, trials)
10 20
5 15
0 10

Example console output:

Efficiency Results                   
┏━━━━┳━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃  k ┃  n ┃         Mode ┃          Low ┃         High ┃
┡━━━━╇━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
│ 10 │ 20 │ 5.000000e-01 │ 3.332780e-01 │ 6.667220e-01 │
│  5 │ 15 │ 3.333333e-01 │ 1.092969e-01 │ 6.240037e-01 │
│  0 │ 10 │ 0.000000e+00 │ 0.000000e+00 │ 3.085212e-01 │
└────┴────┴──────────────┴──────────────┴──────────────┘

Example TSV file content (results.tsv):

k	n	mode	low	high
10	20	5.00000000000000000e-01	3.33278000000000000e-01	6.66722000000000000e-01
5	15	3.33333333333333315e-01	1.09296900000000000e-01	6.24003700000000000e-01
0	10	0.00000000000000000e+00	0.00000000000000000e+00	3.08521200000000000e-01

Developer Guide

This section describes how to set up a development environment to contribute to pycalceff.

Development Setup

To set up the development environment, you will need to have Miniforge or Miniconda installed.

  1. Clone the repository:

    git clone https://github.com/marcpaterno/pycalceff.git
    cd pycalceff
    
  2. Create and activate the development environment: The Makefile provides a convenient target for this.

    make setup
    conda activate pycalceff-dev
    

    The setup target uses the environment-dev.yml file to create a consistent Conda environment named pycalceff-dev with all necessary build and development tools.

  3. Install the package in editable mode: Once the environment is active, install pycalceff in editable mode with all development dependencies.

    make install
    

    This target uses pip to install the project in "editable" mode (-e), so any changes you make to the source code are immediately reflected when you run the tool. It also installs the [dev] dependencies listed in pyproject.toml.

Development Workflow

The Makefile contains targets for common development tasks.

  • Run all checks: To ensure code quality, run all formatting, linting, type-checking, and unit tests at once.

    make check
    
  • Run unit tests: To run the test suite with pytest.

    make test
    
  • Format code: To automatically format code with ruff.

    make format
    

Packaging and Release Workflow

The build system is configured to produce PyPI packages.

  1. Build the packages: To build the sdist and wheel for PyPI, use the build target.

    make build
    

    The PyPI artifacts will be in the dist/ directory.

  2. Test local package installation: Before publishing, you can test the PyPI package in a clean, isolated environment without uploading it anywhere. This is the most important verification step.

    make test-install
    

    This command will:

    • Build the packages.
    • Create a temporary environment and install the PyPI wheel, then run tests.
    • Clean up the temporary environment afterward.

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

pycalceff-1.0.1.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

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

pycalceff-1.0.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file pycalceff-1.0.1.tar.gz.

File metadata

  • Download URL: pycalceff-1.0.1.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pycalceff-1.0.1.tar.gz
Algorithm Hash digest
SHA256 81eb456481147bee1dfdb5f2a818b0169fa18f986071c5dc6556a294d24b74da
MD5 e336196495c0d1e25661e705fd19d609
BLAKE2b-256 3eb59eb3a35e3b5d30fcd988d81d87d96217a1449b6785515a17e1b748b8d6cb

See more details on using hashes here.

File details

Details for the file pycalceff-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pycalceff-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pycalceff-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0d584bc8c74b7d8c1e8645e9b8bf227d49c50b6d3bc0d68b1f457cd3c121a9a1
MD5 a4c53c7f23a06aff8b2b29d9cf57ce31
BLAKE2b-256 f5b1a080aee5780169015f93e6a865cc0a7c58b475e855e69e451cbba6293b8d

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