def testMaskLoad(): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8.yaml")) sim.config.sim.simName = None sim.config.sim.logfile = None sim.aoinit() mask = numpy.ones((sim.config.sim.pupilSize, sim.config.sim.pupilSize)) # save mask if os.path.isfile('testmask.fits'): os.remove('testmask.fits') hdu = fits.PrimaryHDU(mask) hdulist = fits.HDUList([hdu]) hdulist.writeto('testmask.fits') hdulist.close() try: # attempt to load it sim.config.tel.mask = 'testmask.fits' sim.aoinit() # check its good p = sim.config.sim.simPad pad_mask = numpy.pad(mask, mode="constant", pad_width=((p, p), (p, p))) assert numpy.array_equal(sim.mask, pad_mask) except: raise finally: os.remove('testmask.fits')
def testZernikeDM(self): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8.yaml")) sim.config.wfss[0].type = "ShackHartmannLegacy" sim.config.sim.simName = None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.config.wfss[0].GSPosition = (0, 0) sim.config.sim.nDM = 1 sim.config.dms[0].type = "Zernike" sim.config.dms[0].nxActuators = 45 sim.config.dms[0].svdConditioning = 0.01 sim.config.dms[0].iMatValue = 100 sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose(sim.longStrehl[0, -1], RESULTS["8x8_zernike"], atol=0.2)
def test_load_imat(): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8.yaml")) sim.config.sim.simName = "test_sim" sim.config.sim.logfile = None # 1 scrn for fast init sim.config.atmos.scrnNo = 1 try: sim.aoinit() recon = sim.recon # Make an imat recon.makeIMat() # Save it for later recon.save_interaction_matrix() imat = recon.interaction_matrix.copy() # Set the internat soapy imat to 0 recon.interaction_matrix[:] = 0 # And attempt to load saved one recon.load_interaction_matrix() # Ensure its been loaded as expected assert (numpy.array_equal(imat, recon.interaction_matrix)) finally: shutil.rmtree("test_sim")
def testOnAxis(self): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8.yaml")) sim.config.sim.simName = None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.config.wfss[0].GSPosition = (0, 0) sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose(sim.longStrehl[0, -1], RESULTS["8x8"], atol=0.2)
def testCone(self): sim = soapy.Sim("../conf/sh_8x8_lgs.py") sim.config.sim.simName = None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose(sim.longStrehl[0, -1], RESULTS["8x8_lgs"], atol=0.2)
def testOffAxis(self): sim = soapy.Sim("../conf/sh_8x8.py") sim.config.sim.simName = None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.config.wfss[0].GSPosition = (20, 0) sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose(sim.longStrehl[0, -1], RESULTS["8x8_offAxis"], atol=0.2)
def testLgsUplink_geo(self): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8_lgs-uplink.yaml")) sim.config.sim.simName = None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.config.wfss[0].GSPosition = (0, 0) sim.config.wfss[1].GSPosition = (0, 0) sim.config.wfss[1].lgs.propagationMode = "Geometric" sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose(sim.longStrehl[0, -1], RESULTS["8x8_lgsuplink"], atol=0.2)
def testCone(self): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8_lgs.yaml")) sim.config.sim.simName = None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.config.atmos.randomSeed = 0 sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose(sim.longStrehl[0, -1], RESULTS["8x8_lgs"], atol=0.2)
def testPhysProp(self): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8.yaml")) sim.config.wfss[0].type = "ShackHartmannLegacy" sim.config.sim.simName = None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.config.wfss[0].GSPosition=(0,0) sim.config.wfss[0].propagationMode="Physical" sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose(sim.longStrehl[0,-1], RESULTS["8x8_phys"], atol=0.2)
def testSaveData(self): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8.yaml")) sim.config.sim.simName = 'test_sh8x8' sim.config.sim.logfile = False sim.config.sim.saveSlopes = True sim.config.sim.saveDmCommands = True sim.config.sim.saveLgsPsf = True sim.config.sim.saveWfe = True sim.config.sim.saveStrehl = True sim.config.sim.saveSciPsf = True sim.config.sim.saveInstPsf = True sim.config.sim.saveCalib = True sim.config.sim.saveWfsFrames = True sim.config.sim.saveSciRes = False sim.config.sim.saveInstScieField = False sim.config.sim.nIters = 2 wdir = './' sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() try: assert os.path.isfile(wdir + sim.path + '/slopes.fits') &\ os.path.isfile(wdir + sim.path + '/dmCommands.fits') &\ os.path.isfile(wdir + sim.path + '/lgsPsf.fits') &\ os.path.isfile(wdir + sim.path + '/WFE.fits') &\ os.path.isfile(wdir + sim.path + '/instStrehl.fits') &\ os.path.isfile(wdir + sim.path + '/longStrehl.fits') &\ os.path.isfile(wdir + sim.path + '/sciPsf_00.fits') &\ os.path.isfile(wdir + sim.path + '/sciPsfInst_00.fits') &\ os.path.isfile(wdir + sim.path + '/iMat.fits') &\ os.path.isfile(wdir + sim.path + '/cMat.fits') &\ os.path.isfile(wdir + sim.path + '/wfsFPFrames/wfs-0_frame-0.fits') # os.path.isfile(wdir + sim.path + '/sciResidual_00.fits') &\ # os.path.isfile(wdir + sim.path + '/scieFieldInst_00_real.fits') &\ # os.path.isfile(wdir + sim.path + '/scieFieldInst_00_imag.fits') &\ except: raise finally: dd = os.path.dirname(sim.path) shutil.rmtree(wdir + dd)
def testCone(self): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8_lgs.yaml")) sim.config.wfss[0].type = "ShackHartmannLegacy" sim.config.wfss[1].type = "ShackHartmannLegacy" sim.config.sim.simName= None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.aoinit() print("WFS TYPE: {}".format(sim.wfss[0])) sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose( sim.longStrehl[0,-1], RESULTS["8x8_lgs"], atol=0.2)
def testOpenLoop(self): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8_openloop.yaml")) sim.config.sim.simName = None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.config.wfss[0].GSPosition = (0, 0) for i in range(sim.config.sim.nDM - 1): sim.config.dms[i + 1].closed = False sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose(sim.longStrehl[0, -1], RESULTS["8x8_open"], atol=0.2)
def testZernikeDM(self): sim = soapy.Sim("../conf/sh_8x8.py") sim.config.sim.simName = None sim.config.sim.logfile = None sim.config.sim.nIters = 100 sim.config.wfss[0].GSPosition = (0, 0) sim.config.sim.nDM = 1 sim.config.dms[0].type = "Zernike" sim.config.dms[0].nxActuators = 45 sim.config.dms[0].svdConditioning = 0.01 sim.aoinit() sim.makeIMat(forceNew=True) sim.aoloop() #Check results are ok assert numpy.allclose(sim.longStrehl[0, -1], RESULTS["8x8_zernike"], atol=0.2)
def test_save_imat(): sim = soapy.Sim(os.path.join(CONFIG_PATH, "sh_8x8.yaml")) sim.config.sim.simName = "test_sim" sim.config.sim.logfile = None # 1 scrn for fast init sim.config.atmos.scrnNo = 1 try: sim.aoinit() recon = sim.recon recon.makeIMat() recon.save_interaction_matrix() imat_filename = "test_sim/iMat.fits" imat = fits.getdata(imat_filename) assert (numpy.array_equal(imat, sim.recon.interaction_matrix)) finally: shutil.rmtree("test_sim")
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ N samples on the same phase screen with random speed & direction & starting points """ import numpy as np import datetime from astropy.io import fits import soapy from matplotlib import pyplot as plt from numpy.random import uniform #from random import randint from numpy import sin, cos, pi sim = soapy.Sim("../soapy-master/conf/sh_77.yaml") sim.aoinit() scrnsize = 1024 nb = 1000 seqlen = 100 masksize = 130 allslopes = np.empty((nb, 72 * seqlen)) #looptime = sim.atmos.looptime #pxscale = sim.atmos.pixel_scale vs = uniform(5, 10, nb) dirs = uniform(0, 360, nb) for i in range(nb): sim.config.atmos.windSpeeds = [vs[i]] sim.config.atmos.windDirs = [dirs[i]]
""" generate all slopes and wind info in certain steps for training """ import numpy as np import datetime from astropy.io import fits import soapy from matplotlib import pyplot as plt allslopes = np.empty((1000, 3600)) sim = soapy.Sim("./conf/sh_77.yaml") for j in range(1000): # sim.config.atmos.windSpeeds = [v] sim.aoinit() sim.aoloop() allslopes[j] = sim.allSlopes.reshape(-1) header = fits.Header() header["r_0"] = str([0.16]) header["WINDSPD"] = str([5, 6, 7, 8, 9, 10]) header["WINDDIR"] = str([0]) header["SAVETIME"] = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") header["ITERS"] = str([50]) header['ITERTIME'] = str([0.012]) fits.writeto("trnslos_20180202.fits", trnslos, header, overwrite=True)