Skip to main content

Calculate z-scores of anthropometric measurements based on WHO and CDC child growth standards

Project description

pygrowup-erknet

modified version of: http://github.com/ewheeler/pygrowup

pygrowup calculates z-scores for the following anthropometric indicators:

  • weight-for-age

  • length/height-for-age

  • weight-for-length/height

  • head-circumference-for-age

  • body-mass-index-for-age

based on the WHO Child Growth Standards:

and can optionally use CDC growth standards:

pygrowup avoids floating-point operations to eliminate the unwanted rounding that muddles the precision of some of the igrowup implementations:

thanks to GlobalStrategies for a JavaScript port!

REQUIREMENTS

  • Python 3.4 or later

INSTALLATION

pip install pygrowup_erknet

EXAMPLE USAGE

Typical usage might look like this::

#!/usr/bin/env python

from pygrowup import Calculator
# helpers contains optional utilities for formatting dates, etc
from pygrowup import helpers

# Height adjustments are part of the WHO specification (see section 5.1)
# to correct for recumbent vs standing measurements,
# but none of the existing software seems to implement this.
# default is false so values are closer to those produced
# by igrowup software
#
# WHO specs include adjustments (see Chapter 7) to z-scores of weight-based
# indicators that are greater than +/- 3 SDs. These adjustments
# correct for right skewness and avoid making assumptions about
# the distribution of data beyond the limits of the observed values.
#
# However, when calculating z-scores in a live data collection
# situation, z-scores greater than +/- 3 SDs are likely to indicate
# data entry or anthropometric measurement errors and should not
# be adjusted. Instead, these large z-scores should be used to
# identify poor data quality and/or entry errors.
# These z-score adjustments are appropriate only when there
# is confidence in data quality.
#
# In this example, Calculator is initialized with its default values
# (i.e., ``calculator = Calculator()`` would do the same thing).
# The ``include_cdc`` option will enable CDC measurements for children >5 years.
calculator = Calculator(adjust_height_data=False, adjust_weight_scores=False,
                       include_cdc=False, logger_name='pygrowup',
                       log_level='INFO')

# for a timeless example, lets pick a birthdate nine months ago
import datetime
great_day = datetime.datetime.utcnow().date()
nine_months_ago = great_day - datetime.timedelta(days=(9 * 30.4374))

# nine months ago in an odd, ambiguous string format
dob = nine_months_ago.strftime("%d%m%y")

my_child = {'date_of_birth' : dob, 'sex' : 'male', 'weight' : '8.0', 'height' : '69.5'}

# optionally use helper functions for formatting data

# transform something like '100309' into '2009-03-10'
valid_date = helpers.get_good_date(my_child['date_of_birth'])

# transform 'male' into 'M'
valid_gender = helpers.get_good_sex('male')

# calculate 9 months from valid_date
valid_age = helpers.date_to_age_in_months(valid_date[1])


# calculate length/height-for-age zscore
lhfa_zscore_for_my_child = calculator.lhfa(my_child['height'], valid_age, valid_gender)

# calculate weight-for-age zscore
wfa_zscore_for_my_child = calculator.wfa(my_child['weight'], valid_age, valid_gender)

# calculate weight-for-length zscore
# optional height parameter is only necessary for weight-for-height
# and weight-for-length
wfl_zscore_for_my_child = calculator.wfl(my_child['weight'], valid_age, valid_gender, my_child['height'])

# Note: for backwards compatibility you may still make calls to:
wfl_zscore_for_my_child = calculator.zscore_for_measurement('wfl', my_child['weight'], valid_age, valid_gender, my_child['height'])

EXCEPTIONS

caller should watch for:

  • AssertionError raised when caller provides inappropriate parameters

as well as more specific errors (all subclasses of RuntimeError):

  • InvalidMeasurement raised when measurement is invalid for requested indicator

  • InvalidAge raised when age is invalid for requested indicator

  • DataNotFound raised when WHO/CDC data is not found for the requested observation (e.g., box-cox, median, coeffeciant of vairance for age)

  • DataError raised when an error occurs while loading WHO/CDC data into memory

TESTING

install nose to execute tests: pip install nose

the included tests use example anthropometric data taken from demonstration data shipped with WHO's igrowup software. pygrowup performs the same calculations and compares the results to the WHO results. please see the sofware licence agreement for WHO's igrowup, which is the souce of the test data files: http://www.who.int/childgrowth/software/license2.pdf

currently, 4 cases fail to produce results within 1 standard deviation of the WHO resuts. I believe these discrepencies are due to WHO's use of floating point arithmetic in their igrowup software, which leads to less precise calculations compared to pygrowup. In the absence of any other trusted test data, please be aware that no claims are made to the accuracy or reliability of pygroup's calculations.

to run the tests: $ nosetests tests.py

DEVELOPING

The source WHO .txt tables can be easily converted to json with the help of two amazing python utilities:

heres an example one-liner that changes the source .txt from tsv to csv (with pyp) and then to json (with csvkit's csvjson) $ cat bmi_girls_2_5_zscores.txt | pyp "p.replace('\t', ',')" | csvjson > bmifa_girls_2_5_zscores.json

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

pygrowup_erknet-0.9.1.tar.gz (416.6 kB view details)

Uploaded Source

Built Distribution

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

pygrowup_erknet-0.9.1-py3-none-any.whl (426.8 kB view details)

Uploaded Python 3

File details

Details for the file pygrowup_erknet-0.9.1.tar.gz.

File metadata

  • Download URL: pygrowup_erknet-0.9.1.tar.gz
  • Upload date:
  • Size: 416.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pygrowup_erknet-0.9.1.tar.gz
Algorithm Hash digest
SHA256 e28a8aaa5ad444704cf97d7900b7a4ae440b64ee66eafe8efe594930a5afa9bf
MD5 f8e70b9f713cdc84b422e0544532cc96
BLAKE2b-256 bf761d0154847959dcf2ee7e60c08c013a88ad9afd653794e518cfb6c9f62a26

See more details on using hashes here.

File details

Details for the file pygrowup_erknet-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pygrowup_erknet-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 60ad779b6c2b4e30d72b9bb4e8f33873ea7be39e11aa6af0b461047c150b2328
MD5 353d9f2a2e657f1433bfeb3a96c11eb4
BLAKE2b-256 b7c539be9a3efcb8fb330c3a2417541a6bc45e5a4d0b6df070d2a6cd9cd37082

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