def SersicGalaxy(cell_name, center, r_eff, sersic_n, ellip, angle, num_squares, square_size=1.0, layer=1): # We're going to create a brightness profile by randomly dithering # num_squares squares of size square_size # Create a Cell and add the box cell = gds.core.Cell(cell_name) for n in range(num_squares): # Here we use rejection sampling to generate the 2D Sersic profile Reject = True while Reject: x0 = -6.0 * r_eff + 12.0 * r_eff * rand() y0 = -6.0 * r_eff + 12.0 * r_eff * rand() if Sersic2D.evaluate(x0, y0, 1.0, r_eff, sersic_n, 0.0, 0.0, ellip, 0.0) > rand(): Reject = False x = center[0] + x0 * cos(angle) + y0 * sin(angle) y = center[1] - x0 * sin(angle) + y0 * cos(angle) x = round(x / square_size) * square_size y = round(y / square_size) * square_size pixel = gds.shapes.Rectangle( (x - square_size / 2.0, y - square_size / 2.0), (x + square_size / 2.0, y + square_size / 2.0), layer=layer) cell.add(pixel) return cell
def SersicGalaxy(boundingcell, cell_name, center, r_eff, sersic_n, ellip, angle, m, square_size=1.0, layer=1): # We're going to create a brightness profile by randomly dithering # num_squares squares of size square_size # magnitudes are calculated assuming a 10" exposure at 100% light intensity # Create a Cell and add the box text_step = 2.0 * boundingcell.PixelSizeX num_squares = int(pow(10.0, 0.4 * (27.9 - m))) cell=gds.core.Cell(cell_name) nxmin = max(0, int((center[0] - 10.0 * r_eff - boundingcell.xmin) / boundingcell.dx)) nxmax = min(boundingcell.nx-1, int((center[0] + 10.0 * r_eff - boundingcell.xmin) / boundingcell.dx)) nymin = max(0, int((center[1] - 10.0 * r_eff - boundingcell.ymin) / boundingcell.dy)) nymax = min(boundingcell.ny-1, int((center[1] + 10.0 * r_eff - boundingcell.ymin) / boundingcell.dy)) for n in range(num_squares): # Here we use rejection sampling to generate the 2D Sersic profile Reject = True while Reject: AlreadyFilled = True while AlreadyFilled: nx = randint(nxmin, nxmax) ny = randint(nymin, nymax) AlreadyFilled = boundingcell.data[nx,ny] x = boundingcell.x[nx] y = boundingcell.y[ny] r = sqrt((x-center[0])**2 + (y-center[1])**2) #print n, center, nx, ny, x, y, r, Sersic2D.evaluate(x, y, 1.0, r_eff, sersic_n, center[0], center[1], ellip, angle) if Sersic2D.evaluate(x, y, 1.0, r_eff, sersic_n, center[0], center[1], ellip, angle) > rand(): Reject = False boundingcell.data[nx,ny] = True pixel=gds.shapes.Rectangle((x-boundingcell.dx/2.0, y-boundingcell.dy/2.0), (x+boundingcell.dx/2.0, y+boundingcell.dy/2.0), layer=layer) cell.add(pixel) # Now we annotate it with non-printing text. name = gds.core.Text('Galaxy', (center[0] - 2.0 * text_step, center[1] - 2.0 * text_step), layer=3, magnification=0.002) cell.add(name) mag = gds.core.Text('Mag = %.2f'%m, (center[0] - 2.0 * text_step, center[1] - 3.0 * text_step), layer=3, magnification=0.002) cell.add(mag) reff = gds.core.Text('r_eff = %.2f arcseconds'%(r_eff / boundingcell.PixelSizeX * 0.2), (center[0] - 2.0 * text_step, center[1] - 4.0 * text_step), layer=3, magnification=0.002) cell.add(reff) sersicn = gds.core.Text('n = %.2f'%sersic_n, (center[0] - 2.0 * text_step, center[1] - 5.0 * text_step), layer=3, magnification=0.002) cell.add(sersicn) ell = gds.core.Text('ellip = %.2f'%ellip, (center[0] - 2.0 * text_step, center[1] - 6.0 * text_step), layer=3, magnification=0.002) cell.add(ell) rot = gds.core.Text('angle = %.2f degrees'%(angle*180.0/pi), (center[0] - 2.0 * text_step, center[1] - 7.0 * text_step), layer=3, magnification=0.002) cell.add(rot) #print "Galaxy, m = %f, n = %d"%(m, num_squares) return cell