Ejemplo n.º 1
0
    def _track_process(self, group_number):
        data_name = (str(group_number) + '.hdf5'
                     if self.multiprocess else self.dataname)
        with dataframes.DataStore(data_name, load=False) as data:
            data.add_metadata('num_frames', self.num_frames)
            data.add_metadata('video_filename', self.vidname)
            data.add_metadata('crop', self.manager.preprocessor.crop)
            start = self.frame_div * group_number
            vid = video.ReadVideo(self.vidname)
            vid.set_frame(start)
            if group_number == 3:
                missing = self.num_frames - self.num_processes * (
                    self.frame_div)
                frame_div = self.frame_div + missing
            else:
                frame_div = self.frame_div

            # Iterate over frames
            for f in tqdm(range(frame_div), 'Tracking'):
                frame = vid.read_next_frame()
                info, boundary, info_headings = self.manager.analyse_frame(
                    frame)
                data.add_tracking_data(start + f, info,
                                       col_names=info_headings)
                if f == 0:
                    data.add_metadata('boundary', boundary)
Ejemplo n.º 2
0
 def extra_steps(self, filename):
     vid_name = filename + ".MP4"
     data_name = filename + ".hdf5"
     with dataframes.DataStore(data_name, True) as d:
         f = d.metadata['num_frames']
         duty_cycle = read_audio_file(vid_name, f)
         d.add_frame_property('Duty', duty_cycle)
def calculate_and_save_data(files):
    for file in tqdm(files):
        filename = os.path.splitext(os.path.split(file)[1])[0]
        rate, direction, trial = filename.split('_')
        trial = int(trial)
        df = dataframes.DataStore(file).df
        df.Duty = df.Duty.round()
        df = filter_box(df, 750, 1250, 750, 1250)
        result = df.groupby('frame')[PARAMETER].mean()
        result.to_csv(f'{save_direc}/{rate}_{direction}_{trial}')
def create_csv(file):
    filename = os.path.splitext(os.path.split(file)[1])[0]
    rate, direction, trial = filename.split('_')
    trial = int(trial)
    with dataframes.DataStore(file) as data:
        df = data.df
    df.Duty = df.Duty.round()
    df = filter_hexagon(df, data.metadata['boundary'], 0.8)

    df = df.groupby('Duty')[PARAMETER].mean()
    df.to_csv(f'{save_direc}/{rate}_{direction}_{trial}')
Ejemplo n.º 5
0
def check(filename):
    core_name = os.path.splitext(filename)[0]
    vid_name = core_name + '.MP4'
    data_name = core_name + '.hdf5'
    out_name = core_name + '_check.png'
    data = dataframes.DataStore(data_name)
    crop = data.metadata['crop']
    vid = video.ReadVideo(vid_name)
    print(vid_name)
    frames = np.arange(4)*vid.num_frames//4
    ims = [images.crop(vid.read_frame(f), crop) for f in frames]
    circles = [data.get_info(f, ['x', 'y', 'r']) for f in frames]
    new_ims = [images.draw_circles(im, c) for im, c in zip(ims, circles)]
    out = images.vstack(images.hstack(new_ims[0], new_ims[1]),
                        images.hstack(new_ims[2], new_ims[3]))
    images.save(out, out_name)
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)
Ejemplo n.º 8
0
    '0.6': ['16870001', '16870002'],
    '0.2': ['16870005', '16870006'],
    '0.1': ['16870007', '16870008'],
    '0.05': ['16870009', '16870010'],
    '0.8': ['16870011', '16870012'],
    '1': ['16870013', '16870014'],
    '2': ['16870015', '16870016']
}

files = {r: [direc + d, direc + u] for r, (d, u) in files.items()}
for i, (rate, (down, up)) in enumerate(files.items()):
    print(i)
    print(rate)
    fig, ax = plt.subplots()
    ax.set_title(rate)
    down_data = dataframes.DataStore(down + '.hdf5')
    up_data = dataframes.DataStore(up + '.hdf5')

    if i == 0:
        up_video = video.ReadVideo(up + '.MP4')
        frame = up_video.read_next_frame()
        frame = images.crop(frame, up_data.metadata['crop'])
        result = images.crop_polygon(frame)
        bbox = result.bbox
        with open(save_direc + 'bbox.txt', 'w') as f:
            f.writelines([
                'BBOX xmin, xmax, ymin, ymax',
                str(bbox.xmin),
                str(bbox.xmax),
                str(bbox.ymin),
                str(bbox.ymax)
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
Ejemplo n.º 10
0
from particletracking import dataframes

data = dataframes.DataStore("/media/NAS/share/James/HighSpeed/test.hdf5")
print(data.df.head())
Ejemplo n.º 11
0
import filehandling
from particletracking import dataframes
import trackpy as tp

# direc1 = filehandling.open_directory(initialdir='/media/data/Data')
# files1 = filehandling.get_directory_filenames(direc1+'/*.hdf5')
#
# direc2 = filehandling.open_directory(initialdir='/media/data/Data')
# files2 = filehandling.get_directory_filenames(direc1+'/*.hdf5')
#
# files = files1 + files2

files = ["/media/data/Data/FirstOrder/PhaseDiagram/FlatPlate2Feb2021/2000.hdf5",]

for file in files:
    with dataframes.DataStore(file) as data:
        d = data.df.copy()
        print(d.head())
    d = d.reset_index()
    print(d.head())
    d = tp.link(d, d.r.mean())