根据who和cdc儿童生长标准计算人体测量z值
pygrowup的Python项目详细描述
PyGrowUp计算下列人体测量指标的Z分数:
- 年龄体重
- 年龄的长度/身高
- 长度/高度的重量
- 年龄的头围
- 年龄的体重指数
根据世卫组织儿童成长标准: *http://www.who.int/childgrowth/standards/en/ *http://www.who.int/entity/childgrowth/standards/technical_report/en/index.html
并且可以选择使用CDC增长标准: *http://www.cdc.gov/growthcharts
PyGrowUp避免浮点运算以消除不需要的舍入 这混淆了一些igrowup实现的精度: *http://docs.sun.com/source/806-3568/ncg_goldberg.html
要求
- python 2.7.x、python 3.x或更高版本
- 另外还需要https://pypi.python.org/pypi/six
安装
pip安装pygrowup
示例用法
典型用法如下:
#!/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'])
例外情况
来电者应注意:
- 断言错误在调用方提供不适当的参数时引发
以及更具体的错误(runtimeerror的所有子类):
- 无效测量当测量对请求的指示器无效时引发
- invalid age当年龄对请求的指标无效时引发
- 未发现数据当未找到所需观察的世卫组织/疾病预防控制中心数据时(如Box Cox、Midenal、Coeffeciant of Varance for Age)提出
- 数据错误在将who/cdc数据加载到内存中时发生错误时引发
测试
安装nose以执行测试: pip安装鼻子
所包含的测试使用从 世卫组织igrowup软件附带的演示数据。 pygroup执行相同的计算并比较结果 世界卫生组织结果。 请参阅“谁是iGrowUp”的软件许可协议,其中 是测试数据文件的来源: http://www.who.int/childgrowth/software/license2.pdf
目前,有4例不能在1个标准差内产生结果 世界卫生组织的报告。我相信这些谨慎是由于谁在使用 在他们的igrowup软件中使用浮点运算,这导致 与PyGrowUp相比的精确计算。如果没有其他的 受信任的测试数据,请注意没有对 pygroup计算的准确性或可靠性。
要运行测试: $nosetests tests.py
开发
借助于 两个惊人的python实用程序:
下面是一个从tsv更改source.txt的示例 到csv(使用pyp)然后到json(使用csvkit的csvjson) $cat bmi_girls_2_5_zscores.txt pyp“p.replace('t',',',')”csvjson>;bmifa_girls_2_5_zscores.json