<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_ref_dir(region, coordsys):
 """ Finds and returns the reference direction for a given HEALPix region string. region : a string describing a HEALPix region coordsys : coordinate system, GAL | CEL """

        if region is None:
            if coordsys == "GAL":
                c = SkyCoord(0., 0., frame=Galactic, unit="deg")
            elif coordsys == "CEL":
                c = SkyCoord(0., 0., frame=ICRS, unit="deg")
            return c

        tokens = parse_hpxregion(region)
        if tokens[0] in ['DISK', 'DISK_INC']:
            if coordsys == "GAL":
                c = SkyCoord(float(tokens[1]), float(
                    tokens[2]), frame=Galactic, unit="deg")
            elif coordsys == "CEL":
                c = SkyCoord(float(tokens[1]), float(
                    tokens[2]), frame=ICRS, unit="deg")
            return c
        elif tokens[0] == 'HPX_PIXEL':
            nside_pix = int(tokens[2])
            ipix_pix = int(tokens[3])
            if tokens[1] == 'NESTED':
                nest_pix = True
            elif tokens[1] == 'RING':
                nest_pix = False
            else:
                raise Exception(
                    "Did not recognize ordering scheme %s" % tokens[1])
            theta, phi = hp.pix2ang(nside_pix, ipix_pix, nest_pix)
            lat = np.degrees((np.pi / 2) - theta)
            lon = np.degrees(phi)
            if coordsys == "GAL":
                c = SkyCoord(lon, lat, frame=Galactic, unit="deg")
            elif coordsys == "CEL":
                c = SkyCoord(lon, lat, frame=ICRS, unit="deg")
            return c
        else:
            raise Exception(
                "HPX.get_ref_dir did not recognize region type %s" % tokens[0])
        return None