from typing import Union
from pathlib import Path
import re


def get_plotid(filepath: Union[str, Path]) -> str:
    """
    Get the plot id from a file name.

    Parameters
    ----------
    filepath : str or pathlibs Path object
        Path to the data file

    """
    filepath = Path(filepath)
    ftype = ["AT", "EC", "BC", "EB", "DB"]
    r = re.compile("|".join(["[A-Z]{{2}}-{}[0-9]".format(i) for i in ftype]))
    m = r.search(filepath.name)
    return m.group() if m else ""