def _generateSubHarmonics(self, numberOfSubHarmonics): nSub = 3 lowFreqScreen = np.zeros((self._screenSzInPx, self._screenSzInPx), dtype=np.complex) freqX = bfft.frequencies_x_map(nSub, 1. / nSub) freqY = bfft.frequencies_y_map(nSub, 1. / nSub) freqMod = bfft.frequencies_norm_map(nSub, 1. / nSub) vv = np.arange(self._screenSzInPx) / self._screenSzInPx xx = np.tile(vv, (self._screenSzInPx, 1)) yy = xx.T depth = 0 while depth < numberOfSubHarmonics: depth += 1 phase = self._randomPhase() freqMod /= nSub freqX /= nSub freqY /= nSub modul = self._kolmogorovAmplitudeMap(freqMod) for ix in range(nSub): for jx in range(nSub): sh = np.exp(2 * np.pi * 1j * (xx * freqX[ix, jx] + yy * freqY[ix, jx] + phase[ix, jx])) sh0 = sh.sum() / self._screenSzInPx**2 lowFreqScreen += 1. / nSub**depth * modul[ix, jx] * (sh - sh0) lowFreqScreen *= np.sqrt(0.0228) * self._screenSzInPx**(5. / 6) return lowFreqScreen
def testFrequenciesXMapOdd(self): sizeInPoints = 11 pixelSize = 0.12 frequenciesMap = bfft.frequencies_x_map(sizeInPoints, pixelSize) sz2 = int(sizeInPoints / 2) mostPosFrequency = bfft.most_positive_frequency( sizeInPoints, pixelSize) mostNegFrequency = bfft.most_negative_frequency( sizeInPoints, pixelSize) self.assertEqual((sizeInPoints, sizeInPoints), frequenciesMap.shape) self.assertTrue(np.all(0 == frequenciesMap[:, sz2])) self.assertTrue(np.all(mostNegFrequency == frequenciesMap[:, 0])) self.assertTrue(np.all(mostPosFrequency == frequenciesMap[:, -1]))
def testDirectTransformSinusX(self): sizeInPoints = 500 pixelSize = 0.2 periodInLengthUnits = 4.0 amplitude = 13.4 phase = 0.8 spatialMap = self._makeSinusMap(sizeInPoints, pixelSize, amplitude, periodInLengthUnits, phase) spectralMap = bfft.direct_transform(spatialMap) 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 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 _createPupilPlaneSpatialFrequencyCoordiantesInInverseMeters(self): return bfft.frequencies_x_map( self.focalPlaneSizeInPixels(), self.pupilPlanePixelSizeInMeters())
def _createFocalPlaneAngularFrequencyCoordinatesInInverseRadians(self): return bfft.frequencies_x_map( self.focalPlaneSizeInPixels(), self.focalPlanePixelSizeInArcsec() * self.ARCSEC2RAD)