Exemplo n.º 1
0
def sample(data, fraction=0.1):
    from booq import utils
    if utils.is_number(data):
        return sample_rows(data, fraction)
    else:
        assert utils.is_array(data), "Currently, array objects accepted are numpy's"
        return sample_array(data, fraction)
Exemplo n.º 2
0
 def read(self, columns=None, rows=None, ucds=None, match_ucds='any'):
     '''
     '''
     from booq.utils import is_number
     if is_number(rows):
         logging.debug("Argument 'rows' is a number.")
         from booq.data.utils import sample
         rows = sample(self.nrows,fraction=rows)
     if ucds:
         logging.info("using 'ucds' to define 'columns' to read.")
         logging.debug("'ucds' requested: {!s}".format(ucds))
         ucdcols = self.colnames_by_ucd(ucds, match=match_ucds)
         if ucdcols:
             if not columns:
                 columns = []
             columns.extend(ucdcols)
             #REVIEW: do not guarantee order of columns after 'set'
             columns = list(set(columns))
     logging.debug("'columns' to be read: {!s}".format(columns))
     data,meta = read_from_handler(self._handler, columns=columns, rows=rows)
     return Fits(data,meta,self)