Skip to content

Commit

Permalink
add fwd_model_default_param
Browse files Browse the repository at this point in the history
* resolve recursive call
* fix plt.show to fig.show
* add fwd_model_default_param
* fix fill_dict1_with_dict2
* set new standard in normNoff
  • Loading branch information
renerichter committed Jun 28, 2022
1 parent adeb6d4 commit c3776d3
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 12 deletions.
3 changes: 1 addition & 2 deletions MicroPy/deconvolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from tiler import Tiler, Merger
from typing import Union

from .inout import store_data
from .general_imports import *


Expand Down Expand Up @@ -307,7 +306,7 @@ def deconv_test_param_on_list(ims, psfs, pad, resd, rparams, ddh, sname=['dec2D'
# blueprint for saving in case something breaks on the fly
if 0:
pad['save_name'] = pad['save_name_base'] + snamef+'_resd'
store_data(param_dict=pad, proc_dict=resd, data_dict=None)
#store_data(param_dict=pad, proc_dict=resd, data_dict=None)

# done?
return resd
Expand Down
6 changes: 3 additions & 3 deletions MicroPy/inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


# mipy imports
from .utility import normNoff, add_multi_newaxis, transpose_arbitrary, fill_dict_with_default
from .utility import normNoff, add_multi_newaxis, transpose_arbitrary, fill_dict1_with_dict2
from .transformations import radial_sum
from .microscopyCalculations import calculate_resolution, convert_x_to_k
from .filters import moving_average_2d
Expand Down Expand Up @@ -851,7 +851,7 @@ def print_stack2subplot(imstack, im_minmax=[None, None], imdir='row', inplace=Fa
if colorbar == 'global':
# sanity
grid_param_default = default_grid_param(plt_raster)
gp = grid_param = grid_param_default if grid_param is None else fill_dict_with_default(
gp = grid_param = grid_param_default if grid_param is None else fill_dict1_with_dict2(
grid_param, grid_param_default)

# generate grid
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def print_stack2subplot(imstack, im_minmax=[None, None], imdir='row', inplace=Fa
plt.tight_layout()

if plt_show:
plt.show()
fig.show()

if ax_ret:
return fig,ax
Expand Down
134 changes: 134 additions & 0 deletions MicroPy/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .transformations import irft3dz, rft3dz, rftnd, polar2cartesian, lp_norm
from .utility import shiftby_list, add_multi_newaxis, set_val_atpos, get_center
from .microscopyCalculations import convert_phot2int, convert_int2phot
from .deconvolution import default_dict_tiling,default_dict_deconv

# %%
# ------------------------------------------------------------------
Expand Down Expand Up @@ -1045,6 +1046,139 @@ def dsax_fwd_model(pad, prd={}, psd={}):
pad['ism_method'] == 'dsax'
return fwd_model(pad=pad, prd=prd, psd=psd)

def fwd_model_default_param(dolist=[1,0,1,1]):
'''dolist = [ism,dsax,thickslice,processing]=[1,0,1,1] to activate all but dsax'''
pad_general = {
# general image parameters
'imsize': (32, 128, 128),
'overscan': (1, 1, 1.25),
'obj_centerpos': None, # [32, 32, 38], # None
'noise': ['Poisson',10],
'noise_realizations': None,
'pixelsize': (100, 37.1, 37.1),
'nbr_spokes': 14,
'do_testobject': 0,
'obj_shifts': False, # [[-4, 0, 0], [3, 0, 0]],
'dtype_real': np.float32,
'dtype_complex': np.complex64,
'normalize_fwd_im': False,

# general PSF-parameters
'NA': 1.3,
'n_immersion': 1.4, # assume for silicon oil
'lex': 488,
'lem': 515,
'asymmt_ex': None, # ['spheric', ],
'asymms_ex': None, # np.arange(0, 1.05, 0.05),
'asymmt_em': None, # ['spheric', ],
'asymms_em': None, # [0.1, ],
'bead_roi': [16, 16],

# general plotting parameters
'dpi': 300,
'show_phases': False,
'format_vid': 'libx264',
'format_im': 'pdf',

# general IO parameters
'del_extra': False,
'save_name_base': None,
'save_path': None,
}
pad_ism={
# ism-parameters
'fmodel': 'fft',
'faxes': [-2, -1],
'raxis': -2, # None
'imaging_method': 'ism',
# as camera-pixel-size=13μm, system-magnification=144 and hence camera-pixel-spacing-in-sample-coordinates=90/144*1000/pixelsize[-1]; assume perpendicular orientation with sample -> need to check via correlation
'shift_offset': np.array([[2.4, 0], [0, 2.4]]),
'shift_axes': [-2, -1],
'shift_method': 'uvec',
'nbr_det': np.array([16, 16]), # np.array([2, 2]), # np.array([5, 5]), # [3, 5],
'det_shifts': None,
'pinhole': None,
'do_norm': True,
'psf_shifts': None, # for multi-psfs
'psf_shifts_axes': None,
'sheppSUM_shift_method': 'nearest',
}
pad_dsax={
# dsax parameters
'dsax_Iex_max': 850,
'dsax_Iex': [90, 250, 850],
'dsax_ψmax': 3/6,
'dsax_NPhot_factor': 1,
'dsax_normax': (-3, -2, -1),
'dsax_tau': None,
'dsax_sigma': None,
# Iex1,Iex2,Iex3,NL1,NL2
'dsax_plot_colors': ['lime', 'turquoise', 'magenta', 'green', 'blue'],
'dsax_exp_det_pixpitch': 13000,
'dsax_exp_magnification': 144,
'drift_subpix_thresh': 0.2,
}
pad_thickslice={
# thickslice parameters
'eps_mask': 10**(-5.0), # -3.5
'eps_reg': 10**(-7.5), # -8.5
'eps_reg_rel': 0,
'svdlim': None,
'svdnum': 10,
'use_own': True,
'closing': -2,
'svd_stat': True,
'verbose': True,
'full_ret': True,
'ret_real': True,
}
pad_processing={
# wavg parameters
'noise_norm': True,
'use_mask': True,
'reg_aeps': 0,
'reg_reps': 0,

# wiener parameters
'wiener_use_generalized': True,
'multiview_dim': 0,
'wiener_reg_aeps': 0,
'wiener_reg_reps': 10**(-1.5),
}
dlist=[pad_ism,pad_dsax,pad_thickslice,pad_processing]
pad = {**pad_general, **dlist[dolist[0]],**dlist[dolist[1]],**dlist[dolist[2]],**dlist[dolist[3]]}
psd = {
'do_load_data': True,
'do_save_plots':True,
'do_store_data':True,
'do_free_space':True,
'do_calculate': True,
'do_deconvolve': True,
'do_3D': True,
'do_aberrated': False,
'do_noisy': True,
'do_ncc': True,
}

# standard tiling dict
pad['td'] = default_dict_tiling([np.prod(pad['nbr_det']), ]+list(pad['imsize']),
basic_shape=list(pad['imsize']),
basic_roverlap=[0, 0.2, 0.2],
atol=1e-8,
diffdim_im_psf=None)

# standard deconv-dict
pad['dd'] = default_dict_deconv(
NIter=200, lambdal=[10**(-5.0), ], regl=['GS', ], BorderRegion=[0, 0.1, 0.1, 0.1])

# detector-plane properties
pad['det_center'] = pad['nbr_det']//2

prd={}

#done?
return pad, psd, prd

def fwd_model(pad, prd={}, psd={}):

# generate object
Expand Down
16 changes: 9 additions & 7 deletions MicroPy/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@author René Lachmann
@email [email protected]
@create date 2019 11:53:25
@modify date 2022-06-08 16:13:54
@modify date 2022-06-28 15:52:17
@desc Utility package
---------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1102,7 +1102,7 @@ def norm_back(imstack, normstack, normtype):
return imstack_changed


def normNoff(im, dims=None, method='max', offset=None, direct=False, atol=1e-10):
def normNoff(im, dims=(-2,-1), method='max', offset=None, direct=False, atol=1e-10):
"""Subtracts offset and normalizes by calling normto. Read description of normto for further parameter info.
Parameters
Expand Down Expand Up @@ -1512,12 +1512,14 @@ def split_nd(im, tile_sizes=[8, 8], split_axes=[-1, -2]):
return im, sal


def fill_dict_with_default(din, ddefault):
for m in ddefault:
if not m in din:
din[m] = ddefault[m]
def fill_dict1_with_dict2(dict1, dict2, overwrite=True):
for m in dict2:
if overwrite:
dict1[m] = dict2[m]
else:
dict1[m] = dict2[m] if not m in dict1 else dict1[m]

return din
return dict1

# %% -----------------------------------------------------
# ---- NOISE AND STATISTIC-ANALYSIS
Expand Down

0 comments on commit c3776d3

Please sign in to comment.