mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-09-18 08:42:08 +02:00
27 lines
954 B
Python
27 lines
954 B
Python
from __future__ import division, print_function, absolute_import
|
|
|
|
from CDTools.tools import cmath
|
|
from CDTools.tools import projectors
|
|
import numpy as np
|
|
import torch as t
|
|
from scipy.fftpack import fftshift, ifftshift
|
|
|
|
def test_modulus():
|
|
# Create a complex array with modulus 12 and phase pi/4
|
|
np_result = 6**.5*(np.ones((10,10))+1j*np.ones((10,10)))
|
|
# Test without masks
|
|
assert(np.allclose(cmath.torch_to_complex(projectors.modulus(t.ones((10,10,2)), 12*t.ones((10,10)))), np_result))
|
|
# Test with mask
|
|
mask = t.ones((10,10,2), dtype = t.uint8)
|
|
mask[5]*=0
|
|
np_result[5] = 1+1j
|
|
assert(np.allclose(cmath.torch_to_complex(projectors.modulus(t.ones((10,10,2)), 12*t.ones((10,10)), mask = mask)), np_result))
|
|
|
|
|
|
def test_support():
|
|
# Test masking
|
|
support = t.zeros((10,10))
|
|
np_result = np.zeros((10,10))
|
|
|
|
assert(np.allclose(cmath.torch_to_complex(projectors.support(t.ones((10,10,2)), support)), np_result))
|