1

My first post here.

So I'm loading data into a variable called f1_data, then passing it to pm.removeDC() function to do some signal processing, and keeping the result into the same variable. But then, I want to replace only the column 8, with the original f1_data that I called raw_data and I can't figure it out why it doesn't work. Here are the functions. Help anyone?

inside file pm.py

def removeDC(data):    
    # define the filter
    butter_order = 2
    hp_cutoff_Hz = 1.0
    b, a = signal.butter(butter_order, hp_cutoff_Hz/(fs_Hz / 2.0), 'highpass')

    for i in range(1,9):
        data[:,i] = signal.lfilter(b, a, data[:,i], 0)

    return (data)

def get_epoch1(data, t_sec, epoch, f_tup, col):
#f_tup = (f_wdir, f_name, f_columns, out_save, out_dir, out_number, fig_width)
    f_name = f_tup[1]
    fig_width = f_tup[6]

    epoch_boolvector = (t_sec >= epoch[0][0]) & (t_sec <= epoch[0][1])
    epoch_timescale = t_sec[epoch_boolvector]
    epoch_data = data[epoch_boolvector]

    plt.figure(figsize=(fig_width,8), dpi=96)
    plt.plot(epoch_timescale, epoch_data[:,col]);
    plt.xlim(epoch_timescale[0], epoch_timescale[-1])
    plt.show()
    return (epoch_boolvector, epoch_timescale, epoch_data)

inside main file

#load the whole data
(f1_data, f1_data_indices, f1_timescale) = pm.load_data(f1_wdir, f1_name)

raw_data = f1_data[:] #create copy of f1_data

(f1ep1_boolvector, f1ep1_timescale, f1ep1_data) = pm.get_epoch1(f1_data, f1_timescale, f1_epochs[1], f1_tup, 8)

#--- filter data to remove DC (1Hz)
f1_data = pm.removeDC(f1_data)


# replace only channel 8 with original data
f1_data[:,8] = raw_data[:,8]
(f1ep2_boolvector, f1ep2_timescale, f1ep2_data) = pm.get_epoch1(f1_data, f1_timescale, f1_epochs[1], f1_tup, 8)
7
  • what doesn't work? Commented Jun 6, 2017 at 19:34
  • 1
    A minimal example (barebones code, with print statements as output) would be more useful for your understanding and our troubleshooting. Commented Jun 6, 2017 at 19:36
  • Wild guess: what happens if you use copy.deepcopy to create raw_data instead of raw_data = f1_data[:]? Commented Jun 6, 2017 at 19:37
  • Is f1_data a numpy array? Commented Jun 6, 2017 at 19:37
  • 2
    What is f1_data? Doing raw_data = f1_data[:] will create a shallow copy, you may need to use deepcopy instead: docs.python.org/2/library/copy.html Commented Jun 6, 2017 at 19:38

1 Answer 1

1

The solution is import copy and use copy.deepcopy function. For further info check this link: docs.python.org/2/library/copy.html

When I have raw_data = f1_data[:] I get, after pm.removeDC():

 raw_data is f1_data: False
(raw_data == f1_data).all(): True  

But when I have raw_data = copy.deepcopy(f1_data) I get, after pm.removeDC():

 raw_data is f1_data: False  
(raw_data == f1_data).all(): False
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.