def convertMetas(lfn): """set some values for the metadata tags cercal_distance, class, cercus, and directional_tuning. Use these to set color. Sets cercal_distance to 10 (proximal). Uses the dircolors module to infer class and thus direction and color. This module assumes the data are stored in a file name of origin, using "." as the field separator.""" for fn in lfn: print fn doc = io.read(fn) els = doc.getElements(["Cell", "Fiducial", "SpatialField"], depth=1) for e in els: e.setAttrib("meta_cercal_distance", 10) aclass = e.attrib("meta_class") if aclass == None: try: dc._getclass(e) aclass = e.attrib("meta_class") except: print "failed to get class for %s" % fn continue cerc = e.attrib("meta_cercus").lower()[0] try: d = dc.DIRECTIONS[aclass] except: print "no directional tuning for %s" % (str(aclass),) continue if cerc == "r": d = 360 - d e.setAttrib("meta_directional_tuning", d) d = d % 360 ang = d * pi / 180 c = dc._getAngleColor(ang) pycol = dc.convertColor(c, "py") if "Color" in e.attributes: del (e.attributes["Color"]) e.setAttrib("color", pycol) io.write(doc, fn)
def setMetasFromNames_(lfn): """construct metadata tags based on structured file names""" for fn in lfn: doc = io.read(fn) atr = meta_from_name(fn) for e in doc.getElements(): for a in atr: e.setAttrib(a, atr[a]) for a in ["meta_cercal_length"]: if a in e.attributes: del (e.attributes[a]) ang = e.attrib("meta_directional_tuning") % 360 ang = ang * dc.pi / 180 c = dc._getAngleColor(ang) pycol = dc.convertColor(c, "py") e.setAttrib("color", pycol) io.write(doc, fn)