def test_cmscr1d_img_zero_Dirichlet(self): print("Running test 'test_cmscr1d_img_custom_mesh'") # Create zero image. img = np.zeros((10, 25)) v, k, res, fun, converged = cmscr1d_img(img, 1.0, 1.0, 1.0, 1.0, 1.0, 'mesh', bc='zero') np.testing.assert_allclose(v.shape, img.shape) np.testing.assert_allclose(v, np.zeros_like(v)) np.testing.assert_allclose(k.shape, img.shape) np.testing.assert_allclose(k, np.zeros_like(k))
def test_cmscr1d_img_default_fd(self): print("Running test 'test_cmscr1d_img_default_fd'") # Create zero image. img = np.zeros((10, 25)) v, k, res, fun, converged = cmscr1d_img(img, 1.0, 1.0, 1.0, 1.0, 1.0, 'fd') np.testing.assert_allclose(v.shape, img.shape) np.testing.assert_allclose(v, np.zeros_like(v)) np.testing.assert_allclose(k.shape, img.shape) np.testing.assert_allclose(k, np.zeros_like(k))
def test_cmscr1d_img_custom_mesh(self): print("Running test 'test_cmscr1d_img_custom_mesh'") # Create zero image. img = np.zeros((10, 25)) # Create custom mesh. m, n = img.shape mesh = RectangleMesh(Point(0, 0), Point(0.1, 1), m - 1, n - 1) v, k, res, fun, converged = cmscr1d_img(img, 1.0, 1.0, 1.0, 1.0, 1.0, 'mesh', mesh=mesh) np.testing.assert_allclose(v.shape, img.shape) np.testing.assert_allclose(v, np.zeros_like(v)) np.testing.assert_allclose(k.shape, img.shape) np.testing.assert_allclose(k, np.zeros_like(k))
cax = ax.imshow(err, cmap=cm.viridis) ax.set_title('Error') fig.colorbar(cax, orientation='vertical') # Set regularisation parameters. alpha0 = 1e-1 alpha1 = 1e-2 alpha2 = 1e3 alpha3 = 1e3 beta = 1e-10 # Compute velocities. # vel = of1d(f, alpha0, alpha1) # vel = cm1d(f, alpha0, alpha1) # vel, k = cms1d(f, alpha0, alpha1, alpha2, alpha3) vel, k, res, fun, converged = cmscr1d_img(f, alpha0, alpha1, alpha2, alpha3, beta, 'mesh') # vel, k, res, fun converged = cmscr1dnewton(f, alpha0, alpha1, alpha2, # alpha3, beta) # Plot and save figures. saveimage(os.path.join(resultpath, 'artificial'), name, f) savevelocity(os.path.join(resultpath, 'artificial'), name, f, vel) savevelocity(os.path.join(resultpath, 'artificial'), 'artificial-gt', f, v) savesource(os.path.join(resultpath, 'artificial'), name, k) saveerror(os.path.join(resultpath, 'artificial'), name, np.abs(v - vel[:-1, :])) # Compute differences. # Compute and save strain rate. m, n = f.shape
res_cmscr1d = [collections.defaultdict(dict) for x in range(len(prod_cmscr1d))] fun_cmscr1d = [collections.defaultdict(dict) for x in range(len(prod_cmscr1d))] converged_cmscr1d = [collections.defaultdict(dict) for x in range(len(prod_cmscr1d))] count = 1 for idx, p in enumerate(prod_cmscr1d): # Run through datasets. for gen in genotypes: for dat in datasets[gen]: print("{0}/{1}".format(count, num_datasets * len(prod_cmscr1d))) vel_cmscr1d[idx][gen][dat], \ k_cmscr1d[idx][gen][dat], \ res_cmscr1d[idx][gen][dat], \ fun_cmscr1d[idx][gen][dat], \ converged_cmscr1d[idx][gen][dat] = \ cmscr1d_img(imgp[gen][dat], p[0], p[1], p[2], p[3], p[4], 'mesh') count += 1 # Store results. with open(os.path.join(resultpath, 'pkl', 'vel_cmscr1d.pkl'), 'wb') as f: pickle.dump(vel_cmscr1d, f, pickle.HIGHEST_PROTOCOL) with open(os.path.join(resultpath, 'pkl', 'k_cmscr1d.pkl'), 'wb') as f: pickle.dump(k_cmscr1d, f, pickle.HIGHEST_PROTOCOL) with open(os.path.join(resultpath, 'pkl', 'res_cmscr1d.pkl'), 'wb') as f: pickle.dump(res_cmscr1d, f, pickle.HIGHEST_PROTOCOL) with open(os.path.join(resultpath, 'pkl', 'fun_cmscr1d.pkl'), 'wb') as f: pickle.dump(fun_cmscr1d, f, pickle.HIGHEST_PROTOCOL) with open(os.path.join(resultpath, 'pkl', 'converged_cmscr1d.pkl'), 'wb') as f: pickle.dump(converged_cmscr1d, f, pickle.HIGHEST_PROTOCOL) # Clear memory.