0

I have computed a variable for a directory that has 6 subfolders within. At the time of computation, due to my method, I obtained "NaN" which I converted them to 0, and by using interpolation I tried to make it better. But there some big anomalies that I do not know where does it happens? Also, I do not know what should I do to solve it? All efforts will be appreciated. The code that I have written is below, moreover, I have attached the graph that I mentioned above.

root = r'/home/hossein/Desktop/Out/CUVATURE&SINOUSITY/Beta 10'


def find_threshold(arr, value):
    for i, a in enumerate(arr):
        if a == value:
            break
    return i

# The function to find the index of peak points(local maxima and minima) 


def find_peak(arr):
    indices = []
    res = []
    for i in range(1,len(arr)-1):
        if arr[i] > arr[i-1] and arr[i] > arr[i+1]:
            res.append(arr[i]) 
            indices.append(i)
        elif arr[i] < arr[i-1] and arr[i] < arr[i+1]:
            res.append(arr[i])
            indices.append(i)

    return indices, res

# The function to find spatial differenc (Using the "s" coordinate)

def find_diff(arr):
    res = []
    for i in range(1,len(arr)):
        res.append(arr[i] - arr[i-1])
    return res

# The collection of function into one function 

def compute_Lh(theta, spatial):
    indices, peaks = find_peak(theta)
    selected_spatial = spatial[indices]
    diffs = find_diff(selected_spatial)
    mean = np.mean(diffs)
    return mean

my_A_H=[]
x = []
y = []
my_list = os.listdir(root)
my_list =  [file for file in my_list if os.path.isdir(os.path.join(root, file))]
for directory in my_list:
    CASES = [file for file in os.listdir(os.path.join(root, directory)) if file.startswith('config')]
    if len(CASES)==0:
        continue
    maxnum = np.max([int(os.path.splitext(f)[0].split('_')[1]) for f in CASES])
    CASES = ['configuration_%d.out' % i for i in range(maxnum)]
    my_A_H=[]
    for i, d in enumerate (CASES):
        a = np.loadtxt(os.path.join(root, directory,d)).T
        spatial = a[2]
        theta = a[3]
        curve = a[4]
        Bend_appex = max(curve)

        threshold = find_threshold(curve, Bend_appex)

        theta_u = theta[:threshold]
        spatial_u = spatial[:threshold]

        theta_d = theta[threshold:]
        spatial_d = spatial[threshold:]




        mean_u = compute_Lh(theta_u, spatial_u)

        mean_d = compute_Lh(theta_d, spatial_d)

        mean_a = compute_Lh(theta, spatial)


        Ah_mean = (mean_u - mean_d) / mean_a

        x.append(i)
        my_A_H.append(Ah_mean)


    my_A_H =  np.array(my_A_H)

    t = np.arange(0,len(my_A_H))

    good_mask = np.isfinite(my_A_H)

    plt.plot(t [good_mask], my_A_H[good_mask],label=directory)

enter image description here

Mir.Emad
  • 83
  • 8
  • 1
    The main way would be to filter outliers out of the data. [Python remove outliers from data](https://stackoverflow.com/questions/36864917/python-remove-outliers-from-data) – Trenton McKinney Jun 18 '20 at 21:50
  • @TrentonMcKinney Great, do you have any idea that this removing should be done when? At the end and on the last list? – Mir.Emad Jun 18 '20 at 21:57
  • 1
    It's difficult to determine without seeing the raw data. My understanding is it is best to remove outliers at the beginning. If that doesn't work, then maybe the transformations are introducing irregularities. – Trenton McKinney Jun 18 '20 at 22:02
  • It's better to focus your question in a small range, for example, show a simple data file, and a simle, short and executable program, show the result and expect result. Then I think you will get your solution soon. – Jason Yang Jun 19 '20 at 02:59
  • @JasonYang You are absolutely right. In case, I wrote a symbolic executable question with fake up data but someone voted -1 and no one answered me. I'll try to follow your point. Thanks a lot. I'm extremely interested in learning python – Mir.Emad Jun 19 '20 at 07:52

0 Answers0