def get_Di(M, A, Ds, S=None):
    """
    Obtain the IFOV vector in GCI coordinates.

    Parameters
    ----------
    M : numpy.matrix
        3x3 nadir-to-GCI rotation matrix M
    A : numpy.matrix
        3x3 Spacecraft Attitude Matrix
    Ds : 1-dimensional array of floats
        3-element IFOV vector in sensor coordinates
    S : numpy.matrix or None
        Optional 3x3 Sensor Alignment Matrix

    Returns
    -------
    Di : 1-dimensional array of floats
        3-element IFOV vector in GCI coordinates
    """
    if S is None:
        return M * A.T * Ds
    else:
        return M * A.T * S.T * Ds