def global_to_local_direction(coord1d: int, global_dir: int, lattice_dir: int, dir_size: int):
    """
    Helper function to compute local coordinate

    Args:
        coord1d: process coordinate in the x or y
        global_dir: global coordinate in x or y
        lattice_dir: lattice grid size in x or y
        dir_size: number of processes in x or y given the cartesian topology

    Returns:
        local x or y coordinate

    """
    return int(global_dir - coord1d * (lattice_dir // dir_size)) + 1