Commit aeb25645 authored by daniel.schellhorn's avatar daniel.schellhorn
Browse files

added non-relative path references to GetDate while implementing zip...

added non-relative path references to GetDate while implementing zip extraction, adding SetProxyPythonPath.py in phase and links in experiments in phase
parent dd7370d1
import SetProxPythonPath
from proxtoolbox.experiments.phase.phaseExperiment import PhaseExperiment
from proxtoolbox import proxoperators
import numpy as np
......@@ -46,7 +47,7 @@ class JWST_Experiment(PhaseExperiment):
'graphics': 1
}
return defaultParams
def __init__(self, **kwargs):
super(JWST_Experiment, self).__init__(**kwargs)
......@@ -74,20 +75,20 @@ class JWST_Experiment(PhaseExperiment):
self.use_farfield_formula = 0
else:
self.fresnel_nr = 0
self.use_farfield_formula = 1
self.use_farfield_formula = 1
"""
# So far Matlab code used only Nx to set the desired
# resolution
newres = self.Nx
# The following value for snr does not work well in Python
# as this creates numerical issues with Poisson noise
# as this creates numerical issues with Poisson noise
# (data_ball is far too small)
# snr = self.data_ball
# Instead, we choose the following bigger value which
# Instead, we choose the following bigger value which
# works well.
snr = 1e-8
snr = 1e-8
print('Loading data.')
with open('../InputData/Phase/pupil.pmod','r') as fid:
......@@ -155,7 +156,7 @@ class JWST_Experiment(PhaseExperiment):
for ii in range(newres):
for jj in range(newres):
k_j[ii,jj]= utils.PoissonRan(k_j[ii,jj])*snr # this matches what is currently done in Matlab
#k_j[ii,jj]= np.random.poisson(k_j[ii,jj])*snr # does not work: throw an exception if snr is too small
#k_j[ii,jj]= np.random.poisson(k_j[ii,jj])*snr # does not work: throw an exception if snr is too small
k_j = np.round(k_j)
rt_k_j = np.sqrt(k_j)
......@@ -172,23 +173,23 @@ class JWST_Experiment(PhaseExperiment):
self.rt_data = rt_k
self.data = k
self.norm_rt_data = norm_rt_data # this is correct since
# is is calculated in the
# is is calculated in the
# object domain
self.data_zeros = data_zeros
self.abs_illumination = Xi_A
# Normalize the illumination so that it has the
# Normalize the illumination so that it has the
# same energy as the data.
self.abs_illumination = self.abs_illumination/norm(self.abs_illumination)*self.norm_rt_data
# self.illumination_phase = aberration -> now input.FT_conv_kernel
# initial guess
perturb = (np.random.rand(newres, newres)).T # to match Matlab
perturb = (np.random.rand(newres, newres)).T # to match Matlab
if self.formulation == "cyclic":
self.u0 = self.abs_illumination*exp(1j*2*pi*perturb)
else: # product space
self.u0 = Cell(self.sets)
for j in range(self.sets):
u0_j = self.abs_illumination*exp(1j*2*pi*perturb)
u0_j = self.abs_illumination*exp(1j*2*pi*perturb)
self.u0[j] = u0_j
self.truth = true_object
......@@ -203,7 +204,7 @@ class JWST_Experiment(PhaseExperiment):
# add propagator and inverse propagator
# used by Approx_Pphase_FreFra_Poisson prox operator
# we do this now as those are needed when instantiating
# we do this now as those are needed when instantiating
# Approx_Pphase_FreFra_Poisson below
self.propagator = 'Propagator_FreFra'
self.inverse_propagator = 'InvPropagator_FreFra'
......@@ -218,7 +219,7 @@ class JWST_Experiment(PhaseExperiment):
self.proxOperators.append('Approx_Pphase_FreFra_Poisson')
self.proxOperators.append('P_amp_support')
else: # product space formulation
# add prox operators
# add prox operators
self.nProx = 2
self.proxOperators.append('P_diag')
self.proxOperators.append('Prox_product_space')
......@@ -232,7 +233,7 @@ class JWST_Experiment(PhaseExperiment):
if self.algorithm_name == 'ADMM':
# set-up variables in cells for block-wise algorithms
# ADMM has three blocks of variables, primal, auxilliary (primal
# variables in the image space of some linear mapping) and dual.
# variables in the image space of some linear mapping) and dual.
# we sort these into a 3D cell.
u0 = self.u0
self.u0 = Cell(3)
......@@ -250,7 +251,7 @@ class JWST_Experiment(PhaseExperiment):
self.u0[1][j] = fft2(self.FT_conv_kernel[j]*tmp_u0) / (self.Nx*self.Ny)
self.u0[2][j] = self.u0[1][j] / self.lambda_0
self.proxOperators.append('Prox_primal_ADMM_indicator')
self.proxOperators.append('Approx_Pphase_FreFra_ADMM_Poisson')
self.proxOperators.append('Approx_Pphase_FreFra_ADMM_Poisson')
elif self.algorithm_name == 'AvP2':
# u_0 should be a cell...we change it into a cell of cells
u0 = self.u0
......@@ -262,7 +263,7 @@ class JWST_Experiment(PhaseExperiment):
P_Diag_prox = P_Diag_class(self)
tmp_u = P_Diag_prox.eval(self.u0[2])
self.u0[1] = tmp_u[0]
self.u0[0] = u0[self.product_space_dimension-1]
self.u0[0] = u0[self.product_space_dimension-1]
elif self.algorithm_name == 'PHeBIE':
# set up variables in cells for block-wise, implicit-explicit algorithms
u0 = self.u0
......@@ -287,7 +288,7 @@ class JWST_Experiment(PhaseExperiment):
self.masks = Cell(L)
for j in range(L):
self.masks[j] = self.indicator_ampl * self.FT_conv_kernel[j]
self.data_zeros = None
self.data_zeros = None
self.FT_conv_kernel = self.masks
self.proxOperators[1] = 'Approx_Pphase_JWST_Wirt'
self.use_farfield_formula = True
......@@ -338,7 +339,7 @@ class JWST_Experiment(PhaseExperiment):
dpi = self.figure_dpi)
self.createImageSubFigure(f, ax1, abs(u), titles[0])
self.createImageSubFigure(f, ax2, real(u), titles[1])
ax3.semilogy(changes)
ax3.set_xlabel(label)
ax3.set_ylabel('Log of change in iterates')
......@@ -352,8 +353,5 @@ class JWST_Experiment(PhaseExperiment):
f.suptitle(title)
plt.subplots_adjust(hspace = 0.3) # adjust vertical space (height) between subplots (default = 0.2)
plt.subplots_adjust(wspace = 0.3) # adjust horizontal space (width) between subplots (default = 0.2)
show()
show()
#Sylvain
# Module to be imported by test modules to set the ProxPython path
# after this is called, can use import statements like this one:
# from proxtoolbox.experiments.phase import Phase, JWST_AltP_in
import sys
import os
# add the proxpython directory into the Python's path
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../../..")
import SetProxPythonPath
from proxtoolbox.experiments.experiment import Experiment
from proxtoolbox.utils.cell import Cell, isCell
from proxtoolbox.utils.size import size_matlab
......@@ -15,7 +16,7 @@ class PhaseExperiment(Experiment):
experiments should derive from this class
'''
def __init__(self,
def __init__(self,
distance='far field',
farfield=True,
**kwargs):
......@@ -33,11 +34,11 @@ class PhaseExperiment(Experiment):
Reshape data based on the given arguments. This method is called
during the initialization of the Experiment object, after the call
to loadData().
Parameters
----------
Nx, Ny, Nz: int
The new dimensions to be used.
The new dimensions to be used.
Notes
-----
......@@ -121,7 +122,7 @@ class PhaseExperiment(Experiment):
if u2.ndim > 2:
u2 = u2[:,:,0]
changes = self.output['stats']['changes']
if 'time' in self.output['stats']:
time = self.output['stats']['time']
......@@ -130,7 +131,7 @@ class PhaseExperiment(Experiment):
m = u2.shape[0]
if u2.ndim > 1:
n = u2.shape[1]
algo_desc = self.algorithm.getDescription()
title = "Algorithm: " + algo_desc
......@@ -161,7 +162,7 @@ class PhaseExperiment(Experiment):
f = self.createFourImageFigure(u_tmp, u2_tmp, titles)
f.suptitle(title)
plt.subplots_adjust(hspace = 0.3) # adjust vertical space (height) between subplots (default = 0.2)
# figure 900
if m == self.product_space_dimension or m == 1:
f = self.createTwoGraphFigure(u[0:], titles)
......@@ -175,7 +176,7 @@ class PhaseExperiment(Experiment):
u_tmp = u[:,:,0]
f = self.createTwoImageFigure(u_tmp, titles)
f.suptitle(title)
time_str = "{:.{}f}".format(time, 5) # 5 is precision
label = "Iterations (time = " + time_str + " s)"
......@@ -202,7 +203,7 @@ class PhaseExperiment(Experiment):
Display animation. This method is called
after each iteration of the algorithm `alg` if
data member `anim` is set to True.
Parameters
----------
alg : instance of Algorithm class
......@@ -216,7 +217,7 @@ class PhaseExperiment(Experiment):
u = u[0]
if isCell(u):
u = u[0]
m, n, _p, _q = size_matlab(u)
image = None
if self.Nx == 1 or self.Ny == 1:
......@@ -237,22 +238,22 @@ class PhaseExperiment(Experiment):
title = "Phase of reconstructed object, iteration " + str(alg.iter)
self.animateFigure(image, title)
def createGraphSubFigure(self, ax, u, title = None):
ax.plot(u)
if title is not None:
ax.set_title(title)
def createImageSubFigure(self, f, ax, u, title = None):
im = ax.imshow(u, cmap='gray')
# The "magic" values for fraction and pad adjust the
# The "magic" values for fraction and pad adjust the
# size of the color bar so that its height is comparable
# to the plot:
f.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
if title is not None:
ax.set_title(title)
def createFourGraphFigure(self, u, u2, titles):
f, ((ax1, ax2), (ax3, ax4)) = subplots(2, 2, \
figsize = (self.figure_width, self.figure_height),
......@@ -260,7 +261,7 @@ class PhaseExperiment(Experiment):
self.createGraphSubFigure(ax1, abs(u), titles[0])
self.createGraphSubFigure(ax2, real(u), titles[1])
self.createGraphSubFigure(ax3, abs(u2), titles[2])
self.createGraphSubFigure(ax4, real(u2), titles[3])
self.createGraphSubFigure(ax4, real(u2), titles[3])
return f
def createFourImageFigure(self, u, u2, titles):
......@@ -272,7 +273,7 @@ class PhaseExperiment(Experiment):
self.createImageSubFigure(f, ax3, abs(u2), titles[2])
self.createImageSubFigure(f, ax4, real(u2), titles[3])
return f
def createTwoGraphFigure(self, u, titles):
f, (ax1, ax2) = subplots(1, 2, \
figsize = (self.figure_width, self.figure_height),
......@@ -288,7 +289,3 @@ class PhaseExperiment(Experiment):
self.createImageSubFigure(f, ax1, abs(u), titles[0])
self.createImageSubFigure(f, ax2, real(u), titles[1])
return f
This diff is collapsed.
[tool.poetry]
name = "ProxPython"
version = "1.0.4"
description = ""
authors = ["Russell Luke <r.luke@math.uni-goettingen.de>"]
[tool.poetry.dependencies]
python = "^3.8"
numpy = "^1.19.2"
scikit-image = "^0.17.2"
matplotlib = "^3.3.2"
scipy = "^1.5.2"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment