Simulation and experimental results of the time inconsistent

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
cui weiling
Posts: 27
Joined: Tue Feb 28, 2017 5:28 am

Simulation and experimental results of the time inconsistent

Post by cui weiling » Sun Nov 19, 2017 5:55 pm

hello everyone,
I have got static optimization results and wanted to compare with the experimental results, but the time of test and simulation inconsistent, how can I solve this problems?
thanks.

User avatar
Pierre Kibleur
Posts: 19
Joined: Tue Sep 19, 2017 2:16 am

Re: Simulation and experimental results of the time inconsistent

Post by Pierre Kibleur » Mon Nov 20, 2017 12:22 am

Hello,

I have this Python function that I use for such cases, it requires the Pandas library (

Code: Select all

import pandas as pd
). Well, there are probably neater ways of doing it, but maybe it can help :)

Best,
Pierre

EDIT: maybe it's less headache prone if you also know how I read OpenSim files into pandas:

Code: Select all

dfCMC_q = pd.read_csv(r"CMC\Kinematics_q.sto", header=8, sep="\t", index_col="time")

Code: Select all

def sync_dfs(df, df1, rolling_mean_size=3):
    """
    From two data frames sampled at slightly different times, return two dataframes 
    at synchronized time points. It uses linear interpolation to fill missing data, 
    and returns an averaged over some time points data.
    
    Example: 
        df has 10 entries, each at half a second (.5, 1.5, 2.5 ...)
        df1 has 30 entries, each at every third of a second (.33, .66, 1, 1.33, ...)
        rolling_mean_size = 3
        
        this function first computes a dataframe "whole" containing time points (.33, .5, .66, 1, 1.33, 1.5, ...)
        it fills the missing values by linearly interpolating between two know data points (e.g. between .5 and 1.5)
        it then averages over 3 time points, resulting in a "whole" data frame of size 40/3
        
        And it finally returns two dataframes, adaptations of the input ones, both of the same size and sampling times.
    """
    whole = pd.merge(df.reset_index(), df1.reset_index(), how='outer', on='time', suffixes=('_x', '_y')).set_index("time").sort_index().interpolate()
    whole = whole.rolling(rolling_mean_size).mean()
    df_ = whole.loc[:, whole.columns.str.endswith('x')].rename(columns = lambda x : str(x).rsplit('_', 1)[0])
    df1_ = whole.loc[:, whole.columns.str.endswith('y')].rename(columns = lambda x : str(x).rsplit('_', 1)[0])
    return df_, df1_

POST REPLY