def test_saveloadScrn(self): # test the saving and loading phase screens config = confParse.Configurator(os.path.join(CONFIG_PATH,"sh_8x8.py")) config.loadSimParams() config.atmos.wholeScrnSize = 512 atmos = atmosphere.atmos(config) # Make a directory to save the screens in if os.path.exists('testscrns'): shutil.rmtree('testscrns') os.makedirs('testscrns') atmos.saveScrns('testscrns') try: # change config to load scrns config.atmos.scrnNames = [] for i in range(config.atmos.scrnNo): config.atmos.scrnNames.append('testscrns/scrn{}.fits'.format(i)) atmos2 = atmosphere.atmos(config) # Check that all scrns are identical for i in range(config.atmos.scrnNo): assert numpy.allclose(atmos.wholeScrns[i], atmos2.wholeScrns[i]) # delete that dir shutil.rmtree('testscrns') except: # always delete that dir - even in case of failure shutil.rmtree('testscrns') raise
def test_saveloadScrn(self): # test the saving and loading phase screens config = confParse.loadSoapyConfig(os.path.join(CONFIG_PATH,"sh_8x8.yaml")) config.atmos.wholeScrnSize = 512 config.atmos.infinite = False atmos = atmosphere.atmos(config) # Make a directory to save the screens in if os.path.exists('testscrns'): shutil.rmtree('testscrns') os.makedirs('testscrns') atmos.saveScrns('testscrns') try: # change config to load scrns config.atmos.scrnNames = [] for i in range(config.atmos.scrnNo): config.atmos.scrnNames.append('testscrns/scrn{}.fits'.format(i)) atmos2 = atmosphere.atmos(config) # Check that all scrns are identical for i in range(config.atmos.scrnNo): assert numpy.allclose(atmos.wholeScrns[i], atmos2.wholeScrns[i]) # delete that dir shutil.rmtree('testscrns') except: # always delete that dir - even in case of failure shutil.rmtree('testscrns') raise
def run_scrns(self): slopes = numpy.zeros((N_SCRNS * self.nIters, 2, self.wfs.activeSubaps)) for iscrn in range(N_SCRNS): atmos = atmosphere.atmos(self.config) print('Made screen - starting run') for i in range(self.nIters): fullSlopes = self.wfs.frame(atmos.moveScrns()) slopes[iscrn*self.nIters + i, 0] = fullSlopes[:self.wfs.activeSubaps] slopes[iscrn*self.nIters + i, 1] = fullSlopes[self.wfs.activeSubaps:] return slopes
def run_scrns(self): slopes = numpy.zeros((N_SCRNS * self.nIters, 2, self.wfs.activeSubaps)) for iscrn in range(N_SCRNS): atmos = atmosphere.atmos(self.config) print('Made screen - starting run') for i in range(self.nIters): fullSlopes = self.wfs.frame(atmos.moveScrns()) slopes[iscrn * self.nIters + i, 0] = fullSlopes[:self.wfs.activeSubaps] slopes[iscrn * self.nIters + i, 1] = fullSlopes[self.wfs.activeSubaps:] return slopes
def test_randomAtmos(self): config = confParse.Configurator(os.path.join(CONFIG_PATH,"sh_8x8.py")) config.loadSimParams() atmos = atmosphere.atmos(config) atmos.randomScrns()
import numpy as np import matplotlib.pyplot as pl from soapy import confParse, SCI, atmosphere # load a sim config that defines lots of science cameras across the field config = confParse.loadSoapyConfig('sh_8x8.py') # Init a science camera sci_camera = SCI.PSF(config, mask=np.ones((154,154))) # init some atmosphere atmos = atmosphere.atmos(config) # Now loop over lots of difference turbulence for i in range(100): print(i) # Get phase for this time step phase_scrns = atmos.moveScrns() # Calculate all the PSF for this turbulence psf = sci_camera.frame(phase_scrns) # You can also get the phase if you’d like from each science detector with # phase = sci_camera.los.phase pl.imshow(psf) pl.show()
def test_randomAtmos(self): config = confParse.Configurator(os.path.join(CONFIG_PATH, "sh_8x8.py")) config.loadSimParams() atmos = atmosphere.atmos(config) atmos.randomScrns()
def initAtmos(self, whole_scrn_size=None): if whole_scrn_size is not None: self.config.atmos.wholeScrnSize = whole_scrn_size self.atmos = atmosphere.atmos(self.config)
def test_randomAtmos(self): config = confParse.loadSoapyConfig(os.path.join(CONFIG_PATH,"sh_8x8.yaml")) atmos = atmosphere.atmos(config) atmos.randomScrns()
import numpy from soapy import confParse, SCI, atmosphere, DM from SPGD import SPGD # setup soapy conf conf_path = "conf/sim.yaml" conf = confParse.loadSoapyConfig(conf_path) # setup atmospheric distortion atmos = atmosphere.atmos(conf) dist = atmos.randomScrns() # setup simulations DM dm = DM.Piezo(conf) n_acts = dm.getActiveActs() # initiate control object control = numpy.zeros((conf.sim.nDM, conf.sim.scrnSize, conf.sim.scrnSize)) # setup camera cam = SCI.PSF(conf) # light with no correction beam = cam.frame(dist[0]).copy() # target target = cam.frame(None).copy() # import SPGDutils # target = SPGDutils.generate_gaussian_target(beam, 10)
def test_initAtmos(self): config = confParse.Configurator(os.path.join(CONFIG_PATH,"sh_8x8.py")) config.loadSimParams() atmos = atmosphere.atmos(config.sim, config.atmos)
def generate_training(n_patches, n_patches_validation, n_stars, n_frames): # Size of final images nx = 256 ny = 256 n_zernike = 40 # GREGOR telescope_radius = 1.44 * 1.440 * u.meter secondary_radius = 0.404 * 0.404 * u.meter pixSize = (6.0/512.0) * u.arcsec / u.pixel lambda0 = 850.0 * u.nm fov = 3.0 * u.arcsec border = 100 f_images = h5py.File('database.h5', 'w') f_images_validation = h5py.File('database_validation.h5', 'w') database_images = f_images.create_dataset('intensity', (n_patches, n_frames+1, nx, ny, 1), 'f') database_images_validation = f_images_validation.create_dataset('intensity', (n_patches_validation, n_frames+1, nx, ny, 1), 'f') loop = 0 loop_val = 0 # load a sim config that defines lots of science cameras across the field config = confParse.loadSoapyConfig('sh_8x8.py') # Init a science camera sci_camera = SCI.PSF(config, mask=np.ones((154,154))) # init some atmosphere atmos = atmosphere.atmos(config) ############## # Training set ############## for i in range(n_patches): progressbar(i, n_patches, text='Progress (traininig set)') star_field = np.zeros((nx, ny)) indx = np.random.randint(border, nx-border) indy = np.random.randint(border, ny-border) star_field[indx, indy] = 1.0 # Save original image in file database_images[i,0,:,:,0] = star_field star_field_fft = pyfftw.interfaces.numpy_fft.fft2(star_field) for j in range(n_frames): # Get phase for this time step phase_scrns = atmos.moveScrns() # Calculate all the PSF for this turbulence psf = sci_camera.frame(phase_scrns) nx_psf, ny_psf = psf.shape psf_roll = np.roll(psf.data, int(nx_psf/2), axis=0) psf_roll = np.roll(psf_roll, int(ny_psf/2), axis=1) psf_fft = pyfftw.interfaces.numpy_fft.fft2(psf_roll) image_final = np.real(pyfftw.interfaces.numpy_fft.ifft2(psf_fft * star_field_fft)) database_images[i,j+1,:,:,0] = image_final for j in range(50): phase_scrns = atmos.moveScrns() ############## # Validation set ############## for i in range(n_patches_validation): progressbar(i, n_patches_validation, text='Progress (validation set)') star_field = np.zeros((nx, ny)) indx = np.random.randint(border, nx-border) indy = np.random.randint(border, ny-border) star_field[indx, indy] = 1.0 # Save original image in file database_images_validation[i,0,:,:,0] = star_field star_field_fft = pyfftw.interfaces.numpy_fft.fft2(star_field) for j in range(n_frames): # Get phase for this time step phase_scrns = atmos.moveScrns() # Calculate all the PSF for this turbulence psf = sci_camera.frame(phase_scrns) nx_psf, ny_psf = psf.shape psf_roll = np.roll(psf.data, int(nx_psf/2), axis=0) psf_roll = np.roll(psf_roll, int(ny_psf/2), axis=1) psf_fft = pyfftw.interfaces.numpy_fft.fft2(psf_roll) image_final = np.real(pyfftw.interfaces.numpy_fft.ifft2(psf_fft * star_field_fft)) database_images_validation[i,j+1,:,:,0] = image_final for j in range(50): phase_scrns = atmos.moveScrns() f_images.close() f_images_validation.close()