Function to convert point water head (as outputted by seawat) into freshwater head, using Eq.3 from Guo, W., & Langevin, C. D. (2002):

$h_{f}=\frac{\rho}{\rho_{f}}h-\frac{\rho-\rho_{f}}{\rho_{f}}Z$

An edge case arises when the head is below the cell centre, or entirely below the cell. Strictly applying Eq.3 would result in freshwater heads that are lower than the original point water head, which is physically impossible. This function then outputs the freshwaterhead for the uppermost underlying cell where the original point water head exceeds the cell centre.

Parameters
• pointwaterhead (float or xr.DataArray of floats) – the point water head as outputted by SEAWAT, in m.

• density (float or xr.DataArray of floats) – the water density at the same locations as pointwaterhead.

• elevation (float or xr.DataArray of floats) – elevation at the same locations as pointwaterhead, in m.

• density_fresh (float, optional) – the density of freshwater (1000 kg/m3), or a different value if different units are used, or a different density reference is required.

Returns