def rotate(data_np, theta_deg, rotctr_x=None, rotctr_y=None):

    # If there is no rotation, then we are done
    if math.fmod(theta_deg, 360.0) == 0.0:
        return data_np

    ht, wd = data_np.shape[:2]

    ## ocx, ocy = rotctr_x, rotctr_y
    ## if ocx is None:
    ##     ocx = wd // 2
    ## if ocy is None:
    ##     ocy = ht // 2
    ocx, ocy = wd // 2, ht // 2

    # Make a square with room to rotate
    slop = 20
    side = int(math.sqrt(wd**2 + ht**2) + slop)
    new_wd = new_ht = side
    dims = (new_ht, new_wd) + data_np.shape[2:]
    # TODO: fill with a different value?
    newdata = numpy.zeros(dims)
    # Find center of new data array
    ncx, ncy = new_wd // 2, new_ht // 2

    # Overlay the old image on the new (blank) image
    ldx, rdx = min(ocx, ncx), min(wd - ocx, ncx)
    bdy, tdy = min(ocy, ncy), min(ht - ocy, ncy)

    newdata[ncy-bdy:ncy+tdy, ncx-ldx:ncx+rdx] = \
                             data_np[ocy-bdy:ocy+tdy, ocx-ldx:ocx+rdx]

    # find offsets of old image in new image
    #dx, dy = ncx - ocx, ncy - ocy

    # Now rotate as usual
    newdata = rotate_clip(newdata, theta_deg,
                          rotctr_x=rotctr_x, rotctr_y=rotctr_y,
                          out=newdata)
    return newdata
dataset/ETHPy150Open ejeschke/ginga/ginga/trcalc.py/rotate/original