Commit 953c9894 authored by alexander.dornheim's avatar alexander.dornheim
Browse files

Added CDI_data_processor and tasse_raar_in. Not yet tested.

parent 6c4474c3
# CDI_data_processor.m
# written on Jan 10, 2012 by
# Russell Luke
# Inst. Fuer Numerische und Angewandte Mathematik
# Universitaet Goettingen
#
# DESCRIPTION: Data processing subroutine called by
# Loads data and prepares it for
# phase retrieval algorithms.
#
# INPUT: all the input is set in Phase_in
# data_file = character string identifying the data
# file to load
# step_up = number of dyads to increase resolution.
# noise = numeric toggle for adding noise to original
# image
# data_ball = noise parameter
# support_type = character string for type of
# support. Either 'autocorr', 'box' or 'autocorr_box'
# tightness = numeric parameter adjusts the tightness
# of the autocorrelation support constraint.
#
# OUTPUT: u_0 = the algorithm initial guess (I use a bad initial guess on
# purpose)
# S = the object domain constraints. This is either a
# structure or an array.
# Func_params = image domain measurements and paramters.
# This is a data structure.
#
# USAGE: [S,M,u_0,true_object,success] =
# Data_processor(data_file,program,step_up, noise,data_ball,support_type,tightness)
#
# Data loaded: CDI data
# Nonstandard function calls: none
#
#################################################################################
from scipy.io import loadmat
from matplotlib.pyplot import colorbar, show, imshow
from numpy import log10, log2, ceil, floor, argmax, unravel_index, zeros, where, nonzero, pi, sqrt
from numpy.fft import fftshift, ifft2
from numpy.linalg import norm
from numpy.random import rand
def CDI_data_processor(config):
data_file = config['data_filename']
data_ball = config['data_ball']
f = loadmat('../InputData/phase_retrieval/CDI_intensity.mat')
# diffraction pattern
print(f.keys())
dp = f['intensity']['img'][0,0]
print(dp.dtype)
print(dp.shape)
im = imshow(log10(dp))
colorbar(im)
show(block=False)
orig_res = dp.size # actual data size
step_up = ceil(log2(config['Nx'])-log2(orig_res))
workres = 2**(step_up)*2**(floor(log2(orig_res)))#desired array size
N=int(workres)
print(N)
## center data and use region of interest around center
#central pixel
#find max data value
argmx = unravel_index(argmax(dp), dp.shape)
print(argmx)
Xi = argmx[0]
Xj = argmx[1]
#get desired roi:
#necessary conversion
Di = N/2-(Xi-1)
Dj = N/2-(Xj-1)
# roi around central pixel
Ni = 2*(Xi+Di*(Di<0)-1)
Nj = 2*(Xj+Dj*(Dj<0)-1)
tmp = zeros((N,N))
tmp[int(Di*(Di>0)+1):int(Di*(Di>0)+Ni),int(Dj*(Dj>0)+1):int(Dj*(Dj>0)+Nj)] = dp[int(Xi-Ni/2):int(Xi+Ni/2-1),int(Xj-Nj/2):int(Xj+Nj/2-1)]
M=(fftshift(tmp))**(.5)
# M=tmp.^(.5)
## define support
DX = ceil(N/7)
S = zeros((N,N))
S[int(N/4+1+DX):int(3/4*N-1-DX),int(N/4+1+DX):int(3/4*N-1-DX)] = 1
# config['data_ball=config['Nx*config['Ny*data_ball
config['rt_data']=M
# standard for the main program is that
# the data field is the magnitude SQUARED
# in Luke.m this is changed to the magnitude.
config['data']=M**M
config['norm_rt_data']=norm(ifft2(M),'fro')
config['data_zeros'] = where(M==0)
config['support_idx'] = nonzero(S)
config['product_space_dimension'] = 1
# use the abs_illumination field to represent the
# support constraint.
config['abs_illumination'] = S
config['supp_phase'] = []
# initial guess
config['u_0'] = S*rand(N)
config['u_0'] = config['u_0']/norm(config['u_0'],'fro')*config['norm_rt_data']
if config['fresnel_nr']*config['magn'] <= 2*pi*sqrt(config['Nx']*config['Ny']):
config['use_farfield_formula'] = 1
print('Using farfield formula.')
else:
config['use_farfield_formula'] = 0
print('Using nearfield formula.')
## 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' : 'CDI_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' : 'single diffraction',
## Next we move to things that most of our users will know
## better than we will. Some of these may be overwritten in the
## data processor file which the user will most likely write.
## Are the measurements in the far field or near field?
## Options are: 'far field' or 'near field',
'distance' : 'far field',
## What are the dimensions of the measurements?
'Nx' : 128,
'Ny' : 128,
#moved this to phase
#if(strcmp('distance,'near field'))
# 'fresnel_nr' : 1*2*pi*'Nx,
#else
# 'fresnel_nr' : 0, #1*2*pi*'Nx,
'magn' : 1,
## What are the noise characteristics (Poisson or Gaussian)?
'noise' : 'Poisson',
##==========================================
## Algorithm parameters
##==========================================
## Now set some algorithm parameters that the user should be
## able to control (without too much damage)
## Algorithm:
'method' : 'RAAR', # 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 RAAR, HPR, and HAAR that the
## user should be able to set/modify. Surely
## there will be other algorithm specific parameters that a user might
## want to play with. Don't know how best
## to do this. Thinking of a GUI interface, we could hard code all the
## parameters the user might encounter and have the menu options change
## depending on the value of the 'method field.
## do different things depending on the chosen algorithm:
#if(strcmp('method,'RAAR')||strcmp('method,'AP')||...
# strcmp('method,'HPR')||strcmp('method,'HAAR'))
# 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',
#else # moreregularization parameters for Thorsten's algorithms:
# prbl' : complete_itreg_par(prbl),
# This is just a patch to Thorsten's tools. May want to change this
# later
#'problem_family='Hohage',
#end
#if(strcmp('problem_family,'Phase'))
## maximum number of iterations and tolerances
'MAXIT' : 1000,
'TOL' : 1e-12,
## relaxaton parameters in RAAR, HPR and HAAR
'beta_0' : 0.95, # starting relaxation prameter (only used with
# HAAR, HPR and RAAR)
'beta_max' :0.50, # maximum relaxation prameter (only used with
# HAAR, RAAR, and HPR)
'beta_switch' : 30, # iteration at which beta moves from beta_0 -> beta_max
## parameter for the data regularization
## need to discuss how/whether the user should
## put in information about the noise
'data_ball' : .999826,
# 'data_ball' : .9998261e-0,
# 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.
#elseif(strcmp('problem_family,'Hohage'))
# 'alpha0' : 1e4,
# 'N_CG' : 70,
#end
# ##==========================================
# ## parameters for plotting and diagnostics
# ##==========================================
# 'plotWhat.n1=2,
# 'plotWhat.n2=3,
# 'plotWhat.plots' : 'PYWpyw',
# 'verbose' : 1, # options are 0 or 1
# 'graphics' : 1, # whether or not to display figures, options are 0 or 1.
# # default is 1.
# 'anim' : 1, # whether or not to disaply ``real time" reconstructions
# # options are 0=no, 1=yes, 2=make a movie
# # default is 1.
# 'graphics_display' : [], # unless specified, a default
# # plotting subroutine will generate
# # the graphics. Otherwise, the user
# # can write their own plotting subroutine
#
##==========================================
## parameters for plotting and diagnostics
##==========================================
'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
}
##======================================================================
## Technical/software specific parameters
##======================================================================
## Given the parameter values above, the following technical/algorithmic
## parameters are automatically set. The user does not need to know
## about these details, and so probably these parameters should be set in
## a module one level below this one.
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