def _assert_valid(self, data, expected_data): tested_data = {key: data[key] for key in expected_data} self.assertEqual(tested_data, expected_data) self.assertEqual(data["t"].size, data["gh"].shape[1]) self.assertEqual(data["nm"].shape[0], data["gh"].shape[0]) self.assertEqual(data["nm"].shape[1], 2) self.assertEqual(data["nm"][..., 0].min(), data["degree_min"]) self.assertEqual(data["nm"][..., 0].max(), data["degree_max"]) self.assertTrue(aabs(data["nm"][..., 1]).max() <= data["degree_max"])
def __init__(self, indices, coefficients, **kwargs): SHCoefficients.__init__(self, **kwargs) n_idx, m_idx = indices[..., 0], indices[..., 1] self._degree = n_idx.max() self._index = stack(( aabs(m_idx) + (n_idx * (n_idx + 1)) // 2, (m_idx < 0).astype('int'), n_idx, ), 1) self._coeff = coefficients
def __init__(self, indices, coefficients, **kwargs): SHCoefficients.__init__(self, **kwargs) n_idx, m_idx = indices[..., 0], indices[..., 1] self._degree = n_idx.max() self._index = stack(( aabs(m_idx) + (n_idx*(n_idx + 1))//2, (m_idx < 0).astype('int'), n_idx, ), 1) self._coeff = coefficients
def _assert_valid(self, data, expected_data): tested_data = {key: data[key] for key in expected_data} assert_allclose(data["t"], [data["epoch"], data["epoch"] + WMM_VALIDITY_PERIOD]) self.assertEqual(tested_data, expected_data) self.assertEqual(data["t"].size, data["gh"].shape[1]) self.assertEqual(data["nm"].shape[0], data["gh"].shape[0]) self.assertEqual(data["nm"].shape[1], 2) self.assertEqual(data["nm"][..., 0].min(), data["degree_min"]) self.assertEqual(data["nm"][..., 0].max(), data["degree_max"]) self.assertTrue(aabs(data["nm"][..., 1]).max() <= data["degree_max"])
def _assert_valid(self, data, expected_data): tested_data = { key: data[key] for key in expected_data } self.assertEqual(tested_data, expected_data) self.assertEqual(data["t"].size, data["gh"].shape[1]) self.assertEqual(data["nm"].shape[0], data["gh"].shape[0]) self.assertEqual(data["nm"].shape[1], 2) self.assertEqual(data["nm"][..., 0].min(), data["degree_min"]) self.assertEqual(data["nm"][..., 0].max(), data["degree_max"]) self.assertTrue(aabs(data["nm"][..., 1]).max() <= data["degree_max"])
def _assert_valid(self, data, expected_data): tested_data = { key: data[key] for key in expected_data } assert_allclose( data["t"], [data["epoch"], data["epoch"] + WMM_VALIDITY_PERIOD] ) self.assertEqual(tested_data, expected_data) self.assertEqual(data["t"].size, data["gh"].shape[1]) self.assertEqual(data["nm"].shape[0], data["gh"].shape[0]) self.assertEqual(data["nm"].shape[1], 2) self.assertEqual(data["nm"][..., 0].min(), data["degree_min"]) self.assertEqual(data["nm"][..., 0].max(), data["degree_max"]) self.assertTrue(aabs(data["nm"][..., 1]).max() <= data["degree_max"])
def _extend( data , sgm , I , eps = 1e-6 , clock_wise = True ) : """ extend hull find a point closely located to the boundary segement but not part of the footprint polygon eps is the absolute tolerance of the distance below which the point is considered part of the bounary """ if len(I) < 1 : return None # distance from the line segment and parametric projection of the point # to the boundary segement dist , parm = _evalPoint2LineDistAndParmam( data[I] ,_getLineCoef( data[sgm] , clock_wise ) ) # select points below the threshold and projected on the boundary segment idx = aand( aabs( dist ) < eps , aand( parm >= 0 , parm <= 1 ) ).nonzero()[0] return None if ( len(idx) < 1 ) else I[idx[0]]
def generalPSF(mask, x, y, a, r, wl, T=None, gamma=None, sigma=None): ''' Returns the diffraction-limited PSF generated by a given pupil, convolved with a Voigt profile specified by the parameters gamma and sigma. Parameters ========== mask : array_like (2D) The actual pupil of the telescope x, y : array_like Coordinate array of the image a : scalar (float) Aperture r : scalar (float) Distance from the optics to the object wl : scalar (float) / array_like Wavelength(s) T : scalar (float), required when wl is array_like Black body temperature gamma : scalar (float) Parameter of the Lorentz profile (in arcsec) sigma : scalar (float) Parameter of the Gaussian profile (in arcsec) Note: The convolution of the Lorentz and the Gaussian profiles lead to the ===== Voigt profile ''' if not hasattr(wl, '__len__'): wl = [wl] multiple_wl = False else: multiple_wl = True if T == None: raise ValueError('Black body temperature must be provided') psf_bol = [] N = 0. x = asarray(x) y = asarray(y) Nx = len(x) Ny = len(y) dx = x[1] - x[0] dy = y[1] - y[0] if any(x[1:] - x[:-1] != dx) or any(y[1:] - y[:-1] != dy): warn("Coordinates must be equidistant") if not (gamma is None and sigma is None): X = roll(arange(-floor(Nx / 2.) * dx, Nx / 2. * dx, dx), -int(floor(Nx / 2.))) Y = roll(arange(-floor(Ny / 2.) * dy, Ny / 2. * dy, dy), -int(floor(Ny / 2.))) R, theta, z = coordCyl(X, Y, [0], [X[0], Y[0], 0], [0, 0, 1]) R = sqrt(R[0][:, :, 0]**2 + R[1][:, :, 0]**2) nonIdeal = ones((Nx, Ny), dtype=complex) if gamma == 0.: gamma = None if sigma == 0.: sigma = None if not gamma is None: gamma = r * arctan(gamma * 2. * pi / (360. * 3600.)) nonIdeal *= fft2(.5 * gamma / (pi * (R**2 + .25 * gamma**2))) if not sigma is None: sigma = r * arctan(sigma * 2. * pi / (360. * 3600.)) nonIdeal *= fft2( exp(-R**2 / (2. * sigma**2)) / (sqrt(2. * pi) * sigma)) for l in wl: Lx = l / (Nx * sin(dx / r)) Ly = l / (Ny * sin(dy / r)) s = (1 + 2 * int(floor(.5 * a / Lx)), 1 + 2 * int(floor(.5 * a / Ly))) mask_resampled = resample(mask, s) mask_padded = real(zeroPadding(mask_resampled, (Nx, Ny))) #mask_shifted = (-1)**sum(meshgrid(arange(Nx), arange(Ny)))*mask_padded psf_val = aabs(fft2(mask_padded))**2 #psf_val = psf_val/psf_val[int(floor(Nx/2.)),int(floor(Ny/2.))] psf_val = psf_val / asum(psf_val) if multiple_wl: pl = planck(l, T) else: pl = 1. psf_bol += [pl * psf_val] N += pl if gamma is None and sigma is None: return sum(psf_bol) / N else: nonIdeal /= nonIdeal[0, 0] psf_nonIdeal = real(ifft2(fft2(sum(psf_bol) / N) * nonIdeal)) #return aabs(ifft2(nonIdeal)) #print(mean(psf_nonIdeal)) return psf_nonIdeal