import math


def ToMercDegrees(y, num_tiles):
  """Calculate latitude of southern border of yth tile in degrees.

  LOD is log2(num_tiles)
  Args:
    y: (float) Position of tile in qt grid moving from south to north.
       Non-integer values give latitude within tile.
    num_tiles: (integer) Number of tiles in the qt grid.
  Returns:
    Latitude of southern border of tile in degrees.
  """
  # Calculate on standard Mercator scale that spans from -pi to pi.
  # There is no intrinsic reason for using these values, which correspond to
  # about -85 to 85 degrees, other than it matches (albeit somewhat
  # misleadingly) the longitudinal radian span, and it's the span Google
  # uses for its 2d maps.
  y_merc = 2.0 * math.pi * y / num_tiles - math.pi
  latitude_rad = (math.atan(math.exp(y_merc)) - math.pi / 4.0) * 2.0
  return latitude_rad / math.pi * 180.0