def init(self): ''' ; Pre-compute the parameters and save them in the COMMOM block :return: ''' ngrid = self.ngrid d = self.d eps = self.eps alambda = self.alambda pixel = self.pixel self.sflag = 0 # fast seeing blur, set to 1 for slow calc. # Find reasonable limits on the grid parameters asperpix = 206265.*(1e-6*alambda)/d # maximum fine-pixel size ccdpix = float(pixel) k = np.floor(np.log10(ccdpix/asperpix)/np.log10(2.)) +1. npixperpix = 2**k fovpix = 2*ngrid/npixperpix # CCD field size asperpix = ccdpix/npixperpix size = 206266.*(1e-6*alambda)/asperpix Rpix = ngrid/size*d # log.info('Rebinning factor: %s'% npixperpix) # log.info('Grid pixel: %s arcsec'%asperpix) # log.info('Grid size: %s m'%size) # log.info('CCD pixel: %s arcsec'%ccdpix) # log.info('CCD field: %s arcsec'%(fovpix*ccdpix)) # log.info('CCD format: %s'% fovpix) r = np.roll(np.roll(ztools.dist(2*ngrid), ngrid, axis=0), ngrid, axis=1) #distance from grid center, pixs # # log.debug('INIT: %s %s'%(Rpix,Rpix*eps)) inside = np.bitwise_and( r <= Rpix , r >= Rpix*eps ) pupil = np.zeros((2*ngrid,2*ngrid)) # zero array pupil[inside] = 1 n = inside.size # x = (findgen(2*ngrid) - ngrid) # replicate(1.,2*ngrid) x = np.array([(np.arange(2*ngrid) - ngrid)]*2*ngrid) # replicate(1.,2*ngrid) theta = np.arctan2(x.T,x) # theta[ngrid]=0. self.zgrid = np.zeros((2,r[inside].shape[0])) # print self.zgrid.shape,r[inside].shape,inside.shape,n flat_inside=[i for i in inside.flat] # log.debug('flat_inside: %s %s'%(len(flat_inside),self.zgrid.shape)) self.zgrid[0] = r[inside]/Rpix self.zgrid[1] = theta[inside] self.inside = inside self.fovpix = fovpix self.asperpix = asperpix self.ccdpix = ccdpix self.npixperpix = npixperpix self.Rpix = Rpix
def newimage(self, a, jzer): ''' a is the amplitude change of aberration (micron), Jzer is the Zernike number (1=seeing, 4=focus etc.) :param a: :param jzer: :return: ''' #COMMON imagedata, uampl, filter2, seeing newampl = np.array(self.uampl, copy=True) if (jzer > 1): # Change Zernike coefficient newphase = 2. * np.pi / self.alambda * a * ztools.zernike_estim( jzer, self.zgrid) tmp = np.zeros_like(newphase, dtype=np.complex) tmp += np.cos(newphase) tmp += np.sin(newphase) * np.complex(0., 1.) newampl[self.inside] *= tmp filter = self.filter2 else: # new seeing newseeing = self.seeing + a if (self.sflag > 0): filter = np.exp( -2. * np.pi**2 * (newseeing / 2.35 / self.asperpix / 2 / self.ngrid)**2 * self.r**2) # unbinned image else: rr = ztools.shift(ztools.dist(self.fovpix), self.fovpix / 2, self.fovpix / 2) filter = np.exp( -2. * np.pi**2 * (newseeing / 2.35 / self.ccdpix / self.fovpix)**2 * rr**2) # binned image #--------- compute the image ---------------------- imh = np.abs( ztools.shift( np.fft.ifft2(ztools.shift(newampl, self.ngrid, self.ngrid)), self.ngrid, self.ngrid))**2 # imh = np.abs(ztools.shift(np.fft.ifft2(ztools.shift(newampl,self.ngrid+self.fovpix/2,self.ngrid+self.fovpix/2)),self.ngrid+self.fovpix/2,self.ngrid+self.fovpix/2))**2. if (self.sflag > 0): # exact seing blur imh = np.abs( np.fft2( ztools.shift(np.fft.fft2(imh), self.ngrid, self.ngrid) * filter)) impix = ztools.rebin( imh, [self.fovpix, self.fovpix]) # rebinning into CCD pixels else: impix = ztools.rebin( imh, [self.fovpix, self.fovpix]) # rebinning into CCD pixels impix = np.abs( np.fft.fft2( ztools.shift(np.fft.fft2(impix), self.fovpix / 2, self.fovpix / 2) * filter)) # Seeing blur return impix / np.sum(impix)
def getimage(self,z): ''' :param z: the Zernike vector in microns, starting from Z=2 (tip) z[0] is seeing in arcseconds :return: ''' #COMMON imagedata, uampl, filter2, seeing fact = 2.*np.pi/self.alambda nzer = len(z) phase = np.zeros_like(self.zgrid[0]) # empty array for phase for j in range(1, nzer): phase += fact*z[j]*ztools.zernike_estim(j+1,self.zgrid) # # log.debug('GETIMAGE: %s %s'%(phase[0],phase[-1])) # exit(0) uampl = np.zeros((self.ngrid*2,self.ngrid*2),dtype=np.complex) #uampl = np.complex(tmp, tmp) self.uampl = uampl uampl[self.inside] += np.cos(phase) #, uampl[self.inside] += (np.sin(phase)*np.complex(0,1)) #uampl[np.bitwise_not(self.inside)] = 0. self.seeing = z[0] #--------- compute the image ---------------------- # imh = np.abs(ztools.shift(np.fft.ifft2(ztools.shift(uampl,self.ngrid+self.fovpix/2,self.ngrid+self.fovpix/2)),self.ngrid+self.fovpix/2,self.ngrid+self.fovpix/2))**2. imh = np.abs(ztools.shift(np.fft.ifft2(ztools.shift(uampl,self.ngrid,self.ngrid)),self.ngrid,self.ngrid))**2. if (self.sflag > 0): # exact seeing blur filter2 = np.exp(-2.*np.pi**2*(self.seeing/2.35/self.asperpix/2/self.ngrid)**2*self.r**2) # unbinned image imh = np.abs(np.fft2(ztools.shift(np.fft2(imh),self.ngrid,self.ngrid)*filter2)) impix = ztools.rebin(imh,(self.fovpix,self.fovpix)) # rebinning into CCD pixels else: rr = ztools.shift(ztools.dist(self.fovpix),self.fovpix/2,self.fovpix/2) filter2 = np.exp(-2.*np.pi**2*(self.seeing/2.35/self.ccdpix/self.fovpix)**2*rr**2) # binned image impix = ztools.rebin(imh,[self.fovpix,self.fovpix]) # rebinning into CCD pixels impix = np.abs(np.fft.fft2(ztools.shift(np.fft.fft2(impix),self.fovpix/2,self.fovpix/2)*filter2)) # Seeing blur self.filter2 = filter2 return impix/np.sum(impix)
def newimage(self, a, jzer): ''' a is the amplitude change of aberration (micron), Jzer is the Zernike number (1=seeing, 4=focus etc.) :param a: :param jzer: :return: ''' #COMMON imagedata, uampl, filter2, seeing newampl = np.array(self.uampl,copy=True) if (jzer > 1): # Change Zernike coefficient newphase = 2.*np.pi/self.alambda*a*ztools.zernike_estim(jzer,self.zgrid) tmp = np.zeros_like(newphase,dtype=np.complex) tmp += np.cos(newphase) tmp += np.sin(newphase)*np.complex(0.,1.) newampl[self.inside] *= tmp filter = self.filter2 else: # new seeing newseeing = self.seeing + a if (self.sflag > 0): filter = np.exp(-2.*np.pi**2*(newseeing/2.35/self.asperpix/2/self.ngrid)**2*self.r**2) # unbinned image else: rr = ztools.shift(ztools.dist(self.fovpix),self.fovpix/2,self.fovpix/2) filter = np.exp(-2.*np.pi**2*(newseeing/2.35/self.ccdpix/self.fovpix)**2*rr**2) # binned image #--------- compute the image ---------------------- imh = np.abs(ztools.shift(np.fft.ifft2(ztools.shift(newampl,self.ngrid,self.ngrid)),self.ngrid,self.ngrid))**2 # imh = np.abs(ztools.shift(np.fft.ifft2(ztools.shift(newampl,self.ngrid+self.fovpix/2,self.ngrid+self.fovpix/2)),self.ngrid+self.fovpix/2,self.ngrid+self.fovpix/2))**2. if (self.sflag > 0): # exact seing blur imh = np.abs(np.fft2(ztools.shift(np.fft.fft2(imh),self.ngrid,self.ngrid)*filter)) impix = ztools.rebin(imh,[self.fovpix,self.fovpix]) # rebinning into CCD pixels else: impix = ztools.rebin(imh,[self.fovpix,self.fovpix]) # rebinning into CCD pixels impix = np.abs(np.fft.fft2(ztools.shift(np.fft.fft2(impix),self.fovpix/2,self.fovpix/2)*filter)) # Seeing blur return impix/np.sum(impix)