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 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]
x = x + midpoint[0]
Esempio n. 3
0
ax2.plot(rolling.L1, rolling.index/3600, 'r', alpha=0.3)
ax2.plot(rolling.L2, rolling.index/3600, 'r', alpha=0.3)
ax2.plot(rolling.S1, rolling.index/3600, 'b', alpha=0.3)
ax2.plot(rolling.S2, rolling.index/3600, 'b', alpha=0.3)

rolling = time_data.rolling(window=600).mean()
ax2.plot(rolling.L1, rolling.index/3600, 'r', alpha=1)
ax2.plot(rolling.L2, rolling.index/3600, 'r', alpha=1)
ax2.plot(rolling.S1, rolling.index/3600, 'b', alpha=1)
ax2.plot(rolling.S2, rolling.index/3600, 'b', alpha=1)

ax2.set_xlabel('Position (mm)', fontsize=FONTSIZE)
ax2.set_ylabel('Time (hrs)', fontsize=FONTSIZE)


display_frame = images.load("/media/data/Data/Orderphobic/TwoIntruders/SpikyIntruder/Sample.png")
ax_im.imshow(display_frame[:, :, ::-1])

from matplotlib import ticker
ax2.xaxis.set_major_formatter(ticker.FuncFormatter(lambda x, pos: ('%d') % (x * pix2mm)))
ax_im.set_yticks([])
# ax_im.set_xticks([])

def vlines(ax, arr, color):
    ax.axvline(arr.mean(), linestyle='--', color=color)
    ax.axvline(arr.mean()-(arr.std()/sqrt(len(arr))), linestyle='--', color=color, alpha=0.5)
    ax.axvline(arr.mean()+(arr.std()/sqrt(len(arr))), linestyle='--', color=color, alpha=0.5)

# Add vertical lines to show the mean positions
vlines(ax1, lx1, 'r')
vlines(ax1, lx2, 'r')
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
Esempio n. 5
0
ax2.plot(rolling.L1, rolling.index / 3600, 'r', alpha=0.3)
ax2.plot(rolling.L2, rolling.index / 3600, 'r', alpha=0.3)
ax2.plot(rolling.S1, rolling.index / 3600, 'b', alpha=0.3)
ax2.plot(rolling.S2, rolling.index / 3600, 'b', alpha=0.3)

rolling = time_data.rolling(window=600).mean()
ax2.plot(rolling.L1, rolling.index / 3600, 'r', alpha=1)
ax2.plot(rolling.L2, rolling.index / 3600, 'r', alpha=1)
ax2.plot(rolling.S1, rolling.index / 3600, 'b', alpha=1)
ax2.plot(rolling.S2, rolling.index / 3600, 'b', alpha=1)

ax2.set_xlabel('Position (mm)', fontsize=FONTSIZE)
ax2.set_ylabel('Time (hrs)', fontsize=FONTSIZE)

display_frame = images.load(
    "/media/data/Data/Orderphobic/TwoIntruders/FoamPlaIntruders/Logging/08-09_logs/sample_im.png"
)
ax_im.imshow(display_frame[:, :, ::-1])

from matplotlib import ticker

ax2.xaxis.set_major_formatter(
    ticker.FuncFormatter(lambda x, pos: ('%d') % (x * pix2mm)))
ax_im.set_yticks([])
# ax_im.set_xticks([])

# Add vertical lines to show the mean positions
ax1.axvline(lx1.mean(), linestyle='--', color='r')
ax1.axvline(lx2.mean(), linestyle='--', color='r')
ax1.axvline(sx1.mean(), linestyle='--', color='b')
ax1.axvline(sx2.mean(), linestyle='--', color='b')