def add_gaussian_holes(array, nholes=100, rad_max=30, rad_min=10, return_info=False, hole_level=None): ylim, xlim = array.shape yy, xx = np.mgrid[-ylim/2:ylim/2, -xlim/2:xlim/2] xcenters = np.random.random_integers(-(xlim/2-rad_max), high=xlim/2-rad_max, size=nholes) ycenters = np.random.random_integers(-(ylim/2-rad_max), high=ylim/2-rad_max, size=nholes) radii = np.random.random_integers(rad_min, rad_max, size=nholes) if hole_level is None: # Choose random hole bkg levels bkgs = np.random.uniform(0.5, 0.75, size=nholes) else: bkgs = np.array([hole_level] * nholes, dtype=np.int) for x, y, radius, amp in zip(xcenters, ycenters, radii, bkgs): gauss = Gaussian2D.evaluate(yy, xx, amp, x, y, radius, radius, 0.0) array -= gauss if return_info: return array, np.vstack([ycenters+ylim/2, xcenters+xlim/2, radii]) return array
def GaussianGalaxy(cell_name, center, sigmax, sigmay, 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 Gaussian Profile # This is slower, but more general. Reject = True while Reject: x0 = -3.0 * sigmax + 6.0 * sigmax * rand() y0 = -3.0 * sigmay + 6.0 * sigmay * rand() if Gaussian2D.evaluate(x0, y0, 1.0, 0.0, 0.0, sigmax, sigmay, 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 add_gaussian_peaks(array, nholes=100, rad_max=30, rad_min=10): ylim, xlim = array.shape yy, xx = np.mgrid[-ylim/2:ylim/2, -xlim/2:xlim/2] xcenters = np.random.random_integers(-(xlim/2-rad_max), high=xlim/2-rad_max, size=nholes) ycenters = np.random.random_integers(-(ylim/2-rad_max), high=ylim/2-rad_max, size=nholes) radii = np.random.random_integers(rad_min, rad_max, size=nholes) for x, y, radius in zip(xcenters, ycenters, radii): amp = np.random.uniform(0.5, 0.75) gauss = Gaussian2D.evaluate(yy, xx, amp, x, y, radius, radius, 0.0) array += gauss return array