def make_branch_array(self, _widths, _lengths, nx, ny, spacing_structs,
                          spacing_arrays, rot_angle, layers):
        if not (type(layers) == list):
            layers = [layers]
        if not (type(_lengths) == list):
            _lengths = [_lengths]
        if not (type(_widths) == list):
            _widths = [_widths]
        l = layers[0]
        _length = _lengths[0]

        manyslits = i = j = None

        slits = []
        for width in _widths:
            slit = Cell("Slit_{:.0f}".format(width * 1000))
            line = Path([[-_length / 2., 0], [_length / 2., 0]],
                        width=width,
                        layer=l)
            slit.add(line)
            slits.append(slit)

        many_crosses = Cell("CrossArray")
        x_pos = 0
        y_pos = 0

        array_pitch = ny * (length +
                            spacing_structs) - spacing_structs + spacing_arrays

        for j, width_vert in enumerate(_widths[::-1]):
            for i, width_horiz in enumerate(_widths):
                # Define a single cross
                cross = Cell("Cross_{:.0f}_{:.0f}".format(
                    width_horiz * 1000, width_vert * 1000))
                cross.add(slits[i])  # Horizontal slit
                cross.add(slits[j], rotation=90)  # Vertical slit
                # Define the cross array
                cross_array = Cell("CrossArray_{:.0f}_{:.0f}".format(
                    width_horiz * 1000, width_vert * 1000))
                slit_array = CellArray(
                    cross, nx, ny,
                    (_length + spacing_structs, _length + spacing_structs))
                slit_array.translate(
                    (-(nx - 1) * (_length + spacing_structs) / 2.,
                     (-(ny - 1) * (_length + spacing_structs) / 2.)))
                cross_array.add(slit_array)
                many_crosses.add(cross_array, origin=(x_pos, y_pos))
                x_pos += array_pitch
            y_pos += array_pitch
            x_pos = 0

        # Make the labels
        lbl_cell = Cell("Lbl_Cell")
        for i, width in enumerate(_widths):
            text_string = 'W{:.0f}'.format(width * 1000)
            text = Label(text_string, 5, layer=l)
            text.translate(tuple(np.array(-text.bounding_box.mean(0))))
            x_offset = -1.5 * array_pitch + i * array_pitch
            text.translate(np.array((x_offset, 0)))  # Center justify label
            lbl_cell.add(text)

        centered_cell = Cell('Centered_Cell')
        bbox = np.mean(many_crosses.bounding_box, 0)  # Get center of cell

        centered_cell.add(many_crosses, origin=tuple(-bbox))
        lbl_vertical_offset = 1.5
        centered_cell.add(lbl_cell, origin=(0, -bbox[1] * lbl_vertical_offset))
        centered_cell.add(lbl_cell,
                          origin=(-bbox[1] * lbl_vertical_offset, 0),
                          rotation=90)

        self.add(centered_cell, rotation=rot_angle)
    def make_tapered_cross_array(self, _nom_width, _taper_widths, _length,
                                 _taper_length, nx, ny, spacing_structs,
                                 spacing_arrays, rot_angle, layers):

        if not (type(layers) == list):
            layers = [layers]
        if not (type(_taper_widths) == list):
            _taper_widths = [_taper_widths]

        if type(_nom_width
                ) == list:  # Only accept a single membrane width for now
            _nom_width = _nom_width[0]
        if type(_length
                ) == list:  # Only accept a single membrane length for now
            _length = _length[0]
        if type(_taper_length
                ) == list:  # Only accept a single taper length for now
            _taper_length = _taper_length[0]

        layer = layers[0]

        many_crosses = Cell("CrossArray")
        x_pos = 0
        y_pos = 0

        array_pitch = ny * (length +
                            spacing_structs) - spacing_structs + spacing_arrays

        membrane_cell = Cell('Testing')

        # fix the taper length, put this in a loop and iterate over various combined taper width values

        for j, tw_vert in enumerate(_taper_widths):
            for i, tw_horiz in enumerate(_taper_widths):
                # Define a single cross
                cross = self.make_tapered_cross(_nom_width, _nom_width,
                                                tw_horiz, tw_vert, _length,
                                                _length, _taper_length,
                                                _taper_length, layer)
                # Define the cross array
                cross_array = Cell("TaperedCrossArray_{:.0f}_{:.0f}".format(
                    tw_horiz * 1000, tw_vert * 1000))
                slit_array = CellArray(
                    cross, nx, ny,
                    (_length + spacing_structs, _length + spacing_structs))
                slit_array.translate(
                    (-(nx - 1) * (_length + spacing_structs) / 2.,
                     (-(ny - 1) * (_length + spacing_structs) / 2.)))
                cross_array.add(slit_array)
                many_crosses.add(cross_array, origin=(x_pos, y_pos))
                x_pos += array_pitch
            y_pos += array_pitch
            x_pos = 0

        # Make the labels
        lbl_cell = Cell("Lbl_Cell")
        for i, width in enumerate(_taper_widths):
            text_string = 'TW{:.0f}'.format(width * 1000)
            text = Label(text_string, 5, layer=layer)
            text.translate(tuple(np.array(-text.bounding_box.mean(0))))
            x_offset = -1.5 * array_pitch + i * array_pitch
            text.translate(np.array((x_offset, 0)))  # Center justify label
            lbl_cell.add(text)

        # Make label for the whole field
        frame_lbl = Cell("Cell_Label")
        text_string = 'NomW {:.0f}, TL {:.0f}'.format(_nom_width * 1000,
                                                      _taper_length * 1000)
        text = Label(text_string, 5, layer=layer)
        text.translate(tuple(np.array(-text.bounding_box.mean(0))))
        frame_lbl.add(text)

        centered_cell = Cell('Centered_Cell')
        bbox = np.mean(many_crosses.bounding_box, 0)  # Get center of cell

        centered_cell.add(many_crosses, origin=tuple(-bbox))
        centered_cell.add(frame_lbl, origin=(0, -200))
        lbl_vertical_offset = 1.5
        centered_cell.add(lbl_cell, origin=(0, -bbox[1] * lbl_vertical_offset))
        centered_cell.add(lbl_cell,
                          origin=(-bbox[1] * lbl_vertical_offset, 0),
                          rotation=90)

        self.add(centered_cell, rotation=rot_angle)
    def make_slit_array(self, _pitches, spacing, _widths, _lengths, rot_angle,
                        array_height, array_width, array_spacing, layers):
        if not (type(layers) == list):
            layers = [layers]
        if not (type(_pitches) == list):
            _pitches = [_pitches]
        if not (type(_lengths) == list):
            _lengths = [_lengths]
        if not (type(_widths) == list):
            _widths = [_widths]
        manyslits = i = j = None
        for l in layers:
            i = -1
            j = -1
            manyslits = Cell("SlitArray")
            pitch = _pitches[0]
            for length in _lengths:
                j += 1
                i = -1

                for width in _widths:
                    # for pitch in pitches:
                    i += 1
                    if i % 3 == 0:
                        j += 1  # Move to array to next line
                        i = 0  # Restart at left

                    nx = int(array_width / (length + spacing))
                    ny = int(array_height / pitch)
                    # Define the slits
                    slit = Cell("Slits")
                    rect = Rectangle((-length / 2., -width / 2.),
                                     (length / 2., width / 2.),
                                     layer=l)
                    slit.add(rect)
                    slits = CellArray(slit, nx, ny, (length + spacing, pitch))
                    slits.translate((-(nx - 1) * (length + spacing) / 2.,
                                     -(ny - 1) * pitch / 2.))
                    slit_array = Cell("SlitArray")
                    slit_array.add(slits)
                    text = Label('w/p/l\n%i/%i/%i' %
                                 (width * 1000, pitch, length),
                                 5,
                                 layer=l)
                    lbl_vertical_offset = 1.35
                    if j % 2 == 0:
                        text.translate(
                            tuple(
                                np.array(-text.bounding_box.mean(0)) +
                                np.array((0,
                                          -array_height / lbl_vertical_offset))
                            ))  # Center justify label
                    else:
                        text.translate(
                            tuple(
                                np.array(-text.bounding_box.mean(0)) +
                                np.array((0, array_height / lbl_vertical_offset
                                          ))))  # Center justify label
                    slit_array.add(text)
                    manyslits.add(
                        slit_array,
                        origin=((array_width + array_spacing) * i,
                                (array_height + 2. * array_spacing) * j -
                                array_spacing / 2.))

        # This is an ugly hack to center rotated slits, should fix this properly...
        if rot_angle == 45:  # TODO: fix this ugly thing
            hacky_offset_x = 200
            hacky_offset_y = -25
        elif rot_angle == 90:
            hacky_offset_x = 356
            hacky_offset_y = 96.5
        else:
            hacky_offset_x = 0
            hacky_offset_y = 0

        self.add(manyslits,
                 origin=(-i * (array_width + array_spacing) / 2 +
                         hacky_offset_x, -(j + 1.5) *
                         (array_height + array_spacing) / 2 + hacky_offset_y),
                 rotation=rot_angle)