calculate densities