spipy-blog logo spipy-blog

Phase Retrieval Network Framework (Suggested)

In this framework, you can use different algorithms to build a phasing network, just like building a neural network using pytorch. Here every node contains an algorithm and the data stream goes through all of the nodes in your specified order. The framework supports multiple input nodes and single output node. It could do phasing of both 2D pattern and 3D volume inputs.

Now the framework contains ERA / HIO / DM / RAAR / HPR algorithms. More methods are under design and will be released later. See an example network below for a straight forward look.

example

phase.phmodel

NOTE-1 : All of the classes in ‘phmodel’ module has a ‘run’ function, which will be called by phexec.Runner to run a node, please do not change it.

NOTE-2 : Every instance of classes in ‘phmodel’ has an ‘id’ attribute, which is the identical number of a node in the network.

phase.phexec

— Programming example to build a network model like the figure above —

# Examles of using PRNF programming,
# you can find more at "spipy/test_spipy/phase/test_phmodel.py"

import numpy as np
from spipy.phase import phexec, phmodel

from mpi4py import MPI
comm = MPI.COMM_WORLD
mrank = comm.Get_rank()
msize = comm.Get_size()

if __name__ == "__main__":

    config_input = {
        "pattern_path" : "pattern.npy",
        "mask_path" : "pat_mask.npy",
        "center_mask" : 5,
        "edge_mask" : None,
        "subtract_percentile" : False,
        "fixed_support_r" : None,
        "background" : True,
        "initial_model" : None
    }
    iters = [150,100,200]
    support_size = 85
    beta = 0.8
    gamma = 0.05
    newdataset = {"pattern_path" : "pattern.npy", "mask_path" : "pat_mask.npy", "initial_model" : None}

    # set up network
    l1_0 = phmodel.pInput(config_input)
    l1_1 = phmodel.pInput(config_input)
    l2_0 = phmodel.HIO(iters[0], support_size, gamma).after(l1_0)
    l2_1 = phmodel.ERA(iters[0], support_size).after(l1_1)
    l2_2 = phmodel.RAAR(iters[0], support_size, beta).after(l1_1)
    lm = phmodel.pMerge().after(l2_0).after(l2_1).after(l2_2)
    l4 = phmodel.DM(iters[1], support_size).after(lm)
    l5 = phmodel.HIO(iters[2], support_size, gamma).after(l4)
    l6 = phmodel.pOutput().after(l5)

    # run
    runner = phexec.Runner(inputnodes = [l1_0, l1_1], outputnode = l6, comm=comm)
    out = runner.run(repeat = 2)

    if mrank == 0:
        runner.plot_result(out)

    # Dump network
    runner.dump_model("temp_model.json", skeleton=False)

    # Reload network
    runner2 = phexec.Runner(inputnodes = None, outputnode = None, \
        loadfile = "temp_model.json", reload_dataset = {l1_0.id:newdataset}, comm=comm)
    out = runner2.run(repeat = 1)

Functional based phase retrieval program (deprecated)

phase.phase2d

-> 2d pattern phase retrieval

# 2d phase retrieval basic parameters
- 'input|shape' : input pattern shape, default='123,123'

- 'input|padd_to_pow2' : zero padding to make the size of pattern to be a 2^n number, default=True

- 'input|inner_mask' : pixels whose radius<inner_mask are allowed to float while phasing, default=5

- 'input|outer_mask' : pixels whose radius>outer_mask are set to zero, default=64

- 'input|outer_outer_mask' : pixels whose radius are between outer_mask and outer_outer_mask are allowed to float, default=None

- 'input|mask_edges' : bool, whether allow pixels between outer_mask and outer_outer_mask to float, default=True

- 'phasing|repeats' : how many times of independent phasing for **every process**, default=40

- 'phasing|iters' : schedual iterations for 1 phasing loop, default is '100RAAR 200DM 200ERA' which means '100 times RAAR algorithm -> 200 times DM algorithm -> 200 times ER algorithm'

- 'phasing_parameters|support_size' : set restriction to the number of pixels inside final support of shrinkwrap process, default=200

- 'phasing_parameters|beta' : beta value for RAAR algorithm, float from 0 to 1, default=0.8

# 2d phase retrieval advanced parameters
- 'input|subtract_percentile' : subtract the X percentile value of data for all pixels, float value from 0 to 100, default=None

- 'input|spherical_support' : radius of spherical support that added at the initiation, default=None

- 'input|init_model' : filepath of initial REAL space model. Support .npy, .bin and .mat file formats. The size of init model should agree with 'input|shape' after 'input|padd_2_pow', default=None

- 'phasing_parameters|background' : evaluate background while phasing, default=True

phase.phase3d

-> 3d volume phase retrieval

# 3d phase retrieval basic parameters
- 'input|shape' : input pattern shape, default='120,120,120'

- 'input|padd_to_pow2' : zero padding to make the size of pattern to be a 2^n number, default=True

- 'input|inner_mask' : pixels whose radius<inner_mask are allowed to float while phasing, default=3

- 'input|outer_mask' : pixels whose radius>outer_mask are set to zero, default=64

- 'input|outer_outer_mask' : pixels whose radius are between outer_mask and outer_outer_mask are allowed to float, default=None

- 'input|mask_edges' : bool, whether allow pixels between outer_mask and outer_outer_mask to float, default=False

- 'phasing|repeats' : how many times of independent phasing for **every process**, default=40

- 'phasing|iters' : schedual iterations for 1 phasing loop, default is '100RAAR 200DM 200ERA' which means '100 times RAAR algorithm -> 200 times DM algorithm -> 200 times ER algorithm'

- 'phasing_parameters|voxel_number' : set restriction to the number of pixels inside final support of shrinkwrap process, default=2000

- 'phasing_parameters|beta' : beta value for RAAR algorithm, float from 0 to 1, default=0.8

# 3d phase retrieval advanced parameters
- 'input|subtract_percentile' : subtract the X percentile value of data for all pixels, float value from 0 to 100, default=None

- 'input|spherical_support' : radius of spherical support that added at the initiation, default=None

- 'input|init_model' : filepath of initial REAL space model. Support .npy, .bin and .mat file formats. The size of init model should agree with 'input|shape' after 'input|padd_2_pow', default=None

- 'phasing_parameters|background' : evaluate background while phasing, default=True

phase.phase3d and phase.phase2d have same APIs :