def main(argv): f = open(argv[1][:-3] + 'vhd', 'w') sys.stdout = f if len(argv) < 2: print('Usage: python %s <filename>' % (argv[0])) exit() return printStart(argv) src = graphics.Image(graphics.Point(0, 0), argv[1]) display.displayImage(src, argv[1][:-4]) num_rows = src.getHeight() num_cols = src.getWidth() row = 0 col = 0 while row < num_rows: while col < num_cols: (r, g, b) = src.getPixel(col, row) pixelString = "\"" + dec2bin4(r / 16) + dec2bin4( g / 16) + dec2bin4(b / 16) + "\" when X = " + str( col) + " AND Y = " + str(row) + " else" print(pixelString) col += 1 col = 0 row += 1 print('"000000000000"; -- should never get here') print("end rtl;") f.close() return
def sideBySideList(): ''' Function to test out placing an image (left) next to its filtered version (right) ''' # Create an image width = 300 height = 400 img = gr.Image(gr.Point(0, 0), width, height) # Make image list, with x, y placement info, how to process it (str), # and the `Image` object # We want a yellow image on the left, a pink one on the rights imgListofLists = [[0, 0, 'pink', img], [width, 0, 'yellow', img]] # Make 1x2 canvas canvas = gr.Image(gr.Point(0, 0), 2 * width, height) '''Process is: - Loop through the list, deal with one sublist at a time. - Clone the image object (original image by default). - Apply the solid color depending on the color name in the sublist. - Place it on the canvas. - Display. ''' for imgList in imgListofLists: # imgList is a SUBLIST currentImage = imgList[-1].clone() if imgList[2] == 'red': solid.solid_fill(currentImage, r=255) elif imgList[2] == 'blue': solid.solid_fill(currentImage, b=255) elif imgList[2] == 'yellow': solid.solid_fill(currentImage, r=255, g=255) elif imgList[2] == 'pink': solid.solid_fill(currentImage, r=255, b=255) solid.placeImageinCanvas(canvas, currentImage, imgList[0], imgList[1]) # Update image object in list of lists imgList[-1] = currentImage # Display canvas screen = display.displayImage(canvas, 'Our canvas') # Wait for mouse click to close window and end program screen.getMouse()
mask_full=getFullMask(diam=pupilSize,border=0.0,scale=scale) #load jwst mask mask_jwst=np.load('jwst_1000.npy') #activeMask mask=mask_n # image image = np.ones((scale*pupilSize,scale*pupilSize),dtype='complex') + 0j # scale factor for FFT #scale_f=1.22*wl/(np.power(pupilSize,2)*mas2rad(plateScale)*scale) scale_f=wl/(pupilSize*mas2rad(plateScale)) # p=getDistFocalImage(image,mask,wl_delay,pupilSize,scale,v,exp=exp_time) p=getDistFocalImage(image,mask, phases,pupilSize,scale,plateScale,detectorSize=chip_px,v=1.0,t=0.0, wl=wl,expTime=exp_time) displayImage(p**0.1, axisSize=[-plateScale*len(p)/2,plateScale*len(p)/2,-plateScale*len(p)/2,plateScale*len(p)/2], xlabel='mas', ylabel='mas', title='Power Spectrum **0.1',showColorbar=True,flipY=True,cmap='gray') ps=getDistFocalImages(image,mask, phases,pupilSize,scale,plateScale,detectorSize=chip_px, v=v,sfrq=10,stime=2.0,wl=wl,expTime=exp_time, display=True,delay=0.4,displayFactor=0.2,returnData=True)
# golay 9 mask mask_golay9=getNHolesMask(diam=pupilSize*2,holeDiam=0.01*pupilSize, holeCoords=[-2.7,-1.56,-2.7,1.56,-1.35,0.78,1.35,-3.9,1.35,-2.34,1.35,3.9,2.7,1.56,4.05,-2.34,4.05,2.34],border=0.0,scale=scale) #activeMask mask=mask_n # scale factor for FFT #scale_f=1.22*wl/(np.power(pupilSize,2)*mas2rad(plateScale)*scale) scale_f=wl/(pupilSize*mas2rad(plateScale)) #propagating (1 image) p=getFocalImage(pupil,mask,pupilScreens[0],scale=scale_f,cropPix=chip_px) displayImage(p**0.1, axisSize=[-plateScale*len(p)/2,plateScale*len(p)/2,-plateScale*len(p)/2,plateScale*len(p)/2], xlabel='mas', ylabel='mas', title='Power Spectrum **0.1',showColorbar=True,flipY=True,cmap='gray') # display atmosphere displayImage(phases,axisSize=[-pupilSize/2,pupilSize/2,-pupilSize/2,pupilSize/2],xlabel='m', ylabel='m', title='Pupil Phase Screen',showColorbar=True,flipY=True) #display mask displayImage(mask, axisSize=[-pupilSize/2,pupilSize/2,-pupilSize/2,pupilSize/2], xlabel='m', ylabel='m', title='Pupil Mask',showColorbar=False,flipY=True, cmap='binary_r') # propagating (all images) ps=getFocalImages(pupil,mask,pupilScreens,scale=scale_f,cropPix=chip_px) displayImages(ps**0.1,delay=0.3, axisSize=[-plateScale*len(p[0])/2,plateScale*len(p[0])/2,-plateScale*len(p[0])/2,plateScale*len(p[0])/2],
#input full pupil Mask mask=getFullMask(diam=pupilSize,border=0.0,scale=scale) pupil = np.ones((scale*pupilSize,scale*pupilSize),dtype='complex') + 0j # plane wave # scale factor for FFT #scale_f=1.22*wl/(np.power(pupilSize,2)*mas2rad(plateScale)*scale) scale_f=wl/(pupilSize*mas2rad(plateScale)) #phaseScreen f = fits.open('/suphys/latyshev/Code/idl_toy_imaging/screen.fits') phases=f[0].data a,p=getFocalImage(pupil,mask,seeing=np.cos(phases)+1j*np.sin(phases),compl=False,scale=scale_f,cropPix=chip_px) displayImage(abs(a)**0.2, axisSize=[-plateScale*len(a)/2,plateScale*len(a)/2,-plateScale*len(a)/2,plateScale*len(a)/2], xlabel='mas', ylabel='mas', title='Focal Plane Amplitudes **0.2',showColorbar=True,flipY=True,cmap='gray') f = fits.open('/suphys/latyshev/Code/idl_toy_imaging/image.fits') a1=f[0].data a2=a**2 a1_norm=(a1-a1.min())/(a1.max()-a1.min()) a2_norm=(a2-a2.min())/(a2.max()-a2.min()) displayImage(abs(a2_norm)**0.1-abs(a1_norm)**0.1, axisSize=[-plateScale*len(a)/2,plateScale*len(a)/2,-plateScale*len(a)/2,plateScale*len(a)/2], xlabel='mas', ylabel='mas', title='Focal Plane Amplitudes **0.2',showColorbar=True,flipY=True,cmap='gray')
f = fits.open('/suphys/latyshev/Code/idl_toy_imaging/screen.fits') phases = f[0].data a, p = getFocalImage(pupil, mask, seeing=np.cos(phases) + 1j * np.sin(phases), compl=False, scale=scale_f, cropPix=chip_px) displayImage(abs(a)**0.2, axisSize=[ -plateScale * len(a) / 2, plateScale * len(a) / 2, -plateScale * len(a) / 2, plateScale * len(a) / 2 ], xlabel='mas', ylabel='mas', title='Focal Plane Amplitudes **0.2', showColorbar=True, flipY=True, cmap='gray') f = fits.open('/suphys/latyshev/Code/idl_toy_imaging/image.fits') a1 = f[0].data a2 = a**2 a1_norm = (a1 - a1.min()) / (a1.max() - a1.min()) a2_norm = (a2 - a2.min()) / (a2.max() - a2.min()) displayImage(abs(a2_norm)**0.1 - abs(a1_norm)**0.1, axisSize=[
import graphics as gr import display # Load image img = gr.Image(gr.Point(200, 200), 'Jan_26/miller.ppm') print(type(img)) # Show screen screen = display.displayImage(img, 'This is Miller Library!') # Close screen screen.getMouse() screen.close()
if __name__ == '__main__': # Create a new 400x300 image (height x width format), then creating another by cloning # (deep copy) # Remember: Image constructor takes in width first, then height # my `red` image leftImg = gr.Image(gr.Point(0, 0), 300, 400) # my `blue` image rightImg = leftImg.clone() # Fill the left and right images different solid colors solid_fill(leftImg, r=255) solid_fill(rightImg, b=255) # Make larger canvas that would fit both image horizontally side-by-side canvas = gr.Image(gr.Point(0, 0), 2 * leftImg.getWidth(), leftImg.getHeight()) # Place the images in a new window placeImageinCanvas(canvas, leftImg, 0, 0) placeImageinCanvas(canvas, rightImg, leftImg.getWidth(), 0) # Display the image in a new window screen = display.displayImage(canvas, 'Our canvas with two colors') # Display image until we get a mouse click screen.getMouse() screen.close()
def getDistFocalImages(image,mask, phaseScreen,pupilSize,scale, plateScale=0.1, detectorSize=0, v=1.0,sfrq=10,stime=0.0, wl=0.0, expTime=0.0, expNum=5, display=True,delay=0.0,displayFactor=1.0, returnData=True) : '''A function for generating evolving images through a mask with atmospheric phasescreen over the pupil''' # # duration of sample sdur=1.0/sfrq # getting screen size by X axis in pixels screenpix = phaseScreen.shape[1] # calculating pupil diameter in pixels pupilpix=int(np.floor(scale*pupilSize)) # plate size - plate field of view in mas plateSize = plateScale * pupilpix # calculating Vpix_x - projected speed of wind in pixels/s vpix_x=int(np.round(np.floor(scale*v)*screenpix/np.hypot(screenpix,pupilpix))) s_time = stime if stime==0 : # calculating maximum sampling time s_time = (np.floor(screenpix/pupilpix*scale)*screenpix/vpix_x) elif stime*vpix_x > np.floor(screenpix/pupilpix)*screenpix : print("Sampling time is too long. The maximum time is %f s" % (np.floor(screenpix/pupilpix)*screenpix/vpix_x)) return # if returnData : nSamples = int(s_time*sfrq) else : nSamples=1 # # initializing time counter time = 0.0 i = 0 if returnData : pows = np.empty((nSamples),dtype='object') # Sampling while (time<s_time and i<nSamples) : print("Time=%fs. End time: %fs" % (time,s_time)) pows[i]=getDistFocalImage(image,mask,phaseScreen, pupilSize,scale,plateScale,detectorSize, v,time,x0=0.0,y0=0.0,wl=wl,expTime=expTime,expNum=expNum) if display and not returnData: displayImage(np.power(np.abs(pows),displayFactor),axisSize=[-plateSize/2,plateSize/2,-plateSize/2,plateSize/2], xlabel='mas', ylabel='mas', title=("Focal Plane Power Spectrum ** %3.1f" % displayFactor), showColorbar=True,flipY=True,cmap='gray') time+=sdur if returnData: i+=1 # if returnData : if display : displayImages(np.power(np.abs(pows),displayFactor),delay, axisSize=[-plateSize/2,plateSize/2,-plateSize/2,plateSize/2], xlabel='mas', ylabel='mas', title=("Focal Plane Power Spectrum ** %3.1f" % displayFactor), figureNum=1,showColorbar=True,flipY=True,cmap='gray') return pows