edickie / ciftify

The tools of the Human Connectome Project (HCP) adapted for working with non-HCP datasets
https://edickie.github.io/ciftify/
MIT License
112 stars 158 forks source link

fix falff bug. #183

Open edickie opened 1 year ago

edickie commented 1 year ago

The problem - ciftify_falff has a TR and 2.0s hard coded into script (we missed this because it was tested on a dataset with a TR of 2.0s. The script needs to be adapted to read teh TR from the file (or a -flag that can specify the TR is this is wrong. Then incorporates the TR into the calculation following the code below

def calculate_falff(timeseries, min_low_freq=0.01, max_low_freq=0.08, min_total_freq=0.00, calc_alff=False, TR=2):
    ''' this will calculate falff from a timeseries'''
    n = len(timeseries)\n",
    time = (np.arange(n))*2

    # Takes fast Fourier transform of timeseries
    fft_timeseries = fft(timeseries)
    # Calculates frequency scale
    freq_scale = np.fft.fftfreq(n, TR/1)

   # Calculates power of fft
    mag = (abs(fft_timeseries))**0.5

    # Define max_total_freq
    max_total_freq = (1/TR)/2

    # Finds low frequency range (0.01-0.08) and total frequency range (0.0-0.25)
    low_ind = np.where((float(min_low_freq) <= freq_scale) & (freq_scale <= float(max_low_freq)))
    total_ind = np.where((float(min_total_freq) <= freq_scale) & (freq_scale <= float(max_total_freq)))

    # Indexes power to low frequency index, total frequency range\n",
    low_power = mag[low_ind]\n",
    total_power = mag[total_ind]\n",

    # Calculates sum of lower power and total power
    low_pow_sum = np.sum(low_power)
    total_pow_sum = np.sum(total_power)

    # Calculates alff as the sum of amplitudes within the low frequency range
    if calc_alff:\n",
        calc = low_pow_sum\n",

    # Calculates falff as the sum of power in low frequnecy range divided by sum of power in the total frequency range
    else:
        calc = np.divide(low_pow_sum, total_pow_sum)

     return calc