Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sample GUI script to time-normalize motion and storage files #1497

Open
mrrezaie opened this issue Mar 15, 2024 · 0 comments
Open

Add a sample GUI script to time-normalize motion and storage files #1497

mrrezaie opened this issue Mar 15, 2024 · 0 comments

Comments

@mrrezaie
Copy link

mrrezaie commented Mar 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant