def loadField(h5, resNode): longname = unicode(h5.getNodeAttr(resNode, "longname"), 'utf-8') shortname = unicode(h5.getNodeAttr(resNode, "shortname"), 'utf-8') try: creator = unicode(h5.getNodeAttr(resNode, "creator"), 'utf-8') machine = unicode(h5.getNodeAttr(resNode, "machine"), 'utf-8') except: from pyphant.core.Helpers import emd52dict emd5dict = emd52dict(resNode._v_title) creator = emd5dict['creator'] machine = emd5dict['machine'] data = scipy.array(resNode.data.read()) def loads(inputList): if type(inputList)==type([]): try: return map(lambda s: eval(s),inputList) except: return map(lambda s: unicode(s, 'utf-8'),inputList) else: return map(loads,inputList) if data.dtype.char == 'S': data = scipy.array(loads(data.tolist())) attributes = {} for key in resNode.data._v_attrs._v_attrnamesuser: attributes[key]=h5.getNodeAttr(resNode.data,key) try: error = scipy.array(resNode.error.read()) except tables.NoSuchNodeError, e: error = None
def loadField(h5, resNode): longname = unicode(h5.getNodeAttr(resNode, "longname"), 'utf-8') shortname = unicode(h5.getNodeAttr(resNode, "shortname"), 'utf-8') try: creator = unicode(h5.getNodeAttr(resNode, "creator"), 'utf-8') machine = unicode(h5.getNodeAttr(resNode, "machine"), 'utf-8') except: from pyphant.core.Helpers import emd52dict emd5dict = emd52dict(resNode._v_title) creator = emd5dict['creator'] machine = emd5dict['machine'] data = scipy.array(resNode.data.read()) def loads(inputList): if type(inputList) == type([]): try: return map(lambda s: eval(s), inputList) except: return map(lambda s: unicode(s, 'utf-8'), inputList) else: return map(loads, inputList) if data.dtype.char == 'S': data = scipy.array(loads(data.tolist())) attributes = {} for key in resNode.data._v_attrs._v_attrnamesuser: attributes[key] = h5.getNodeAttr(resNode.data, key) try: error = scipy.array(resNode.error.read()) except tables.NoSuchNodeError, e: error = None
def __init__(self, emd5, cursor, type): self.cursor = cursor self.emd5 = emd5 self.emd5dict = emd52dict(emd5) self.emd5dict['id'] = emd5 self.select_query = "SELECT %s FROM km_%s WHERE %s_id=?"\ % ('%s', type, type) self.update_query = "UPDATE km_%s SET %s=? WHERE %s_id=?"\ % (type, '%s', type) self.attr_query = "SELECT key, value FROM km_attributes WHERE dc_id=?"
def loadField(h5, resNode): longname = unicode(h5.getNodeAttr(resNode, "longname"), 'utf-8') shortname = unicode(h5.getNodeAttr(resNode, "shortname"), 'utf-8') try: creator = unicode(h5.getNodeAttr(resNode, "creator"), 'utf-8') machine = unicode(h5.getNodeAttr(resNode, "machine"), 'utf-8') except: from pyphant.core.Helpers import emd52dict emd5dict = emd52dict(resNode._v_title) creator = emd5dict['creator'] machine = emd5dict['machine'] data = scipy.array(resNode.data.read()) def loads(inputList): if type(inputList) == type([]): try: return map(lambda s: eval(s), inputList) except: return map(lambda s: unicode(s, 'utf-8'), inputList) else: return map(loads, inputList) if data.dtype.char == 'S': data = scipy.array(loads(data.tolist())) attributes = {} for key in resNode.data._v_attrs._v_attrnamesuser: attributes[key] = h5.getNodeAttr(resNode.data, key) try: error = scipy.array(resNode.error.read()) except tables.NoSuchNodeError: error = None try: mask = scipy.array(resNode.mask.read()) except tables.NoSuchNodeError: mask = None unit = eval(unicode(h5.getNodeAttr(resNode, "unit"), 'utf-8')) try: dimTable = resNode.dimensions dimensions = [ loadField( h5, h5.getNode( "/results/result_" + DataContainer.parseId(row['id'])[0] ) ) for row in dimTable.iterrows() ] except tables.NoSuchNodeError: dimensions = DataContainer.INDEX result = DataContainer.FieldContainer(data, unit, error, mask, dimensions, longname, shortname, attributes) result.creator = creator result.machine = machine result.seal(resNode._v_title) return result
def loadSummary(self, dcId=None): """ Extracts meta data about a given DataContainer and returns it as a dictionary. dcId -- emd5 of the DC to summarize. If the emd5 belongs to an IndexMarker object, u'IndexMarker' is returned. If dcId == None, a dictionary that maps emd5s to summaries is returned, where IndexMarker objects are ignored. """ if dcId == None: summary = {} for group in self.handle.walkGroups(where="/results"): currDcId = group._v_attrs.TITLE if len(currDcId) > 0: tmp = self.loadSummary(currDcId) if tmp == 'IndexMarker': summary[im_id] = im_summary else: summary[currDcId] = tmp elif self.isIndexMarker(dcId): return u'IndexMarker' else: summary = {} summary['id'] = dcId resNode, uriType = self.getNodeAndTypeFromId(dcId) summary['longname'] = utf82uc( self.handle.getNodeAttr(resNode, "longname")) summary['shortname'] = utf82uc( self.handle.getNodeAttr(resNode, "shortname")) summary.update(emd52dict(dcId)) try: summary['machine'] = utf82uc( self.handle.getNodeAttr(resNode, "machine")) summary['creator'] = utf82uc( self.handle.getNodeAttr(resNode, "creator")) except: pass # machine, creator set by emd52dict(dcId) before attributes = {} if uriType == 'field': for key in resNode.data._v_attrs._v_attrnamesuser: attributes[key] = self.handle.getNodeAttr( resNode.data, key) unit = eval(utf82uc(self.handle.getNodeAttr(resNode, "unit"))) summary['unit'] = unit dimTable = resNode.dimensions def filterIndexMarker(emd5): if self.isIndexMarker(emd5): return im_id else: return emd5 dimensions = [filterIndexMarker(row['id']) \ for row in dimTable.iterrows()] summary['dimensions'] = dimensions elif uriType == 'sample': for key in resNode._v_attrs._v_attrnamesuser: if key not in PyTablesPersister._reservedAttributes: attributes[key] = self.handle.getNodeAttr(resNode, key) columns = [] for resId in self.handle.getNodeAttr(resNode, "columns"): nodename = "/results/" + resId columnId = self.handle.getNodeAttr(nodename, "TITLE") columns.append(columnId) summary['columns'] = columns summary['attributes'] = attributes return summary
def loadSummary(self, dcId=None): """ Extracts meta data about a given DataContainer and returns it as a dictionary. dcId -- emd5 of the DC to summarize. If the emd5 belongs to an IndexMarker object, u'IndexMarker' is returned. If dcId == None, a dictionary that maps emd5s to summaries is returned, where IndexMarker objects are ignored. """ if dcId is None: summary = {} for group in self.handle.walkGroups(where="/results"): currDcId = group._v_attrs.TITLE if len(currDcId) > 0: tmp = self.loadSummary(currDcId) if tmp == 'IndexMarker': summary[im_id] = im_summary else: summary[currDcId] = tmp elif self.isIndexMarker(dcId): return u'IndexMarker' else: summary = {} summary['id'] = dcId resNode, uriType = self.getNodeAndTypeFromId(dcId) summary['longname'] = utf82uc(self.handle.getNodeAttr(resNode, "longname")) summary['shortname'] = utf82uc( self.handle.getNodeAttr(resNode, "shortname") ) summary.update(emd52dict(dcId)) try: summary['machine'] = utf82uc( self.handle.getNodeAttr(resNode, "machine") ) summary['creator'] = utf82uc( self.handle.getNodeAttr(resNode, "creator") ) except: pass # machine, creator set by emd52dict(dcId) before attributes = {} if uriType == 'field': for key in resNode.data._v_attrs._v_attrnamesuser: attributes[key] = self.handle.getNodeAttr( resNode.data, key ) unit = eval(utf82uc(self.handle.getNodeAttr(resNode, "unit"))) summary['unit'] = unit dimTable = resNode.dimensions def filterIndexMarker(emd5): if self.isIndexMarker(emd5): return im_id else: return emd5 dimensions = [filterIndexMarker(row['id']) \ for row in dimTable.iterrows()] summary['dimensions'] = dimensions elif uriType == 'sample': for key in resNode._v_attrs._v_attrnamesuser: if key not in PyTablesPersister._reservedAttributes: attributes[key] = self.handle.getNodeAttr(resNode, key) columns = [] for resId in self.handle.getNodeAttr(resNode, "columns"): nodename = "/results/" + resId columnId = self.handle.getNodeAttr(nodename, "TITLE") columns.append(columnId) summary['columns'] = columns summary['attributes'] = attributes return summary