Ejemplo n.º 1
Archivo: aosWFS.py Proyecto: bxin/IM
def runcwfs(argList):
    I1File = argList[0]
    I1Field = argList[1]
    I2File = argList[2]
    I2Field = argList[3]
    inst = argList[4]
    algo = argList[5]
    model = argList[6]
    I1 = Image(readFile(I1File), I1Field, 'intra')
    I2 = Image(readFile(I2File), I2Field, 'extra')
    algo.reset(I1, I2)
    algo.runIt(inst, I1, I2, model)
    return np.append(algo.zer4UpNm*1e-3, algo.caustic)
Ejemplo n.º 2
    def testMatlab(self):
        global doPlot
        if doPlot:
            fig = plt.figure(figsize=(10, 10))

        j = 0                           # counter for matlab outputs, self.matlabZFile_Tol
        for imgDir, filenameFmt, fldxy, algorithms, model in self.tests:
            imgDir = os.path.join(str(self.rootdir), imgDir)
            intraFile = os.path.join(imgDir, filenameFmt % "intra")
            I1 = Image(readFile(intraFile), fldxy, Image.INTRA)

            extraFile = os.path.join(imgDir, filenameFmt % "extra")
            I2 = Image(readFile(extraFile), fldxy, Image.EXTRA)

            inst = Instrument(self.myinst, I1.sizeinPix)

            for algorithm in algorithms:
                matlabZFile, tol = self.matlabZFile_Tol[j]; j += 1

                algo = Algorithm(algorithm, inst, 1)
                algo.runIt(inst, I1, I2, model)

                zer = algo.zer4UpNm
                matZ = np.loadtxt(os.path.join(self.validationDir, matlabZFile))

                aerr = np.abs(matZ - zer)
                print("%-31s max(abs(err)) = %8.3g median(abs(err)) = %8.3g [Z_%d]" %
                      (matlabZFile, np.max(aerr), np.median(aerr), self.Zernike0 + np.argmax(aerr)))

                if doPlot:
                    ax = plt.subplot(self.nTest, 1, j)
                    plt.plot(self.x, matZ, label='Matlab', marker='o', color='r', markersize=10)
                    plt.plot(self.x, zer, label='Python',  marker='.', color='b', markersize=10)
                    plt.axvline(self.Zernike0 + np.argmax(aerr), ls=':', color='black')
                    plt.legend(loc="best", shadow=True, title=matlabZFile, fancybox=True)
                    plt.xlim(self.x[0] - 0.5, self.x[-1] + 0.5)

                assert np.max(aerr) < tol

        if doPlot:
Ejemplo n.º 3
Archivo: cwfs.py Proyecto: bxin/cwfs
def main():

    parser = argparse.ArgumentParser(
        description='-----This is cwfs (Curvature Wavefront Sensing) code----')

    parser.add_argument('intra', help='intra focal image file name (no path)')
    parser.add_argument('extra', help='extra focal image file name (no path)')

    parser.add_argument('-dir', dest='imgDir',
                        help='relative or absolute path for input images')
    parser.add_argument('-ixy', dest='intra_xy', nargs=2,
                        type=float, default=[0, 0],
                        help='intra focal field (x,y) in deg, default=[0 0]')
    parser.add_argument('-exy', dest='extra_xy', nargs=2,
                        type=float, default=[0, 0],
                        help='extra focal field (x,y) in deg, default=[0 0]')
    parser.add_argument('-i', dest='instruFile', default='lsst',
                        help='instrument parameter file, default=lsst,\
                         ".param" is appended automatically \
                        default path is data/lsst/')
    parser.add_argument('-a', dest='algoFile', default='fft',
                        help='algorithm parameter file, default=fft,\
                         ".algo" is appended automatically\
                        default path is data/algo/')
    parser.add_argument('-m', dest='model',
                        choices=('paraxial', 'onAxis', 'offAxis'),
                        help='Optical model to be used, default=paraxial')
    parser.add_argument('-op', dest='outputParam', default='',
                        help='file name for dumping all parameters, \
                        default=no output')
    parser.add_argument('-oz', dest='outputZerFile', default='',
                        help='file name for output Zernikes (in unit of nm), \
                        default=no output')
    parser.add_argument('-v', '--version', action='version',
                        version='%(prog)s 1.0')
    parser.add_argument('-d', dest='debugLevel', type=int,
                        default=0, choices=(-1, 0, 1, 2, 3),
                        help='debug level, -1=quiet, 0=Zernikes, \
                        1=operator, 2=expert, 3=everything, default=0')
    args = parser.parse_args()

    if args.debugLevel >= 1:

    # load intra and extra focal images
    intraFile, extraFile = args.intra, args.extra

    if args.imgDir:
        intraFile = os.path.join(args.imgDir, intraFile)
        extraFile = os.path.join(args.imgDir, extraFile)

    I1 = Image(readFile(intraFile), args.intra_xy, Image.INTRA, intraFile)
    I2 = Image(readFile(extraFile), args.extra_xy, Image.EXTRA, intraFile)

    # load instrument and algorithm parameters
    inst = Instrument(args.instruFile, I1.sizeinPix)
    algo = Algorithm(args.algoFile, inst, args.debugLevel)

    # run it
    algo.runIt(inst, I1, I2, args.model)

    # output Zernikes 4 and up
    if not(args.outputZerFile == '') or args.debugLevel >= 0:
        outZer4Up(algo.zer4UpNm, 'nm', args.outputZerFile)

    # output parameters
    if not(args.outputParam == '') or args.debugLevel >= 1:
        outParam(args.outputParam, algo, inst, I1, I2, args.model)