funpack.schema.coding

This module contains the loadCodingFile() function, which can be used to load descriptions of the values for a given data coding.

The data coding information for data codings in the UKBiobank is downloaded from the UK Biobank showcase at https://biobank.ctsu.ox.ac.uk/crystal/schema.cgi. Some pre-downloaded backup files are stored in in funpack/schema/coding/.

funpack.schema.coding.getCoding(dtable=None, vid=None, coding=None)[source]

Return a data coding ID for the given vid or coding. See the loadCodingFile() function for details.

Parameters:
  • dtable – The DataTable

  • vid – The variable ID

  • coding – Data coding ID

Returns:

An integer ID for the corresponding data coding.

funpack.schema.coding.getCodingFilePath(coding)[source]

Return a file path to a backup file for the given coding. The file is not guaranteed to exist.

funpack.schema.coding.loadCodingFile(dtable=None, vid=None, coding=None, download=True)[source]

Loads a UK Biobank data coding scheme.

Coding files can be looked up with one of the following methods, in order of precedence:

  1. By specifying a data coding (coding). This takes precedence.

  2. By passing a DataTable (dtable) and variable ID (vid)

The descriptions are returned in a pandas.DataFrame, with the coding values as the index, and a single column called meaning, containing the descriptions for each value.

Parameters:
  • dtable – The DataTable

  • vid – Variable ID

  • coding – Data coding ID

  • download – Defaults to True - coding files are downloaded from the UK Biobank showcase. Set to False to force loading from the backup files in funpack/schema/coding/.

Returns:

A DataFrame containing descriptions