'A string representation of the angle.
Parameters
unit : `~astropy.units.UnitBase`, optional
Specifies the unit.  Must be an angular unit.  If not
provided, the unit used to initialize the angle will be
used.
decimal : bool, optional
If `True`, a decimal representation will be used, otherwise
the returned string will be in sexagesimal form.
sep : str, optional
The separator between numbers in a sexagesimal
representation.  E.g., if it is \':\', the result is
``\'12:41:11.1241\'``. Also accepts 2 or 3 separators. E.g.,
``sep=\'hms\'`` would give the result ``\'12h41m11.1241s\'``, or
sep=\'-:\' would yield ``\'11-21:17.124\'``.  Alternatively, the
special string \'fromunit\' means \'dms\' if the unit is
degrees, or \'hms\' if the unit is hours.
precision : int, optional
The level of decimal precision.  If ``decimal`` is `True`,
this is the raw precision, otherwise it gives the
precision of the last place of the sexagesimal
representation (seconds).  If `None`, or not provided, the
number of decimal places is determined by the value, and
will be between 0-8 decimal places as required.
alwayssign : bool, optional
If `True`, include the sign no matter what.  If `False`,
only include the sign if it is negative.
pad : bool, optional
If `True`, include leading zeros when needed to ensure a
fixed number of characters for sexagesimal representation.
fields : int, optional
Specifies the number of fields to display when outputting
sexagesimal notation.  For example:
- fields == 1: ``\'5d\'``
- fields == 2: ``\'5d45m\'``
- fields == 3: ``\'5d45m32.5s\'``
By default, all fields are displayed.
format : str, optional
The format of the result.  If not provided, an unadorned
string is returned.  Supported values are:
- \'latex\': Return a LaTeX-formatted string
- \'unicode\': Return a string containing non-ASCII unicode
characters, such as the degree symbol
Returns
strrepr : str or array
A string representation of the angle. If the angle is an array, this
will be an array with a unicode dtype.'

def to_string(self, unit=None, decimal=False, sep=u'fromunit', precision=None, alwayssign=False, pad=False, fields=3, format=None):

    if (unit is None):
        unit = self.unit
    else:
        unit = self._convert_unit_to_angle_unit(u.Unit(unit))
    separators = {None: {u.degree: u'dms', u.hourangle: u'hms'}, u'latex': {u.degree: [u'^\\circ', u'{}^\\prime', u'{}^{\\prime\\prime}'], u.hourangle: [u'^\\mathrm{h}', u'^\\mathrm{m}', u'^\\mathrm{s}']}, u'unicode': {u.degree: u'\xb0\u2032\u2033', u.hourangle: u'\u02b0\u1d50\u02e2'}}
    if (sep == u'fromunit'):
        if (format not in separators):
            raise ValueError(u"Unknown    format    '{0}'".format(format))
        seps = separators[format]
        if (unit in seps):
            sep = seps[unit]
    if (unit is u.degree):
        if decimal:
            values = self.degree
            if (precision is not None):
                func = ((u'{0:0.' + str(precision)) + u'f}').format
            else:
                func = u'{0:g}'.format
        else:
            if (sep == u'fromunit'):
                sep = u'dms'
            values = self.degree
            func = (lambda x: util.degrees_to_string(x, precision=precision, sep=sep, pad=pad, fields=fields))
    elif (unit is u.hourangle):
        if decimal:
            values = self.hour
            if (precision is not None):
                func = ((u'{0:0.' + str(precision)) + u'f}').format
            else:
                func = u'{0:g}'.format
        else:
            if (sep == u'fromunit'):
                sep = u'hms'
            values = self.hour
            func = (lambda x: util.hours_to_string(x, precision=precision, sep=sep, pad=pad, fields=fields))
    elif unit.is_equivalent(u.radian):
        if decimal:
            values = self.to_value(unit)
            if (precision is not None):
                func = ((u'{0:1.' + str(precision)) + u'f}').format
            else:
                func = u'{0:g}'.format
        elif (sep == u'fromunit'):
            values = self.to_value(unit)
            unit_string = unit.to_string(format=format)
            if (format == u'latex'):
                unit_string = unit_string[1:(-1)]
            if (precision is not None):
                def plain_unit_format(val):
                    return ((u'{0:0.' + str(precision)) + u'f}{1}').format(val, unit_string)
                func = plain_unit_format
            else:
                def plain_unit_format(val):
                    return u'{0:g}{1}'.format(val, unit_string)
                func = plain_unit_format
        else:
            raise ValueError(u"'{0}'    can    not    be    represented    in    sexagesimal    notation".format(unit.name))
    else:
        raise u.UnitsError(u'The    unit    value    provided    is    not    an    angular    unit.')
    def do_format(val):
        s = func(float(val))
        if (alwayssign and (not s.startswith(u'-'))):
            s = (u'+' + s)
        if (format == u'latex'):
            s = u'${0}$'.format(s)
        return s
    format_ufunc = np.vectorize(do_format, otypes=[u'U'])
    result = format_ufunc(values)
    if (result.ndim == 0):
        result = result[()]
    return result
