Contents
- Simple Calories
- Pandolf-Santee Model
- LCDA Model
- Minimum Mechanics Model
- Calorie Ensemble
- Sample Data
Estimating Energy Expenditure and Calories Burned
This package is a dependency-free module that estimates calories burned during physical activities (walking, hiking, rucking, etc) with functions for both simple calorie estimates, and more advanced methods utilizing GPS data.
Creating accurate estimates of the number of calories burned during a physical activity period is notoriously difficult, especially when attempting to incorporate positional data. Most instances of estimating calories burned are simply calculated as an exertion effort based on body weight, time duration and a known MET (Metabolic Equivalent Task) value for a given activity. This method doesn't include positional data such as distance, velocity or elevation changes. This can be considered a simple calorie estimate.
There are several, more advanced methods for estimating calories burned that do attempt to incorporate GPS data for a richer, more nuanced estimate. This package provides more advanced functions to calculate calories burned using either the Pandolf-Santee, Minimum Mechanics or LCDA predictive models.
Using
python -m pip install calories-py
from calories import simpleCalories, pandolfCalories, lcdaCalories, minimumMechanicsCalories, calorieEnsemble
All of the functions in the calories-py package are fully documented, with descriptions of argument types, default values and return types. Use the help(<function>) function to view the documentation.
Simple Calories
Using Metabolic Equivalent Tasks
The simple calories calculation takes 3 parameters: minutes, weights, and MET, and returns a positive floating point value. The function raises a ValueError if the required parameters are missing, or of the wrong type. The required body weight parameter is measured in kilograms. You need to know the MET value for any specific activity you are measuring. A good list of MET values can be found at the Compendium of Physical Activities.
# The number of minutes MET activity is performed.
# Required and must be greater than zero.
minutes = 35
# Weights, measured in Kilograms. Body weight is
# required. If a ruck weight was carried, include
# that too. Optionally include weight of water
# carried as well.
# useful conversions:
# 1Kg == 2.2lbs or 1lbs == 0.45359Kg
# 1 fl oz of water == 1.042oz or 15.355 fl oz == 1lbs or 33.781 fl oz == 1kg
weights = {
"body": 70, # required Kg
"ruck": 5, # optional Kg
"water": 0, # optional Kg
}
# The MET number for a particular task. For example:
# Walking slowly: 2.0
# Walking, 2.5 mph: 3.0
# Walking for pleasure 3.5 <-- Default value
# Weight lifting: 5.0
# Backpacking: 7.5
# Swimming: 8.0
# Rope jumping (84/min): 10.5
# Jogging, 6.8 mph: 11.2
MET = 7.5 # Backpacking
try:
simple_calories = simpleCalories(minutes, weights, MET)
except ValueError as v:
print(v)
except TypeError as t:
print(t)
execpt Exception as e:
print(f'there was a problem with the arugments {minutes} or {weights} or {MET}')
print(e)
print(simple_calories)
# 143.381765625
# try help(simpleCalories) for function documentation.
Advanced Calorie Predictive Models
The Pandolf-Santee Model
This method of estimating energy expenditure is based on the Pandolf-Santee equation. The required parameters include an array of GPS coordinate data, and a body weight, measured in kilograms. Additional values can be provided in the options parameter; including the weight of a ruck load, the weight of additional water carried, and the type of terrain covered. There is also an option to smooth out the GPS elevation data. If the elevation data comes from a GPS sensor (rather than a barometric pressure sensor), it can be useful to smooth out the values with a rolling average because some GPS sensors can provide pretty jittery values for this field.
The pandolfCalories() function expects the coordinates parameter to be an List of Lists with the following format: [longitude, latitude, heading, altitude (m), accuracy (m), timestamp (ms)]. In this particular implementation, the heading and accuracy fields are not currently being used. Those fields can be empty or None. The fields for longitude, latitude, altitude and timestamp must be valid, non-null values. Altitude is measured in meters and the timestamp is recorded in milliseconds.
The Santee correction factor for including downhill travel (negative grade values) is being applied when calculating the advanced estimates. This correction factor results in energy expenditure estimates that are typically about 16% - 25% higher when the GPS data contains significant amounts of downhill travel vs the original pandolf equation that couldn't account for negative grade values.
To calculate the results, the pandolf-santee model is executed over each consecutive pair-wise GPS points in the the coordinates array. Each of these pair-wise calculations is referred to as a segment. To get the final results, the segments are aggregated together. The boolean options property options["returnSegments"] controls whether a list of segment results is included in the function return value. The default value is False. Setting this to True includes this segments list. The function raises a ValueError if the required parameters are missing, or of the wrong type.
cooords = [
# [gps longitude, gps latitude, heading (in deg), altitude (meters), gps accuracy (m), timestamp (ms)],
[-122.18413372578239, 37.82762389320808, 289.500900176593, 410.60703301243484, 6.935079779936697, 1781733047033],
[-122.18414765202105, 37.827625731095864, 291.71648070840496, 411.11239344626665, 6.935079779936697, 1781733048037],
[-122.1841647535281, 37.82762780033335, 286.09169894511865, 410.85964420530945, 7.091013324104003, 1781733049031],
[-122.18417633225566, 37.827625146283225, 284.4996500921467, 411.22145825996995, 7.091013324104003, 1781733050034],
...,
]
# Optional terrain characterization values include:
# Paved road / treadmill: 1.0
# Dirt path / packed trail: 1.1
# Light off-trail, grass: 1.2
# Soft sand, deep grass, loose gravel: 1.5
# Snow, heavy brush, swamp: 1.8
# To remove GPS elevation jitter, set smooth to true.
# The window size sets amount of smoothing, 5 is usually
# sufficient. If elevation data comes from a barometric
# sensor, set smooth to false.
options = {
"bodyWeightKg": 70, # Required, measured in kilograms
"loadKg": 13.6, # optional, measured in kilograms
"waterKg": 0, # optional, measured in kilograms
"terrain": 1.1, # optional, default value = 1.1
"smooth": True, # optional, smooth GSP elvation values
"smoothWindow": 5, # optional, default value == 5
"returnSegments": False # optional, return calculated GPS segments
}
try:
pandolf_calories = pandofCalories(coords, options)
except ValueError as v:
print(v)
print(f'there was a problem with the arugments {coords} or {options}')
print(pandolf_calories)
# {
# 'totalKcal': 581.492205191523,
# 'totalDistanceM': 5544.758689134893,
# 'totalDurationSec': 3829.9640000000027,
# 'avgSpeedMs': 1.4477312813214143,
# 'segments': [{...},{...},...], # Only included if options["returnSegments"] == True
# }
# try help(pandolfCalories) for function documentation.
The LCDA Model
A much more recently developed predictive model for calculating energy expenditure over distance, while carrying a load is the Load Carrying Decision Aid model. LCDA is considered to be slightly more accurate than the Pandolf model at the extra expense of requiring parameters to calculate basal metabolic rate.
The coords and options parameters for lcdaCalories() are the same as for the above pandolfCalories() function. The values in the BMR parameter object are used to create a value for basal metabolic rate using the Mifflin-St Jeor equation. The function raises a ValueError if the required parameters are missing, or of the wrong type.
BMR = {
"height": 162.5 # Required, measured in centimeters
"weight": 70 # Required, measured in kilograms
"age": 45 # Required, measured in years
"sex": 'm' # Required, either 'm' or 'f'
}
options = {
"bodyWeightKg": 70, # Required, measured in kilograms
"loadKg": 13.6, # optional, measured in kilograms
"waterKg": 0, # optional, measured in kilograms
"terrain": 1.1, # optional, default value == 1.1
"smooth": True, # optional, smooth GSP elvation values
"smoothWindow": 5, # optional, default value == 5
"returnSegments": False # optional, return calculated GPS segments
}
try:
lcda_calories = lcdaCalories(coords, BMR, options)
except ValueError as v:
print(v)
print(f'there was a problem with the arugments {coords} or {BMR} or {options}')
print(lcda_calories)
# {
# 'totalKcal': 590.292205191523,
# 'totalDistanceM': 5544.758689134893,
# 'totalDurationSec': 3829.9640000000027,
# 'avgSpeedMs': 1.4477312813214143
# }
# try help(lcdaCalories) for function documentation.
The Minimum Mechanics Model
The Minimum Mechanics predictive model was developed by Ludlow & Weyland as a less complex model altrnative to the negative grade-corrective Pandolf-Santee model. This model incorporates the basal metabolic rate, like the LCDA model above, but forgoes terrain characterization. The function signature is the same as that for LCDA. The function raises a ValueError if the required parameters are missing, or of the wrong type.
BMR = {
"height": 162.5 # Required, measured in centimeters
"weight": 70 # Required, measured in kilograms
"age": 45 # Required, measured in years
"sex": 'm' # Required, either 'm' or 'f'
}
options = {
"bodyWeightKg": 70, # Required, measured in kilograms
"loadKg": 13.6, # optional, measured in kilograms
"waterKg": 0, # optional, measured in kilograms
"smooth": True, # optional, smooth GSP elvation values
"smoothWindow": 5, # optional, default value == 5
"returnSegments": False # optional, return calculated GPS segments
}
try:
minMech_calories = minimumMechanicsCalories(coords, BMR, options)
except ValueError as v:
print(v)
print(f'there was a problem with the arugments {coords} or {BMR} or {options}')
print(lcda_calories)
# {
# 'totalKcal': 476.211434723359,
# 'totalDistanceM': 5544.758689134893,
# 'totalDurationSec': 3829.9640000000027,
# 'avgSpeedMs': 1.4477312813214143
# }
# try help(minimumMechanicsCalories) for function documentation.
The Calorie Ensemble
If you would like to compare the results of each of the predictive models for a given hike's dataset, you can use the calorieEnsemble() function. This function maps each of the predictive models over each segment of the coordinates array in a single pass, to give comparative results. For this function, the BMR parameter is combined into the options parameter. You will notice that each of the predictive models gives a slightly different result for totalKcal. This is expected and indicative of the differences in the respective models. The function raises a ValueError if the required parameters are missing, or of the wrong type.
options = {
"bodyWeightKg": 70, # Required, measured in kilograms
"loadKg": 13.6, # optional, measured in kilograms
"waterKg": 0, # optional, measured in kilograms
"smooth": True, # optional, smooth GSP elvation values
"smoothWindow": 5, # optional, default value == 5
"returnSegments": False # optional, return calculated GPS segments
"BMR": {
"height": 162.5 # Required, measured in centimeters
"weight": 70 # Required, measured in kilograms
"age": 45 # Required, measured in years
"sex": 'm' # Required, either 'm' or 'f'
},
}
try:
resultSet = calorieEnsemble(coords, options)
except ValueError as v:
print(v)
print(f'there was a problem with the arugments {coords} or {options}')
print(resultSet)
# {
# 'lcda': {
# 'totalKcal': 590.292205191523,
# 'totalDistanceM': 5544.758689134893,
# 'totalDurationSec': 3829.9640000000027,
# 'avgSpeedMs': 1.4477312813214143
# },
# 'pandolf': {
# 'totalKcal': 581.492205191523,
# 'totalDistanceM': 5544.758689134893,
# 'totalDurationSec': 3829.9640000000027,
# 'avgSpeedMs': 1.4477312813214143
# },
# 'minMech': {
# 'totalKcal': 476.211434723359,
# 'totalDistanceM': 5544.758689134893,
# 'totalDurationSec': 3829.9640000000027,
# 'avgSpeedMs': 1.4477312813214143
# }
# }
# try help(calorieEnsemble) for function documentation.
Sample Data
This package includes a sample data file to help illustrate the data format. sample_data.json is a GEOJson formatted data file containing a single LineString feature with a coordinates array that can be passed into the calorie functions. In this sample data, the features[0]["properties"]["weights"] dict contains the necessary weight values to supply in the options parameter of the calories functions (these weights are recorded in lbs so convert them to kgs).
The coordinates array in this sample data does not conform exactly to the GEOJson specification, which only defines longitude and latitude values in the array. No guarantee is given to the validity of values following latitude. In this case, typical GPS values of accuracy, altitude, timestamp, etc. are provided to support the calorie functions.
from calories import pandolfCalories, load_sample_data
sample_data = load_sample_data()
coords = sample_data["features"][0]["geometry"]["coordinates"]
options = {
"bodyWeightKg": sample_data["features"][0]["properties"]["weights"]["body"] / 2.2, # convert sample data body weight from lbs to kgs
"loadKg": sample_data["features"][0]["properties"]["weights"]["ruck"] / 2.2, # convert sample data ruck weight from lbs to kgs
"smooth": True,
"smoothWindow": 5
}
cals = pandolfCalories(coords, options)
print(cals)
'totalKcal': , 'totalDistanceM': , 'totalDurationSec': 949, 'avgSpeedMs': 2.001495567183388}
# {
# 'totalKcal': 222.3793135896461,
# 'totalDistanceM': 1899.4192932570354,
# 'totalDurationSec': 949,
# 'avgSpeedMs': 2.001495567183388
# }
# try help(load_sample_data) for function documentation.
Metadata
Release files for calories-py 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| calories_py-1.1.3.tar.gz | 91.2 kB | Without provenance | Details for calories_py-1.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| calories_py-1.1.3-py3-none-any.whl | Python 3 | none | any | Details for calories_py-1.1.3-py3-none-any.whl |
Total release size: 182.9 kB
Release files / calories_py-1.1.3.tar.gz
| Download URL | calories_py-1.1.3.tar.gz |
|---|---|
| Size | 91.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3c55d4aec562a59c204c6d1a556110ce7d84dd19b2b98d1a4bc548a9b384137
|
|
BLAKE2b-256 checksum How to use checksums |
bf5189014446302c9dc6ecaa4ace69d6ef4994b808d541a3b71ad30b6440742e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Release files / calories_py-1.1.3-py3-none-any.whl
| Download URL | calories_py-1.1.3-py3-none-any.whl |
|---|---|
| Size | 91.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ad36a1cc6ea58dd1abac1ce61e49c42b85d7d67d6c068ad7c1b58a77f6923cf3
|
|
BLAKE2b-256 checksum How to use checksums |
395b1730e0a03a20d26813c2ef193e3283506dff126d7d3099d22956330c946c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Security for calories-py 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.