def rechoose_boundary(self):
     meta = helpy.load_meta(self.prefix)
     boundary, path = ring_motion.find_boundary(self.prefix)
     meta.update(boundary = boundary)
     meta['path_to_tiffs'] = path
     helpy.save_meta(self.prefix, meta)
     self.x0, self.y0, self.R = boundary
     self.side_len = self.R * self.real_particle /4.0
     self.boundary_shape = Point(self.y0, 1024 - self.x0).buffer(self.R)
     return
Beispiel #2
0
    elif args.plotmsd or args.rr:
        if verbose: print "loading msd data from npz files"
        datapath = absprefix+"_MSD.npz"
        msdnpz = np.load(datapath)
        msds = msdnpz['msds']
        try: msdids = msdnpz['msdids']
        except KeyError: msdids = None
        try:
            dt0  = np.asscalar(msdnpz['dt0'])
            dtau = np.asscalar(msdnpz['dtau'])
        except KeyError:
            dt0  = 10 # here's assuming...
            dtau = 10 #  should be true for all from before dt* was saved

    if args.save:
        helpy.save_meta(absprefix, meta)

if __name__=='__main__':
    if args.plotmsd:
        if verbose: print 'plotting msd now!'
        plot_msd(msds, msdids, dtau, dt0, data['f'].max()+1, tnormalize=False,
                 prefix=absprefix, show_tracks=args.showtracks, show=args.show,
                 singletracks=args.singletracks, fps=fps, S=S, save=args.save,
                 kill_flats=args.killflat, kill_jumps=args.killjump*S*S)
    if args.plottracks:
        if verbose: print 'plotting tracks now!'
        bgimage = helpy.find_first_frame([locdir, prefix])
        if args.singletracks:
            mask = np.in1d(trackids, args.singletracks)
        else:
            mask = None
Beispiel #3
0
            areas = point[:, 5].astype(int)
            amin, amax = size['min_area'], size['max_area']
            s = np.ceil(hist_bin_auto(areas))
            bins = np.arange(amin, amax + s, s)
            label = "{} area ({} - {})".format(dot, amin, amax)
            aax.hist(areas, bins, alpha=0.5, color='g', label=label)
            aax.axvline(size['min_area'], c='g', lw=2)
            aax.set_xlim(0, bins[-1])
            aax.legend(loc='best', fontsize='small')
        if args.save:
            print savenotice(dot, out, ext)
            np.savetxt(out + ext,
                       point,
                       header=hfmt.format(**size),
                       delimiter='     ',
                       fmt=txtfmt)
            helpy.txt_to_npz(out + ext, verbose=args.verbose, compress=args.gz)
    if args.save:
        from shutil import copy
        copy(first, prefix + '_' + os.path.basename(first))
        helpy.save_meta(prefix,
                        meta,
                        path_to_tiffs=os.path.abspath(filepattern),
                        first_frame=os.path.abspath(first),
                        detect_thresh=args.thresh,
                        detect_removed=args.remove)
        if args.plot:
            fig.savefig(prefix + '_SEGMENTSTATS.pdf')
    elif args.plot:
        plt.show()
Beispiel #4
0
        prefix_pattern = args.prefix
        args.prefix = helpy.replace_all(args.prefix, '*?', '') + '_MRG'
        helpy.save_log_entry(args.prefix, 'argv')
        prefixes = [p[:-9] for p in glob.iglob(
            helpy.with_suffix(prefix_pattern, '_MELT.npz'))]
        metas, mdatas = zip(*[(helpy.load_meta(prefix),
                               helpy.load_data(prefix, 'm'))
                              for prefix in prefixes])
        for meta, mdata in zip(metas, mdatas):
            mdata['f'] = mdata['f'].astype(int) - int(meta['start_frame'])
        mdata = np.concatenate(mdatas)
        meta = helpy.merge_meta(metas, excl={'start_frame'},
                                excl_start=('center', 'corner'))
        if args.save:
            np.savez_compressed(args.prefix+'_MELT', data=mdata)
            helpy.save_meta(args.prefix, meta, merged=prefixes)
            print 'merged sets', prefixes, 'saved to', args.prefix
    else:
        helpy.save_log_entry(args.prefix, 'argv')
        meta = helpy.load_meta(args.prefix)

    helpy.sync_args_meta(
        args, meta,
        ['side', 'fps', 'start', 'width', 'zoom'],
        ['sidelength', 'fps', 'start_frame', 'crystal_width', 'crystal_zoom'],
        [1, 1, 0, None, 1])

    M = 4  # number of neighbors

    W = args.width
    if W is None:
Beispiel #5
0
            eax.set_xlim(0, 1)
            eax.set_xticks(np.arange(0, 1.1, .1))
            eax.set_xticklabels(map('.{:d}'.format, np.arange(10)) + ['1'])
            eax.legend(loc='best', fontsize='small')

            areas = point[:, 5].astype(int)
            amin, amax = size['min_area'], size['max_area']
            s = np.ceil(hist_bin_auto(areas))
            bins = np.arange(amin, amax+s, s)
            label = "{} area ({} - {})".format(dot, amin, amax)
            aax.hist(areas, bins, alpha=0.5, color='g', label=label)
            aax.axvline(size['min_area'], c='g', lw=2)
            aax.set_xlim(0, bins[-1])
            aax.legend(loc='best', fontsize='small')
        if args.save:
            print savenotice(dot, out, ext)
            np.savetxt(out+ext, point, header=hfmt.format(**size),
                       delimiter='     ', fmt=txtfmt)
            helpy.txt_to_npz(out+ext, verbose=args.verbose, compress=args.gz)
    if args.save:
        from shutil import copy
        copy(first, prefix+'_'+os.path.basename(first))
        helpy.save_meta(prefix, meta,
                        path_to_tiffs=os.path.abspath(filepattern),
                        first_frame=os.path.abspath(first),
                        detect_thresh=args.thresh, detect_removed=args.remove)
        if args.plot:
            fig.savefig(prefix+'_SEGMENTSTATS.pdf')
    elif args.plot:
        plt.show()
        print "Creating new directory", outdir
        makedirs(outdir)
    if output.endswith('.gz'):
        gz = 1
        output = output[:-3]
    if output.endswith('.txt'):
        output = output[:-4]
    if output.endswith(suffix):
        prefix = output[:-len(suffix)]
    else:
        prefix = output
        output += suffix
    outs = output, prefix + '_CORNER' + suffix

    helpy.save_log_entry(prefix, argv)
    helpy.save_meta(prefix, path_to_tiffs=path.abspath(filepattern))

    kern_area = np.pi*args.kern**2
    if args.min == -1:
        args.min = kern_area/2
        if args.verbose: print "using min =", args.min
    if args.max == -1:
        args.max = 2*kern_area
        if args.verbose: print "using max =", args.max

    thresh = {'center': {'max_ecc' : args.ecc,
                         'min_area': args.min,
                         'max_area': args.max,
                         'kern'   : args.kern}}

    if args.ckern:
Beispiel #7
0
        'center': {
            'max_ecc': args.ecc,
            'min_area': args.min or int(kern_area // 2),
            'max_area': args.max or int(kern_area * 2 + 1),
            'kern': float(args.kern),
            'thresh': args.thresh,
            'convex': args.convex
        }
    }
    meta.update({k: v for k, v in size['center'].iteritems()})
    #initialize boundary
    boundary = meta.get('boundary')
    if boundary is None or boundary == [0.0] * 3:
        boundary = helpy.circle_click(first)
    meta.update(boundary=boundary)
    helpy.save_meta(prefix, meta)
    x0, y0, R0 = boundary
    #initialize model for machine leanring
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
    # load category network
    net_cat = ClassNet()
    net_cat.load_state_dict(torch.load(args.cpath))
    net_cat.eval()
    net_cat.to(device)
    # load orientation network
    net = ConvNet()
    net.load_state_dict(torch.load(args.opath))
    net.eval()
    net.to(device)

    def extract_image(xys, image, image_size=32):
Beispiel #8
0
        prefixes = [
            p[:-9]
            for p in glob.iglob(helpy.with_suffix(prefix_pattern, '_MELT.npz'))
        ]
        metas, mdatas = zip(*[(helpy.load_meta(prefix),
                               helpy.load_data(prefix, 'm'))
                              for prefix in prefixes])
        for meta, mdata in zip(metas, mdatas):
            mdata['f'] = mdata['f'].astype(int) - int(meta['start_frame'])
        mdata = np.concatenate(mdatas)
        meta = helpy.merge_meta(metas,
                                excl={'start_frame'},
                                excl_start=('center', 'corner'))
        if args.save:
            np.savez_compressed(args.prefix + '_MELT', data=mdata)
            helpy.save_meta(args.prefix, meta, merged=prefixes)
            print 'merged sets', prefixes, 'saved to', args.prefix
    else:
        helpy.save_log_entry(args.prefix, 'argv')
        meta = helpy.load_meta(args.prefix)

    helpy.sync_args_meta(
        args, meta, ['side', 'fps', 'start', 'width', 'zoom'],
        ['sidelength', 'fps', 'start_frame', 'crystal_width', 'crystal_zoom'],
        [1, 1, 0, None, 1])

    M = 4  # number of neighbors

    W = args.width
    if W is None:
        data = helpy.load_data(args.prefix)
Beispiel #9
0
        'x': '-.',
        'y': ':',
        'par': '-.',
        'perp': ':',
        'etapar': '--'
    }
    cs = {'mean': 'r', 'var': 'g', 'std': 'b'}

if __name__ == '__main__':
    if 'widths' in args.command:
        command_widths(tsets, compile_args, args)
    if 'autocorr' in args.command:
        command_autocorr(tsets, args)
    if 'hist' in args.command:
        fits = command_hist(args, meta, compile_args)

if __name__ == '__main__' and args.save:
    savename = os.path.abspath(args.prefix.rstrip('/._?*'))
    helpy.save_meta(savename, meta)
    if 'hist' in args.command:
        helpy.save_fits(savename, fits)
    savename += '_v' + ('corr' if args.autocorr else 'hist')
    if args.suffix:
        savename += '_' + args.suffix.strip('_')
    savename += '.pdf'
    print 'Saving plot to {}'.format(savename)
    plt.savefig(savename)

if __name__ == '__main__' and args.show:
    plt.show()
Beispiel #10
0
             for prefix in data}

    label = {'o': r'$\xi$', 'par': r'$v_\parallel$', 'perp': r'$v_\perp$',
             'etapar': r'$\eta_\parallel$', 'x': '$v_x$', 'y': '$v_y$'}
    ls = {'o': '-', 'x': '-.', 'y': ':',
          'par': '-.', 'perp': ':', 'etapar': '--'}
    cs = {'mean': 'r', 'var': 'g', 'std': 'b'}

if __name__ == '__main__':
    if 'widths' in args.command:
        command_widths(tsets, compile_args, args)
    if 'autocorr' in args.command:
        command_autocorr(tsets, args)
    if 'hist' in args.command:
        fits = command_hist(args, meta, compile_args)

if __name__ == '__main__' and args.save:
    savename = os.path.abspath(args.prefix.rstrip('/._?*'))
    helpy.save_meta(savename, meta)
    if 'hist' in args.command:
        helpy.save_fits(savename, fits)
    savename += '_v' + ('corr' if args.autocorr else 'hist')
    if args.suffix:
        savename += '_' + args.suffix.strip('_')
    savename += '.pdf'
    print 'Saving plot to {}'.format(savename)
    plt.savefig(savename)

if __name__ == '__main__' and args.show:
    plt.show()