<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_file(self, fname, binary=False, **kwargs):
 """ Initialize the class instance from gridded data in a file. Usage ----- x = SHGrid.from_file(fname, [binary, **kwargs]) Returns ------- x : SHGrid class instance Parameters fname : str The filename containing the gridded data. For text files (default) the file is read using the numpy routine loadtxt(), whereas for binary files, the file is read using numpy.load(). The dimensions of the array must be nlon=nlat or nlon=2*nlat for Driscoll and Healy grids, or nlon=2*nlat-1 for Gauss-Legendre Quadrature grids. binary : bool, optional, default = False If False, read a text file. If True, read a binary 'npy' file. **kwargs : keyword arguments, optional Keyword arguments of numpy.loadtxt() or numpy.load(). """

        if binary is False:
            data = _np.loadtxt(fname, **kwargs)
        elif binary is True:
            data = _np.load(fname, **kwargs)
        else:
            raise ValueError('binary must be True or False. '
                             'Input value is {:s}'.format(binary))

        if _np.iscomplexobj(data):
            kind = 'complex'
        else:
            kind = 'real'

        if (data.shape[1] == data.shape[0]) or (data.shape[1] ==
                                                2 * data.shape[0]):
            grid = 'DH'
        elif data.shape[1] == 2 * data.shape[0] - 1:
            grid = 'GLQ'
        else:
            raise ValueError('Input grid must be dimensioned as ' +
                             '(nlat, nlon). For DH grids, nlon = nlat or ' +
                             'nlon = 2 * nlat. For GLQ grids, nlon = ' +
                             '2 * nlat - 1. Input dimensions are nlat = ' +
                             '{:d}, nlon = {:d}'.format(data.shape[0],
                                                        data.shape[1]))

        for cls in self.__subclasses__():
            if cls.istype(kind) and cls.isgrid(grid):
                return cls(data)