def get_convert_audio(synapse_table, row, column_name, convert_file_append='', convert_command='ffmpeg', convert_input_args='-y -i', convert_output_args='-ac 2', out_path='.', username='', password=''): """ Read data from a row of a Synapse table and convert audio file. Calls :: from mhealthx.xio import read_file_from_synapse_table from mhealthx.xio import convert_audio_file 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 convert_file_append : string append to file name to indicate converted file format (e.g., '.wav') convert_command : string executable command without arguments convert_input_args : string arguments preceding input file name for convert_command convert_output_args : string arguments preceding output file name for convert_command out_path : string or None a local path in which to store downloaded files. username : string Synapse username (only needed once on a given machine) password : string Synapse password (only needed once on a given machine) Returns ------- row : pandas Series same as passed in: row of a Synapse table as a file or Series new_file : string full path to the converted file Examples -------- >>> from mhealthx.xio import get_convert_audio >>> from mhealthx.xio import extract_synapse_rows, read_file_from_synapse_table >>> import synapseclient >>> syn = synapseclient.Synapse() >>> syn.login() >>> synapse_table = 'syn4590865' >>> row_series, row_files = extract_synapse_rows(synapse_table, save_path='.', limit=3, username='', password='') >>> column_name = 'audio_audio.m4a' #, 'audio_countdown.m4a'] >>> convert_file_append = '.wav' >>> convert_command = 'ffmpeg' >>> convert_input_args = '-y -i' >>> convert_output_args = '-ac 2' >>> out_path = '.' >>> 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) >>> row, new_file = get_convert_audio(synapse_table, >>> row, column_name, >>> convert_file_append, >>> convert_command, >>> convert_input_args, >>> convert_output_args, >>> out_path, username, password) """ from mhealthx.xio import read_file_from_synapse_table, convert_audio_file row, file_path = read_file_from_synapse_table(synapse_table, row, column_name, out_path, username, password) if convert_file_append: renamed_file = file_path + convert_file_append new_file = convert_audio_file(old_file=file_path, new_file=renamed_file, command=convert_command, input_args=convert_input_args, output_args=convert_output_args) else: new_file = None return row, new_file
def get_tap(synapse_table, row, column_name, start=0, out_path='.', username='', password=''): """ Read screen tapping json data from Synapse table row. Calls :: from mhealthx.xio import read_file_from_synapse_table from mhealthx.xio import read_tap_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) 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 ------- tx : list x-axis screen tap data ty : list y-axis screen tap data t : list time points for accelerometer data 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_tap >>> 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' >>> 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) >>> tx, ty, t, sample_rate, duration, row, file_path = get_tap(synapse_table, >>> row, column_name, >>> start, out_path, username, password) """ from mhealthx.xio import read_file_from_synapse_table, read_tap_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, tx, ty, button, sample_rate, duration = read_tap_json(file_path, start) return tx, ty, t, sample_rate, duration, row, file_path
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