def raw_locations_query(table_name='%(table_name)s', cell_cname='cell_id',
    antenna_cname='antenna_id', long_cname='longitude', lat_cname='latitude'):
    """
    Extract raw locations of cells and antennas while getting rid of
    potential duplicates.

    Inputs
    ------
    table_name : Name of the table the query is supposed to run on,
                 defaulting to '%(table_name)s', i.e. no substitution.
    cell_cname : Name of the column which holds the ids of single cells/bts.
    antenna_cname : Name of the column which holds the ids of the
                    antennas/towers (i.e. unique GPS coordinates per id).
    long_cname : Name of column which holds the longitude coordinate.
    lat_cname : Name of column which holds the latitude coordinate.

    Output
    ------
    GPS information of availables cells and antennas.
    """
    query = """
        SELECT
          cell_id,
          antenna_id,
          MEAN(longitude) as longitude,
          MEAN(latitude) as latitude
        FROM
        (
            SELECT
              %(cell_cname)s as cell_id,
              %(antenna_cname)s as antenna_id,
              ROUND(%(long_cname)s, 6) as longitude, -- 6 digits are sufficient
              ROUND(%(lat_cname)s, 6) as latitude -- to identify humans
            FROM %(table_name)s
        )
        GROUP BY cell_id, antenna_id -- kick duplicates
    """
    return query % {'table_name': table_name, 'cell_cname': cell_cname,
        'antenna_cname': antenna_cname, 'long_cname': long_cname,
        'lat_cname': lat_cname}
