import torch


def _add_rician_noise(dat, noise_prct=0.1):
    """Adds rician noise to a tensor as:
    dat = dat + n_real + i*n_img, where n_real, n_img ~ N(0, std**2)
    dat = magnitude(dat)

    Parameters
    ----------
    dat : tensor
        Input data
    noise_prct : float, default=0.1
        Amount of noise to add, as a percentage of input max value

    Returns
    ----------
    dat : tensor
        Noisy data
	std : float
		Noise standard deviation

    """
    std = noise_prct * dat.max()
    dat = ((dat + std*torch.randn_like(dat))**2 + (std*torch.randn_like(dat))**2).sqrt()

    return dat, std