opensim-gui
opensim-gui copied to clipboard
Add a sample GUI script to time-normalize motion and storage files
Hi, many non-scripting OpenSim users may need to time-normalize the output motion/storage files and I think it would be great to provide a GUI script in Resources.zip\Code\GUI
, something like this:
import org.opensim.utils as utils
import os
FC = -1 # cutoff frequency for lowpass Butterworth filter (negative means no filter)
N = 101 # number of frames for time normalization (Default = 101 (0-100%))
# choose a file in GUI
fullFileName = utils.FileUtils.getInstance().browseForFilename( \
utils.FileUtils.MotionFileFilter, 'Select a Motion or Storage File')
# separate directory, file name and the extension
folderName = os.path.dirname(fullFileName)
fileName, fileExt = os.path.splitext( os.path.basename(fullFileName) )
outputName = os.path.join(folderName, fileName+'_resampled'+fileExt)
# read file
data = modeling.Storage(fullFileName)
# get first and last time frames
tf = data.getFirstTime()
tl = data.getLastTime()
if FC>0:
# add pad to the signal and apply Butterworth filter
row = data.size
data.pad( int(row/2) )
data.lowpassIIR(FC)
# data.lowpassFIR(4, FC)
data.crop(tf,tl) # remove pad
# time interval
dt = float(tl-tf)/(N-1)
# resample (normalize) to N points
# data.resample(dt, 5)
data.resampleLinear(dt)
data.print(outputName)
print(outputName)
print('Resampled Successfully.')
Thank you.