Skip to content

Commit

Permalink
enh: support reading 'tables' from DCOR datasets (close #221)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed May 3, 2023
1 parent 4b68e71 commit 7d1b68c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.50.2
- enh: support reading 'tables' from DCOR datasets (#221)
0.50.1
- enh: support reading 'logs' from DCOR datasets
- enh: hierarchy parents inherit their parent's logs and tables
Expand Down
35 changes: 35 additions & 0 deletions dclab/rtdc_dataset/fmt_dcor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import re
import time

import numpy as np

from ...util import hashobj

from ..config import Configuration
Expand Down Expand Up @@ -141,6 +143,36 @@ def _logs(self):
return self.api.get(query="logs")


class DCORTables:
def __init__(self, api):
self.api = api

def __getitem__(self, key):
return self._tables[key]

def __len__(self):
return len(self._tables)

def keys(self):
return self._tables.keys()

@property
@functools.lru_cache()
def _tables(self):
table_data = self.api.get(query="tables")
# assemble the tables
tables = {}
for key in table_data:
columns, data = table_data[key]
ds_dt = np.dtype({'names': columns,
'formats': [float] * len(columns)})
tab_data = np.asarray(data)
rec_arr = np.rec.array(tab_data, dtype=ds_dt)
tables[key] = rec_arr

return tables


class RTDC_DCOR(RTDCBase):
def __init__(self, url, host="dcor.mpl.mpg.de", api_key="",
use_ssl=None, cert_path=None, *args, **kwargs):
Expand Down Expand Up @@ -199,6 +231,9 @@ def __init__(self, url, host="dcor.mpl.mpg.de", api_key="",
# Lazy logs
self.logs = DCORLogs(self.api)

# Lazy tables
self.tables = DCORTables(self.api)

# Get size
self._size = int(self.api.get(query="size"))

Expand Down

0 comments on commit 7d1b68c

Please sign in to comment.