import requests


def detection_update(addr, auth, **kwargs):
    """
    Update an extising detection. 
    observationid, pulsar and subband, coherent form a unique set per detection.

    Args:
        addr: hostname or ip address of database server.
        auth: tuple of username and password.
        observationid: observation id. 
        pulsar: name of pulsar (string). 
        subband: subband of detection.
        coherent: coherent data set (True), incoherent (False)
        observation_type: type of observation (1: Contiguous, 2: Picket Fence)
        calibrator: id of calibrator (or None).
        startcchan: start course channel (or None).
        stopcchan: stop course channel (or None). 
        flux: mJy (or None)
        flux_error: ±mJy (or None)
        width: ms (or None)
        width_error: ±ms (or None)
        scattering: s (or None)
        scattering_error: ±s (or None)
        dm: pc/cm³ (or None)
        dm_error: ±pc/cm³
        version: version number of client script used. (default 1)

    Raises:
        Exception if detection already exists or there is an input error.
    """
    path = '{0}/{1}/'.format(addr, 'detection_update')
    r = requests.post(url=path, auth=auth, data=kwargs)
    r.raise_for_status()
    return r.json()