def test_of1d_img_default_fd(self): # Create zero image. img = np.zeros((10, 25)) v, res, fun = of1d_img(img, 1, 1, 'fd') np.testing.assert_allclose(v.shape, img.shape) np.testing.assert_allclose(v, np.zeros_like(v))
w = 0.1 lambdap = 1 / (4 * np.pi) tau = 1.0 c0 = 0.0 # Create mesh and function spaces. m, n = 30, 100 mesh = UnitSquareMesh(m - 1, n - 1) V = dh.create_function_space(mesh, 'default') W = dh.create_function_space(mesh, 'periodic') # Run experiments with non-decaying data. f = ConstantData().create(m, n, w, lambdap, tau) datastr = ConstantData().string() v, res, fun = of1d_img(f, alpha0, alpha1, 'mesh') saveresults(resultpath, 'analytic_example_const_of1d_l2h1_img', 'l2h1', f, v) v, res, fun = of1d_img_pb(f, alpha0, alpha1, 'mesh') saveresults(resultpath, 'analytic_example_const_of1d_l2h1_img_pb', 'l2h1', f, v) v, res, fun = cm1d_img(f, alpha0, alpha1, 'mesh') saveresults(resultpath, 'analytic_example_const_cm1d_l2h1_img', 'l2h1', f, v) v, res, fun = cm1d_img_pb(f, alpha0, alpha1, 'mesh') saveresults(resultpath, 'analytic_example_const_cm1d_l2h1_img_pb', 'l2h1', f, v) v, k, res, fun = cms1d_img(f, alpha0, alpha1, alpha2, alpha3, 'mesh') saveresults(resultpath, 'analytic_example_const_cms1d_l2h1h1_img', 'l2h1h1', f,
# Compute velocity and source for all parameter pairs. print("Running of1d on {0} datasets ".format(num_datasets) + "and {0} parameter combinations.".format(len(prod_of1d))) vel_of1d = [collections.defaultdict(dict) for x in range(len(prod_of1d))] res_of1d = [collections.defaultdict(dict) for x in range(len(prod_of1d))] fun_of1d = [collections.defaultdict(dict) for x in range(len(prod_of1d))] count = 1 for idx, p in enumerate(prod_of1d): # Run through datasets. for gen in genotypes: for dat in datasets[gen]: print("{0}/{1}".format(count, num_datasets * len(prod_of1d))) vel_of1d[idx][gen][dat], \ res_of1d[idx][gen][dat], \ fun_of1d[idx][gen][dat] = of1d_img(imgp[gen][dat], p[0], p[1], 'mesh') count += 1 # Store results. with open(os.path.join(resultpath, 'pkl', 'vel_of1d.pkl'), 'wb') as f: pickle.dump(vel_of1d, f, pickle.HIGHEST_PROTOCOL) with open(os.path.join(resultpath, 'pkl', 'res_of1d.pkl'), 'wb') as f: pickle.dump(res_of1d, f, pickle.HIGHEST_PROTOCOL) with open(os.path.join(resultpath, 'pkl', 'fun_of1d.pkl'), 'wb') as f: pickle.dump(fun_of1d, f, pickle.HIGHEST_PROTOCOL) # Clear memory. del vel_of1d # Compute velocity and source for all parameter pairs. print("Running cms1dl2 on {0} datasets ".format(num_datasets) +
# Load kymograph. datfolder = os.path.join(datapath, os.path.join(gen, dat)) img, name = load_kymo(datfolder, dat) # Prepare image. imgp = prepareimage(img) # Figure 5: different models. # Set regularisation parameters for of1d. alpha0 = 5e-3 alpha1 = 5e-3 # Compute velocity. vel, res, fun = of1d_img(imgp, alpha0, alpha1, 'mesh') # Plot and save figures. path = os.path.join(*[resultpath, 'of1d', gen, dat]) if not os.path.exists(resultpath): os.makedirs(resultpath) ph.saveimage(path, name, imgp) ph.savevelocity(path, name, img, vel) # Set regularisation parameters for cms1dl2. alpha0 = 5e-3 alpha1 = 5e-3 gamma = 1e-1 # Compute velocity and source.