<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function <EOL> import numpy as np <EOL> __keywords__ = "<STR_LIT>" <EOL> def ufftn ( inarray , dim = None ) : <EOL> """<STR_LIT>""" <EOL> if dim is None : <EOL> dim = inarray . ndim <EOL> outarray = np . fft . fftn ( inarray , axes = range ( - dim , <NUM_LIT:0> ) ) <EOL> return outarray / np . sqrt ( np . prod ( inarray . shape [ - dim : ] ) ) <EOL> def uifftn ( inarray , dim = None ) : <EOL> """<STR_LIT>""" <EOL> if dim is None : <EOL> dim = inarray . ndim <EOL> outarray = np . fft . ifftn ( inarray , axes = range ( - dim , <NUM_LIT:0> ) ) <EOL> return outarray * np . sqrt ( np . prod ( inarray . shape [ - dim : ] ) ) <EOL> def urfftn ( inarray , dim = None ) : <EOL> """<STR_LIT>""" <EOL> if dim is None : <EOL> dim = inarray . ndim <EOL> outarray = np . fft . rfftn ( inarray , axes = range ( - dim , <NUM_LIT:0> ) ) <EOL> return outarray / np . sqrt ( np . prod ( inarray . shape [ - dim : ] ) ) <EOL> def uirfftn ( inarray , dim = None , shape = None ) : <EOL> """<STR_LIT>""" <EOL> if dim is None : <EOL> dim = inarray . ndim <EOL> outarray = np . fft . irfftn ( inarray , shape , axes = range ( - dim , <NUM_LIT:0> ) ) <EOL> return outarray * np . sqrt ( np . prod ( outarray . shape [ - dim : ] ) ) <EOL> def ufft2 ( inarray ) : <EOL> """<STR_LIT>""" <EOL> return ufftn ( inarray , <NUM_LIT:2> ) <EOL> def uifft2 ( inarray ) : <EOL> """<STR_LIT>""" <EOL> return uifftn ( inarray , <NUM_LIT:2> ) <EOL> def urfft2 ( inarray ) : <EOL> """<STR_LIT>""" <EOL> return urfftn ( inarray , <NUM_LIT:2> ) <EOL> def uirfft2 ( inarray , shape = None ) : <EOL> """<STR_LIT>""" <EOL> return uirfftn ( inarray , <NUM_LIT:2> , shape = shape ) <EOL> def image_quad_norm ( inarray ) : <EOL> """<STR_LIT>""" <EOL> if inarray . shape [ - <NUM_LIT:1> ] != inarray . shape [ - <NUM_LIT:2> ] : <EOL> return ( <NUM_LIT:2> * np . sum ( np . sum ( np . abs ( inarray ) ** <NUM_LIT:2> , axis = - <NUM_LIT:1> ) , axis = - <NUM_LIT:1> ) - <EOL> np . sum ( np . abs ( inarray [ ... , <NUM_LIT:0> ] ) ** <NUM_LIT:2> , axis = - <NUM_LIT:1> ) ) <EOL> else : <EOL> return np . sum ( np . sum ( np . abs ( inarray ) ** <NUM_LIT:2> , axis = - <NUM_LIT:1> ) , axis = - <NUM_LIT:1> ) <EOL> def ir2tf ( imp_resp , shape , dim = None , is_real = True ) : <EOL> """<STR_LIT>""" <EOL> if not dim : <EOL> dim = imp_resp . ndim <EOL> irpadded = np . zeros ( shape ) <EOL> irpadded [ tuple ( [ slice ( <NUM_LIT:0> , s ) for s in imp_resp . shape ] ) ] = imp_resp <EOL> for axis , axis_size in enumerate ( imp_resp . shape ) : <EOL> if axis >= imp_resp . ndim - dim : <EOL> irpadded = np . roll ( irpadded , <EOL> shift = - int ( np . floor ( axis_size / <NUM_LIT:2> ) ) , <EOL> axis = axis ) <EOL> if is_real : <EOL> return np . fft . rfftn ( irpadded , axes = range ( - dim , <NUM_LIT:0> ) ) <EOL> else : <EOL> return np . fft . fftn ( irpadded , axes = range ( - dim , <NUM_LIT:0> ) ) <EOL> def laplacian ( ndim , shape , is_real = True ) : <EOL> """<STR_LIT>""" <EOL> impr = np . zeros ( [ <NUM_LIT:3> ] * ndim ) <EOL> for dim in range ( ndim ) : <EOL> idx = tuple ( [ slice ( <NUM_LIT:1> , <NUM_LIT:2> ) ] * dim + <EOL> [ slice ( None ) ] + <EOL> [ slice ( <NUM_LIT:1> , <NUM_LIT:2> ) ] * ( ndim - dim - <NUM_LIT:1> ) ) <EOL> impr [ idx ] = np . array ( [ - <NUM_LIT:1.0> , <EOL> <NUM_LIT:0.0> , <EOL> - <NUM_LIT:1.0> ] ) . reshape ( [ - <NUM_LIT:1> if i == dim else <NUM_LIT:1> <EOL> for i in range ( ndim ) ] ) <EOL> impr [ ( [ slice ( <NUM_LIT:1> , <NUM_LIT:2> ) ] * ndim ) ] = <NUM_LIT> * ndim <EOL> return ir2tf ( impr , shape , is_real = is_real ) , impr </s>
