def get_accel(synapse_table, row, column_name, start=0, device_motion=True, out_path='.', username='', password=''): """ Read accelerometer json data from Synapse table row. Calls :: from mhealthx.xio import read_file_from_synapse_table from mhealthx.xio import read_accel_json Parameters ---------- synapse_table : string or Schema a synapse ID or synapse table Schema object row : pandas Series or string row of a Synapse table converted to a Series or csv file column_name : string name of file handle column start : integer starting index (remove beginning) device_motion : Boolean use deviceMotion vs. accelerometer json file? out_path : string or None a local path in which to store downloaded files. If None, stores them in (~/.synapseCache) username : string Synapse username (only needed once on a given machine) password : string Synapse password (only needed once on a given machine) Returns ------- t : list time points for accelerometer data ax : list x-axis acceleration ay : list y-axis acceleration az : list z-axis acceleration gx : list x-axis gravity acceleration gy : list y-axis gravity acceleration gz : list z-axis gravity acceleration rx : list x-axis rotationRate ry : list y-axis rotationRate rz : list z-axis rotationRate uw : list w of attitude quaternion ux : list x of attitude quaternion uy : list y of attitude quaternion uz : list z of attitude quaternion sample_rate : float sample rate duration : float duration of time series row : pandas Series same as passed in: row of a Synapse table as a file or Series file_path : string path to accelerometer file Examples -------- >>> from mhealthx.xio import extract_synapse_rows, read_file_from_synapse_table, get_accel >>> import synapseclient >>> syn = synapseclient.Synapse() >>> syn.login() >>> synapse_table = 'syn4590866' >>> row_series, row_files = extract_synapse_rows(synapse_table, save_path='.', limit=3, username='', password='') >>> column_name = 'deviceMotion_walking_outbound.json.items' >>> device_motion = True >>> start = 150 >>> out_path = None >>> username = '' >>> password = '' >>> for i in range(1): >>> row = row_series[i] >>> row, filepath = read_file_from_synapse_table(synapse_table, row, >>> column_name, out_path, username, password) >>> print(row) >>> t, ax, ay, az, gx, gy, gz, rx, ry, rz, uw, ux, uy, uz, sample_rate, duration, row, file_path = get_accel(synapse_table, >>> row, column_name, >>> start, device_motion, >>> out_path, username, password) """ from mhealthx.xio import read_file_from_synapse_table, read_accel_json # Load row data and accelerometer json file (full path): row, file_path = read_file_from_synapse_table(synapse_table, row, column_name, out_path, username, password) # Read accelerometer json file: t, axyz, gxyz, wxyz, rxyz, sample_rate, \ duration, = read_accel_json(file_path, start, device_motion) ax, ay, az = axyz gx, gy, gz = gxyz rx, ry, rz = rxyz uw, ux, uy, uz = wxyz return t, ax, ay, az, gx, gy, gz, rx, ry, rz, uw, ux, uy, uz, \ sample_rate, duration, row, file_path
import numpy as np from mhealthx.xio import read_accel_json from mhealthx.extractors.dead_reckon import velocity_from_acceleration,\ position_from_velocity from mhealthx.utilities import plotxyz #------------------------------------------------------------------------- # Load accelerometer x,y,z values (and clip beginning from start): #------------------------------------------------------------------------- #input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/accel_walking_outbound.json.items-6dc4a144-55c3-4e6d-982c-19c7a701ca243282023468470322798.tmp' #device_motion = False input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/deviceMotion_walking_outbound.json.items-5981e0a8-6481-41c8-b589-fa207bfd2ab38771455825726024828.tmp' device_motion = True start = 150 t, axyz, gxyz, uxyz, rxyz, sample_rate, duration = read_accel_json( input_file, start, device_motion) ax, ay, az = axyz #------------------------------------------------------------------------- # De-mean accelerometer readings: #------------------------------------------------------------------------- ax -= np.mean(ax) ay -= np.mean(ay) az -= np.mean(az) plotxyz(ax, ay, az, t, 'Acceleration') #------------------------------------------------------------------------- # Estimate velocity: #------------------------------------------------------------------------- vx, vy, vz = velocity_from_acceleration(ax, ay, az, t)
import numpy as np from mhealthx.xio import read_accel_json from mhealthx.extractors.dead_reckon import velocity_from_acceleration,\ position_from_velocity from mhealthx.utilities import plotxyz #------------------------------------------------------------------------- # Load accelerometer x,y,z values (and clip beginning from start): #------------------------------------------------------------------------- #input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/accel_walking_outbound.json.items-6dc4a144-55c3-4e6d-982c-19c7a701ca243282023468470322798.tmp' #device_motion = False input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/deviceMotion_walking_outbound.json.items-5981e0a8-6481-41c8-b589-fa207bfd2ab38771455825726024828.tmp' device_motion = True start = 150 t, axyz, gxyz, uxyz, rxyz, sample_rate, duration = read_accel_json(input_file, start, device_motion) ax, ay, az = axyz #------------------------------------------------------------------------- # De-mean accelerometer readings: #------------------------------------------------------------------------- ax -= np.mean(ax) ay -= np.mean(ay) az -= np.mean(az) plotxyz(ax, ay, az, t, 'Acceleration') #------------------------------------------------------------------------- # Estimate velocity: #------------------------------------------------------------------------- vx, vy, vz = velocity_from_acceleration(ax, ay, az, t)