utilities

Module: utilities

Utility functions.

Authors:

Copyright 2015, Sage Bionetworks (http://sagebase.org), Apache v2.0 License

Functions

mhealthx.utilities.plot_vectors(x, y, z, hx=[], hy=[], hz=[], title='')

Plot vectors in 3-D from the origin [0,0,0].

(If trouble with “projection=‘3d’”, try: ipython –pylab)

From: http://stackoverflow.com/questions/22867620/
putting-arrowheads-on-vectors-in-matplotlibs-3d-plot
x : list or numpy array of floats
x-axis data for vectors
y : list or numpy array of floats
y-axis data for vectors
z : list or numpy array of floats
z-axis data for vectors
hx : list or numpy array of floats
x-axis data for vectors to highlight
hy : list or numpy array of floats
y-axis data for vectors to highlight
hz : list or numpy array of floats
z-axis data for vectors to highlight
title : string
title
>>> from mhealthx.xio import read_accel_json
>>> #input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/accel_walking_outbound.json.items-6dc4a144-55c3-4e6d-982c-19c7a701ca243282023468470322798.tmp'
>>> input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/deviceMotion_walking_outbound.json.items-5981e0a8-6481-41c8-b589-fa207bfd2ab38771455825726024828.tmp'
>>> #input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/deviceMotion_walking_outbound.json.items-a2ab9333-6d63-4676-977a-08591a5d837f5221783798792869048.tmp'
>>> start = 150
>>> device_motion = True
>>> t, axyz, gxyz, uxyz, rxyz, sample_rate, duration = read_accel_json(input_file, start, device_motion)
>>> x, y, z = axyz
>>> hx, hy, hz = [[0,1],[0,1],[0,1]]
>>> title = 'Test vectors'
>>> from mhealthx.utilities import plot_vectors
>>> plot_vectors(x, y, z, hx, hy, hz, title)
mhealthx.utilities.plotxyz(x, y, z, t, title='', limits=[])

Plot each accelerometer axis separately against relative time.

x : list or numpy array of floats y : list or numpy array of floats z : list or numpy array of floats t : list or numpy array of floats

time points

title : string limits : list of floats

>>> from mhealthx.xio import read_accel_json
>>> #input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/accel_walking_outbound.json.items-6dc4a144-55c3-4e6d-982c-19c7a701ca243282023468470322798.tmp'
>>> input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/deviceMotion_walking_outbound.json.items-5981e0a8-6481-41c8-b589-fa207bfd2ab38771455825726024828.tmp'
>>> #input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/deviceMotion_walking_outbound.json.items-a2ab9333-6d63-4676-977a-08591a5d837f5221783798792869048.tmp'
>>> start = 150
>>> device_motion = True
>>> t, axyz, gxyz, uxyz, rxyz, sample_rate, duration = read_accel_json(input_file, start, device_motion)
>>> ax, ay, az = axyz
>>> from mhealthx.utilities import plotxyz
>>> plotxyz(ax, ay, az, t, title='', limits=[])
mhealthx.utilities.plotxyz3d(x, y, z, title='')

Plot accelerometer readings in 3-D.

(If trouble with “projection=‘3d’”, try: ipython –pylab)

x : list or numpy array of floats y : list or numpy array of floats z : list or numpy array of floats title : string

title
>>> from mhealthx.xio import read_accel_json
>>> #input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/accel_walking_outbound.json.items-6dc4a144-55c3-4e6d-982c-19c7a701ca243282023468470322798.tmp'
>>> input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/deviceMotion_walking_outbound.json.items-5981e0a8-6481-41c8-b589-fa207bfd2ab38771455825726024828.tmp'
>>> #input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/deviceMotion_walking_outbound.json.items-a2ab9333-6d63-4676-977a-08591a5d837f5221783798792869048.tmp'
>>> start = 150
>>> device_motion = True
>>> t, axyz, gxyz, uxyz, rxyz, sample_rate, duration = read_accel_json(input_file, start, device_motion)
>>> x, y, z = axyz
>>> title = 'Test vectors'
>>> from mhealthx.utilities import plotxyz3d
>>> plotxyz3d(x, y, z, title)
mhealthx.utilities.run_command(command, flag1='', arg1='', flags='', args=[], flagn='', argn='', closing='')

Run a generic command.

command : string
name of command: “SMILExtract”
flag1 : string
optional first command line flag
arg1 : string
optional first argument, handy for iterating over in the pipeline
flags : string or list of strings
command line flags precede their respective args: [“-C”, “-I”, “-O”]
args : string or list of strings
command line arguments: [“config.conf”, “input.wav”, “output.csv”]
flagn : string
optional last command line flag
argn : string
optional last argument, handy for iterating over in the pipeline
closing : string
closing string in command
command_line : string
full command line
args : list of strings
command line arguments
arg1 : string
optional first argument, handy for iterating over in the pipeline
argn : string
optional last argument, handy for iterating over in the pipeline
>>> from mhealthx.utilities import run_command
>>> command = 'ls'
>>> flag1 = ''
>>> arg1 = ''
>>> flags = ['-l', '']
>>> args = ['/software', '/desk']
>>> flagn = ''
>>> argn = ''
>>> closing = '' #'> test.txt'
>>> command_line, args, arg1, argn = run_command(command, flag1, arg1, flags, args, flagn, argn, closing)