[file_handler] add best xdim, suggested plotter to item Description
This commit is contained in:
parent
b388c7c68c
commit
d2e58b9a6f
@ -1,29 +1,7 @@
|
|||||||
import nixio as nix
|
import nixio as nix
|
||||||
|
|
||||||
|
|
||||||
def guess_best_xdim(array):
|
|
||||||
data_extent = array.shape
|
|
||||||
if len(data_extent) > 2:
|
|
||||||
print("Cannot handle more than 2D, sorry!")
|
|
||||||
if len(data_extent) == 1:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
d1 = array.dimensions[0]
|
|
||||||
d2 = array.dimensions[1]
|
|
||||||
|
|
||||||
if d1.dimension_type == nix.DimensionType.Sample:
|
|
||||||
return 0
|
|
||||||
elif d2.dimension_type == nix.DimensionType.Sample:
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
if (d1.dimension_type == nix.DimensionType.Set) and \
|
|
||||||
(d2.dimension_type == nix.DimensionType.Range):
|
|
||||||
return 1
|
|
||||||
elif (d1.dimension_type == nix.DimensionType.Range) and \
|
|
||||||
(d2.dimension_type == nix.DimensionType.Set):
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
def suggested_plotter(array):
|
def suggested_plotter(array):
|
||||||
|
@ -17,6 +17,8 @@ class ItemDescriptor():
|
|||||||
self.source_id = source_id
|
self.source_id = source_id
|
||||||
self.created_at = None
|
self.created_at = None
|
||||||
self.updated_at = None
|
self.updated_at = None
|
||||||
|
self.best_xdim = None
|
||||||
|
self.suggested_plotter = None
|
||||||
|
|
||||||
def to_html(self):
|
def to_html(self):
|
||||||
descr = "<html><h4>%s: %s</h4>" % (self.type, self.name)
|
descr = "<html><h4>%s: %s</h4>" % (self.type, self.name)
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
from nixview.file_utils import suggested_plotter
|
||||||
import os
|
import os
|
||||||
import nixio as nix
|
import nixio as nix
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from nixview.util.descriptors import FileDescriptor, ItemDescriptor
|
from nixview.util.descriptors import FileDescriptor, ItemDescriptor
|
||||||
from nixview.util.enums import NodeType
|
from nixview.util.enums import NodeType, PlotterTypes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -197,6 +198,8 @@ class FileHandler(metaclass=Singleton):
|
|||||||
infos.append(itd)
|
infos.append(itd)
|
||||||
if entity_type == NodeType.DataArray:
|
if entity_type == NodeType.DataArray:
|
||||||
itd.value = "%s %s entries" % (str(e.shape), e.dtype)
|
itd.value = "%s %s entries" % (str(e.shape), e.dtype)
|
||||||
|
itd.best_xdim = self.guess_best_xdim(e)
|
||||||
|
itd.suggested_plotter = self.suggested_plotter(e)
|
||||||
elif entity_type == NodeType.Tag:
|
elif entity_type == NodeType.Tag:
|
||||||
point_or_segment = "segment" if e.extent else "point"
|
point_or_segment = "segment" if e.extent else "point"
|
||||||
start = str(e.position)
|
start = str(e.position)
|
||||||
@ -285,4 +288,74 @@ class FileHandler(metaclass=Singleton):
|
|||||||
sources = []
|
sources = []
|
||||||
for src in srcs:
|
for src in srcs:
|
||||||
sources.extend(get_subsources(src))
|
sources.extend(get_subsources(src))
|
||||||
return sources
|
return sources
|
||||||
|
|
||||||
|
def guess_best_xdim(self, array):
|
||||||
|
data_extent = array.shape
|
||||||
|
if len(data_extent) > 2:
|
||||||
|
print("Cannot handle more than 2D, sorry!")
|
||||||
|
return None
|
||||||
|
if len(data_extent) == 1:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
d1 = array.dimensions[0]
|
||||||
|
d2 = array.dimensions[1]
|
||||||
|
|
||||||
|
if d1.dimension_type == nix.DimensionType.Sample:
|
||||||
|
return 0
|
||||||
|
elif d2.dimension_type == nix.DimensionType.Sample:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
if (d1.dimension_type == nix.DimensionType.Set) and \
|
||||||
|
(d2.dimension_type == nix.DimensionType.Range):
|
||||||
|
return 1
|
||||||
|
elif (d1.dimension_type == nix.DimensionType.Range) and \
|
||||||
|
(d2.dimension_type == nix.DimensionType.Set):
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def suggested_plotter(self, array):
|
||||||
|
if len(array.dimensions) > 3:
|
||||||
|
print("cannot handle more than 3D")
|
||||||
|
return None
|
||||||
|
dim_types = [d.dimension_type for d in array.dimensions]
|
||||||
|
dim_count = len(dim_types)
|
||||||
|
if dim_count == 1:
|
||||||
|
if dim_types[0] == nix.DimensionType.Sample:
|
||||||
|
return PlotterTypes.LinePlotter
|
||||||
|
elif dim_types[0] == nix.DimensionType.Range:
|
||||||
|
if array.dimensions[0].is_alias:
|
||||||
|
return PlotterTypes.EventPlotter
|
||||||
|
else:
|
||||||
|
return PlotterTypes.LinePlotter
|
||||||
|
elif dim_types[0] == nix.DimensionType.Set:
|
||||||
|
return PlotterTypes.CategoryPlotter
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
elif dim_count == 2:
|
||||||
|
if dim_types[0] == nix.DimensionType.Sample:
|
||||||
|
if dim_types[1] == nix.DimensionType.Sample or \
|
||||||
|
dim_types[1] == nix.DimensionType.Range:
|
||||||
|
return PlotterTypes.ImagePlotter
|
||||||
|
else:
|
||||||
|
return PlotterTypes.LinePlotter
|
||||||
|
elif dim_types[0] == nix.DimensionType.Range:
|
||||||
|
if dim_types[1] == nix.DimensionType.Sample or \
|
||||||
|
dim_types[1] == nix.DimensionType.Range:
|
||||||
|
return PlotterTypes.ImagePlotter
|
||||||
|
else:
|
||||||
|
return PlotterTypes.LinePlotter
|
||||||
|
elif dim_types[0] == nix.DimensionType.Set:
|
||||||
|
if dim_types[1] == nix.DimensionType.Sample or \
|
||||||
|
dim_types[1] == nix.DimensionType.Range:
|
||||||
|
return PlotterTypes.LinePlotter
|
||||||
|
else:
|
||||||
|
return PlotterTypes.CategoryPlotter
|
||||||
|
else:
|
||||||
|
print("Sorry, not a supported combination of dimensions!")
|
||||||
|
return None
|
||||||
|
elif dim_count == 3:
|
||||||
|
return PlotterTypes.ImagePlotter
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user