Fill the cache from the `astropy.table.Table`
344939
def _fill_cache(self):
        """"""
        for irow in range(len(self._table)):
            job_details = self.make_job_details(irow)
            self._cache[job_details.fullkey] = job_details
112621
def flush(self):
        """"""
        self.log.info('Flushing tables and arrays to disk...')
        for tab in self._tables.values():
            tab.flush()
        self._write_ndarrays_cache_to_disk()
501365
def _fill_result_cache(self):
        

        idx = 0
        try:
            while True:
                idx += 1000
                self._fill_result_cache_to_idx(idx)
        except StopIteration:
            pass

        self._count = len(self._result_cache)
150589
def refresh_table(self):
        """"""
        if self.is_visible and self.isVisible():
            self.shellwidget.refresh_namespacebrowser()
            try:
                self.editor.resizeRowToContents()
            except TypeError:
                pass
310449
def _read_table_file(self, table_file):
        """"""
        self._table_file = table_file
        if os.path.exists(self._table_file):
            self._table = Table.read(self._table_file, hdu='JOB_ARCHIVE')
            self._table_ids = Table.read(self._table_file, hdu='FILE_IDS')
        else:
            self._table, self._table_ids = JobDetails.make_tables({})
        self._table_id_array = self._table_ids['file_id'].data
        self._fill_cache()
149396
def fill_in_table(self, table, worksheet, flags):
        '''
        
        '''
        max_row = 0
        min_row = sys.maxint
        for row in table:
            if len(row) > max_row:
                max_row = len(row)
            if len(row) < min_row:
                min_row = len(row)
        if max_row != min_row:
            for row in table:
                if len(row) < max_row:
                    row.extend([None]*(max_row-len(row)))
1298060
def get_cached_data(datatable, **kwargs):
    
    cache_key = '%s%s' % (CACHE_PREFIX, datatable.get_cache_key(**kwargs))
    data = cache.get(cache_key)
    log.debug("Reading data from cache at %r: %r", cache_key, data)
    return data
347428
def _init_jobs_table():
    """"""
    _jobs_table = sqlalchemy.Table(
        'jobs', _METADATA,
        sqlalchemy.Column('job_id', sqlalchemy.UnicodeText, primary_key=True),
        sqlalchemy.Column('job_type', sqlalchemy.UnicodeText),
        sqlalchemy.Column('status', sqlalchemy.UnicodeText, index=True),
        sqlalchemy.Column('data', sqlalchemy.UnicodeText),
        sqlalchemy.Column('error', sqlalchemy.UnicodeText),
        sqlalchemy.Column('requested_timestamp', sqlalchemy.DateTime),
        sqlalchemy.Column('finished_timestamp', sqlalchemy.DateTime),
        sqlalchemy.Column('sent_data', sqlalchemy.UnicodeText),
        # Callback URL:
        sqlalchemy.Column('result_url', sqlalchemy.UnicodeText),
        # CKAN API key:
        sqlalchemy.Column('api_key', sqlalchemy.UnicodeText),
        # Key to administer job:
        sqlalchemy.Column('job_key', sqlalchemy.UnicodeText),
        )
    return _jobs_table
1048370
def load_table(self, table):
        
        table = self._valid_table_name(table)
        schema, table = self.parse_table_name(table)
        if not schema:
            schema = self.schema
            tables = self.tables
        else:
            tables = self.tables_in_schema(schema)
        if table in tables:
            return Table(self, schema, table)
        else:
            return None
583335
def loader(filepath, logger=None, **kwargs):
    
    # see ginga.util.loader module
    # TODO: return an AstroTable if loading a table, etc.
    #   for now, assume always an image
    from ginga import AstroImage
    image = AstroImage.AstroImage(logger=logger)

    with asdf.open(filepath) as asdf_f:
        #image.load_asdf(asdf_f, **kwargs)
        image.load_asdf(asdf_f)

    return image
1108259
def from_(self, table, alias=None):
        
        if isinstance(table, str):
            table = [[table, alias]]
        self.raw_tables = table
        return self
508839
def add_cache(self, namespace, key, query_hash, length, cache):
        """"""
        start = 0
        bulk_insert = self.bulk_insert
        cache_len = len(cache)
        row = '(%s,%s,%s,%s,%s,%s)'
        query = 'INSERT INTO gauged_cache ' \
            '(namespace, key, "hash", length, start, value) VALUES '
        execute = self.cursor.execute
        query_hash = self.psycopg2.Binary(query_hash)
        while start < cache_len:
            rows = cache[start:start+bulk_insert]
            params = []
            for timestamp, value in rows:
                params.extend((namespace, key, query_hash, length,
                               timestamp, value))
            insert = (row + ',') * (len(rows) - 1) + row
            execute(query + insert, params)
            start += bulk_insert
        self.db.commit()
670823
def put_cache(self, minions):
        '''
        
        '''
        self.cupd_out.send(self.serial.dumps(minions))
1012942
def _cache_dataset(dataset, prefix):
    
    if not os.path.exists(_constants.CACHE_PATH):
        os.makedirs(_constants.CACHE_PATH)
    src_data = np.concatenate([e[0] for e in dataset])
    tgt_data = np.concatenate([e[1] for e in dataset])
    src_cumlen = np.cumsum([0]+[len(e[0]) for e in dataset])
    tgt_cumlen = np.cumsum([0]+[len(e[1]) for e in dataset])
    np.savez(os.path.join(_constants.CACHE_PATH, prefix + '.npz'),
             src_data=src_data, tgt_data=tgt_data,
             src_cumlen=src_cumlen, tgt_cumlen=tgt_cumlen)
1373339
def fill(image, mask=None, iterations=1):
    '''
    '''
    global fill_table
    if mask is None:
        masked_image = image
    else:
        masked_image = image.astype(bool).copy()
        masked_image[~mask] = True
    result = table_lookup(masked_image, fill_table, True, iterations)
    if not mask is None:
        result[~mask] = image[~mask]
    return result
1269506
def load_data(self, table_name, obj, **kwargs):
        
        # kwargs is a catch all for any options required by other backends.
        self.dictionary[table_name] = pd.DataFrame(obj)
442484
def refresh(self, fetch_data):
        
        self.win.erase()
        height, width = getmaxyx()
        if curses.is_term_resized(height, width):
            self.win.clear()
            curses.resizeterm(height, width)
        y = 1  # Starts at 1 because of date string
        x = 0
        columns = []
        column = []
        for table in self._tables:
            desc = self.engine.describe(table, fetch_data, True)
            line_count = 1 + 2 * len(desc.consumed_capacity)
            if (column or columns) and line_count + y > height:
                columns.append(column)
                column = []
                y = 1
            y += line_count
            column.append(desc)

        columns.append(column)
        y = 1

        # Calculate the min width of each column
        column_widths = []
        for column in columns:
            column_widths.append(max(map(self._calc_min_width, column)))
        # Find how many columns we can support
        while len(columns) > 1 and sum(column_widths) > width - len(columns) + 1:
            columns.pop()
            column_widths.pop()
        effective_width = width - len(columns) + 1
        # Iteratively expand columns until we fit the width or they are all max
        while sum(column_widths) < effective_width and any(
            (w < self._max_width for w in column_widths)
        ):
            smallest = min(column_widths)
            i = column_widths.index(smallest)
            column_widths[i] += 1

        status = datetime.now().strftime("%H:%M:%S")
        status += " %d tables" % len(self._tables)
        num_displayed = sum(map(len, columns))
        if num_displayed < len(self._tables):
            status += " (%d visible)" % num_displayed
        self.win.addstr(0, 0, status[:width])

        for column, col_width in zip(columns, column_widths):
            for table in column:
                cap = table.consumed_capacity["__table__"]
                self.win.addstr(y, x, table.name, curses.color_pair(1))
                self._add_throughput(
                    y + 1, x, col_width, "R", "", table.read_throughput, cap["read"]
                )
                self._add_throughput(
                    y + 2, x, col_width, "W", "", table.write_throughput, cap["write"]
                )
                y += 3
                for index_name, cap in iteritems(table.consumed_capacity):
                    if index_name == "__table__":
                        continue
                    index = table.global_indexes[index_name]
                    self._add_throughput(
                        y,
                        x,
                        col_width,
                        "R",
                        index_name,
                        index.read_throughput,
                        cap["read"],
                    )
                    self._add_throughput(
                        y + 1,
                        x,
                        col_width,
                        "W",
                        index_name,
                        index.write_throughput,
                        cap["write"],
                    )
                    y += 2
            x += col_width + 1
            y = 1

        self.win.refresh()