<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_shape(self, shape, rho, gm, nmax=7, lmax=None, lmax_grid=None, lmax_calc=None, omega=None):
 """ Initialize a class of gravitational potential spherical harmonic coefficients by calculuting the gravitational potential associatiated with relief along an interface. Usage ----- x = SHGravCoeffs.from_shape(shape, rho, gm, [nmax, lmax, lmax_grid, lmax_calc, omega]) Returns ------- x : SHGravCoeffs class instance. Parameters shape : SHGrid or SHCoeffs class instance The shape of the interface, either as an SHGrid or SHCoeffs class instance. If the input is an SHCoeffs class instance, this will be expaned on a grid using the optional parameters lmax_grid and lmax_calc. rho : int, float, or ndarray, or an SHGrid or SHCoeffs class instance The density contrast associated with the interface in kg / m3. If the input is a scalar, the density contrast is constant. If the input is an SHCoeffs or SHGrid class instance, the density contrast will vary laterally. gm : float The gravitational constant times the mass that is associated with the gravitational potential coefficients. nmax : integer, optional, default = 7 The maximum order used in the Taylor-series expansion when calculating the potential coefficients. lmax : int, optional, shape.lmax The maximum spherical harmonic degree of the output spherical harmonic coefficients. lmax_grid : int, optional, default = lmax If shape or rho is of type SHCoeffs, this parameter determines the maximum spherical harmonic degree that is resolvable when expanded onto a grid. lmax_calc : optional, integer, default = lmax If shape or rho is of type SHCoeffs, this parameter determines the maximum spherical harmonic degree that will be used when expanded onto a grid. omega : float, optional, default = None The angular rotation rate of the body. Description Initialize an SHGravCoeffs class instance by calculating the spherical harmonic coefficients of the gravitational potential associated with the shape of a density interface. The potential is calculated using the finite-amplitude technique of Wieczorek and Phillips (1998) for a constant density contrast and Wieczorek (2007) for a density contrast that varies laterally. The output coefficients are referenced to the mean radius of shape, and the potential is strictly valid only when it is evaluated at a radius greater than the maximum radius of shape. The input shape (and density contrast rho for variable density) can be either an SHGrid or SHCoeffs class instance. The routine makes direct use of gridded versions of these quantities, so if the input is of type SHCoeffs, it will first be expanded onto a grid. This exansion will be performed on a grid that can resolve degrees up to lmax_grid, with only the first lmax_calc coefficients being used. The input shape must correspond to absolute radii as the degree 0 term determines the reference radius of the coefficients. As an intermediate step, this routine calculates the spherical harmonic coefficients of the interface raised to the nth power, i.e., (shape-r0)**n, where r0 is the mean radius of shape. If the input shape is bandlimited to degree L, the resulting function will thus be bandlimited to degree L*nmax. This subroutine assumes implicitly that the maximum spherical harmonic degree of the input shape (when SHCoeffs) or maximum resolvable spherical harmonic degree of shape (when SHGrid) is greater or equal to this value. If this is not the case, aliasing will occur. In practice, for accurate results, the effective bandwidth needs only to be about three times the size of L, though this should be verified for each application. The effective bandwidth of shape (when SHCoeffs) can be increased by preprocessing with the method pad(), or by increaesing the value of lmax_grid (when SHGrid). """

        mass = gm / _G.value

        if type(shape) is not _SHRealCoeffs and type(shape) is not _DHRealGrid:
            raise ValueError('shape must be of type SHRealCoeffs '
                             'or DHRealGrid. Input type is {:s}'
                             .format(repr(type(shape))))

        if (not issubclass(type(rho), float) and type(rho) is not int
                and type(rho) is not _np.ndarray and
                type(rho) is not _SHRealCoeffs and
                type(rho is not _DHRealGrid)):
            raise ValueError('rho must be of type float, int, ndarray, '
                             'SHRealCoeffs or DHRealGrid. Input type is {:s}'
                             .format(repr(type(rho))))

        if type(shape) is _SHRealCoeffs:
            shape = shape.expand(lmax=lmax_grid, lmax_calc=lmax_calc)

        if type(rho) is _SHRealCoeffs:
            rho = rho.expand(lmax=lmax_grid, lmax_calc=lmax_calc)

        if type(rho) is _DHRealGrid:
            if shape.lmax != rho.lmax:
                raise ValueError('The grids for shape and rho must have the '
                                 'same size. '
                                 'lmax of shape = {:d}, lmax of rho = {:d}'
                                 .format(shape.lmax, rho.lmax))
            cilm, d = _CilmPlusRhoHDH(shape.data, nmax, mass, rho.data,
                                      lmax=lmax)

        else:
            cilm, d = _CilmPlusDH(shape.data, nmax, mass, rho, lmax=lmax)

        clm = SHGravRealCoeffs(cilm, gm=gm, r0=d, omega=omega,
                               normalization='4pi', csphase=1)
        return clm