# Path: tkp/db/quality.py
# def sync_rejectreasons(session):
# def reject(imageid, reason, comment, session):
# def unreject(imageid, session):
# def isrejected(imageid, session):


import tkp.quality
from tkp.utility import nice_format
from tkp.db.quality import reject_reasons

    :param semibmaj/semibmin: size of the beam in pixels

    :returns: True/False
    """

    formatted = "bmaj=%s and bmin=%s (pixels)" % (nice_format(semibmaj),
                                                 nice_format(semibmin))

    if tkp.quality.restoringbeam.infinite(semibmaj, semibmin, theta):
        return "Beam infinte. %s" % formatted
    if tkp.quality.restoringbeam.undersampled(semibmaj, semibmin):
        return "Beam undersampled. %s" % formatted
    elif tkp.quality.restoringbeam.oversampled(semibmaj, semibmin,
        oversampled_x):
        return "Beam oversampled. %s" % formatted
    elif tkp.quality.restoringbeam.highly_elliptical(semibmaj, semibmin, elliptical_x):
        return "Beam too elliptical. %s" % formatted

    #TODO: this test has been disabled untill antonia solves issue discribed in #3802
    #elif not tkp.quality.restoringbeam.full_fieldofview(nx, ny, cellsize, fov):
    #    return "Full field of view not imaged. Imaged FoV=XXdegrees, Observed FoV=XXdegrees"

    else:
        return False


def reject_beam(semimaj, semimin, theta, oversampled_x=30, elliptical_x=2.0):
    beam_check = beam_invalid(semimaj, semimin, theta, oversampled_x, elliptical_x)
    if beam_check:

# Path: tkp/db/quality.py
# def sync_rejectreasons(session):
# def reject(imageid, reason, comment, session):
# def unreject(imageid, session):
# def isrejected(imageid, session):


# Path: tkp/quality/restoringbeam.py
import tkp.quality
from tkp.utility import nice_format
from tkp.db.quality import reject_reasons


    :param semibmaj/semibmin: size of the beam in pixels

    :returns: True/False
    """

    formatted = "bmaj=%s and bmin=%s (pixels)" % (nice_format(semibmaj),
                                                 nice_format(semibmin))

    if tkp.quality.restoringbeam.infinite(semibmaj, semibmin, theta):
        return "Beam infinte. %s" % formatted
    if tkp.quality.restoringbeam.undersampled(semibmaj, semibmin):
        return "Beam undersampled. %s" % formatted
    elif tkp.quality.restoringbeam.oversampled(semibmaj, semibmin,
        oversampled_x):
        return "Beam oversampled. %s" % formatted
    elif tkp.quality.restoringbeam.highly_elliptical(semibmaj, semibmin, elliptical_x):
        return "Beam too elliptical. %s" % formatted

    #TODO: this test has been disabled untill antonia solves issue discribed in #3802
    #elif not tkp.quality.restoringbeam.full_fieldofview(nx, ny, cellsize, fov):
    #    return "Full field of view not imaged. Imaged FoV=XXdegrees, Observed FoV=XXdegrees"

    else:
        return False


def reject_beam(semimaj, semimin, theta, oversampled_x=30, elliptical_x=2.0):
    beam_check = beam_invalid(semimaj, semimin, theta, oversampled_x, elliptical_x)
    if beam_check:

        return reject_reasons['beam'],beam_check