# Buggy code
def hgs_to_hcc(heliogcoord, heliocframe):
    """
    Convert from Heliographic Stonyhurst to Heliocentric Cartesian.
    """
    hglon = heliogcoord.lon
    hglat = heliogcoord.lat
    r = heliogcoord.radius
    if r.unit is u.one and quantity_allclose(r, 1 * u.one):
        r = np.ones_like(r)
        r *= RSUN_METERS

    if not isinstance(heliocframe.observer, BaseCoordinateFrame):
        raise ConvertError(
            "Cannot transform heliographic coordinates to "
            "heliocentric coordinates for observer '{}' "
            "without `obstime` being specified.".format(heliocframe.observer)
        )

    l0_rad = heliocframe.observer.lon.to(u.rad)
    b0_deg = heliocframe.observer.lat

    lon = np.deg2rad(hglon)
    lat = np.deg2rad(hglat)

    cosb = np.cos(b0_deg.to(u.rad))
    sinb = np.sin(b0_deg.to(u.rad))

    lon = lon - l0_rad

    cosx = np.cos(lon)
    sinx = np.sin(lon)
    cosy = np.cos(lat)
    siny = np.sin(lat)

    x = r * cosy * sinx
    y = r * (siny * cosb - cosy * cosx * sinb)
    zz = r * (siny * sinb + cosy * cosx * cosb)

    representation = CartesianRepresentation(x.to(u.km), y.to(u.km), zz.to(u.km))

    return heliocframe.realize_frame(representation)


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-46-77d08794e7f4> in <module>()
----> 1 foo.transform_to(sunpy.coordinates.Helioprojective(observer=obs))

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/astropy/coordinates/sky_coordinate.py in transform_to(self, frame, merge_attributes)
480         # Do the transformation, returning a coordinate frame of the desired
481         # final type (not generic).
--> 482         new_coord = trans(self.frame, generic_frame)
483
484         # Finally make the new SkyCoord object from the `new_coord` and

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/astropy/coordinates/transformations.py in __call__(self, fromcoord, toframe)
1312
1313             curr_toframe = t.tosys(**frattrs)
-> 1314             curr_coord = t(curr_coord, curr_toframe)
1315
1316         # this is safe even in the case where self.transforms is empty, because

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/astropy/coordinates/transformations.py in __call__(self, fromcoord, toframe)
747
748     def __call__(self, fromcoord, toframe):
--> 749         res = self.func(fromcoord, toframe)
750         if not isinstance(res, self.tosys):
751             raise TypeError('the transformation function yielded {0} but '

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/sunpy/coordinates/transformations.py in hgs_to_hcc(heliogcoord, heliocframe)
186     # TODO: Revert this.
187     from astropy.tests.helper import quantity_allclose
--> 188     hglon = heliogcoord.lon
189     hglat = heliogcoord.lat
190     r = heliogcoord.radius

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/astropy/coordinates/baseframe.py in __getattr__(self, attr)
1249             return val
1250
-> 1251         return self.__getattribute__(attr)  # Raise AttributeError.
1252
1253     def __setattr__(self, attr, value):

AttributeError: 'HeliographicStonyhurst' object has no attribute 'lon'

# Fixed code
def hgs_to_hcc(heliogcoord, heliocframe):
    """
    Convert from Heliographic Stonyhurst to Heliocentric Cartesian.
    """
    hglon = heliogcoord.spherical.lon
    hglat = heliogcoord.spherical.lat
    r = heliogcoord.spherical.distance
    if r.unit is u.one and quantity_allclose(r, 1 * u.one):
        r = np.ones_like(r)
        r *= RSUN_METERS

    if not isinstance(heliocframe.observer, BaseCoordinateFrame):
        raise ConvertError(
            "Cannot transform heliographic coordinates to "
            "heliocentric coordinates for observer '{}' "
            "without `obstime` being specified.".format(heliocframe.observer)
        )

    l0_rad = heliocframe.observer.lon.to(u.rad)
    b0_deg = heliocframe.observer.lat

    lon = np.deg2rad(hglon)
    lat = np.deg2rad(hglat)

    cosb = np.cos(b0_deg.to(u.rad))
    sinb = np.sin(b0_deg.to(u.rad))

    lon = lon - l0_rad

    cosx = np.cos(lon)
    sinx = np.sin(lon)
    cosy = np.cos(lat)
    siny = np.sin(lat)

    x = r * cosy * sinx
    y = r * (siny * cosb - cosy * cosx * sinb)
    zz = r * (siny * sinb + cosy * cosx * cosb)

    representation = CartesianRepresentation(x.to(u.km), y.to(u.km), zz.to(u.km))

    return heliocframe.realize_frame(representation)