Пример #1
0
    frame = vid.read_next_frame()
    return images.crop_polygon(frame)


def go(files, crop_result):
    for i, file in tqdm(enumerate(files)):
        # file = direc + '/' + file
        name, ext = os.path.splitext(file)
        if ext == '.MP4':
            if i == 0 and crop_result is None:
                print('cropping')
                crop_result = get_crop_result(file)
            data_file = name + '.hdf5'
            if not os.path.exists(data_file):
                tracker = tracking.ParticleTracker(
                    file, track.HoughManager(crop_result=crop_result), True)
                tracker.track()
                # tracker.link()
    return crop_result


parent = "/media/data/Data/N32/PhaseDiagram_2021_07_06"
all_files = []
for direc in os.listdir(parent):
    new_direc = parent + '/' + direc
    print(new_direc)
    files = filehandling.get_directory_filenames(new_direc + '/*.MP4')
    all_files += files

print(all_files)
go(all_files, None)
import filehandling
from particletracking import dataframes

import numpy as np
import pandas as pd
import os
import matplotlib.pyplot as plt

directory = filehandling.open_directory('/media/data/Data')
files = filehandling.get_directory_filenames(directory + '/*.hdf5')

duties = np.arange(750, 525, 25)
numbers = np.arange(1700, 2400, 50)

counts = {n: {d: 0 for d in duties} for n in numbers}
for file in files:
    filename = os.path.splitext(os.path.split(file)[1])[0]
    number, duty = filename.split('_')
    number = int(number)
    duty = int(duty)
    data = dataframes.DataStore(file)
    order = data.df.order
    count = np.count_nonzero(order > 0.95) / len(order)
    counts[number][duty] = count
    # print(count)
counts = pd.DataFrame(counts)
counts.plot()
plt.show()
def run():
    direc = "/media/data/Data/FirstOrder/Interfaces/RecordFluctuatingInterfaceJanuary2020/Quick/first_frames"
    savename = f"{direc}/data_new.hdf5"
    files = filehandling.get_directory_filenames(direc + '/*.png')
    ims = [images.load(f, 0) for f in tqdm(files, 'Loading images')]
    ims = [images.bgr_to_gray(im) for im in ims]
    circles = [images.find_circles(im, 27, 200, 7, 16, 16)
               for im in tqdm(ims, 'Finding Circles')]

    data = dataframes.DataStore(savename, load=False)
    for f, info in tqdm(enumerate(circles), 'Adding Circles'):
        data.add_tracking_data(f, info, ['x', 'y', 'r'])

    calc = statistics.PropertyCalculator(data)
    calc.order()

    lattice_spacing = 10
    x = np.arange(0, ims[0].shape[1], lattice_spacing)
    y = np.arange(0, ims[0].shape[0], lattice_spacing)
    x, y = np.meshgrid(x, y)

    # cgw = get_cgw(data.df.loc[0], 1.85) # k=1.85 looked the best
    cgw = get_cgw(data.df.loc[0], 1.85)

    fields = [coarse_order_field(data.df.loc[f], cgw, x, y)
              for f in tqdm(range(len(ims)), 'Calculating Fields')]

    field_threshold = get_field_threshold(fields, lattice_spacing, ims[0])

    contours = [find_contours(f, field_threshold)
                for f in tqdm(fields, 'Calculating contours')]

    # Multiply the contours by the lattice spacing and squeeze
    contours = [c.squeeze() * lattice_spacing for c in contours]

    # Close contours
    contours = [close_contour(c) for c in contours]

    # Convert to LineString
    contours = [LineString(c) for c in contours]

    # Select the line to query the points across
    print("Select the line to query points")
    ls = LineSelector(ims[0])
    p1, p2 = ls.points
    centre_line = get_extended_centre_line(p1, p2)

    # Distance between query points that determines one end of the frequency
    dL = data.df.loc[0].r.mean() / 10
    L = np.sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)
    N_query = int(L/dL)
    xq, yq = np.linspace(p1[0], p2[0], N_query), np.linspace(p1[1], p2[1],
                                                             N_query)
    dL = np.sqrt((xq[1] - xq[0]) ** 2 + (yq[1] - yq[0]) ** 2)
    dists, crosses = zip(
        *[get_dists(xq, yq, c, centre_line) for c in tqdm(contours)])

    # plot_crosses(crosses, ims)

    # Select points from inside red edge to inside red edge across the centre
    # of the tray which is 200mm to convert pixels to mm
    PIX_2_mm = get_pix_2_mm(ims[0])

    plot_fft(dists, dL, PIX_2_mm, data.df.loc[0].r.mean(), cgw)
import numpy as np
import matplotlib.pyplot as plt
import filehandling
from labvision import images
from math import atan, sin, cos
import cv2

direc = "/media/data/Data/January2020/RecordFluctuatingInterface/Quick/first_frames/"

pixels_to_mms = 0.11797
x = np.loadtxt(direc + 'x.txt') / pixels_to_mms
hs = np.loadtxt(direc + 'hs.txt') / pixels_to_mms
h = hs[20]

files = filehandling.get_directory_filenames(direc + '/*.png')

im = images.load(files[20])


def rotate_points(points, center, a):
    rot = np.array(((cos(a), -sin(a)), (sin(a), cos(a))))
    a1 = points - center
    a2 = rot @ a1.T
    a3 = a2.T + center
    return a3


p1 = [333, 1318]
p2 = [1784, 528]
midpoint = np.array([p1[0] - p2[0], p1[1] - p2[1]])
h = h + midpoint[1]
Пример #5
0
from particletracking import statistics, dataframes
import filehandling
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

direc = "/media/data/Data/August2020/Hysterisis/RedTray2"
save_direc = "/media/data/Data/August2020/Hysterisis/RedTray2/Results_boxed_density_frame"
files = filehandling.get_directory_filenames(direc + '/*.hdf5')
#
# for file in files:
#     print(file)
#     filename = os.path.splitext(os.path.split(file)[1])[0]
#     rate, direction, trial = filename.split('_')
#     trial = int(trial)
#     df = dataframes.DataStore(file).df
#     if file == files[0]:
#         r = df.r.mean()
#     df = df.loc[(df.x > 750) * (df.x < 1250) * (df.y > 750) * (df.y < 1250)]
#     # df = df.loc[df.edge_distance > 5*r]
#     df.Duty = df.Duty.round()
#     # xmean = df.x.mean()
#     # df = df.loc[df.x > xmean]
#
#     result = df.groupby(df.index)['density'].mean()
#     result.to_csv(save_direc+'/{}_{}_{}'.format(rate, direction, trial))

data_files = filehandling.get_directory_filenames(save_direc + '/*')

results = {}
def run(direc, lattice_spacing=5):
    files = filehandling.get_directory_filenames(direc + '/*.png')
    print(files)
    savename = direc + '/data.hdf5'

    N = len(files)

    # load images
    ims = [images.load(f, 0) for f in tqdm(files, 'Loading images')]

    images.display(ims[0])
    # Find Circles
    ims = [images.bgr_to_gray(im) for im in ims]
    circles = [
        images.find_circles(im, 27, 200, 7, 16, 16)
        for im in tqdm(ims, 'Finding Circles')
    ]

    # Save data
    data = dataframes.DataStore(savename, load=False)
    for f, info in tqdm(enumerate(circles), 'Adding Circles'):
        data.add_tracking_data(f, info, ['x', 'y', 'r'])

    # Calculate order parameter
    calc = statistics.PropertyCalculator(data)
    calc.order()

    # Get the course graining width
    cgw = get_cgw(data.df.loc[0]) / 2

    # Create the lattice points
    x = np.arange(0, max(data.df.x), lattice_spacing)
    y = np.arange(0, max(data.df.y), lattice_spacing)
    x, y = np.meshgrid(x, y)

    # Calculate the coarse order fields
    fields = [
        coarse_order_field(data.df.loc[f], cgw, x, y)
        for f in tqdm(range(N), 'Calculating Fields')
    ]

    # Calculate the field threshold
    field_threshold = get_field_threshold(fields, lattice_spacing, ims[0])

    # Find the contours representing the boundary in each frame
    contours = [
        find_contours(f, field_threshold)
        for f in tqdm(fields, 'Calculating contours')
    ]

    # Multiply the contours by the lattice spacing
    contours = [c * lattice_spacing for c in contours]

    # Find the angle of the image to rotate the boundary to the x-axis
    a, c, p1, p2 = get_angle(ims[0])
    print(p1)
    print(p2)
    # Rotate the selection points and the contours by the angle
    p1 = rotate_points(np.array(p1), c, a)
    p2 = rotate_points(np.array(p2), c, a)
    contours = [rotate_points(contour.squeeze(), c, a) for contour in contours]

    xmin = int(p1[0])
    xmax = int(p2[0])
    h = int(p1[1])

    # Get the heights of the fluctuations from the straight boundary
    hs = [
        get_h(contour, ims[0].shape, xmin, xmax, h)
        for contour in tqdm(contours, 'Calculating heights')
    ]

    # Calculate the fourier transforms for all the frames
    L = xmax - xmin
    pixels_to_mms = 195 / L
    print("pixels_to_mms = ", pixels_to_mms)

    # convert to mm
    hs = [h * pixels_to_mms for h in hs]
    L = L * pixels_to_mms
    x = np.linspace(0, L, len(hs[0]))

    np.savetxt(direc + '/x.txt', x)
    np.savetxt(direc + '/hs.txt', hs)

    # k, yplot = get_fourier(hs, L)

    return k, yplot