def read_and_filter_sqlitecurve(lcfile,<EOL>columns=None,<EOL>sqlfilters=None,<EOL>raiseonfail=False,<EOL>returnarrays=True,<EOL>forcerecompress=False,<EOL>quiet=True):
<EOL>try:<EOL><INDENT>if '<STR_LIT>' in lcfile[-<NUM_LIT:4>:]:<EOL><INDENT>lcf = _uncompress_sqlitecurve(lcfile)<EOL><DEDENT>else:<EOL><INDENT>lcf = lcfile<EOL><DEDENT>db = sql.connect(lcf)<EOL>cur = db.cursor()<EOL>query = ("<STR_LIT>")<EOL>cur.execute(query)<EOL>objectinfo = cur.fetchone()<EOL>query = ("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>cur.execute(query)<EOL>lcinfo = cur.fetchone()<EOL>(lcversion, lcdatarelease, lccols, lcsortcol,<EOL>lcapertures, lcbestaperture,<EOL>objinfocols, objidcol,<EOL>lcunixtime, lcgitrev, lccomment) = lcinfo<EOL>lcapertures = json.loads(lcapertures)<EOL>lcbestaperture = json.loads(lcbestaperture)<EOL>objectinfokeys = objinfocols.split('<STR_LIT:U+002C>')<EOL>objectinfodict = {x:y for (x,y) in zip(objectinfokeys, objectinfo)}<EOL>objectid = objectinfodict[objidcol]<EOL>query = ("<STR_LIT>")<EOL>cur.execute(query)<EOL>filterinfo = cur.fetchall()<EOL>if columns and all([x in lccols.split('<STR_LIT:U+002C>') for x in columns]):<EOL><INDENT>LOGINFO('<STR_LIT>' % columns)<EOL>proceed = True<EOL><DEDENT>elif columns is None:<EOL><INDENT>columns = lccols.split('<STR_LIT:U+002C>')<EOL>proceed = True<EOL><DEDENT>else:<EOL><INDENT>proceed = False<EOL><DEDENT>if not proceed:<EOL><INDENT>if '<STR_LIT>' in lcfile[-<NUM_LIT:4>:] and lcf:<EOL><INDENT>_compress_sqlitecurve(lcf, force=forcerecompress)<EOL><DEDENT>LOGERROR('<STR_LIT>')<EOL>return None, "<STR_LIT>"<EOL><DEDENT>lcdict = {'<STR_LIT>':objectid,<EOL>'<STR_LIT>':objectinfodict,<EOL>'<STR_LIT>':objectinfokeys,<EOL>'<STR_LIT>':lcversion,<EOL>'<STR_LIT>':lcdatarelease,<EOL>'<STR_LIT>':columns,<EOL>'<STR_LIT>':lcsortcol,<EOL>'<STR_LIT>':lcapertures,<EOL>'<STR_LIT>':lcbestaperture,<EOL>'<STR_LIT>':lcunixtime,<EOL>'<STR_LIT>':lcgitrev,<EOL>'<STR_LIT>':lccomment,<EOL>'<STR_LIT>':filterinfo}<EOL>if ((sqlfilters is not None) and<EOL>(isinstance(sqlfilters,str) or<EOL>isinstance(sqlfilters, unicode))):<EOL><INDENT>validatedfilters = _validate_sqlitecurve_filters(sqlfilters,<EOL>lccols.split('<STR_LIT:U+002C>'))<EOL>if validatedfilters is not None:<EOL><INDENT>LOGINFO('<STR_LIT>' % validatedfilters)<EOL>filtersok = True<EOL><DEDENT>else:<EOL><INDENT>filtersok = False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>validatedfilters = None<EOL>filtersok = None<EOL><DEDENT>if validatedfilters is not None:<EOL><INDENT>query = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>).format(<EOL>columns='<STR_LIT:U+002C>'.join(columns),  <EOL>sqlfilter=validatedfilters,<EOL>sortcol=lcsortcol<EOL>)<EOL>lcdict['<STR_LIT>'] = validatedfilters<EOL><DEDENT>else:<EOL><INDENT>query = ("<STR_LIT>") % (<EOL>'<STR_LIT:U+002C>'.join(columns),<EOL>lcsortcol<EOL>)<EOL><DEDENT>cur.execute(query)<EOL>lightcurve = cur.fetchall()<EOL>if lightcurve and len(lightcurve) > <NUM_LIT:0>:<EOL><INDENT>lightcurve = list(zip(*lightcurve))<EOL>lcdict.update({x:y for (x,y) in zip(lcdict['<STR_LIT>'],<EOL>lightcurve)})<EOL>lcok = True<EOL>lcdict['<STR_LIT>']['<STR_LIT>'] = len(lightcurve[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>LOGWARNING('<STR_LIT>' % lcdict['<STR_LIT>'])<EOL>lcdict.update({x:y for (x,y) in<EOL>zip(lcdict['<STR_LIT>'],<EOL>[[] for x in lcdict['<STR_LIT>']])})<EOL>lcok = False<EOL><DEDENT>if filtersok is True and lcok:<EOL><INDENT>statusmsg = '<STR_LIT>'<EOL><DEDENT>elif filtersok is None and lcok:<EOL><INDENT>statusmsg = '<STR_LIT>'<EOL><DEDENT>elif filtersok is False and lcok:<EOL><INDENT>statusmsg = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>statusmsg = '<STR_LIT>'<EOL><DEDENT>returnval = (lcdict, statusmsg)<EOL>if '<STR_LIT>' in lcfile[-<NUM_LIT:4>:] and lcf:<EOL><INDENT>_compress_sqlitecurve(lcf, force=forcerecompress)<EOL><DEDENT>if returnarrays:<EOL><INDENT>for column in lcdict['<STR_LIT>']:<EOL><INDENT>lcdict[column] = np.array([x if x is not None else np.nan<EOL>for x in lcdict[column]])<EOL><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>if not quiet:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>' % lcfile)<EOL><DEDENT>returnval = (None, '<STR_LIT>')<EOL>if '<STR_LIT>' in lcfile[-<NUM_LIT:4>:] and lcf:<EOL><INDENT>_compress_sqlitecurve(lcf, force=forcerecompress)<EOL><DEDENT>if raiseonfail:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>return returnval<EOL>
This reads a HAT sqlitecurve and optionally filters it.

    Parameters
    ----------

    lcfile : str
        The path to the HAT sqlitecurve file.

    columns : list
        A list of columns to extract from the ligh curve file. If None, then
        returns all columns present in the latest `columnlist` in the light
        curve.

    sqlfilters : list of str
        If no None, it must be a list of text SQL filters that apply to the
        columns in the lightcurve.

    raiseonfail : bool
        If this is True, an Exception when reading the LC will crash the
        function instead of failing silently and returning None as the result.

    returnarrays : bool
        If this is True, the output lcdict contains columns as np.arrays instead
        of lists. You generally want this to be True.

    forcerecompress : bool
        If True, the sqlitecurve will be recompressed even if a compressed
        version of it is found. This usually happens when sqlitecurve opening is
        interrupted by the OS for some reason, leaving behind a gzipped and
        un-gzipped copy. By default, this function refuses to overwrite the
        existing gzipped version so if the un-gzipped version is corrupt but
        that one isn't, it can be safely recovered.

    quiet : bool
        If True, will not warn about any problems, even if the light curve
        reading fails (the only clue then will be the return value of
        None). Useful for batch processing of many many light curves.

    Returns
    -------

    tuple : (lcdict, status_message)
        A two-element tuple is returned, with the first element being the
        lcdict.