Skip to content

Commit

Permalink
updates to plot
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrogers committed Nov 8, 2023
1 parent 095e349 commit 2d2e131
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
30 changes: 30 additions & 0 deletions pycinema/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import traceback
import pprint
import re
import numpy as np

class Image():
def __init__(self, channels=None, meta=None):
Expand Down Expand Up @@ -64,6 +65,35 @@ def isNumber(s):
return False
return False

#
# table helper functions
#

#
# get the column index from a table, return -1 on failure
#
def getColumnIndexFromTable(table, colname):
ID = -1

colnames = table[0]
if colname in colnames:
ID = colnames.index(colname)

return ID

#
# get a column of values from a table
#
def getColumnFromTable(table, colname):
colID = getColumnIndexFromTable(table, colname)

if colID == -1:
print("ERROR: no column named \'" + colname + "\'")
return None

else:
return [row [colID] for row in table[1:]]

def getTableExtent(table):
try:
nRows = len(table)
Expand Down
6 changes: 2 additions & 4 deletions pycinema/filters/PlotBarItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ def __init__(self):
)

def _update(self):
xID = self._getColumnIndex(self.inputs.x.get())
xdata = self._getColumnFromTable(xID)
yID = self._getColumnIndex(self.inputs.y.get())
ydata = self._getColumnFromTable(yID)
xdata = self._getColumnFromTable(self.inputs.x.get())
ydata = self._getColumnFromTable(self.inputs.y.get())

out = { 'x' : {
'label' : self.inputs.x.get(),
Expand Down
22 changes: 3 additions & 19 deletions pycinema/filters/PlotItem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycinema import Filter, isNumber
from pycinema import Filter, isNumber, getColumnFromTable

import PIL
import numpy as np
Expand All @@ -15,21 +15,5 @@ class PlotItem(Filter):
def __init__(self, inputs={}, outputs={}):
super().__init__(inputs, outputs)

def _getColumnIndex(self, colname):
ID = 0

colnames = self.inputs.table.get()[0]
ID = colnames.index(colname)

return ID

def _getColumnFromTable(self, colID):
data = self.inputs.table.get()
t = np.array(data)
coldata = t[:, colID]
column = coldata[1:]

if isNumber(column[0]):
return column.astype(float)
else:
return column
def _getColumnFromTable(self, colname):
return getColumnFromTable(self.inputs.table.get(), colname)
6 changes: 2 additions & 4 deletions pycinema/filters/PlotLineItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ def __init__(self):
)

def _update(self):
xID = self._getColumnIndex(self.inputs.x.get())
xdata = self._getColumnFromTable(xID)
yID = self._getColumnIndex(self.inputs.y.get())
ydata = self._getColumnFromTable(yID)
xdata = self._getColumnFromTable(self.inputs.x.get())
ydata = self._getColumnFromTable(self.inputs.y.get())

out = { 'x' : {
'label' : self.inputs.x.get(),
Expand Down
6 changes: 2 additions & 4 deletions pycinema/filters/PlotScatterItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def __init__(self):
)

def _update(self):
xID = self._getColumnIndex(self.inputs.x.get())
xdata = self._getColumnFromTable(xID)
yID = self._getColumnIndex(self.inputs.y.get())
ydata = self._getColumnFromTable(yID)
xdata = self._getColumnFromTable(self.inputs.x.get())
ydata = self._getColumnFromTable(self.inputs.y.get())

out = { 'x' : {
'label' : self.inputs.x.get(),
Expand Down

0 comments on commit 2d2e131

Please sign in to comment.