Exemple #1
0
 def get_bare_col(col):
     """
     Given a col that could be a bare column (list or array), or measure or
     quantity containing a bare column, return the bare column.
     """
     barecol = col
     if hasattr(barecol, 'has_key'):
         if barecol.has_key('comment'):
             barecol = barecol.get('data')
         if type(barecol)==dict and me.ismeasure(barecol):
             barecol = barecol['m0']
         # if qa.isquantity(data) can't be trusted.
         if hasattr(barecol, 'has_key') and barecol.has_key('unit') and barecol.has_key('value'):
             barecol = barecol['value']
     return barecol
Exemple #2
0
 def get_bare_col(col):
     """
     Given a col that could be a bare column (list or array), or measure or
     quantity containing a bare column, return the bare column.
     """
     barecol = col
     if hasattr(barecol, 'has_key'):
         if barecol.has_key('comment'):
             barecol = barecol.get('data')
         if type(barecol) == dict and me.ismeasure(barecol):
             barecol = barecol['m0']
         # if qa.isquantity(data) can't be trusted.
         if hasattr(barecol, 'has_key') and barecol.has_key(
                 'unit') and barecol.has_key('value'):
             barecol = barecol['value']
     return barecol
Exemple #3
0
         mytb.removerows(0)
     else: 
         mytb.create(tablepath, tabdesc)
     if type(info) == dict:
         mytb.putinfo(info)
     mytb.addrows(nrows)     # Must be done before putting the columns.
 except Exception, e:
     print "Error", e, "trying to create", tablepath
     retval = False
 for c in cols:
     try:
         #print "tabdesc[%s] =" % c, tabdesc[c]
         data = indict[c]  # Note the trickle-down nature below.
         if hasattr(indict[c], 'has_key') and indict[c].has_key('comment'):
             data = data['data']
         if type(data)==dict and me.ismeasure(data):
             mytb.putcolkeyword(c, 'MEASINFO', {'Ref': data['refer'],
                                                'type': data['type']})
             data = data['m0']   # = quantity         
         # if qa.isquantity(data) can't be trusted.
         if hasattr(data, 'has_key') and data.has_key('unit') and data.has_key('value'):
             mytb.putcolkeyword(c, 'QuantumUnits',
                              numpy.array([data['unit']]))
             data = data['value']
         mytb.putcol(c, data)
     except Exception, e:
         print "Error", e, "trying to put column", c, "in", tablepath
         print "data[0] =", data[0]
         print "tabdesc[c] =", tabdesc[c]
         retval = False
 for k in keywords:
Exemple #4
0
         mytb.removerows(0)
     else:
         mytb.create(tablepath, tabdesc)
     if type(info) == dict:
         mytb.putinfo(info)
     mytb.addrows(nrows)  # Must be done before putting the columns.
 except Exception, e:
     print "Error", e, "trying to create", tablepath
     retval = False
 for c in cols:
     try:
         #print "tabdesc[%s] =" % c, tabdesc[c]
         data = indict[c]  # Note the trickle-down nature below.
         if hasattr(indict[c], 'has_key') and indict[c].has_key('comment'):
             data = data['data']
         if type(data) == dict and me.ismeasure(data):
             mytb.putcolkeyword(c, 'MEASINFO', {
                 'Ref': data['refer'],
                 'type': data['type']
             })
             data = data['m0']  # = quantity
         # if qa.isquantity(data) can't be trusted.
         if hasattr(data, 'has_key') and data.has_key(
                 'unit') and data.has_key('value'):
             mytb.putcolkeyword(c, 'QuantumUnits',
                                numpy.array([data['unit']]))
             data = data['value']
         mytb.putcol(c, data)
     except Exception, e:
         print "Error", e, "trying to put column", c, "in", tablepath
         print "data[0] =", data[0]