Commit c2881ca3 authored by Russell Luke's avatar Russell Luke
Browse files

Merge branch 'dornheim' of gitlab.gwdg.de:nam/ProxPython into dornheim

parents d6aea421 4dcf492f
import sys
sys.path.append('../proxtoolbox/Problems/Phase')
sys.path.append('..')
import tasse_ap_in
from phase import Phase
tasse = Phase(tasse_ap_in.new_config)
tasse.solve()
tasse.show()
import sys
sys.path.append('../proxtoolbox/Problems/Phase')
sys.path.append('..')
import Nanoscale_Photonic_Imaging_ProxToolbox_Coffee_in
from phase import Phase
tasse = Phase(Nanoscale_Photonic_Imaging_ProxToolbox_Coffee_in.new_config)
tasse.solve()
tasse.show()
import sys
sys.path.append('../proxtoolbox/Problems/Phase')
sys.path.append('..')
from proxtoolbox.Problems import Ptychography
pp=Ptychography()
pp.solve()
pp.show()
# DRl.m
# written on Dez.5 , 2018 by
# Russell Luke
# Inst. Fuer Numerische und Angewandte Mathematik
#
# DESCRIPTION: User-friendly version of the Relaxed Douglas-Rachford algorithm.
# For background see:
# D.R.Luke, Inverse Problems 21:37-50(2005)
# D.R. Luke, SIAM J. Opt. 19(2): 714--739 (2008).
from .SimpleAlgortihm import SimpleAlgorithm
from numpy import exp
class DRl(SimpleAlgorithm):
def evaluate(self, u):
iter = self.config['iter']+1 #add 1 to conform with matlab version (iter influences lambda and we sometimes want to compare results between python and matlab), matlab counts starting at 1, python starts at 0
lambda0 = self.config['lambda_0']
lambda_max = self.config['lambda_max']
lambda_switch = self.config['lambda_switch']
tmp1 = 2*self.prox2.work(u)-u
tmp2=self.prox1.work(tmp1)
# update
lambda = exp((-iter/lambda_switch)**3)*lambda0+(1-exp((-iter/lambda_switch)**3))*lambda_max # unrelaxes as the
unew = (lambda*(2*tmp2-tmp1) + (1-lambda)*tmp1 + u)/2
return unew
......@@ -31,6 +31,7 @@
from numpy import zeros, shape, sqrt
from scipy.linalg import norm
from .SimpleAlgortihm import SimpleAlgorithm
from .algorithms import Algorithm
from proxtoolbox import Algorithms
from proxtoolbox import ProxOperators
......
......@@ -15,7 +15,7 @@ from .HPR import *
from .RAAR import *
from .RAAR_expert import *
from .GRAAL import *
from .HAAR import *
from .QNAP import *
# from .HAAR import *
# from .DRl import *
__all__ = ["AP","HPR","RAAR", "AP_expert", "GRAAL", "HAAR", "RAAR_expert", "QNAP"]
__all__ = ["AP","HPR","RAAR", "AP_expert", "GRAAL", "RAAR_expert"]
......@@ -7,6 +7,12 @@ from proxtoolbox.Utilities.mypoissonrnd import mypoissonrnd
from proxtoolbox.Utilities.gaussian import gaussian
from matplotlib.pyplot import subplots, show
#for loading data
import proxtoolbox.Utilities.GetData as GetData
import urllib.request
import tarfile
def Goettingen_data_processor(config):
# Parameters of the forward problem
......@@ -15,10 +21,10 @@ def Goettingen_data_processor(config):
if not(my_file.is_file()):
print("Phase input data is missing.")
if GetData.query_yes_no("Do you want to download the phase input data?"):
urllib.request.urlretrieve("http://num.math.uni-goettingen.de/~r.luke/tmp/Phase.tar.gz","../InputData/Phase.tar.gz", reporthook=GetData.dlProgress)
urllib.request.urlretrieve("http://vaopt.math.uni-goettingen.de/data/Phase.tar.gz","../InputData/Phase.tar.gz", reporthook=GetData.dlProgress)
print("\nExtracting data...")
tar = tarfile.open("../InputData/Phase.tar.gz", "r:gz")
tar.extractall("../InputData/")
tar.extractall("../InputData/Phase/")
tar.close()
if not(my_file.is_file()):
print('***************************************************************************************')
......
## This is the input file that the user sees/modifies. It should be simple,
## avoid jargon or acronyms, and should be a model for a menu-driven GUI
new_config = {
## We start very general.
##==========================================
## Problem parameters
##==========================================
## What is the name of the data file?
'data_filename' : 'Goettingen_data_processor',
## What type of object are we working with?
## Options are: 'phase', 'real', 'nonnegative', 'complex'
'object' : 'nonnegative',
## What type of constraints do we have?
## Options are: 'support only', 'real and support', 'nonnegative and support',
## 'amplitude only', 'sparse real', 'sparse complex', and 'hybrid'
'constraint' : 'nonnegative and support',
## What type of measurements are we working with?
## Options are: 'single diffraction', 'diversity diffraction',
## 'ptychography', and 'complex'
'experiment' : 'CDI',
## The user can set the dimension of the reconstructions from full dimension to
## some downsampled version
'Nx' : 128,
'Ny' : 128,
## What are the noise characteristics (Poisson or Gaussian or none)?
'noise' : 'Poisson',
## Not unreasonable to allow the user to choose this, especially if
## the example is a simmulation. For real experimental data, the structure
## of the noise is just a guess.
##==========================================
## Algorithm parameters
##==========================================
## Now set some algorithm parameters that the user should be
## able to control (without too much damage)
## Algorithm:
'algorithm' : 'DRl', # used to be 'Projection',
'numruns' : 1, # the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
# would be doing.
## The following are parameters specific to DRl, HPR, and HAAR that the
## user should be able to set/modify.
# the following just points this driver to a patch that communicates
# the parameters defined at this level to the structures used in the
# algorithms developed by Russell.
'problem_family' : 'Phase',
## maximum number of iterations and tolerances
'MAXIT' : 1000,
'TOL' : 1e-12,
## relaxaton parameters in DRl, HPR and HAAR
'lambda_0' : 0.95, #0.95 # starting relaxation prameter (only used with
# HAAR, HPR and DRl)
'lambda_max' :0.50, # maximum relaxation prameter (only used with
# HAAR, DRl, and HPR)
'lambda_switch' : 30, # iteration at which lambda moves from lambda_0 -> lambda_max
## parameter for the data regularization
'data_ball' : .999826,
# the above is the percentage of the gap
# between the measured data and the
# initial guess satisfying the
# qualitative constraints. For a number
# very close to one, the gap is not expected
# to improve much. For a number closer to 0
# the gap is expected to improve a lot.
# Ultimately the size of the gap depends
# on the inconsistency of the measurement model
# with the qualitative constraints.
##==========================================
## parameters for plotting and diagnostics
##==========================================
'diagnostic' : True, # if False, only the stepsizes will be monitored
'verbose' : 1, # options are 0 or 1
'graphics' : 1, # whether or not to display figures, options are 0 or 1.
# default is 1.
'anim' : 2, # whether or not to disaply ``real time" reconstructions
# options are 0=no, 1=yes, 2=make a movie
# default is 1.
'graphics_display' : 'Phase_graphics' # unless specified, a default
# plotting subroutine will generate
# the graphics. Otherwise, the user
# can write their own plotting subroutine
}
## This is the input file that the user sees/modifies. It should be simple,
## avoid jargon or acronyms, and should be a model for a menu-driven GUI
new_config = {
## We start very general.
##==========================================
## Problem parameters
##==========================================
## What is the name of the data file?
'data_filename' : 'Goettingen_data_processor',
## What type of object are we working with?
## Options are: 'phase', 'real', 'nonnegative', 'complex'
'object' : 'nonnegative',
## What type of constraints do we have?
## Options are: 'support only', 'real and support', 'nonnegative and support',
## 'amplitude only', 'sparse real', 'sparse complex', and 'hybrid'
'constraint' : 'nonnegative and support',
## What type of measurements are we working with?
## Options are: 'single diffraction', 'diversity diffraction',
## 'ptychography', and 'complex'
'experiment' : 'CDI',
## The user can set the dimension of the reconstructions from full dimension to
## some downsampled version
'Nx' : 128,
'Ny' : 128,
## What are the noise characteristics (Poisson or Gaussian or none)?
'noise' : 'Poisson',
## Not unreasonable to allow the user to choose this, especially if
## the example is a simmulation. For real experimental data, the structure
## of the noise is just a guess.
##==========================================
## Algorithm parameters
##==========================================
## Now set some algorithm parameters that the user should be
## able to control (without too much damage)
## Algorithm:
'algorithm' : 'AP', # used to be 'Projection',
'numruns' : 1, # the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
# would be doing.
## The following are parameters specific to DRl, HPR, and HAAR that the
## user should be able to set/modify.
# the following just points this driver to a patch that communicates
# the parameters defined at this level to the structures used in the
# algorithms developed by Russell.
'problem_family' : 'Phase',
## maximum number of iterations and tolerances
'MAXIT' : 1000,
'TOL' : 1e-12,
## relaxaton parameters in DRl, HPR and HAAR
'lambda_0' : 0.95, #0.95 # starting relaxation prameter (only used with
# HAAR, HPR and DRl)
'lambda_max' :0.50, # maximum relaxation prameter (only used with
# HAAR, DRl, and HPR)
'lambda_switch' : 30, # iteration at which lambda moves from lambda_0 -> lambda_max
## parameter for the data regularization
'data_ball' : .999826,
# the above is the percentage of the gap
# between the measured data and the
# initial guess satisfying the
# qualitative constraints. For a number
# very close to one, the gap is not expected
# to improve much. For a number closer to 0
# the gap is expected to improve a lot.
# Ultimately the size of the gap depends
# on the inconsistency of the measurement model
# with the qualitative constraints.
##==========================================
## parameters for plotting and diagnostics
##==========================================
'diagnostic' : True, # if False, only the stepsizes will be monitored
'verbose' : 1, # options are 0 or 1
'graphics' : 1, # whether or not to display figures, options are 0 or 1.
# default is 1.
'anim' : 2, # whether or not to disaply ``real time" reconstructions
# options are 0=no, 1=yes, 2=make a movie
# default is 1.
'graphics_display' : 'Phase_graphics' # unless specified, a default
# plotting subroutine will generate
# the graphics. Otherwise, the user
# can write their own plotting subroutine
}
......@@ -23,6 +23,10 @@ from proxtoolbox.ProxOperators import magproj
from proxtoolbox.ProxOperators.proxoperators import ProxOperator
from multiprocessing import Pool
#choose backend
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib import colors, pyplot
from math import atan, atan2, ceil, exp, log, sqrt
......@@ -1937,7 +1941,7 @@ class Ptychography(Problem):
sample_plane = None;
if self.config['sim_data_type'] == 'gaenseliesel':
g = pyplot.imread('inputdata/gaenseliesel.png').astype(numpy.float);
g = pyplot.imread('../InputData/Ptychography/gaenseliesel.png').astype(numpy.float);
g /= numpy.amax(g);
g = 0.8*g + 0.1;
sample_plane = numpy.abs(g) * (numpy.cos(g) + 1j*numpy.sin(g));
......@@ -2441,18 +2445,18 @@ class Ptychography_NTT_01_26210(Ptychography):
Overloads the corresponding method of :class:`Ptychography`
to create other experiment data
"""
data = scipy.io.loadmat('../inputdata/data_NTT_01_26210_192x192.mat');
data = scipy.io.loadmat('../InputData/Ptychography/data_NTT_01_26210_192x192.mat');
d1y = data['d1y'][0][0];
d1x = data['d1x'][0][0];
i_exp = data['I_exp'];
l = data['lambda'][0][0];
z01 = data['z01'][0][0];
self.config['fmask'] = data['fmask'].astype(numpy.float);
data = scipy.io.loadmat('../inputdata/reconstruction_data_NTT_01_26210_192x192.mat');
data = scipy.io.loadmat('../InputData/Ptychography/reconstruction_data_NTT_01_26210_192x192.mat');
probe = data['Probe'];
sample_plane = data['object'];
data = scipy.io.loadmat('../inputdata/positions_NTT_01_26210.mat')
data = scipy.io.loadmat('../InputData/Ptychography/positions_NTT_01_26210.mat')
positions = data['positions'].astype(numpy.float);
positions[:,0] /= d1y;
positions[:,0] -= numpy.amin(positions[:,0]);
......
......@@ -6,4 +6,4 @@ from .query_yes_no import *
from .dlProgress import *
__all__ = ["dlProgress,query_yes_no"]
__all__ = ["dlProgress", "query_yes_no"]
Supports Markdown
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