#NEWLINE# def pi_modulus( recon_pattern , diffracted_pattern , offset_v = 1e-12 ) : #NEWLINE# #INDENT# '\n    Transfer sample from real space to q space.\n    Use constraint based on diffraction pattern from experiments.\n\n    Parameters\n    ----------\n    recon_pattern : array\n        reconstructed pattern in real space\n    diffracted_pattern : array\n        diffraction pattern from experiments\n    offset_v : float, optional\n        add small value to avoid the case of dividing something by zero\n\n    Returns\n    -------\n    array :\n        updated pattern in real space\n    ' #NEWLINE# diff_tmp = ( np . fft . fftn ( recon_pattern ) / np . sqrt ( np . size ( recon_pattern ) ) ) #NEWLINE# index = ( diffracted_pattern > 0 ) #NEWLINE# diff_tmp [ recon_pattern ] = ( ( diffracted_pattern [ index ] * diff_tmp [ index ] ) / ( np . abs ( diff_tmp [ index ] ) + offset_v ) ) #NEWLINE# return ( np . fft . ifftn ( diff_tmp ) * np . sqrt ( np . size ( diffracted_pattern ) ) )