Exemplo n.º 1
0
    def test_shifted_domain_should_not_affect_spectrum(self):
        sz = 4
        spatial_step = 2.54
        ampl = 42.0
        xy = DomainXY.from_shape((sz, sz), spatial_step)
        xy.shift(3, 2)
        values = ampl * np.ones(xy.shape)
        spatial_funct = ScalarBidimensionalFunction(values, domain=xy)
        spectr_shifted = bfft.direct(spatial_funct)

        xy = DomainXY.from_shape((sz, sz), spatial_step)
        values = ampl * np.ones(xy.shape)
        spatial_funct = ScalarBidimensionalFunction(values, domain=xy)
        spectr = bfft.direct(spatial_funct)

        self.assertTrue(np.allclose(spectr_shifted.values, spectr.values))
Exemplo n.º 2
0
 def test_inverse_of_direct_return_original(self):
     sz = 4
     spatial_step = 1.0
     ampl = 1.0
     xy = DomainXY.from_shape((sz, sz), spatial_step)
     constant_map = ampl * np.ones(xy.shape)
     original = ScalarBidimensionalFunction(constant_map, domain=xy)
     spectr = bfft.direct(original)
     inverse_spectr = bfft.inverse(spectr)
     self.assertTrue(np.allclose(inverse_spectr.values, original.values))
Exemplo n.º 3
0
 def test_with_units(self):
     from astropy import units as u
     szx, szy = (20, 10)
     stepx, stepy = (0.1 * u.m, 0.4 * u.kg)
     ampl = 1.0 * u.V
     xy = DomainXY.from_shape((szy, szx), (stepy, stepx))
     map_in_V = ampl * np.ones(xy.shape)
     spatial_funct = ScalarBidimensionalFunction(map_in_V, domain=xy)
     spectr = bfft.direct(spatial_funct)
     self.assertTrue(spectr.xmap.unit.is_equivalent((1 / u.m).unit))
     self.assertTrue(spectr.ymap.unit.is_equivalent((1 / u.kg).unit))
     self.assertTrue(spectr.xcoord.unit.is_equivalent((1 / u.m).unit))
     self.assertTrue(spectr.ycoord.unit.is_equivalent((1 / u.kg).unit))
     self.assertTrue(spectr.values.unit.is_equivalent((u.V)))
Exemplo n.º 4
0
    def test_rectangular_domain(self):

        szx, szy = (20, 10)
        stepx, stepy = (0.1, 0.4)
        ampl = 1.0
        xy = DomainXY.from_shape((szy, szx), (stepy, stepx))
        constant_map = ampl * np.ones(xy.shape)
        spatial_funct = ScalarBidimensionalFunction(constant_map, domain=xy)
        spectr = bfft.direct(spatial_funct)
        freq_step_x, freq_step_y = spectr.domain.step

        self.assertAlmostEqual(0, spectr.xmap[szy // 2, szx // 2])
        self.assertAlmostEqual(0, spectr.ymap[szy // 2, szx // 2])
        self.assertAlmostEqual(np.sqrt(ampl * szx * szy),
                               spectr.values[szy // 2, szx // 2])

        self.assertAlmostEqual(-0.5 / stepx, spectr.xcoord[0])
        self.assertAlmostEqual(1 / (szx * stepx), freq_step_x)

        self.assertAlmostEqual(-0.5 / stepy, spectr.ycoord[0])
        self.assertAlmostEqual(1 / (szy * stepy), freq_step_y)
Exemplo n.º 5
0
    def test_direct_sinus_x(self):
        sizeInPoints = 500
        pixelSize = 0.2
        periodInLengthUnits = 4.0
        amplitude = 13.4
        phase = 0.8
        spatialMap = self._makeSinusMap(sizeInPoints, pixelSize, amplitude,
                                        periodInLengthUnits, phase)
        xyDomain = DomainXY.from_shape((sizeInPoints, sizeInPoints), pixelSize)
        xyFunct = ScalarBidimensionalFunction(spatialMap, domain=xyDomain)
        fftFunct = bfft.direct(xyFunct)
        spectralMap = fftFunct.values
        freqX = bfft.frequencies_x_map(sizeInPoints, pixelSize)
        freqY = bfft.frequencies_y_map(sizeInPoints, pixelSize)

        self.assertEqual((sizeInPoints, sizeInPoints), spectralMap.shape)
        self.assertEqual(
            1.0 / periodInLengthUnits,
            np.abs(freqX.flatten()[np.argmax(np.abs(spectralMap))]))
        self.assertEqual(
            0.0, np.abs(freqY.flatten()[np.argmax(np.abs(spectralMap))]))
        self._checkParseval(spatialMap, spectralMap)
 def _autoCorrelate(self, scalar2dfunct):
     functFT = bfft.direct(scalar2dfunct)
     aa = S2DF(np.abs(functFT.values() ** 2),
               functFT.xCoord(),
               functFT.yCoord())
     return bfft.inverse(aa)