def extract_coords(filename):
    """Extract J2000 coordinates from filename or filepath

    Parameters
    ----------
    filename : str
        name or path of file

    Returns
    -------
    str
        J2000 coordinates
    """

    # in case path is entered as argument
    filename = filename.split("/")[-1] if "/" in filename else filename
    # to check whether declination is positive or negative
    plus_minus = "+" if "+" in filename else "-"

    # extracting right acesnsion (ra) and declination(dec) from filename
    filename = filename.split("_")[0].strip("J").split(plus_minus)
    ra_extracted = [
        "".join(filename[0][0:2]),
        "".join(filename[0][2:4]),
        "".join(filename[0][4:]),
    ]
    dec_extracted = [
        "".join(filename[1][0:2]),
        "".join(filename[1][2:4]),
        "".join(filename[1][4:]),
    ]

    coordinates = " ".join(ra_extracted) + " " + plus_minus + " ".join(dec_extracted)

    # return coordinates as a string in HH MM SS.SSS format
    return coordinates