code: def from_astropy(cls, arr, unit_registry=None):
          
          # Converting from AstroPy Quantity
          try:
              u = arr.unit
              _arr = arr
          except AttributeError:
              u = arr
              _arr = 1.0 * u
          ap_units = []
          for base, exponent in zip(u.bases, u.powers):
              unit_str = base.to_string()
              # we have to do this because AstroPy is silly and defines
              # hour as "h"
              if unit_str == "h":
                  unit_str = "hr"
              ap_units.append("%s**(%s)" % (unit_str, Rational(exponent)))
          ap_units = "*".join(ap_units)
          if isinstance(_arr.value, np.ndarray) and _arr.shape != ():
              return unyt_array(_arr.value, ap_units, registry=unit_registry)
          else:
              return unyt_quantity(_arr.value, ap_units, registry=unit_registry)
docs: Convert an AstroPy "Quantity" to a unyt_array or unyt_quantity.
  
          Parameters
          ----------
          arr : AstroPy Quantity
              The Quantity to convert from.
          unit_registry : yt UnitRegistry, optional
              A yt unit registry to use in the conversion. If one is not
              supplied, the default one will be used.
  
          Example
          -------
          >>> from astropy.units import km
          >>> unyt_quantity.from_astropy(km)
          unyt_quantity(1., 'km')
          >>> a = [1, 2, 3]*km
          >>> a
          <Quantity [1., 2., 3.] km>
          >>> unyt_array.from_astropy(a)
          unyt_array([1., 2., 3.], 'km')