calc_densities function

Calculate densities