Phase_graphics.py 3.17 KB
Newer Older
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
33
from .complex_field_visualization import complex_to_rgb
34
from .stack_viewer import XYZStackViewer, SingleStackViewer
35
36
37


def Phase_graphics(config, output):
38
39
40
41
    # algortihm=config['algorithm']
    # beta0 = config['beta_0']
    # beta_max = config['beta_max']
    # u_0 = config['u_0']
42
43
44
45
    if output['u1'].ndim == 2:
        u = output['u1']
        u2 = output['u2']
    else:
46
47
48
        u = output['u1'][:, :, 0]
        u2 = output['u2'][:, :, 0]
    # iter = output['iter']
49
50
51
    change = output['change']


52
    f, ((ax1, ax2), (ax3, ax4)) = subplots(2, 2, figsize=(12,8))
53

54
    im = ax1.imshow(np.abs(u), cmap='gray')
55
56
57
    f.colorbar(im, ax=ax1)
    ax1.set_title('best approximation amplitude - physical constraint satisfied')

58
59
60
    im = ax2.imshow(complex_to_rgb(u))
    # im = ax2.imshow(np.real(u), cmap='gray')
    # f.colorbar(im, ax=ax2)
61
62
    ax2.set_title('best approximation phase - physical constraint satisfied')

63
    im = ax3.imshow(np.abs(u2), cmap='gray')
64
65
66
    f.colorbar(im, ax=ax3)
    ax3.set_title('best approximation amplitude - Fourier constraint satisfied')

67
68
69
    im = ax4.imshow(complex_to_rgb(u2))
    # im = ax4.imshow(np.real(u2), cmap='gray')
    # f.colorbar(im, ax=ax4)
70
71
    ax4.set_title('best approximation amplitude - Fourier constraint satisfied')

72
73
    g, ((bx1, bx2), (bx3, bx4)) = subplots(2, 2, figsize=(12,8))
    im = bx1.imshow(np.abs(u), cmap='gray')
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    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()
88
89
90
91
92


def Phase_graphics_3d(config, output):
    # TODO: do something smart
    return 0