Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MS structure inspection #86

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions daskms/chunking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-

import os
from os.path import join as pjoin

import numpy as np
import pyrap.tables as pt

from daskms.reads import DatasetFactory


class TableChunking(object):
def __init__(self, ms, group_cols=None, index_cols=None):
self._ms = ms
self._group_cols = group_cols
self._index_cols = index_cols
self._dataset_factory = None

def __call__(self, *args, **kwargs):
if self._dataset_factory is None:
factory = DatasetFactory(self._ms, [],
self._group_cols,
self._index_cols)
self._dataset_factory = factory
else:
factory = self._dataset_factory

table_proxy = factory.table_proxy_factory()

return self.chunk(table_proxy)

def chunk(self, table_proxy):
from pprint import pprint
pprint(inspect_ms(self._ms))

print(table_proxy)


class MSChunking(TableChunking):
pass


# {(subtable, required): number_column}
SUBTABLES = {
("FEED", False): "NUM_RECEPTORS",
("FIELD", False): "NUM_POLY",
("POINTING", False): "NUM_POLY",
("POLARIZATION", True): "NUM_CORR",
("SOURCE", False): "NUM_LINES",
("SPECTRAL_WINDOW", True): "NUM_CHAN"
}


def _inspect_subtables(ms):
for (subtable, required), num_column in SUBTABLES.items():
subtable_path = pjoin(ms, subtable)
subtable_name = "::".join((ms, subtable))

if not os.path.isdir(subtable_path):
if required:
raise ValueError("%s required but not present", subtable)

continue

with pt.table(subtable_name, ack=False, readonly=True) as T:
yield ((subtable, num_column), T.getcol(num_column))


def inspect_ms(ms):
subtables = dict(_inspect_subtables(ms))

ddid_name = "::".join((ms, "DATA_DESCRIPTION"))

spw = subtables[("SPECTRAL_WINDOW", "NUM_CHAN")]
pol = subtables[("POLARIZATION", "NUM_CORR")]

with pt.table(ddid_name, ack=False, readonly=True) as T:
spw_id = T.getcol("SPECTRAL_WINDOW_ID")
pol_id = T.getcol("POLARIZATION_ID")

nchan = spw[spw_id]
ncorr = pol[pol_id]

ddid_shapes = np.stack([nchan, ncorr], axis=1)
return subtables, ddid_shapes






54 changes: 54 additions & 0 deletions daskms/ms_structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-

import os
from os.path import join as pjoin

import numpy as np
import pyrap.tables as pt


SUBTABLES = {
("FEED", False): "NUM_RECEPTORS",
("FIELD", False): "NUM_POLY",
("POINTING", False): "NUM_POLY",
("POLARIZATION", True): "NUM_CORR",
("SOURCE", False): "NUM_LINES",
("SPECTRAL_WINDOW", True): "NUM_CHAN"
}


def _inspect_subtables(ms):
for (subtable, required), num_column in SUBTABLES.items():
subtable_path = pjoin(ms, subtable)
subtable_name = "::".join((ms, subtable))

if not os.path.isdir(subtable_path):
if required:
raise ValueError("%s required but not present", subtable)

continue

with pt.table(subtable_name, ack=False, readonly=True) as T:
yield ((subtable, num_column), T.getcol(num_column))


def inspect_ms(ms):
subtables = dict(_inspect_subtables(ms))

ddid_name = "::".join((ms, "DATA_DESCRIPTION"))

spw = subtables[("SPECTRAL_WINDOW", "NUM_CHAN")]
pol = subtables[("POLARIZATION", "NUM_CORR")]

with pt.table(ddid_name, ack=False, readonly=True) as T:
spw_id = T.getcol("SPECTRAL_WINDOW_ID")
pol_id = T.getcol("POLARIZATION_ID")

nchan = spw[spw_id]
ncorr = pol[pol_id]

ddid_shapes = np.stack([nchan, ncorr], axis=1)
return ddid_shapes



4 changes: 2 additions & 2 deletions daskms/reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def __init__(self, table, select_cols, group_cols, index_cols, **kwargs):
if len(kwargs) > 0:
raise ValueError("Unhandled kwargs: %s" % kwargs)

def _table_proxy_factory(self):
def table_proxy_factory(self):
return TableProxy(pt.table, self.table_path, ack=False,
readonly=True, lockoptions='user',
__executor_key__=executor_key(self.canonical_name))
Expand Down Expand Up @@ -385,7 +385,7 @@ def _group_datasets(self, table_proxy, groups, exemplar_rows, orders):
return datasets

def datasets(self):
table_proxy = self._table_proxy_factory()
table_proxy = self.table_proxy_factory()

# No grouping case
if len(self.group_cols) == 0:
Expand Down
11 changes: 11 additions & 0 deletions daskms/tests/test_chunking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-

import pytest

from daskms.chunking import MSChunking
from daskms.table_proxy import TableProxy

def test_chunking():
chunks = MSChunking("/home/sperkins/data/AF0236_spw01.ms/")

chunks(1, 2)
7 changes: 7 additions & 0 deletions daskms/tests/test_ms_structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-

from daskms.ms_structure import inspect_ms


def test_ms_structure():
print(inspect_ms("/home/sperkins/data/WSRT_multiple.MS_p0"))