J-Express forum

J-Express => Jython Scripting => Topic started by: Bjarte Dysvik on September 30, 2005, 12:54:36 PM



Title: clone a dataset, modify and put in tree
Post by: Bjarte Dysvik on September 30, 2005, 12:54:36 PM
This script will clone a dataset and make a data-column be column+column[i+1]. It will also create new identifiers for the column data. It can be easily modified to let a column be for instance ratio of two column in a dataset compiled of [channel1][channel2][channel1][channel2] etc..



#description: Clone a dataset, modify and put in project tree

from java.lang import String

#The column in the identifiers having a concatenated string with calls
APMColumn = 2

inf = data.getInfos()
n=data.getDataLength()
m=data.getDataWidth()

   
a = data.clone()

a.setFile("extracted from python")
dat = data.getData()


newdata = []

for i in range(n):
   newline = []
   for j in range(m/2):
      newline=newline+[ dat[j*2]+dat[(2*j)+1] ]

   newdata = newdata+[newline]



a.removeFromParent()
main.addNode(a,data)
a.unLink(0)

a.setData(newdata)

newcolumnID = []
for j in range(m):
   newColumn =["column "+String.valueOf(j)]
   newcolumnID=newcolumnID+[newColumn]

print(newcolumnID)

a.setColInfos(newcolumnID)


a.setColInfoHeaders( ["New identifiers"] )