Exemplo n.º 1
0
    def loadConfig(self):
        """
        Load the Soapy config file
        """
        self.config = confParse.loadSoapyConfig(self.configfile)

        self.nIters = self.config.sim.nIters

        self.mask = circle.circle(
                self.config.sim.pupilSize/2., self.config.sim.simSize)

        self.wfsPixelScale = self.config.wfss[0].subapFOV/self.config.wfss[0].pxlsPerSubap

        # Initialise the WFS (can use same one for all tests)
        self.wfs = wfs.ShackHartmann(self.config, mask=self.mask)
Exemplo n.º 2
0
    def loadConfig(self):
        """
        Load the Soapy config file
        """
        self.config = confParse.loadSoapyConfig(self.configfile)

        self.nIters = self.config.sim.nIters

        self.mask = circle.circle(self.config.sim.pupilSize / 2.,
                                  self.config.sim.simSize)

        self.wfsPixelScale = self.config.wfss[0].subapFOV / self.config.wfss[
            0].pxlsPerSubap

        # Initialise the WFS (can use same one for all tests)
        self.wfs = wfs.Gradient(self.config, mask=self.mask)
Exemplo n.º 3
0
                                              gsPositions, layerHeights, cn2,
                                              L0)
        residual = theoCovMat - rawCovMat

        print("\n***\nRMS: {}\n***\n\n".format(numpy.sqrt(
            (residual**2).mean())))

        if callback:
            callback(theoCovMat)

        return (residual**2).flatten()


if __name__ == "__main__":

    mask = circle.circle(3.5, 7)

    gsPositions = numpy.array([[1., 0], [0, 0], [-1., 0]])
    gsAltitudes = numpy.array([0, 0, 0])
    nLayers = 1
    layerHeights = numpy.array([12376.])
    cn2 = numpy.array([10.])
    L0 = numpy.array([100.])

    T = TomoAO(3, mask, 0.6)
    covMat = T.makeCovMat(gsAltitudes, gsPositions, layerHeights, cn2, L0)

    # T.fitToData(
    #         covMat, 1, gsAltitudes, gsPositions, layerHeights, cn2, L0,
    #         fitCn2=True)
Exemplo n.º 4
0
TEL_DIAM = 4.2

NWFS = 4
NSUBAPS = numpy.array([749] * NWFS)
NXSUBAPS = numpy.array([31] * NWFS)
SUBAPDIAM = numpy.array([4.2 / NXSUBAPS[0]] * NWFS)
GSALT = numpy.array([0] * NWFS)
GSPOS = numpy.array([[0, 0], [0, 0.1], [0, -.1], [.1, 0]
                     ]) * (1. / 3600) * (numpy.pi / 180.)

NLAYERS = 1
LAYERHEIGHTS = numpy.array([12376.])
CN2 = numpy.array([10.0])
L0 = numpy.array([10.])

PUPIL_MASK = circle.circle(15.5, 31)

# class LATomo(object):

# 	def __init__(self, pxlScale, totSubaps, nxSubaps, subapDiam):
# 		self.pxlScale = pxlScale
# 		self.totSubaps = totSubaps
# 		self.nxSubaps = nxSubaps
# 		self.subapMask = circle.circle(nxSubaps/2., nxSubaps)
# 		self.subapDiam = subapDiam

# 	def loadRawData(self, filename):
# 		self.rawSlopes = fits.getdata(filename)

# 		self.rawSlopes_rad = (self.rawSlopes *
# 				self.pxlScale * numpy.pi/180./3600.)
Exemplo n.º 5
0
        self.covMat = numpy.frombuffer(self.ffiTomo.buffer(c_covMat,
                                                           size=covMatSize**2),
                                       dtype="float64")

        return self.covMat

    def cov_XX(du, dv, ac, ad, bc, bd, L0):

        pass


if __name__ == "__main__":

    covMat = MatCov("matcov.dylib")

    xCoords, yCoords = numpy.where(circle.circle(3.5, 7))

    xCoords = numpy.tile(xCoords, 2) * 4.2
    yCoords = numpy.tile(yCoords, 2) * 4.2

    nSubaps = numpy.array([37, 37])
    nxSubaps = numpy.array([7, 7])

    gsAlt = numpy.array([0, 0])

    wfsType = numpy.array([1, 1])

    gsPosX = numpy.array([0, 5])
    gsPosY = numpy.array([0, -5])

    subapDiam = numpy.array([0.6, 0.6])
Exemplo n.º 6
0
    def test_circle(self):

        log.info("Create circles with (0,5), (1,5), (2,5), (0,6),...,(3,6)")
        # Define the expected outputs:
        # >>> circle.circle(0, 5)
        ce = numpy.array([[0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.],
                          [0., 0., 1., 0., 0.], [0., 0., 0., 0., 0.],
                          [0., 0., 0., 0., 0.]])
        c = circle.circle(0, 5)
        self.assertEqual(c.tolist(), ce.tolist())
        self.assertTrue((c == ce).all())

        #  circle.circle(1, 5)
        ce = numpy.array([[0., 0., 0., 0., 0.], [0., 0., 1., 0., 0.],
                          [0., 1., 1., 1., 0.], [0., 0., 1., 0., 0.],
                          [0., 0., 0., 0., 0.]])
        c = circle.circle(1, 5)
        self.assertEqual(c.tolist(), ce.tolist())
        self.assertTrue((c == ce).all())

        #  circle.circle(2, 5)
        ce = numpy.array([[0., 0., 1., 0., 0.], [0., 1., 1., 1., 0.],
                          [1., 1., 1., 1., 1.], [0., 1., 1., 1., 0.],
                          [0., 0., 1., 0., 0.]])
        c = circle.circle(2, 5)
        self.assertEqual(c.tolist(), ce.tolist())
        self.assertTrue((c == ce).all())

        #  circle.circle(0, 6)
        ce = numpy.array([[0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.],
                          [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.],
                          [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.]])
        c = circle.circle(0, 6)
        self.assertEqual(c.tolist(), ce.tolist())
        self.assertTrue((c == ce).all())

        #  circle.circle(1, 6)
        ce = numpy.array([[0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.],
                          [0., 0., 1., 1., 0., 0.], [0., 0., 1., 1., 0., 0.],
                          [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.]])
        c = circle.circle(1, 6)
        self.assertEqual(c.tolist(), ce.tolist())
        self.assertTrue((c == ce).all())

        #  circle.circle(2, 6)
        ce = numpy.array([[0., 0., 0., 0., 0., 0.], [0., 0., 1., 1., 0., 0.],
                          [0., 1., 1., 1., 1., 0.], [0., 1., 1., 1., 1., 0.],
                          [0., 0., 1., 1., 0., 0.], [0., 0., 0., 0., 0., 0.]])
        c = circle.circle(2, 6)
        self.assertEqual(c.tolist(), ce.tolist())
        self.assertTrue((c == ce).all())

        #  circle.circle(3, 6)
        ce = numpy.array([[0., 1., 1., 1., 1., 0.], [1., 1., 1., 1., 1., 1.],
                          [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.],
                          [1., 1., 1., 1., 1., 1.], [0., 1., 1., 1., 1., 0.]])
        c = circle.circle(3, 6)
        self.assertEqual(c.tolist(), ce.tolist())
        self.assertTrue((c == ce).all())

        # This is a crucial test since this is used in the dragon config file:
        # circle(15.5, 31) - circle(3.7, 31)
        ce = numpy.array([[
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0
        ],
                          [
                              0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
                          ],
                          [
                              0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0
                          ],
                          [
                              0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0
                          ],
                          [
                              0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
                          ],
                          [
                              0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
                          ],
                          [
                              0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
                          ],
                          [
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
                              0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                          ],
                          [
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
                              0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                          ],
                          [
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
                              0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                          ],
                          [
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
                              0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                          ],
                          [
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
                              0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                          ],
                          [
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
                              0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                          ],
                          [
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
                              0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                          ],
                          [
                              0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
                          ],
                          [
                              0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
                          ],
                          [
                              0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
                          ],
                          [
                              0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0
                          ],
                          [
                              0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0
                          ],
                          [
                              0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
                          ],
                          [
                              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
                              1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                          ]])
        c = circle.circle(15.5, 31) - circle.circle(3.7, 31)
        self.assertEqual(c.tolist(), ce.tolist())
        self.assertTrue((c == ce).all())

        log.info("Create circles with (2,6,(0.5,0.5)), (1,5,(0.5,0.5)), etc.")
        c1 = circle.circle(2, 6, (0.5, 0.5))[1:, 1:]
        c2 = circle.circle(2, 5)
        self.assertEqual(c1.tolist(), c2.tolist())
        self.assertTrue((c1 == c2).all())

        c1 = circle.circle(1, 6, (0.5, 0.5))[1:, 1:]
        c2 = circle.circle(1, 5)
        self.assertEqual(c1.tolist(), c2.tolist())
        self.assertTrue((c1 == c2).all())

        c1 = circle.circle(0, 6, (0.5, 0.5))[1:, 1:]
        c2 = circle.circle(0, 5)
        self.assertEqual(c1.tolist(), c2.tolist())
        self.assertTrue((c1 == c2).all())

        c1 = circle.circle(0, 5, (0.5, 0.5))[1:, 1:]
        c2 = circle.circle(0, 6)[1:-1, 1:-1]
        self.assertEqual(c1.tolist(), c2.tolist())
        self.assertTrue((c1 == c2).all())

        c1 = circle.circle(1, 5, (0.5, 0.5))[1:, 1:]
        c2 = circle.circle(1, 6)[1:-1, 1:-1]
        #c2[3,2] = 3.0 # to test the testing
        self.assertEqual(c1.tolist(), c2.tolist())
        self.assertTrue((c1 == c2).all())

        c1 = circle.circle(2, 5, (0.5, 0.5))[1:, 1:]
        c2 = circle.circle(2, 6)[1:-1, 1:-1]
        self.assertEqual(c1.tolist(), c2.tolist())
        self.assertTrue((c1 == c2).all())

        log.info("Raise TypeError if inputs not of correct type")

        # For testing by hand and observing the result:
        if False:
            import pylab
            pylab.ion()

            c = circle.circle(2, 5, (0.5, 0.5))
            pylab.imshow(c, interpolation="nearest")

            c1 = circle.circle(1, 5)
Exemplo n.º 7
0
def makeCovMat_LGSUplink(subaps,
                         d,
                         r0,
                         h,
                         H,
                         mask,
                         samp=1000,
                         pos1=(0, 0),
                         pos2=(0, 0),
                         L0=None,
                         l0=None):
    """
    Parameters:
        subaps (int): No. of subaps in 1d on WFS.
        d (float): diameter of each subap.
        r0 (float): Fried param of layer.
        h (float): height of layer.
        H (float): height of Laser.
        mask (ndarray): 2d array of subaps, 1 if active, 0 if not.
        samp (int, opt): size of oversampled covariance map
        pos1 (tuple, opt): Angular Pos of LGS 1, arcsecs.
        pos2 (tuple, opt): Angular Pos of LGS 2, arcsecs.
        L0 (float, opt): Outer scale.
        l0 (float, opt): innterscale.

    Returns:
        ndarray: The covariance Matrix

    """
    #Size of the telescope
    D = d * subaps
    h = float(h)
    H = float(H)

    pos1 = numpy.array(pos1, dtype="float32") * (1. / 3600) * (numpy.pi / 180.)
    pos2 = numpy.array(pos2, dtype="float32") * (1. / 3600) * (numpy.pi / 180.)

    #Find the maximum seperation in metres
    maxSep = (pos2 - pos1).max() * h
    maxSep += d * (subaps + 1)

    #Make the massively oversampled covaranace maps - make it an odd number
    #if samp%2==0:
    #   samp+=1
    covMaps = makeCovMap(samp, maxSep, r0, subapDiam, L0, l0)
    covMaps /= covMaps[0].max()

    #The subap size at this height
    dSize = d * (1. - (h / H))

    #And set to same scale as covMap array
    dSize *= (covMaps.shape[1] - 1) / (2 * maxSep)
    dSize = int(round(dSize))
    print(dSize)

    #Find total number of subaps, and their positions in subap space.
    #Make a placeholder of the delicious covariance matrix
    totalSubaps = int(mask.sum())
    covMat = numpy.zeros((2 * totalSubaps, 2 * totalSubaps))

    #This is the start of the sub-ap seen by the LGS on the uplink, in metres
    lgs2Pos = (h * pos2) - d / 2.  #Would need to be changed for launch

    #Make an LGS mask to determine the overlap with subaps, each element is a cm
    lgsScale = 100
    lgsMask = circle.circle(lgsScale * d / 2.,
                            lgsScale * d * subaps,
                            centre_offset=lgsScale * lgs2Pos)

    lgsSubapPos = []
    subapPos = []
    for x in range(subaps):
        for y in range(subaps):
            if mask[x, y] == 1:
                subapPos.append([x, y])

    subapPos = numpy.array(subapPos)
    lgsSubapPos = numpy.array(lgsSubapPos)

    for i in range(totalSubaps):
        for j in range(totalSubaps):
            #This is the position in metres from the centre of the WFS field, i
            #to the start of the subap
            maskVal = lgsMask[subapPos[j, 0] * 100:(subapPos[j, 0] + 1) * 100,
                              subapPos[j, 1] * 100:(subapPos[j, 1] + 1) *
                              100].mean()
            if maskVal > 0:

                ix, iy = pos1 * h + ((subapPos[i] * d) - D / 2.) * (1. -
                                                                    (h / H))
                jx, jy = pos2 * h + ((subapPos[j] * d) - D / 2.) * (1. -
                                                                    (h / H))

                #The seperation between the two subap start positions in covMap pxls
                dx = (jx - ix) * (covMaps.shape[1] - 1) / (2 * maxSep)
                dy = (jy - iy) * (covMaps.shape[1] - 1) / (2 * maxSep)
                #print("ix:{}, jx:{}, dx:{}, iy:{}, jy:{},  dy:{}".format(ix, jx, dx, iy, jy, dy))

                #Adjust this for the array coords
                dx = int(round(dx + covMaps.shape[1] / 2. - dSize / 2.))
                dy = int(round(dy + covMaps.shape[1] / 2. - dSize / 2.))

                #print("i:{}, j:{}, ix:{}, jx:{}, dx:{}, iy:{}, jy:{},  dy:{}\n".format(i,j,ix, jx, dx, iy, jy, dy))

                #Get the sum of the covarance for the seperation of
                #each point in the sub-apertures
                #x-x terms
                covMat[i, :totalSubaps] += covMaps[0, dy:dy + dSize, dx:dx +
                                                   dSize].sum() * maskVal
                #y-y terms
                covMat[i + totalSubaps,
                       totalSubaps:] += covMaps[1, dy:dy + dSize,
                                                dx:dx + dSize].sum() * maskVal
                #x-y terms
                covMat[i, :totalSubaps] += covMaps[2, dy:dy + dSize, dx:dx +
                                                   dSize].sum() * maskVal
                covMat[i + totalSubaps,
                       totalSubaps:] += covMaps[2, dx:dx + dSize,
                                                dy:dy + dSize].sum() * maskVal

    #return covMaps
    return covMat
Exemplo n.º 8
0
# Parameters for CANARY
TEL_DIAM = 4.2

NWFS = 2
NSUBAPS = numpy.array([37] * NWFS)
NXSUBAPS = numpy.array([7] * NWFS)
SUBAPDIAM = numpy.array([0.6] * NWFS)
GSALT = numpy.array([0] * NWFS)
GSPOS = numpy.array([[10., 0], [-10, 0]]) * (1. / 3600) * (numpy.pi / 180.)

NLAYERS = 1
LAYERHEIGHTS = numpy.array([12376.])
CN2 = numpy.array([10.0])
L0 = numpy.array([100.])

PUPIL_MASK = circle.circle(3.5, 7)


def canaryCovMat():
    subapPos = (numpy.array(numpy.where(PUPIL_MASK == 1)).T * TEL_DIAM /
                NXSUBAPS[0]).T
    # subapPos = numpy.array(numpy.where(PUPIL_MASK==1))/float(NXSUBAPS[0])
    subapPos = numpy.tile(subapPos, (1, NWFS))

    print(subapPos)
    covMat = numpy.zeros((2 * NSUBAPS.sum(), 2 * NSUBAPS.sum()),
                         dtype="float64")

    covMat = fillCovMat(covMat, subapPos)

    return covMat