Esempio n. 1
0
def test_table_exists(tmp_path):
    ms_path = tmp_path / "test.ms"
    ms_path.mkdir(parents=True, exist_ok=False)
    assert table_exists(str(ms_path)) is True

    ant_path = ms_path / "ANTENNA"
    ant_path.mkdir(parents=True, exist_ok=False)
    # Both the directory and canonical subtable access forms work
    assert table_exists(str(ant_path))
    assert table_exists('::'.join((str(ms_path), "ANTENNA")))
Esempio n. 2
0
    def __init__(self, table, select_cols, group_cols, index_cols, **kwargs):
        if not table_exists(table):
            raise ValueError("'%s' does not appear to be a CASA Table" % table)

        chunks = kwargs.pop('chunks', [{'row': _DEFAULT_ROW_CHUNKS}])

        # Create or promote chunks to a list of dicts
        if isinstance(chunks, dict):
            chunks = [chunks]
        elif not isinstance(chunks, (tuple, list)):
            raise TypeError("'chunks' must be a dict or sequence of dicts")

        self.canonical_name = table
        self.table_path = str(Path(*table_path_split(table)))
        self.select_cols = select_cols
        self.group_cols = [] if group_cols is None else group_cols
        self.index_cols = [] if index_cols is None else index_cols
        self.chunks = chunks
        self.table_schema = kwargs.pop('table_schema', None)
        self.taql_where = kwargs.pop('taql_where', '')
        self.table_keywords = kwargs.pop('table_keywords', False)
        self.column_keywords = kwargs.pop('column_keywords', False)
        self.table_proxy = kwargs.pop('table_proxy', False)

        if len(kwargs) > 0:
            raise ValueError("Unhandled kwargs: %s" % kwargs)
Esempio n. 3
0
def write_datasets(table,
                   datasets,
                   columns,
                   descriptor=None,
                   table_keywords=None,
                   column_keywords=None):
    # Promote datasets to list
    if isinstance(datasets, tuple):
        datasets = list(datasets)
    elif not isinstance(datasets, list):
        datasets = [datasets]

    # If ALL is requested
    if columns == "ALL":
        columns = list(set(ds.data_vars.keys()) for ds in datasets)

        if len(columns) > 0:
            columns = list(sorted(set.union(*columns)))

    if not table_exists(table):
        table_proxy = _create_table(table, datasets, columns, descriptor)
    else:
        table_proxy = _updated_table(table, datasets, columns, descriptor)

    return _write_datasets(table,
                           table_proxy,
                           datasets,
                           columns,
                           descriptor=descriptor,
                           table_keywords=table_keywords,
                           column_keywords=column_keywords)