как сглаживать большие аномалии в графике - PullRequest
0 голосов
/ 19 июня 2020

Я вычислил переменную для каталога, в котором есть 6 подпапок. Во время вычислений, благодаря моему методу, я получил «NaN», который преобразовал их в 0, и, используя интерполяцию, я попытался улучшить его. Но есть некоторые большие аномалии, о которых я не знаю, где это происходит? Кроме того, я не знаю, что мне делать, чтобы решить эту проблему? Будем признательны за все старания. Код, который я написал, ниже, более того, я приложил график, о котором упоминал выше.

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...