예제 #1
0
def new_table(spj, element):

    # Create field infos
    formats = []
    info_dict = {}
    for eColumn in element.findall("Column"):
        # name
        try:
            name = eColumn.attrib["name"]
        except KeyError:
            logger.warn("Could not get column name; using default name instead.")
            name = utils.unique_names(["col"], info_dict.keys())

        # format
        try:
            format = eColumn.attrib["format"]
        except KeyError:
            logger.warn("Could not get column type, using default type instead.")
            format = "f4"
        formats.append(format)

        # create info with attributes
        info = Table.Info()
        for eAttribute in eColumn.findall("Attribute"):
            key = eAttribute.attrib["key"]
            value = eAttribute.text
            if value is not None:
                info.set_value(key, value)
        info_dict[name] = info

    # create table with given format and infos, but w/o any rows
    a = numpy.zeros((0,), {"names": info_dict.keys(), "formats": formats})
    tbl = Table(a, info_dict)

    # node info
    for eItem in element.findall("NodeInfo/Item"):
        key = eItem.attrib["key"]
        value = eItem.text
        if value is not None:
            tbl.node_info.set_value(key, value)

    for eItem in element.findall("NodeInfo/MetaItem"):
        key = eItem.attrib["key"]
        value = eItem.text
        if value is not None:
            tbl.node_info.metadata[key] = value

    # table key is essential
    try:
        key = element.attrib["key"]
    except KeyError:
        logger.warn("Could not get table key. Using generic key instead.")
        key = pdict.unique_key(spj.datasets, "dataset")
    tbl.key = key

    # Right now, the Table is still empty. By setting this callback
    # for the _import attribute, the dataset is loaded from the hard
    # disk on the next access.
    tbl._import = DatasetImporter(spj.get_filename(), tbl.key)
    return tbl
예제 #2
0
def add_experimental_plot(project, undolist=None):

    if undolist is None:
        undolist = project.journal

    ul = UndoList().describe("Experimental Plot")

    a = numpy.array(
        [(1,1),
         (2,4),
         (3,9),
         (4,16),
         (5,25)],
         dtype = {'names':['col1','col2'],
                  'formats':['f4','f4']}
         )
    ds = Table(a)
    ds.infos['col2'].designation = 'Y'
    ds.key = pdict.unique_key(project.datasets, "exp_ds")


    a = numpy.array(
        [(10,12),
         (11,14),
         (13,-5),
         (16,8),
         (18,0)],
         dtype = {'names':['col3','col4'],
                  'formats':['f4','f4']}
         )

    ds2 = Table(a)
    ds2.infos['col4'].designation = 'Y'        
    ds2.key = pdict.unique_key(project.datasets, "exp_ds2")

    plot = Plot()
    plot.key = pdict.unique_key(project.plots, "exp_plot")
    layer1 = Layer(type="line2d",
                   lines=[Line(source=ds,cx=0,cy=1),
                          Line(source=ds2,cx=0,cy=1)],
                   x=0.0, y=0.0, width=1.0, height=0.5)
#     layer2 = Layer(type="line2d",
#                    lines=[Line(source=ds2,cx=0,cy=1)],
#                    x=0.0, y=0.5, width=1.0, height=0.5)
#     plot.layers = [layer1, layer2]
    plot.layers = [layer1]
    
    project.add_datasets([ds,ds2], undolist=ul)
    #project.add_dataset(ds, undolist=ul)
    project.add_plot(plot, undolist=ul)
    undolist.append(ul)
예제 #3
0
        return self.get_columns().index(column)
        #return self.get_columns().index(column) - 1



# register only for pygtk < 2.8
if gtk.pygtk_version[1] < 8:
    gobject.type_register(DatasetView)




###############################################################################

if __name__ == "__main__":

    win = gtk.Window()
    win.connect("destroy", gtk.main_quit)

    ds = Table( numpy.array([(1,2,3),(4,5,6)]) )
#    ds = setup_test_dataset()
#    ds.remove(0)
    ds.dump()
    print ds.nrows

    dsview = DatasetView(None,ds)
    win.add(dsview)
    
    win.show_all()
    gtk.main()