Package: openmovement
Open Movement Python CodeThis repository contains the Python code for theOpen Movementproject.python-mpipinstall"git+https://github.com/digitalinteraction/openmovement-python.git#egg=openmovement"omconvert- wrapper foromconvertbinary executable(omconvert.py) is a Python wrapper for theomconvertexecutable, which processes.cwaand.omxbinary files and produce calculated outputs, such as SVM (signal vector magnitude) and WTV (wear-time validation).  It can also be used to output raw accelerometer.csvfiles (these can be very large).The example code,run_omconvert.py, exports the SVM and WTV files.  A basic usage example is:importosfromopenmovement.processimportOmConvertsource_file='CWA-DATA.CWA'base_name=os.path.splitext(source_file)[0]options={}# Nearest-point samplingoptions['interpolate_mode']=1# Optionally export accelerometer CSV file (can take a long time)#options['csv_file'] = base_name + '.csv'# SVM (no filter)options['svm_filter']=0options['svm_file']=base_name+'.svm.csv'# Wear-time validationoptions['wtv_file']=base_name+'.wtv.csv'# Run the processingom=OmConvert()result=om.execute(source_file,options)Note:You will need theomconvertbinary either in yourPATH, in the current working directory, or in the same directory as theomconvert.pyfile (or, on Windows, if you haveOmGuiinstalled in the default location).  On Windows you can use thebin/build-omconvert.batscript to fetch the source and build the binary, or on macOS/Linux you can use thebin/build-omconvert.shscript.cwa_load- .CWA file loaderLoad.CWAfiles directly into Python (requiresnumpyandpandas).fromopenmovement.loadimportCwaDatafilename='cwa-data.cwa'withCwaData(filename,include_gyro=False,include_temperature=True)ascwa_data:# As an ndarray of [time,accel_x,accel_y,accel_z,temperature]sample_values=cwa_data.get_sample_values()# As a pandas DataFramesamples=cwa_data.get_samples()You can also useMultiDatainstead ofCwaData, which supports .CWA files, .WAV accelerometer files and timeseries .CSV files (all of which could be inside a .ZIP file).zip_helper- "potentially zipped" file helperHandles a "potentially zipped" file: one that may be inside a .ZIP archive but, if so, you need the extracted file on a drive and it can't be a stream from a compressed file.  For example, when you need to memory-map the file (e.g. withcwa_load), or use it with an external process (e.g. withomconvert).Offers a convenientwithsyntax:If the file extension is not '.zip', the original filename is passed through via thewithsyntax.Otherwise, the file is opened as a .ZIP archive, and it is searched for exactly one matching filename (by default, a single-file archive).  The matching file is extracted to a temporary location, and that location is passed through thewithsyntax as the filename to use.  At the end of thewithblock, the temporary file is automatically removed.fromopenmovement.loadimportPotentiallyZippedFilefilename='example.zip'withPotentiallyZippedFile(filename,['*.cwa','*.omx'])asfile:print('Using: '+file)passPython implementations of algorithmsSVMcalc_svm.py- Calculates the meanabs(SVM-1)value (otherwise known as the Euclidean Norm Minus One; where SVM=Signal Vector Magnitude) for an epoch of timestamped accelerometer data (default 60 seconds).run_svm.py- Example showing how to run the SVM calculation from a source data file to an output.csvm.csvfile.WTVcalc_svm.py- Calculates the WTV (wear-time validation) value (30 minute epochs)  for an epoch of timestamped accelerometer data (default 60 seconds).run_wtv.py- Example showing how to run the WTV calculation from a source data file to an output.cwtv.csvfile.