Пример #1
0
def get_rec_dtype(em):
    bad_fields = []
    # Check if already have data type information for this class.
    # Create it otherwise.    
    if em.class_ in dtype_table:
        dtype = dtype_table[em.class_]
    else:
        print 'Creating entries for class:', obj.class_
        fielddict = moose__.getFieldDict(obj.class_, 'valueFinfo')
        print fielddict
        keys = sorted(list(fielddict.keys()))
        fields = [] # [('path', 'S1024')]
        for fieldname in keys:
            ftype = fielddict[fieldname]
            # If we do not have the type of this field in cpp-np data
            # type map, skip it. We can handle vectors as nested
            # table, but the problem with that is numpy requires all
            # entries to have a fixed size for this table. Since
            # vectors can have arbitrary length, we cannot get such a
            # fixed size without checking the size of the vector field
            # in all elements.
            if ftype in cpptonp:
                fields.append((fieldname, cpptonp[ftype]))
        dtype_table[obj.class_] = np.dtype(fields)
        return dtype_table[obj.class_]
Пример #2
0
def get_rec_dtype(em):
    bad_fields = []
    # Check if already have data type information for this class.
    # Create it otherwise.
    if em.className in dtype_table:
        dtype = dtype_table[em.className]
    else:
        print('Creating entries for class:', em.className)
        fielddict = moose.getFieldDict(em.className, 'valueFinfo')
        print(fielddict)

        # If we do not have the type of this field in cpp-np data
        # type map, skip it. We can handle vectors as nested
        # table, but the problem with that is numpy requires all
        # entries to have a fixed size for this table. Since
        # vectors can have arbitrary length, we cannot get such a
        # fixed size without checking the size of the vector field
        # in all elements.
        fields = [
            (fieldname, cpptonp[ftype])  # [('path', 'S1024')]
            for fieldname, ftype in sorted(fielddict.items())
            if ftype in cpptonp
        ]
        dtype_table[em.className] = np.dtype(fields)
        return dtype_table[em.className]
Пример #3
0
def test_other():
    a1 = moose.Pool('/ada')
    assert a1.className == 'Pool', a1.className
    finfo = moose.getFieldDict(a1.className)
    s = moose.Streamer('/asdada')
    p = moose.PulseGen('pg1')
    assert p.delay[0] == 0.0
    p.delay[1] = 0.99
    assert p.delay[1] == 0.99, p.delay[1]
Пример #4
0
    def __init__(self, mooseObject, parent=None):
        """Set up the model. 

        The table model has one moose field in each row.  A field that
        has a set method is editable. Fields listed in extra_fields
        are not shown.

        Members:

        fields -- list of the names of the fields in the object.

        plotNames -- lists the names of the available plot
                     windows. These are displayed as the targets in
                     the plot submenu / combobox.

        fieldFlags -- flags for each field. We calculate these ahead
                      of time by checking if the field can be set, if
                      it is a numerical (so can be dragged to a plot
                      window).

        """
        QtCore.QAbstractTableModel.__init__(self, parent)
        self.mooseObject = mooseObject
        self._header = ('Field', 'Value')
        self.fields = []
        self.plotNames = ['None']
        self.fieldFlags = {}
        self.fieldPlotNameMap = {}
        try:
            self.mooseObject = moose.element(mooseObject.getId())

        except AttributeError:
            config.LOGGER.error('Could not wrap object %s into class %s' % (mooseObject.path, className))
            return
        
        for fieldName in self.mooseObject.getFieldNames('valueFinfo'):
			#print fieldName
			if(fieldName in ObjectFieldsModel.extra_fields):
				continue
			else:
			    value = self.mooseObject.getField(fieldName)
			    #print value
			flag = Qt.ItemIsEnabled | Qt.ItemIsSelectable
			srchField = 'set_'+fieldName
			try:	
			    for fn in (fn for fn in moose.getFieldDict(self.mooseObject.class_,'destFinfo').keys() if fn.startswith(srchField)):
				    flag = flag | Qt.ItemIsEditable
			    value = mooseObject.getField(fieldName)
				
			except Exception, e:
				config.LOGGER.error("%s" % (e))

			self.fieldFlags[fieldName] = flag	
			self.fields.append(fieldName)            	
Пример #5
0
def test_other():
    a1 = moose.Pool('/ada')
    assert a1.className == 'Pool', a1.className
    finfo = moose.getFieldDict(a1.className)
    s = moose.Streamer('/asdada')
    p = moose.PulseGen('pg1')
    assert p.delay[0] == 0.0
    p.delay[1] = 0.99
    assert p.delay[1] == 0.99, p.delay[1]

    c = moose.Stoich('/dadaa')
    v1 = moose.getFieldNames(c)
    v2 = c.getFieldNames()
    assert v1 == v2
    assert len(v1) > 10, v1
Пример #6
0
    def setSelectedElements(self, elementlist):
        """Create a grid of widgets displaying paths of elements in
        `elementlist` if it has at least one plottable field (a field
        with a numeric value). The numeric fields are listed in a
        combobox next to the element path and can be selected for
        plotting by the user.

        """
        for ii in range(self.getPlotListWidget().layout().count()):
            item = self.getPlotListWidget().layout().itemAt(ii)
            if item is None:
                continue
            self.getPlotListWidget().layout().removeItem(item)
            w = item.widget()
            w.hide()
            del w
            del item
        self._elementWidgetsDict.clear()
        label = QLabel('Element')
        label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.getPlotListWidget().layout().addWidget(label, 0, 0, 1, 2)
        self.getPlotListWidget().layout().addWidget(QLabel('Fields to plot'),
                                                    0, 2, 1, 1)
        for ii, entry in enumerate(elementlist):
            el = moose.element(entry)
            plottableFields = []
            for field, dtype in list(
                    moose.getFieldDict(el.className, 'valueFinfo').items()):
                if dtype == 'double':
                    plottableFields.append(field)
            if len(plottableFields) == 0:
                continue
            elementLabel = QLabel(el.path)
            fieldsCombo = CheckComboBox(self)
            fieldsCombo.addItem('')
            for item in plottableFields:
                fieldsCombo.addItem(item)
            self.getPlotListWidget().layout().addWidget(
                elementLabel, ii + 1, 0, 1, 2)
            self.getPlotListWidget().layout().addWidget(
                fieldsCombo, ii + 1, 2, 1, 1)
            self._elementWidgetsDict[el] = (elementLabel, fieldsCombo)
Пример #7
0
    def setSelectedElements(self, elementlist):
        """Create a grid of widgets displaying paths of elements in
        `elementlist` if it has at least one plottable field (a field
        with a numeric value). The numeric fields are listed in a
        combobox next to the element path and can be selected for
        plotting by the user.

        """
        for ii in range(self.getPlotListWidget().layout().count()):
            item = self.getPlotListWidget().layout().itemAt(ii)
            if item is None:
                continue
            self.getPlotListWidget().layout().removeItem(item)
            w = item.widget()
            w.hide()
            del w
            del item
        self._elementWidgetsDict.clear()
        label = QtGui.QLabel('Element')
        label.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        self.getPlotListWidget().layout().addWidget(label, 0, 0, 1, 2)
        self.getPlotListWidget().layout().addWidget(QtGui.QLabel('Fields to plot'), 0, 2, 1, 1)
        for ii, entry in enumerate(elementlist):
            el = moose.element(entry)
            plottableFields = []
            for field, dtype in  list(moose.getFieldDict(el.className, 'valueFinfo').items()):
                if dtype == 'double':
                    plottableFields.append(field)
            if len(plottableFields) == 0:
                continue
            elementLabel = QtGui.QLabel(el.path)
            fieldsCombo = CheckComboBox(self)
            fieldsCombo.addItem('')
            for item in plottableFields:
                fieldsCombo.addItem(item)
            self.getPlotListWidget().layout().addWidget(elementLabel, ii+1, 0, 1, 2)
            self.getPlotListWidget().layout().addWidget(fieldsCombo, ii+1, 2, 1, 1)
            self._elementWidgetsDict[el] = (elementLabel, fieldsCombo)
Пример #8
0
def get_rec_dtype(em):
    bad_fields = []
    # Check if already have data type information for this class.
    # Create it otherwise.
    if em.className in dtype_table:
        dtype = dtype_table[em.className]
    else:
        print('Creating entries for class:', em.className)
        fielddict = moose.getFieldDict(em.className, 'valueFinfo')
        print(fielddict)

        # If we do not have the type of this field in cpp-np data
        # type map, skip it. We can handle vectors as nested
        # table, but the problem with that is numpy requires all
        # entries to have a fixed size for this table. Since
        # vectors can have arbitrary length, we cannot get such a
        # fixed size without checking the size of the vector field
        # in all elements.
        fields = [(fieldname, cpptonp[ftype]) # [('path', 'S1024')]
                  for fieldname, ftype in sorted(fielddict.items())
                  if ftype in cpptonp]
        dtype_table[em.className] = np.dtype(fields)
        return dtype_table[em.className]
Пример #9
0
    def __init__(self, datain, headerdata=['Field','Value'], parent=None, *args):
        QAbstractTableModel.__init__(self, parent, *args)
        self.fieldFlags = {}
        self.fields = []
        self.mooseObject = datain
        self.headerdata = headerdata

        for fieldName in self.mooseObject.getFieldNames('valueFinfo'):
            
            if(fieldName in extra_fields):
                continue
            else:
                value = self.mooseObject.getField(fieldName)
                self.fields.append(fieldName)
            flag = Qt.ItemIsEnabled | Qt.ItemIsSelectable
            srchField = 'set_'+fieldName
            try:	
                for fn in (fn for fn in moose.getFieldDict(self.mooseObject.class_,'destFinfo').keys() if fn.startswith(srchField)):
                    flag = flag | Qt.ItemIsEditable
                    value = self.mooseObject.getField(fieldName)
            except Exception, e:
                pass

            self.fieldFlags[fieldName] = flag
Пример #10
0
def savestate(filename=None):
    """Dump the state of MOOSE in an hdf5 file.
    
    The file will have a data set for each class.
    Each such dataset will be a column of field values.

    This function needs more work on moose serialization.
    """    
    if filename is None:
        filename = 'moose_session_' + time.strftime('%Y%m%d_%H%M%S') + '.hdf5'
    with h5.File(filename, 'w') as fd:
        root = fd.create_group('/elements')
        meta = fd.create_group('/metadata')
        typeinfo_dataset = meta.create_dataset('typeinfo', shape=(size_step,), dtype=[('path', 'S1024'), ('class', 'S64'), ('dims', 'S64'), ('parent', 'S1024')], compression='gzip', compression_opts=6)
        typeinfo = []
        class_dataset_dict = {}
        class_count_dict = {}
        class_array_dict = {}
        objcount = 0
        for obj in moose__.wildcardFind("/##"):
            if obj.path.startswith('/Msg') or obj.path.startswith('/class') or obj.class_ == 'Table' or obj.class_ == 'TableEntry':
                continue
            print 'Processing:', obj.path, obj.class_
            typeinfo.append((obj.path, obj.class_, str(obj.shape), obj[0].parent.path))
            objcount += 1
            if len(typeinfo) == size_step:
                typeinfo_dataset.resize(objcount)
                typeinfo_dataset[objcount - size_step: objcount] = np.rec.array(typeinfo, typeinfo_dataset.dtype)
                typeinfo = []
            # If we do not yet have dataset for this class, create one and keep it in dict
            if obj.class_ not in class_dataset_dict:
                print 'Creating entries for class:', obj.class_
                fielddict = moose__.getFieldDict(obj.class_, 'valueFinfo')
                print fielddict
                keys = sorted(list(fielddict.keys()))
                fields = [] # [('path', 'S1024')]
                for fieldname in keys:
                    ftype = fielddict[fieldname]
                    if ftype in cpptonp:
                        fields.append((fieldname, cpptonp[ftype]))
                    elif ftype == 'Id' or ftype == 'ObjId':
                        fields.append((fieldname, 'S1024'))
                # print fields
                ds = root.create_dataset(obj.class_, shape=(size_step,), dtype=fields, compression='gzip', compression_opts=6)
                class_dataset_dict[obj.class_] = ds
                class_array_dict[obj.class_] = []
                class_count_dict[obj.class_] = 0
            # Lookup the dataset for the class this object belongs to
            ds = class_dataset_dict[obj.class_]
            for entry in obj:
                fields = []
                print entry.path,
                for f in ds.dtype.names:
                    print 'getting field:', f
                    entry.getField(f)
                fields = [f.path if isinstance(f, moose__.ematrix) or isinstance(f, moose__.element) else f for f in fields]
                class_array_dict[obj.class_].append(fields)
                # print 'fields:'
                # print fields
                # print 'length:', len(class_array_dict[obj.class_])
                class_count_dict[obj.class_] += 1
                if class_count_dict[obj.class_] == size_step:
                    oldlen = ds.len()
                    if oldlen <= class_count_dict[obj.class_]:
                        ds.resize((class_count_dict[obj.class_]))
                    ds[oldlen: class_count_dict[obj.class_]] = np.rec.array(class_array_dict[obj.class_], dtype=ds.dtype)
                    class_array_dict[obj.class_] = []
        for classname in class_array_dict:
            ds = class_dataset_dict[classname]
            ds.resize((class_count_dict[classname], ))
            if len(class_array_dict[classname]) > 0:
                start = class_count_dict[classname] - len(class_array_dict[classname])
                ds[start:] = np.rec.array(class_array_dict[classname], dtype=ds.dtype)

        if len(typeinfo) > 0:
            typeinfo_dataset.resize((objcount,))
            typeinfo_dataset[objcount-len(typeinfo): objcount] = np.rec.array(typeinfo, dtype=typeinfo_dataset.dtype)
Пример #11
0
def savestate(filename=None):
    """Dump the state of MOOSE in an hdf5 file.

    The file will have a data set for each class.
    Each such dataset will be a column of field values.

    This function needs more work on moose serialization.
    """
    if filename is None:
        filename = 'moose_session_' + time.strftime('%Y%m%d_%H%M%S') + '.hdf5'
    with h5.File(filename, 'w') as fd:
        root = fd.create_group('/elements')
        meta = fd.create_group('/metadata')
        typeinfo_dataset = meta.create_dataset('typeinfo',
                                               shape=(size_step, ),
                                               dtype=[('path', 'S1024'),
                                                      ('class', 'S64'),
                                                      ('dims', 'S64'),
                                                      ('parent', 'S1024')],
                                               compression='gzip',
                                               compression_opts=6)
        typeinfo = []
        class_dataset_dict = {}
        class_count_dict = {}
        class_array_dict = {}
        objcount = 0
        for obj in moose.wildcardFind("/##"):
            if obj.path.startswith('/Msg') or obj.path.startswith(
                    '/class'
            ) or obj.className == 'Table' or obj.className == 'TableEntry':
                continue
            print('Processing:', obj.path, obj.className)
            typeinfo.append(
                (obj.path, obj.className, str(obj.shape), obj[0].parent.path))
            objcount += 1
            if len(typeinfo) == size_step:
                typeinfo_dataset.resize(objcount)
                typeinfo_dataset[objcount - size_step:objcount] = np.rec.array(
                    typeinfo, typeinfo_dataset.dtype)
                typeinfo = []
            # If we do not yet have dataset for this class, create one and keep it in dict
            if obj.className not in class_dataset_dict:
                print('Creating entries for class:', obj.className)
                fielddict = moose.getFieldDict(obj.className, 'valueFinfo')
                print(fielddict)
                keys = sorted(fielddict)
                fields = []  # [('path', 'S1024')]
                for fieldname in keys:
                    ftype = fielddict[fieldname]
                    if ftype in cpptonp:
                        fields.append((fieldname, cpptonp[ftype]))
                    elif ftype == 'Id' or ftype == 'ObjId':
                        fields.append((fieldname, 'S1024'))
                # print fields
                ds = root.create_dataset(obj.className,
                                         shape=(size_step, ),
                                         dtype=fields,
                                         compression='gzip',
                                         compression_opts=6)
                class_dataset_dict[obj.className] = ds
                class_array_dict[obj.className] = []
                class_count_dict[obj.className] = 0
            # Lookup the dataset for the class this object belongs to
            ds = class_dataset_dict[obj.className]
            for entry in obj:
                fields = []
                print(entry.path, end=' ')
                for f in ds.dtype.names:
                    print('getting field:', f)
                    entry.getField(f)
                fields = [
                    f.path if isinstance(f, moose.vec)
                    or isinstance(f, moose.element) else f for f in fields
                ]
                class_array_dict[obj.className].append(fields)
                # print 'fields:'
                # print fields
                # print 'length:', len(class_array_dict[obj.className])
                class_count_dict[obj.className] += 1
                if class_count_dict[obj.className] == size_step:
                    oldlen = ds.len()
                    if oldlen <= class_count_dict[obj.className]:
                        ds.resize((class_count_dict[obj.className]))
                    ds[oldlen:class_count_dict[obj.className]] = np.rec.array(
                        class_array_dict[obj.className], dtype=ds.dtype)
                    class_array_dict[obj.className] = []
        for classname in class_array_dict:
            ds = class_dataset_dict[classname]
            ds.resize((class_count_dict[classname], ))
            if len(class_array_dict[classname]) > 0:
                start = class_count_dict[classname] - len(
                    class_array_dict[classname])
                ds[start:] = np.rec.array(class_array_dict[classname],
                                          dtype=ds.dtype)

        if len(typeinfo) > 0:
            typeinfo_dataset.resize((objcount, ))
            typeinfo_dataset[objcount - len(typeinfo):objcount] = np.rec.array(
                typeinfo, dtype=typeinfo_dataset.dtype)