Transform from geo coordinates to pixel coordinates

def geo_to_pixel(geo, level):
        """Transform from geo coordinates to pixel coordinates"""
        lat, lon = float(geo[0]), float(geo[1])
        lat = TileSystem.clip(lat, TileSystem.LATITUDE_RANGE)
        lon = TileSystem.clip(lon, TileSystem.LONGITUDE_RANGE)
        x = (lon + 180) / 360
        sin_lat = sin(lat * pi / 180)
        y = 0.5 - log((1 + sin_lat) / (1 - sin_lat)) / (4 * pi)
        # might need to cast to uint
        map_size = TileSystem.map_size(level)
        pixel_x = int(TileSystem.clip(x * map_size + 0.5, (0, map_size - 1)))
        pixel_y = int(TileSystem.clip(y * map_size + 0.5, (0, map_size - 1)))
        # print '\n'+str( ((lat, lon), sin_lat, (x, y), map_size, (pixel_x,
        # pixel_y)) )+'\n'
        return pixel_x, pixel_y