def primMaskTrace(fold, primary, woltVignette=True, foldrot=0.): #Get Wolter parameters alpha, p, d, e = conicsolve.woltparam(220., 8400.) primfoc = conicsolve.primfocus(220., 8400.) #Trace to fold mirror #translate to center of fold mirror PT.transform(0., 85.12, primfoc - 651.57 + 85.12, 0, 0, 0) #rotate so surface normal points in correct direction PT.transform(0, 0, 0, -3 * pi / 4, 0, 0) PT.transform(0, 0, 0, 0, 0, pi) #trace to fold flat PT.flat() #Introduce fold misalignment PT.transform(*fold) PT.zernsurfrot(foldsag, foldfig, 406. / 2, -174.659 * pi / 180 + foldrot) PT.itransform(*fold) PT.reflect() PT.transform(0, 0, 0, 0, 0, -pi) PT.transform(0, 0, 0, pi / 4, 0, 0) #Translate to optical axis mid-plane, then down to image of #primary focus, place primary mirror and trace PT.transform(0, 85.12, 651.57 - 85.12, 0, 0, 0) PT.flat() ## pdb.set_trace() rt = conicsolve.primrad(8475., 220., 8400.) PT.transform(0, -rt, 75., 0, 0, 0) PT.transform(*primary) PT.transform(0, rt, -8475., 0, 0, 0) ## PT.wolterprimary(220.,8400.) PT.primaryLL(220., 8400., 8525., 8425., 30. * np.pi / 180., pcoeff, pax, paz) if woltVignette is True: ind = logical_and(PT.z < 8525., PT.z > 8425.) PT.vignette(ind=ind) PT.reflect() PT.transform(0, -rt, 8475., 0, 0, 0) PT.itransform(*primary) PT.transform(0, rt, -8475., 0, 0, 0) #Move back up to mask plane and trace flat PT.transform(0, 0, 8400. + 134.18, 0, 0, 0) PT.flat() ## pdb.set_trace() #Rays should now be at Hartmann mask plane return
def traceFromMask(N, numholes, cda, fold, retro, primary, foldrot=0., retrorot=0.): #Vignette at proper hole h = hartmannMask() ind = h == N PT.vignette(ind=ind) #Continue trace up to retro and back to CDA PT.transform(0, -123.41, 1156.48 - 651.57 - 134.18, 0, 0, 0) PT.flat() PT.transform(0, 0, 0, pi, 0, 0) PT.transform(*retro) PT.zernsurfrot(retrosag, retrofig, 378. / 2, -8.993 * pi / 180 + retrorot) PT.itransform(*retro) PT.reflect() PT.transform(0, 0, 0, -pi, 0, 0) PT.transform(0, 123.41, -1156.48 + 651.57 + 134.18, 0, 0, 0) PT.flat() h = hartmannMask() ind = h == N PT.vignette(ind=ind) PT.transform(0, 0, -134.18, 0, 0, 0) rt = conicsolve.primrad(8475., 220., 8400.) PT.transform(0, -rt, 75., 0, 0, 0) PT.transform(*primary) PT.transform(0, rt, -8475., 0, 0, 0) PT.wolterprimary(220., 8400.) ind = logical_and(PT.z < 8525., PT.z > 8425.) PT.vignette(ind=ind) PT.reflect() PT.transform(0, -rt, 8475., 0, 0, 0) PT.itransform(*primary) PT.transform(0, rt, -8475., 0, 0, 0) PT.transform(0,-85.12,8400.-651.57+85.12\ ,0,0,0) PT.transform(0, 0, 0, -pi / 4, 0, 0) PT.transform(0, 0, 0, 0, 0, pi) PT.flat() PT.transform(*fold) PT.zernsurfrot(foldsag, foldfig, 406. / 2, -174.659 * pi / 180 + foldrot) PT.itransform(*fold) PT.reflect() PT.transform(0, 0, 0, 0, 0, -pi) PT.transform(0, 0, 0, 3 * pi / 4, 0, 0) PT.transform(0,-85.12,-85.12-(conicsolve.primfocus(220.,8400.)-651.57)\ ,0,0,0) PT.transform(*cda) PT.flat() return
def traceSPO(R, L, F, N, M, span=pi / 12, d=.605, t=.775): """Trace SPO surfaces sequentially. Collect rays from each SPO shell and set them to the PT rays at the end. Start at the inner radius, use the wafer and pore thicknesses to vignette and compute the next radius, loop while radius is less than Rout. """ #Ray bookkeeping arrays tx = np.zeros(M * N) ty = np.zeros(M * N) tz = np.zeros(M * N) tl = np.zeros(M * N) tm = np.zeros(M * N) tn = np.zeros(M * N) tux = np.zeros(M * N) tuy = np.zeros(M * N) tuz = np.zeros(M * N) #Loop through shell radii and collect rays for i in range(M): #Set up source annulus PT.subannulus(R[i], R[i] + d, span, N) #Transform rays to be above xy plane PT.n = -PT.n PT.transform(0, 0, -100., 0, 0, 0) #Trace to primary PT.spoPrimary(R[i], F) PT.reflect() #Vignette ind = np.logical_and(PT.z <= L[i], PT.z >= 0.) if np.sum(ind) < N: pdb.set_trace() PT.vignette(np.logical_and(PT.z <= L[i], PT.z >= 0.)) #Trace to secondary PT.spoSecondary(R[i], F) PT.reflect() #Vignette ind = np.logical_and(PT.z <= 0., PT.z >= -L[i]) if np.sum(ind) < N: pdb.set_trace() PT.vignette(ind) #Collect rays try: tx[i * N:(i + 1) * N] = PT.x ty[i * N:(i + 1) * N] = PT.y tz[i * N:(i + 1) * N] = PT.z tl[i * N:(i + 1) * N] = PT.l tm[i * N:(i + 1) * N] = PT.m tn[i * N:(i + 1) * N] = PT.n tux[i * N:(i + 1) * N] = PT.ux tuy[i * N:(i + 1) * N] = PT.uy tuz[i * N:(i + 1) * N] = PT.uz except: pdb.set_trace() #Set to PT rays try: PT.x = tx PT.y = ty PT.z = tz PT.l = tl PT.m = tm PT.n = tn PT.ux = tux PT.uy = tuy PT.uz = tuz except: pdb.set_trace() return
def traceCyl(align): """Traces a cylindrical approximation to Wolter I geometry Assumes 1 m radius of curvature in accordance with OAB samples align is a 12 element array giving the transformations to be applied to each mirror Uses identical set of rays each run defined upon module import Adds a restraint such that any vignetting over 25% results in a huge merit function """ #Set up source np.random.seed(5) a, p, d, e = con.woltparam(1000., 10000.) r0 = con.primrad(10025., 1000., 10000.) r1 = con.primrad(10125., 1000., 10000.) dphi = 100. / 1000. PT.subannulus(r0, r1, dphi, 10**4) PT.transform(0, 0, 0, np.pi, 0, 0) PT.transform(0, 0, -10500., 0, 0, 0) #Trace primary cylinder: go to tangent point at center #of mirror and then rotate to cone angle, then move #to new cylinder axis and tracecyl rt = con.primrad(10075., 1000., 10000.) PT.transform(rt, 0, 0, 0, a, 0) PT.transform(*align[:6]) PT.transform(0, 0, 0, np.pi / 2, 0, 0) PT.transform(-1000., 0, 0, 0, 0, 0) PT.cyl(1000.) #Vignette rays missing physical surface ind = np.logical_and(abs(PT.z) < 50., abs(PT.y) < 50.) PT.vignette(ind=ind) #Reflect and reverse transformations PT.reflect() PT.transform(1000., 0, 0, 0, 0, 0) PT.itransform(0, 0, 0, np.pi / 2, 0, 0) PT.itransform(*align[:6]) PT.itransform(rt, 0, 0, 0, a, 0) #Trace secondary cylinder: same principle as before rt = con.secrad(9925., 1000., 10000.) PT.transform(0, 0, -150., 0, 0, 0) PT.transform(rt, 0, 0, 0, 3 * a, 0) PT.transform(*align[6:]) PT.transform(0, 0, 0, np.pi / 2, 0, 0) PT.transform(-1000., 0, 0, 0, 0, 0) PT.cyl(1000.) #Vignette rays missing physical surface ind = np.logical_and(abs(PT.z) < 50., abs(PT.y) < 50.) PT.vignette(ind=ind) #Reflect and reverse transformations PT.reflect() PT.transform(1000., 0, 0, 0, 0, 0) PT.itransform(0, 0, 0, np.pi / 2, 0, 0) PT.itransform(*align[6:]) PT.itransform(rt, 0, 0, 0, 3 * a, 0) #Go down to nominal focus PT.transform(0, 0, -9925., 0, 0, 0) PT.flat() #Compute merit function nom = PT.rmsCentroid() / 10**4 * 180. / np.pi * 60**2 nom = nom + max((9500. - np.size(PT.x)), 0.) return nom
def traceWSShell(num,theta,r0,z0,phigh,plow,shigh,slow,\ energy,rough,chaseFocus=False,bestFocus=False): """Trace a WS mirror pair with 10 m focal length and mirror axial cutoffs defined by phigh,plow """ #Define annulus of source rays a,p,d,e = con.woltparam(r0,z0) r1 = PT.wsPrimRad(plow,1.,r0,z0)#np.tan(a/2.)*(plow-10000.) + r0 r2 = PT.wsPrimRad(phigh,1.,r0,z0)#np.tan(a/2.)*(phigh-10000.) + r0 rays = PT.annulus(r1,r2,num) PT.transform(rays,0,0,0,np.pi,0,0) PT.transform(rays,0,0,z0,0,0,0) #Trace to primary PT.wsPrimary(rays,r0,z0,1.) #Handle vignetting ind = np.logical_and(rays[3]<phigh,rays[3]>plow) rays = PT.vignette(rays,ind=ind) #Vignette rays hitting backside of mirror dot = rays[4]*rays[7]+rays[5]*rays[8]+rays[6]*rays[9] ind = dot < 0. rays = PT.vignette(rays,ind=ind) #If all rays are vignetted, return if np.size(rays[1]) < 1: return 0.,0.,0. #Apply pointing error rays = [rays[0],rays[1],rays[2],rays[3],\ rays[4]+np.sin(theta),rays[5],-np.sqrt(1-np.sin(theta)**2),\ rays[7],rays[8],rays[9]] ## PT.l = PT.l + np.sin(theta) ## PT.n = -np.sqrt(1 - PT.l**2) #Reflect PT.reflect() #Compute mean incidence angle for reflectivity ang = np.abs(np.mean(np.arcsin(dot))) #radians refl1 = CXCreflIr(ang,energy,rough) #Total rays entering primary aperture N1 = np.size(rays[1]) #Trace to secondary PT.wsSecondary(r0,z0,1.) #Vignette anything outside the physical range of the mirror ind = np.logical_and(rays[3]>slow,rays[3]<shigh) rays = PT.vignette(rays,ind=ind) #Vignette anything hitting the backside dot = rays[4]*rays[7]+rays[5]*rays[8]+rays[6]*rays[9] ind = dot < 0. rays = PT.vignette(rays,ind=ind) if np.size(rays[1]) < 1: return 0.,0.,0. PT.reflect() #Compute mean incidence angle for reflectivity ang = np.abs(np.mean(np.arcsin(dot))) #radians refl2 = CXCreflIr(ang,energy,rough) #Trace to focal plane rays = PT.flat(rays) ## #Find Chase focus ## delta = 0. ## if chaseFocus or bestFocus: ## cx,cy = PT.centroid() ## r = np.sqrt(cx**2+cy**2) ## delta = .0625*(1.+1)*(r**2*(phigh-plow)/10000.**2)\ ## *(1/np.tan(a))**2 ## PT.transform(0,0,delta,0,0,0) ## PT.flat() ## ## #Find best focus ## delta2 = 0. ## delta3 = 0. ## if bestFocus: ## try: ## tran.focusI(rays,weights= ## except: ## pdb.set_trace() ## PT.flat() return refl1*refl2,rays
def traceChaseParam(num, psi, theta, alpha, L1, z0, bestFocus=False, chaseFocus=False): """Trace a WS mirror pair using the parameters in Eq. 13 of Chase & VanSpeybroeck Return the RMS radius of the focus Can specify whether to find the best focus or not """ #Define annulus of source rays r0 = np.tan(4 * alpha) * z0 alphap = 2 * alpha / (1 + 1 / psi) r1 = PT.wsPrimRad(z0 + L1, 1., r0, z0) #np.tan(alphap/2.)*L1 + r0 PT.annulus(r0, r1, num) PT.transform(0, 0, 0, np.pi, 0, 0) PT.transform(0, 0, -10000., 0, 0, 0) pdb.set_trace() #Trace to primary PT.wsPrimary(r0, z0, psi) #Handle vignetting PT.vignette() ind = np.logical_and(PT.z < z0 + L1, PT.z > z0) PT.vignette(ind=ind) ## pdb.set_trace() #Apply pointing error PT.l = PT.l + np.sin(theta) PT.n = -np.sqrt(1 - PT.l**2) #Anything hitting backside goes away dot = PT.l * PT.ux + PT.m * PT.uy + PT.n * PT.uz ind = dot < 0. PT.vignette(ind=ind) if np.size(PT.x) < 1: return 0., 0., 0. #Reflect PT.reflect() N1 = np.size(PT.x) #Trace to secondary PT.wsSecondary(r0, z0, psi) #Vignette anything that did not converge PT.vignette() #Vignette anything hitting the backside dot = PT.l * PT.ux + PT.m * PT.uy + PT.n * PT.uz ind = dot < 0. PT.vignette(ind=ind) ## #Vignette anything outside the physical range of the mirror ## ind = np.logical_and(PT.z>z0-L1,PT.z<z0) ## PT.vignette(ind=ind) if np.size(PT.x) < 1: return 0., 0., 0. PT.reflect() #Trace to focal plane PT.flat() cx, cy = PT.centroid() r = np.sqrt(cx**2 + cy**2) #Find best focus delta = 0. if chaseFocus or bestFocus: delta = .0625 * (psi + 1) * (r**2 * L1 / z0**2) * (1 / np.tan(alpha))**2 PT.transform(0, 0, delta, 0, 0, 0) PT.flat() delta2 = 0. delta3 = 0. if bestFocus: try: delta2 = PT.findimageplane(20., 100) PT.transform(0, 0, delta2, 0, 0, 0) delta3 = PT.findimageplane(1., 100) PT.transform(0, 0, delta3, 0, 0, 0) except: pdb.set_trace() PT.flat() return PT.rmsCentroid() / z0, delta + delta2 + delta3, r
def traceWSShell(num,theta,r0,z0,phigh,plow,shigh,slow,\ chaseFocus=False,bestFocus=False): """Trace a WS mirror pair with 10 m focal length and mirror axial cutoffs defined by phigh,plow """ #Define annulus of source rays a, p, d, e = con.woltparam(r0, z0) r1 = PT.wsPrimRad(plow, 1., r0, z0) #np.tan(a/2.)*(plow-10000.) + r0 r2 = PT.wsPrimRad(phigh, 1., r0, z0) #np.tan(a/2.)*(phigh-10000.) + r0 ## r2 = np.mean([r1,r2]) PT.annulus(r1, r2, num) PT.transform(0, 0, 0, np.pi, 0, 0) PT.transform(0, 0, z0, 0, 0, 0) ## pdb.set_trace() #Trace to primary PT.wsPrimary(r0, z0, 1.) #Handle vignetting PT.vignette() ind = np.logical_and(PT.z < phigh, PT.z > plow) PT.vignette(ind=ind) #Vignette rays hitting backside of mirror dot = PT.l * PT.ux + PT.m * PT.uy + PT.n * PT.uz ind = dot < 0. PT.vignette(ind=ind) #If all rays are vignetted, return if np.size(PT.x) < 1: return 0., 0., 0. #Apply pointing error PT.l = PT.l + np.sin(theta) PT.n = -np.sqrt(1 - PT.l**2) #Reflect PT.reflect() #Compute mean incidence angle for reflectivity ## ang = np.abs(np.mean(np.arcsin(dot))) #radians ## refl1 = CXCreflIr(ang,energy,rough) #Total rays entering primary aperture N1 = np.size(PT.x) #Trace to secondary PT.wsSecondary(r0, z0, 1.) #Vignette anything that did not converge PT.vignette() #Vignette anything outside the physical range of the mirror ind = np.logical_and(PT.z > slow, PT.z < shigh) PT.vignette(ind=ind) #Vignette anything hitting the backside dot = PT.l * PT.ux + PT.m * PT.uy + PT.n * PT.uz ind = dot < 0. PT.vignette(ind=ind) if np.size(PT.x) < 1: return 0., 0., 0. PT.reflect() #Compute mean incidence angle for reflectivity ## ang = np.abs(np.mean(np.arcsin(dot))) #radians ## refl2 = CXCreflIr(ang,energy,rough) #Trace to focal plane PT.flat() #Find Chase focus delta = 0. if chaseFocus or bestFocus: cx, cy = PT.centroid() r = np.sqrt(cx**2 + cy**2) delta = .0625*(1.+1)*(r**2*(phigh-plow)/10000.**2)\ *(1/np.tan(a))**2 PT.transform(0, 0, delta, 0, 0, 0) PT.flat() #Find best focus delta2 = 0. delta3 = 0. if bestFocus: try: delta2 = PT.findimageplane(20., 100) PT.transform(0, 0, delta2, 0, 0, 0) delta3 = PT.findimageplane(1., 100) PT.transform(0, 0, delta3, 0, 0, 0) except: pdb.set_trace() PT.flat() #return refl1*refl2 return PT.hpd(), PT.rmsCentroid(), delta
def fullFromMask(N, cda, fold, retro, prim, sec, foldrot=0., retrorot=0.): ## pdb.set_trace() #Vignette at proper hole h = hartmannMask() ind = h == N PT.vignette(ind=ind) #Continue trace up to retro and back to CDA PT.transform(0, -123.41, 1156.48 - 651.57 - 134.18, 0, 0, 0) PT.flat() PT.transform(0, 0, 0, pi, 0, 0) PT.transform(*retro) PT.zernsurfrot(retrosag, retrofig, 378. / 2, -8.993 * pi / 180 + retrorot) PT.itransform(*retro) PT.reflect() PT.transform(0, 0, 0, -pi, 0, 0) #Back to mask PT.transform(0, 123.41, -1156.48 + 651.57 + 134.18, 0, 0, 0) PT.flat() h = hartmannMask() ind = h == N PT.vignette(ind=ind) #Place Wolter surfaces PT.transform(0, 0, -134.18 - 8400., 0, 0, 0) PT.transform(0, -conicsolve.primrad(8425., 220., 8400.), 8425., 0, 0, 0) PT.transform(*prim) PT.itransform(0, -conicsolve.primrad(8425., 220., 8400.), 8425., 0, 0, 0) ## PT.wolterprimary(220.,8400.) PT.primaryLL(220., 8400., 8525., 8425., 30. * np.pi / 180., pcoeff, pax, paz) pdb.set_trace() ind = logical_and(PT.z < 8525., PT.z > 8425.) PT.vignette(ind=ind) PT.transform(0, -conicsolve.primrad(8425., 220., 8400.), 8425., 0, 0, 0) PT.itransform(*prim) PT.itransform(0, -conicsolve.primrad(8425., 220., 8400.), 8425., 0, 0, 0) PT.reflect() #Wolter secondary PT.transform(0, -conicsolve.secrad(8325., 220., 8400.), 8325., 0, 0, 0) PT.transform(*sec) PT.itransform(0, -conicsolve.secrad(8325., 220., 8400.), 8325., 0, 0, 0) PT.woltersecondary(220., 8400.) ind = logical_and(PT.z < 8375., PT.z > 8275.) PT.vignette(ind=ind) PT.reflect() PT.transform(0, -conicsolve.secrad(8325., 220., 8400.), 8325., 0, 0, 0) PT.itransform(*sec) PT.itransform(0, -conicsolve.secrad(8325., 220., 8400.), 8325., 0, 0, 0) ## PT.woltersecondary(220.,8400.) ## ind = logical_and(PT.z<8375.,PT.z>8275.) ## PT.vignette(ind=ind) ## PT.reflect() #Back to fold PT.transform(0,-85.12,8400.-651.57+85.12\ ,0,0,0) PT.transform(0, 0, 0, -pi / 4, 0, 0) PT.transform(0, 0, 0, 0, 0, pi) PT.flat() PT.transform(*fold) PT.zernsurfrot(foldsag, foldfig, 406. / 2, -174.659 * pi / 180 + foldrot) PT.itransform(*fold) PT.reflect() PT.transform(0, 0, 0, 0, 0, -pi) #Back to CDA PT.transform(0, 0, 0, 3 * pi / 4, 0, 0) PT.transform(0,-85.12,-85.12-8400.+651.57\ ,0,0,0) PT.transform(*cda) PT.flat() return
def traceArcus(N,span=20.,d=.605,t=.775,gap=50.,\ inc=1.5*pi/180,l=95.,bestFocus=bestfoc,order=0,\ blazeYaw=yaw,wave=1.,marg=marg,findMargin=False,\ analyzeLine=True,offX=0.,offY=0.,calcCentroid=False,\ vis=False): """Trace Arcus sector """ sys.stdout.write(str(wave) + '\t' + str(order) + '\r') sys.stdout.flush() if wave is not 'uniform': #Compute efficiency and determine whether to proceed geff = gratEff(order) #Add in grating efficiency and CCD QE #geff and ccdQE need to be arrays if wave is array g = geff(wave) det = ccdQE(wave) if g * det == 0.: return 0, 0 g = g.reshape(np.size(g)) #Assign random wavelength to each ray if wave == 'uniform': rays,weights,minfoc,lmax,wave,coords = defineSPOaperture(N,wave,\ offX=offX,offY=offY,\ vis=vis) else: rays,weights,minfoc,lmax,coords = defineSPOaperture(N,wave,offX=offX,\ offY=offY,\ vis=vis) #Trace rays through SPO modules ## rays = plotting.pload('/home/rallured/Dropbox/Arcus/' ## 'Raytrace/Performance/160516_SPORays.pkl') ## weights = pyfits.getdata('/home/rallured/Dropbox/Arcus/' ## 'Raytrace/Performance/160516_Weights.fits') ## minfoc = 11972.53195 ## lmax = 115.97497 ## pdb.set_trace() #Determine outermost radius of grating array #outerrad should be fixed outerrad = outerradNom #np.max(sqrt(rays[1]**2+rays[2]**2)) foc = tran.applyTPos(0, 0, 0, coords, inverse=True) hubdist = sqrt(outerrad**2 + foc[2]**2) angle = np.arctan(outerrad / (minfoc - (lmax + gap + 95.))) thetag = angle - 1.5 * pi / 180. ## print 'Outerrad: %f\nHubdist: %f\nLmax: %f\nOuter Focus: %f\n' % \ ## (outerrad,hubdist,L.max(),focVec[-1]) #Trace grating array - need to add in grating efficiency and #CCD quantum efficiency if bestFocus is None: return gratArray(rays,outerrad,hubdist,angle,inc,l=l,\ weights=weights,order=-3,blazeYaw=blazeYaw,\ wave=2.4,coords=coords) ## return traceSector(Rin,Rout,F,N,span=span,d=d,t=t,gap=gap,\ ## inc=inc,l=l,bestFocus=bestFocus,order=order,\ ## blazeYaw=blazeYaw,wave=wave,marg=marg) gratArray(rays,outerrad,hubdist,angle,inc,l=l,bestFocus=bestFocus,\ weights=weights,order=order,blazeYaw=blazeYaw,wave=wave,\ offX=offX,vis=vis,coords=coords) #Grating vignetting weights = weights * (1 - abs(offX) / inc) if np.size(wave) == 1: #Account for grating efficiency weights = weights * g * det #Vignette rays with no weight (evanescence) ## rays = tran.vignette(rays,weights>0.) ## if len(rays[1])==0: ## return 0.,0. #Go to focal plane tran.transform(rays, 0, 0, bestFocus, 0, 0, 0, coords=coords) surf.flat(rays) if vis is True: pyfits.writeto('FocalPlanePos.fits',\ np.array([rays[1],rays[2],rays[3]]),\ clobber=True) pyfits.writeto('Wavelengths.fits',\ wave,clobber=True) if analyzeLine is False: return rays, weights #Get rid of outliers ind = np.abs(rays[2] - np.average(rays[2])) < 10. rays = PT.vignette(rays, ind=ind) weights = weights[ind] if calcCentroid is True: cent = anal.centroid(rays, weights=weights) if cent[0] < 100 or cent[1] < 100: pdb.set_trace() return anal.centroid(rays, weights=weights) #Get rid of rays that made it through ## ind = rays[1] > 0 ## rays = PT.vignette(rays,ind=ind) ## weights = weights[ind] #If no rays made it through if np.size(rays[1]) == 0: return 0, 0, 0, 0 #Look at resolution of this line try: cy = np.average(rays[2], weights=weights) except: pdb.set_trace() if findMargin is True: #Compute FWHM after Gaussian convolution fwhms = np.linspace(1, 3, 201) / 60.**2 * pi / 180 * 12e3 tot = np.array([convolveLSF(rays,.001,m,weights=weights)\ for m in fwhms/2.35]) #Convert to arcsec, return std of margin convolution marg = fwhms[np.argmin( np.abs(tot / 12e3 * 180 / pi * 60**2 - 3.))] / 2.35 return marg, rays fwhm = convolveLSF(rays, .001, marg, weights=weights) resolution = cy / fwhm weights = weights**.799 * .83 * .8 * .9 #Grat plates, azimuthal ribs, packing area = np.sum(weights) #print resolution #print area #print sqrt((cy/3000)**2 - lsf**2)/F * 180/pi*60**2 ## print 'Order: %i, Wave: %.2f\n'%(order,wave) return resolution, area, np.nanmean(rays[1]), np.nanmean(rays[2]),fwhm,\ rays,weights
def traceSector(Rin,Rout,F,N,span=20.,d=.605,t=.775,gap=50.,\ inc=1.5*pi/180,l=95.,bestFocus=None,order=0,\ blazeYaw=0.,wave=1.,marg=0.,findMargin=False,\ analyzeLine=True,offX=0.,offY=0.): """Trace Arcus sector """ #Trace parameters R = np.arange(Rin, Rout, t) #Vector of shell radii tg = .25 * np.arctan((R + d / 2) / F) #Primary graze angles L = d / tan(tg) #Primary length #L = 4*F*d/R #Vector of mirror lengths M = np.size(R) #Number of shells #Create focal length vector to implement spherical principle surface #This should be changed based on nominal focal lengths of #modules from cosine. focConst = F**2 #+Rin**2 focVec = sqrt(focConst - R**2) #Weight vector for shell radii weights = np.zeros(M * N) spanv = np.zeros(M) for i in range(M): #Full angular span of each shell spanv[i] = 2 * np.arcsin(span / 2 / R[i]) #Geometric area in each shell - 10^4 is unit conversion weights[i * N:(i + 1) * N] = ((R[i] + d)**2 - R[i]**2) * spanv[i] / 2 / 10000. #Assign random wavelength to each ray if wave == 'uniform': wave = np.random.uniform(3.6, 3.6 * 2, size=M * N) #Trace rays through SPO modules rays,refl = traceSPO(R,L,focVec,N,M,spanv,wave,d=d,t=t,\ offX=offX,offY=offY) #Can call traceSPO repeatedly for each individual module #Then send rays through grating array #Refl needs to be array if wave is array weights = weights * refl #Determine outermost radius of grating array PT.transform(rays, 0, 0, focVec[-1] - (L.max() + gap + 95.), 0, 0, 0) PT.flat(rays) #outerrad should be fixed outerrad = np.max(sqrt(rays[1]**2 + rays[2]**2)) hubdist = sqrt(outerrad**2 + (focVec[-1] - (L.max() + gap + 95.))**2) angle = np.arctan(outerrad / (focVec[-1] - (L.max() + gap + 95.))) thetag = angle - 1.5 * pi / 180. ## print 'Outerrad: %f\nHubdist: %f\nLmax: %f\nOuter Focus: %f\n' % \ ## (outerrad,hubdist,L.max(),focVec[-1]) pdb.set_trace() #Trace grating array - need to add in grating efficiency and #CCD quantum efficiency if bestFocus is None: return gratArray(rays,outerrad,hubdist,angle,inc,l=l,\ weights=weights,order=-3,blazeYaw=blazeYaw,\ wave=2.4) ## return traceSector(Rin,Rout,F,N,span=span,d=d,t=t,gap=gap,\ ## inc=inc,l=l,bestFocus=bestFocus,order=order,\ ## blazeYaw=blazeYaw,wave=wave,marg=marg) gratArray(rays,outerrad,hubdist,angle,inc,l=l,bestFocus=bestFocus,\ weights=weights,order=order,blazeYaw=blazeYaw,wave=wave) #Account for grating efficiency geff = gratEff(order) #Add in grating efficiency and CCD QE #geff and ccdQE need to be arrays if wave is array g = geff(wave) g = g.reshape(np.size(g)) weights = weights * g * ccdQE(wave) #Go to focal plane tran.transform(rays, 0, 0, bestFocus, 0, 0, 0) surf.flat(rays) if analyzeLine is False: return rays, weights, wave #Get rid of rays that made it through ## ind = rays[1] > 0 ## rays = PT.vignette(rays,ind=ind) ## weights = weights[ind] #Get rid of outliers ind = np.abs(rays[2] - np.average(rays[2])) < 10. rays = PT.vignette(rays, ind=ind) weights = weights[ind] #If no rays made it through if np.size(rays[1]) == 0: return 0, 0, 0, 0 #Look at resolution of this line try: cy = np.average(rays[2], weights=weights) except: pdb.set_trace() if findMargin is True: #Compute FWHM after Gaussian convolution fwhms = np.linspace(1, 3, 201) / 60.**2 * pi / 180 * 12e3 tot = np.array([convolveLSF(rays,.001,m,weights=weights)\ for m in fwhms/2.35]) #Convert to arcsec, return std of margin convolution marg = fwhms[np.argmin( np.abs(tot / 12e3 * 180 / pi * 60**2 - 3.))] / 2.35 return marg, rays fwhm = convolveLSF(rays, .001, marg, weights=weights) resolution = cy / fwhm area = np.sum( weights ) * .799 * .83 * .8 * .9 #Grat plates, azimuthal ribs, usable area #print resolution #print area #print sqrt((cy/3000)**2 - lsf**2)/F * 180/pi*60**2 print 'Done' return resolution, area, np.nanmean(rays[1]), np.nanmean(rays[2]),\ rays,weights