def load_xmatch_external_catalogs(xmatchto, xmatchkeys, outfile=None):
outdict = {}<EOL>for xc, xk in zip(xmatchto, xmatchkeys):<EOL><INDENT>parsed_catdef = _parse_xmatch_catalog_header(xc, xk)<EOL>if not parsed_catdef:<EOL><INDENT>continue<EOL><DEDENT>(infd, catdefdict,<EOL>catcolinds, catcoldtypes,<EOL>catcolnames, catcolunits) = parsed_catdef<EOL>catarr = np.genfromtxt(infd,<EOL>usecols=catcolinds,<EOL>names=xk,<EOL>dtype='<STR_LIT:U+002C>'.join(catcoldtypes),<EOL>comments='<STR_LIT:#>',<EOL>delimiter='<STR_LIT:|>',<EOL>autostrip=True)<EOL>infd.close()<EOL>catshortname = os.path.splitext(os.path.basename(xc))[<NUM_LIT:0>]<EOL>catshortname = catshortname.replace('<STR_LIT>','<STR_LIT>')<EOL>objra, objdecl = (catarr[catdefdict['<STR_LIT>']],<EOL>catarr[catdefdict['<STR_LIT>']])<EOL>cosdecl = np.cos(np.radians(objdecl))<EOL>sindecl = np.sin(np.radians(objdecl))<EOL>cosra = np.cos(np.radians(objra))<EOL>sinra = np.sin(np.radians(objra))<EOL>xyz = np.column_stack((cosra*cosdecl,sinra*cosdecl, sindecl))<EOL>kdt = cKDTree(xyz,copy_data=True)<EOL>catoutdict = {'<STR_LIT>':kdt,<EOL>'<STR_LIT:data>':catarr,<EOL>'<STR_LIT>':xk,<EOL>'<STR_LIT>':catcolnames,<EOL>'<STR_LIT>':catcolunits,<EOL>'<STR_LIT:name>':catdefdict['<STR_LIT:name>'],<EOL>'<STR_LIT>':catdefdict['<STR_LIT:description>']}<EOL>outdict[catshortname] = catoutdict<EOL><DEDENT>if outfile is not None:<EOL><INDENT>if sys.platform == '<STR_LIT>':<EOL><INDENT>dumpbytes = pickle.dumps(outdict, protocol=pickle.HIGHEST_PROTOCOL)<EOL>max_bytes = <NUM_LIT:2>**<NUM_LIT> - <NUM_LIT:1><EOL>with open(outfile, '<STR_LIT:wb>') as outfd:<EOL><INDENT>for idx in range(<NUM_LIT:0>, len(dumpbytes), max_bytes):<EOL><INDENT>outfd.write(dumpbytes[idx:idx+max_bytes])<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>with open(outfile, '<STR_LIT:wb>') as outfd:<EOL><INDENT>pickle.dump(outdict, outfd, pickle.HIGHEST_PROTOCOL)<EOL><DEDENT><DEDENT>return outfile<EOL><DEDENT>else:<EOL><INDENT>return outdict<EOL><DEDENT>
This loads the external xmatch catalogs into a dict for use in an xmatch.

    Parameters
    ----------

    xmatchto : list of str
        This is a list of paths to all the catalog text files that will be
        loaded.

        The text files must be 'CSVs' that use the '|' character as the
        separator betwen columns. These files should all begin with a header in
        JSON format on lines starting with the '#' character. this header will
        define the catalog and contains the name of the catalog and the column
        definitions. Column definitions must have the column name and the numpy
        dtype of the columns (in the same format as that expected for the
        numpy.genfromtxt function). Any line that does not begin with '#' is
        assumed to be part of the columns in the catalog. An example is shown
        below::

            # {"name":"NSVS catalog of variable stars",
            #  "columns":[
            #   {"key":"objectid", "dtype":"U20", "name":"Object ID", "unit": null},
            #   {"key":"ra", "dtype":"f8", "name":"RA", "unit":"deg"},
            #   {"key":"decl","dtype":"f8", "name": "Declination", "unit":"deg"},
            #   {"key":"sdssr","dtype":"f8","name":"SDSS r", "unit":"mag"},
            #   {"key":"vartype","dtype":"U20","name":"Variable type", "unit":null}
            #  ],
            #  "colra":"ra",
            #  "coldec":"decl",
            #  "description":"Contains variable stars from the NSVS catalog"}
            objectid1 | 45.0  | -20.0 | 12.0 | detached EB
            objectid2 | 145.0 | 23.0  | 10.0 | RRab
            objectid3 | 12.0  | 11.0  | 14.0 | Cepheid
            .
            .
            .

    xmatchkeys : list of lists
        This is the list of lists of column names (as str) to get out of each
        `xmatchto` catalog. This should be the same length as `xmatchto` and
        each element here will apply to the respective file in `xmatchto`.

    outfile : str or None
        If this is not None, set this to the name of the pickle to write the
        collected xmatch catalogs to. this pickle can then be loaded
        transparently by the :py:func:`astrobase.checkplot.pkl.checkplot_dict`,
        :py:func:`astrobase.checkplot.pkl.checkplot_pickle` functions to provide
        xmatch info to the
        :py:func:`astrobase.checkplot.pkl_xmatch.xmatch_external_catalogs`
        function below.

        If this is None, will return the loaded xmatch catalogs directly. This
        will be a huge dict, so make sure you have enough RAM.

    Returns
    -------

    str or dict
        Based on the `outfile` kwarg, will either return the path to a collected
        xmatch pickle file or the collected xmatch dict.