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
From PyPI (pip)
pip install pycalceff
From conda-forge
conda install -c conda-forge pycalceff
Or with mamba:
mamba install -c conda-forge 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.
-
Clone the repository:
git clone https://github.com/marcpaterno/pycalceff.git cd pycalceff
-
Create and activate the development environment: The
Makefileprovides a convenient target for this.make setup conda activate pycalceff-dev
The
setuptarget uses theenvironment-dev.ymlfile to create a consistent Conda environment namedpycalceff-devwith all necessary build and development tools. -
Install the package in editable mode: Once the environment is active, install
pycalceffin editable mode with all development dependencies.make installThis target uses
pipto 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 inpyproject.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.
-
Build the packages: To build the sdist and wheel for PyPI, use the
buildtarget.make buildThe PyPI artifacts will be in the
dist/directory. -
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-installThis 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycalceff-1.1.0.tar.gz.
File metadata
- Download URL: pycalceff-1.1.0.tar.gz
- Upload date:
- Size: 40.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9288cc05180756f14bd43ddc0d56c20fe76d22910c81f005503ed9b89276d6c5
|
|
| MD5 |
c0c42f4f559f4311606e965711d24811
|
|
| BLAKE2b-256 |
f420e7045de64a9916354c746823e94284271506d1bfd042b87c278e0f8dad74
|
File details
Details for the file pycalceff-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pycalceff-1.1.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f4b4b1b28ef8eb18a1ee8590c8665f0b390e34da7a0ea4b785ecf3ca11faef1
|
|
| MD5 |
c3ed2075a82946c7cd572d93c4bd08e6
|
|
| BLAKE2b-256 |
35ae5b1a5780014d485bcbd85a0b860292ecc608dd72f911e64b0b8fdedc4e21
|