added Spectrum export/import to bytes
This commit is contained in:
@@ -6,6 +6,33 @@ from scgenerator.physics.units import m_rads
|
||||
from scgenerator.spectra import Spectrum
|
||||
|
||||
|
||||
def test_export():
|
||||
t = np.linspace(-1e-12, 1e-12, 1024)
|
||||
w = wspace(t) + m_rads(800e-9)
|
||||
|
||||
spec = np.fft.fft(np.exp(-((t / 1e-13) ** 2)))
|
||||
spec = Spectrum(spec, w, t)
|
||||
|
||||
new_spec = Spectrum.from_bytes(bytes(spec))
|
||||
assert np.all(new_spec.w == spec.w)
|
||||
assert np.all(new_spec.t == spec.t)
|
||||
assert np.all(new_spec.l == spec.l)
|
||||
assert np.all(new_spec == spec)
|
||||
assert new_spec.ifft is spec.ifft
|
||||
|
||||
t = np.linspace(-1e-12, 1e-12, 512)
|
||||
w = np.fft.rfftfreq(len(t), d=t[1] - t[0]) * 2 * np.pi + m_rads(800e-9)
|
||||
spec = np.exp(2j * np.pi * np.random.rand(4, 2, 5, 257))
|
||||
spec = Spectrum(spec, w, t, np.fft.irfft)
|
||||
|
||||
new_spec = Spectrum.from_bytes(bytes(spec))
|
||||
assert np.all(new_spec.w == spec.w)
|
||||
assert np.all(new_spec.t == spec.t)
|
||||
assert np.all(new_spec.l == spec.l)
|
||||
assert np.all(new_spec == spec)
|
||||
assert new_spec.ifft is spec.ifft
|
||||
|
||||
|
||||
def test_center_gravity():
|
||||
t = np.linspace(-1e-12, 1e-12, 1024)
|
||||
w = wspace(t) + m_rads(800e-9)
|
||||
|
||||
Reference in New Issue
Block a user