<jupyter_start><jupyter_text>Program analiza EMG. Prawidłowe podnoszenie pacjenta   Wczytanie bibliotek<jupyter_code>import numpy as np
import itertools 
import ezc3d
import matplotlib.pyplot as plt
from pathlib import Path
from math import sqrt
from tqdm import tqdm
from ezc3d import c3d
import dataprocesing as dp
import importlib<jupyter_output><empty_output><jupyter_text>Wczytanie ścieżki do pliku<jupyter_code>path=r"Y:\nurse\2019_08_29_B0436\New Session\B0436 PrzenoszeniePrawidlowe T01.c3d"<jupyter_output><empty_output><jupyter_text>Wybranie interesujących wartośći z pliku<jupyter_code>import sys
from matplotlib.pyplot import subplot
from matplotlib.pyplot import figure
import matplotlib.pyplot as plt
from sklearn import preprocessing
import numpy as np
from matplotlib import scale as mscale
from pyomeca import Analogs
    
def normalize_data(data_path):

    muscles2 = [["Voltage.1"],["Voltage.2"],["Voltage.3"],["Voltage.4"],["Voltage.5"],["Voltage.6"],["Voltage.7"],["Voltage.8"],["Voltage.9"],["Voltage.10"],["Voltage.11"],["Voltage.12"],["Voltage.13"],["Voltage.14"],["Voltage.15"],["Voltage.16"]]
    muscles_names = [["Czworoboczny grzbietu L"],["Trójgłowy ramienia L"], ["Dwugłowy ramienia L"], ["Prostownik nadgarstka L"],["Skośny brzucha L"], ["Pośladkowy średni L"],["Czworogłowy uda L"], ["Brzuchaty łydki L"],["Czworoboczny grzbietu P"],["Trójgłowy ramienia P"], ["Dwugłowy ramienia P"], ["Prostownik nadgarstka P"],["Skośny brzucha P"], ["Pośladkowy średni P"],["Czworogłowy uda P"], ["Brzuchaty łydki P"]]
    muscles = ["Voltage.1","Voltage.2","Voltage.3","Voltage.4","Voltage.5","Voltage.6","Voltage.7","Voltage.8","Voltage.9","Voltage.10","Voltage.11","Voltage.12","Voltage.13","Voltage.14","Voltage.15","Voltage.16"]

    muscles_names2 = ["Czworoboczny grzbietu L","Trójgłowy ramienia L", "Dwugłowy ramienia L", "Prostownik nadgarstka L","Skośny brzucha L", "Pośladkowy średni L","Czworogłowy uda L", "Brzuchaty łydki L","Czworoboczny grzbietu P","Trójgłowy ramienia P", "Dwugłowy ramienia P", "Prostownik nadgarstka P","Skośny brzucha P", "Pośladkowy średni P","Czworogłowy uda P", "Brzuchaty łydki P"]

    max_val=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

 
    emg=Analogs.from_c3d(data_path, usecols=muscles)

    emg_p = (
    emg.meca.band_pass(order=2, cutoff=[10, 425])
    .meca.center()
    .meca.abs()
    .meca.low_pass(order=4, cutoff=5, freq=emg.rate)
    .meca.normalize(ref=None, scale=1)
    )
     
    emg_p['channel'] = muscles_names2
 
    return emg_p
processed=normalize_data(path)<jupyter_output><empty_output><jupyter_text>Wyświetlenie całych przebiegów wybranych wartości<jupyter_code>def show_data(processed):
    processed.plot(x="time", col="channel", col_wrap=3)

def load_and_show_data(data_path):
    muscles = ["Voltage.1","Voltage.2","Voltage.3","Voltage.4","Voltage.5","Voltage.6","Voltage.7","Voltage.8","Voltage.9","Voltage.10","Voltage.11","Voltage.12","Voltage.13","Voltage.14","Voltage.15","Voltage.16"]
    processed=Analogs.from_c3d(data_path, usecols=muscles)
    processed.plot(x="time", col="channel", col_wrap=3)
show_data(processed)<jupyter_output><empty_output><jupyter_text>Przebieg pracy mięśni podczas podnoszenia wraz z oznaczeniem eventów<jupyter_code>def show_avr2(data_path,emg_processed=None):
    if emg_processed is None:
        emg_processed=normalize_data(data_path)

    muscles_names2 = ["Czworoboczny grzbietu L","Trójgłowy ramienia L", "Dwugłowy ramienia L", "Prostownik nadgarstka L","Skośny brzucha L", "Pośladkowy średni L","Czworogłowy uda L", "Brzuchaty łydki L","Czworoboczny grzbietu P","Trójgłowy ramienia P", "Dwugłowy ramienia P", "Prostownik nadgarstka P","Skośny brzucha P", "Pośladkowy średni P","Czworogłowy uda P", "Brzuchaty łydki P"]

    aver_arr=np.zeros((16,1000)) 
  
    for num in range(16):
        subplot(1, 2, 1)
        plt.subplots_adjust(left=0.125,
                    bottom=0.1, 
                    right=5, 
                    top=0.3, 
                    wspace=0.25, 
                    hspace=0.35)
         
        emg_processed_event=emg_processed[num]
        emg_processed_event2 = (
        emg_processed_event.meca.normalize(ref=None, scale=1)            
        )
        time_normalized=emg_processed_event2.meca.time_normalize(n_frames=1000)
        
        
        c3d_to_compare= c3d(path)
        eventTime = c3d_to_compare['parameters']['EVENT']['TIMES']['value'][1] 
        nFrames = c3d_to_compare['parameters']['POINT']['FRAMES']['value'][0]
        nn = nFrames/1000
        markevent = eventTime/nn*100
       
        for t in range(1000):
                aver_arr[num][t]=aver_arr[num][t]+time_normalized.values[t]
       
        aver_arr[num]=aver_arr[num]/10
        time=np.linspace(1,1000,1000)
        plt.plot(time,aver_arr[num]) 
        for axl in range(12):
            plt.axvline(markevent[axl], color='r')
        plt.title(muscles_names2[num])
        plt.fill_between(time,aver_arr[num])
        plt.show()
    
    return aver_arr
show_avr2(path,emg_processed=None)<jupyter_output><empty_output><jupyter_text>Wybór poszczególnych części przebiegu<jupyter_code>def showPart(data_path,emg_processed=None,part=False):
    if emg_processed is None:
        emg_processed=normalize_data(data_path)

    muscles_names2 = ["Czworoboczny grzbietu L","Trójgłowy ramienia L", "Dwugłowy ramienia L", "Prostownik nadgarstka L","Skośny brzucha L", "Pośladkowy średni L","Czworogłowy uda L", "Brzuchaty łydki L","Czworoboczny grzbietu P","Trójgłowy ramienia P", "Dwugłowy ramienia P", "Prostownik nadgarstka P","Skośny brzucha P", "Pośladkowy średni P","Czworogłowy uda P", "Brzuchaty łydki P"]

    aver_arr=np.zeros((16,1000)) 
    
    c3d_to_compare= c3d(path)
    eventTime = c3d_to_compare['parameters']['EVENT']['TIMES']['value'][1] 
    nFrames = c3d_to_compare['parameters']['POINT']['FRAMES']['value'][0]
    nn = nFrames/1000
    markevent = eventTime/nn*100
    
    
   
    p0 = round(markevent[int(part)-1])
    p1 = round(markevent[int(part)])
    
    print(p0)
    print(p1)
    print(part)
    for num in range(16):
        subplot(1, 2, 1)
        plt.subplots_adjust(left=0.125,
                    bottom=0.1, 
                    right=5, 
                    top=0.3, 
                    wspace=0.25, 
                    hspace=0.35)
         
        emg_processed_event=emg_processed[num]
        emg_processed_event2 = (
        emg_processed_event.meca.normalize(ref=None, scale=1)            
        )
        time_normalized=emg_processed_event2.meca.time_normalize(n_frames=1000)
   
    

        
        for t in range(1000):
                aver_arr[num][t]=aver_arr[num][t]+time_normalized.values[t]
       
        aver_arr[num]=aver_arr[num]/10
        time=np.linspace(1,1000,1000)
        plt.plot(aver_arr[num][int(p0):int(p1)]) 
       
        plt.title(muscles_names2[num])
        plt.show()
    
    return aver_arr<jupyter_output><empty_output><jupyter_text>part zasięg (0:11)<jupyter_code>showPart(path,emg_processed=None,part=11)<jupyter_output>823.0
892.0
11
{'fraction_non_alphanumeric': 0.14176678445229682, 'fraction_numerical': 0.038869257950530034, 'mean_word_length': 3.941340782122905, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '658774', 'license': 'Apache-2.0', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2882, 'n_words': 417, 'path': 'RDCLabs/2019 - Przenoszenie EMG.ipynb', 'repo_name': 'kkluwak/PJATK2020', 'size': '7075'}