Phase_graphics.py 3.03 KB
 Russell Luke committed May 08, 2019 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ``````# Phase_graphics.m # written on May 23, 2012 by # Russell Luke # Inst. Fuer Numerische und Angewandte Mathematik # Universitaet Gottingen # # # DESCRIPTION: Script driver for viewing results from projection # algorithms on various toy problems # # INPUT: # method = character string for the algorithm used. # true_object = the original image # u_0 = the initial guess # u = the algorithm "fixed point" # change = the norm square of the change in the # iterates # error = squared set distance error at each # iteration # noneg = the norm square of the nonnegativity/support # constraint at each iteration # gap = the norm square of the gap distance, that is # the distance between the projections of the # iterates to the sets # # OUTPUT: graphics # USAGE: Phase_graphics(config,output) # ############################################################# from matplotlib.pyplot import subplots, show import numpy as np `````` jansen31 committed May 29, 2019 33 ``````from .complex_field_visualization import complex_to_rgb `````` Russell Luke committed May 08, 2019 34 35 36 `````` def Phase_graphics(config, output): `````` jansen31 committed May 29, 2019 37 38 39 40 `````` # algortihm=config['algorithm'] # beta0 = config['beta_0'] # beta_max = config['beta_max'] # u_0 = config['u_0'] `````` Russell Luke committed May 08, 2019 41 42 43 44 `````` if output['u1'].ndim == 2: u = output['u1'] u2 = output['u2'] else: `````` jansen31 committed May 29, 2019 45 46 47 `````` u = output['u1'][:, :, 0] u2 = output['u2'][:, :, 0] # iter = output['iter'] `````` Russell Luke committed May 08, 2019 48 49 50 `````` change = output['change'] `````` jansen31 committed May 29, 2019 51 `````` f, ((ax1, ax2), (ax3, ax4)) = subplots(2, 2, figsize=(12,8)) `````` Russell Luke committed May 08, 2019 52 `````` `````` jansen31 committed May 29, 2019 53 `````` im = ax1.imshow(np.abs(u), cmap='gray') `````` Russell Luke committed May 08, 2019 54 55 56 `````` f.colorbar(im, ax=ax1) ax1.set_title('best approximation amplitude - physical constraint satisfied') `````` jansen31 committed May 29, 2019 57 58 59 `````` im = ax2.imshow(complex_to_rgb(u)) # im = ax2.imshow(np.real(u), cmap='gray') # f.colorbar(im, ax=ax2) `````` Russell Luke committed May 08, 2019 60 61 `````` ax2.set_title('best approximation phase - physical constraint satisfied') `````` jansen31 committed May 29, 2019 62 `````` im = ax3.imshow(np.abs(u2), cmap='gray') `````` Russell Luke committed May 08, 2019 63 64 65 `````` f.colorbar(im, ax=ax3) ax3.set_title('best approximation amplitude - Fourier constraint satisfied') `````` jansen31 committed May 29, 2019 66 67 68 `````` im = ax4.imshow(complex_to_rgb(u2)) # im = ax4.imshow(np.real(u2), cmap='gray') # f.colorbar(im, ax=ax4) `````` Russell Luke committed May 08, 2019 69 70 `````` ax4.set_title('best approximation amplitude - Fourier constraint satisfied') `````` jansen31 committed May 29, 2019 71 72 `````` g, ((bx1, bx2), (bx3, bx4)) = subplots(2, 2, figsize=(12,8)) im = bx1.imshow(np.abs(u), cmap='gray') `````` Russell Luke committed May 08, 2019 73 74 75 76 77 78 79 80 81 82 83 84 85 86 `````` f.colorbar(im, ax=bx1) bx1.set_title('best approximation amplitude - physical constraint satisfied') im = bx2.imshow(np.real(u), cmap='gray') f.colorbar(im, ax=bx2) bx2.set_title('best approximation phase - physical constraint satisfied') bx3.semilogy(change) bx3.set_xlabel('iteration') bx3.set_ylabel('\$||x^{2k+2}-x^{2k}||\$') if 'diagnostic' in config: bx4.semilogy(output['gap']) bx4.set_xlabel('iteration') bx4.set_ylabel('\$||x^{2k+1}-x^{2k}||\$') show()``````