Python code snippet for exhibiting the DR structure

A contribution to enlighten the Data Request structure using the API.
The code below will list attributes for each section, and also the class of objects pointed by link attributes (between parenthesis)

from dreq import * dq = loadDreq() for section in dq.coll : ks=dq.coll[section].attDefn.keys() print "% 20s : "%section , for k in ks : if k != 'uid' and k != 'label' : print " %s"%k, if k.find("id") and k != 'uid' : val=dq.coll[section].items[0].__getattribute__(k) if val in dq.inx.uid : pclass=`type(dq.inx.uid[val])` cl=pclass.replace("<class '","").replace("'>","").replace('dreq.dreqItem_',"") print "(%s)"%cl , #print "(%s)"%dq.coll[section].attDefn[k].title, print; print

Output example, with beta03 version
----------------------------------

requestVarGroup : refNote title mip (mip) ref var : procnote description title prov sn units procComment requestItem : nexmax title nenmax nymax expt ny rlid (requestLink) tab esid (experiment) mip (mip) esidComment CMORvar : description shuffle vid (var) title rowIndex type stid (structure) deflate_level deflate valid_min modeling_realm frequency mipTable ok_min_mean_abs prov valid_max positive provNote ok_max_mean_abs spatialShape : levelFlag dimensions title shape levels requestLink : comment refNote opar title opt preset grid tab objective mip (mip) ref refid (requestVarGroup) gridreq tableSection : refNote title (mip) gpid (requestVarGroup) mip (mip) ref varChoice : description title varList optionList class objectiveLink : rid (requestLink) title oid (objective) (mip) exptgroup : tierMin title ntot experiment : nstart yps starty description title endy ensz egid (exptgroup) tier mip (mip) ntot mcfg comment remarks : tattr description title qid techNote prov tid class mip : status description title url (mip) objective : mip (mip) description title requestVar : vid (CMORvar) title priority vgid (requestVarGroup) table mip (mip) temporalShape : dimensions description title structure : procNote odims flag_meanings prov title tmid (temporalShape) cell_methods coords cell_measures spid (spatialShape) flag_values description

Comments

  • Fix : in code above, replace
    k.find("id")
    by
    k.find("id")>=0
  • which will print, for beta.03
    requestVarGroup : refNote title mip ref var : procnote description title prov sn units procComment requestItem : nexmax title nenmax nymax expt ny rlid (requestLink) tab esid (experiment) mip esidComment CMORvar : description shuffle vid (var) title rowIndex type stid (structure) deflate_level deflate valid_min modeling_realm frequency mipTable ok_min_mean_abs prov valid_max positive provNote ok_max_mean_abs spatialShape : levelFlag dimensions title shape levels requestLink : comment refNote opar title opt preset grid tab objective mip ref refid (requestVarGroup) gridreq tableSection : refNote title gpid (requestVarGroup) mip ref varChoice : description title varList optionList class objectiveLink : rid (requestLink) title oid (objective) exptgroup : tierMin title ntot experiment : nstart yps starty description title endy ensz egid (exptgroup) tier mip ntot mcfg comment remarks : tattr description title qid techNote prov tid class mip : status description title url objective : mip description title requestVar : vid (CMORvar) title priority vgid (requestVarGroup) table mip temporalShape : dimensions description title structure : procNote odims flag_meanings prov title tmid (temporalShape) cell_methods coords cell_measures spid (spatialShape) flag_values description
  • edited February 2016
    Here is a modified bit of code with a couple of modifications: (1) it uses the section header to identify which attributes should be links and (2) it scans all the items in each section, rather than just looking at the first:
    
    import string
    from dreqPy import dreq
    
    def dumpa( dq):
     for section in dq.coll :
      ks=dq.coll[section].attDefn.keys()
      print "% 20s : "%section ,
      for k in ks :
        print k,
        if section[0] != '_' and dq.coll[section].attDefn[k].useClass == 'internalLink':
          s = set()
          for i in dq.coll[section].items:
            if i.__dict__[k] in dq.inx.uid:
              s.add( dq.inx.uid[i.__dict__[k]]._h.label )
          print ' (%s)' % string.join( sorted( list( s) ), ', '),
      print
      print
    
    dq=dreq.loadDreq()
    dumpa( dq )

    The output I get is:

    requestItem : treset nexmax uid title nenmax nymax expt ny preset tslice (timeSlice) rlid (requestLink) tab esid (experiment, exptgroup, mip, remarks) mip label esidComment

    grids : uid isGrid boundsValues valid_min tolRequested axis tables title positive label units altLabel type requested direction description isIndex standardName (remarks, standardname) boundsRequested bounds value coords valid_max

    spatialShape : levelFlag dimensions title label shape levels uid

    requestVar : uid vid (CMORvar, remarks) title label priority vgid (requestVarGroup) mip

    __main__ : superclass required description title uid type label techNote useClass

    temporalShape : dimensions description title uid label

    __sect__ : level required itemLabelMode uid labUnique title maxOccurs useClass id label

    modelConfig : uid title label range usage MIPs type

    experiment : nstart yps starty description title endy ensz label egid (exptgroup) tier mip (mip) ntot mcfg comment uid

    var : procnote description title prov label provmip (mip) sn (remarks, standardname) units procComment uid

    mip : url description title uid label

    __core__ : superclass required description title uid type label techNote useClass

    CMORvar : shuffle uid vid (remarks, var) valid_min frequency ok_max_mean_abs title rowIndex prov stid (structure) mipTable label type description deflate_level deflate mipTableSection provNote ok_min_mean_abs defaultPriority modeling_realm positive valid_max

    tableSection : refNote uid title label gpid (requestVarGroup) mip ref

    varChoice : description title varList label optionList class uid

    exptgroup : tierMin title uid ntot label

    remarks : tattr description title qid techNote label prov tid (CMORvar, requestVar, var) class uid

    structure : procNote uid odims flag_meanings prov title tmid (temporalShape) label cell_methods coords cell_measures spid (spatialShape) flag_values description

    requestVarGroup : refNote uid title label mip (mip, remarks) ref

    varChoiceLinkC : cfgid (modelConfig) uid vid (CMORvar) title cfg cid (varChoice) label

    requestLink : comment refNote uid opar title opt label grid tab objective mip (mip) ref refid (requestVarGroup) gridreq

    varChoiceLinkR : uid vid (CMORvar) cid (varChoice) title rank label

    objectiveLink : rid (requestLink) title uid oid (objective) label

    objective : mip (mip) description title uid label

    timeSlice : end uid title nyears label start step sliceLen type

    standardname : units description title uid label
Sign In or Register to comment.