add file utils, let's see if actually required
This commit is contained in:
parent
56ea425a38
commit
dcdfbd0ce4
79
nixview/file_utils.py
Normal file
79
nixview/file_utils.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import nixio as nix
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
class PlotterTypes(Enum):
|
||||||
|
ImagePlotter = "image"
|
||||||
|
LinePlotter = "line"
|
||||||
|
CategoryPlotter = "category"
|
||||||
|
EventPlotter = "event"
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
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