first version of loading data
This commit is contained in:
parent
ce756b5327
commit
56ea425a38
Binary file not shown.
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 7.8 KiB |
@ -1,8 +1,12 @@
|
||||
import os
|
||||
import nixio as nix
|
||||
import numpy as np
|
||||
from enum import Enum
|
||||
import datetime as dt
|
||||
|
||||
from numpy.core.defchararray import not_equal
|
||||
from nixview.constants import io_chunksize as chunksize
|
||||
|
||||
|
||||
class ItemDescriptor():
|
||||
def __init__(self, name=None, id=None, type=None, value=None, definition=None, block_id=None, entity_type=None, shape=None, metadata=None, data_type=None, source_id=None, created_at=None, updated_at=None) -> None:
|
||||
@ -104,6 +108,54 @@ class NodeType(Enum):
|
||||
Feature="Feature"
|
||||
|
||||
|
||||
class DataView():
|
||||
|
||||
def __init__(self, item_descriptor, file_handler) -> None:
|
||||
super().__init__()
|
||||
self._item_descriptor = item_descriptor
|
||||
self._file_handler = file_handler
|
||||
self._buffer = None
|
||||
self._full_shape = item_descriptor.shape
|
||||
self._offset = np.zeros(len(self._full_shape), dtype=int)
|
||||
self._count = None
|
||||
self._max_dim = None
|
||||
self.init_buffer()
|
||||
self.request_more()
|
||||
|
||||
def request_more(self):
|
||||
if self.fully_loaded:
|
||||
return
|
||||
data = self._file_handler.request_data(self._item_descriptor, self._offset, self._count)
|
||||
if data is not None and self._buffer is None:
|
||||
self._buffer = data
|
||||
self._offset = data.shape
|
||||
else:
|
||||
print("need to fetch more!")
|
||||
|
||||
def init_buffer(self):
|
||||
buffer_shape = np.zeros(len(self._full_shape), dtype=int)
|
||||
max_dim_count = chunksize
|
||||
max_dim = np.argmax(self._full_shape)
|
||||
for i, d in enumerate(self._full_shape):
|
||||
if i != max_dim:
|
||||
buffer_shape[i] = self._full_shape[i]
|
||||
max_dim_count /= self._full_shape[i]
|
||||
buffer_shape[max_dim] = max_dim_count
|
||||
self._count = buffer_shape
|
||||
self._max_dim = max_dim
|
||||
|
||||
|
||||
@property
|
||||
def fully_loaded(self):
|
||||
return self._buffer is not None and self._full_shape == self._buffer.shape
|
||||
|
||||
def __str__(self) -> str:
|
||||
r = self._item_descriptor.name + " " + str(self._item_descriptor.entity_type)
|
||||
r += "buffer size: " + str(self._buffer.shape) if self._buffer is not None else "" + "\n"
|
||||
r += "chunk size:" + str(self._count)
|
||||
r += "is fully loaded: " + str(self.fully_loaded)
|
||||
return r
|
||||
|
||||
class Singleton(type):
|
||||
_instances = {}
|
||||
def __call__(cls, *args, **kwargs):
|
||||
@ -195,6 +247,17 @@ class FileHandler(metaclass=Singleton):
|
||||
def filename(self):
|
||||
return self._filename
|
||||
|
||||
def request_data(self, entity_descriptor, offset=None, count=None):
|
||||
entity = self._entity_buffer.get(entity_descriptor.id)
|
||||
if entity is None:
|
||||
print("need to do something else")
|
||||
for i, (o, c) in enumerate(zip(offset, count)):
|
||||
if o + c > entity.shape[i]:
|
||||
count[i] = entity.shape[i] - o
|
||||
seg = tuple([slice(o, o + c) for o, c in zip(offset, count)])
|
||||
print(seg)
|
||||
return entity[seg]
|
||||
|
||||
def request_section_descriptor(self, id):
|
||||
fs = self._entity_buffer.get(id)
|
||||
if fs is None:
|
||||
@ -271,6 +334,13 @@ class FileHandler(metaclass=Singleton):
|
||||
src = e.source if hasattr(e, "source") else None
|
||||
itd.source_id = src.id if src is not None else None
|
||||
infos.append(itd)
|
||||
if entity_type == NodeType.DataArray:
|
||||
itd.value = "%s %s entries" % (str(e.shape), e.dtype)
|
||||
elif entity_type == NodeType.Tag:
|
||||
point_or_segment = "segment" if e.extent else "point"
|
||||
start = str(e.position)
|
||||
end = ("to " + str(tuple(np.array(e.position) + np.array(e.extent)))) if e.extent else ""
|
||||
itd.value = "tags %s %s %s" %(point_or_segment, start, end)
|
||||
# TODO set the value to something meaningful for the various entity types
|
||||
return infos
|
||||
|
||||
|
@ -4,11 +4,12 @@ import matplotlib
|
||||
matplotlib.use('Qt5Agg')
|
||||
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
import nixio as nix
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.widgets import Slider
|
||||
import nixio as nix
|
||||
|
||||
from nixview.file_handler import FileHandler, DataView
|
||||
|
||||
|
||||
|
||||
@ -323,8 +324,9 @@ class MplCanvas(FigureCanvasQTAgg):
|
||||
class PlotScreen(QWidget):
|
||||
close_signal = pyqtSignal()
|
||||
|
||||
def __init__(self, parent) -> None:
|
||||
def __init__(self, parent=None) -> None:
|
||||
super().__init__(parent=parent)
|
||||
self._file_handler = FileHandler()
|
||||
sc = MplCanvas(self, width=5, height=4, dpi=100)
|
||||
sc.axes.plot([0,1,2,3,4], [10,1,20,3,40])
|
||||
|
||||
@ -335,9 +337,16 @@ class PlotScreen(QWidget):
|
||||
close_btn.clicked.connect(self.on_close)
|
||||
|
||||
self.layout().addWidget(close_btn)
|
||||
self._data_view = None
|
||||
|
||||
def on_close(self):
|
||||
self.close_signal.emit()
|
||||
|
||||
def plot(self, item):
|
||||
print("plot!", item)
|
||||
print("plot!", item)
|
||||
print(item.entity_type, item.shape)
|
||||
self._data_view = DataView(item, self._file_handler)
|
||||
self._data_view.request_more()
|
||||
print(self._data_view)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user