def fieldname_with_ucd(self, ucd): """ return the field name that has a given UCD value or None if the UCD is not found. """ search_ucds = set(parse_ucd(ucd, has_colon=True)) for field in (field for field in self.fielddescs if field.ucd): field_ucds = set(parse_ucd(field.ucd, has_colon=True)) if search_ucds & field_ucds: return field.name return None
def def_ucd(word): out = OrderedDict() #TODO: implement 'unknown' UCD if word is None or not word.strip(): return out from astropy.io.votable import ucd _nw = ucd.parse_ucd(word,check_controlled_vocabulary=True,has_colon=True) for ns,w in _nw: _ucd = UCDWord(w,ns) #REVIEW: 'None' is here just to fill the hole for the time being out[_ucd] = None return out
def getUCD(tab): """Returns a list with all (valid) UCDs from a table""" from astropy.io.votable import ucd l1 = [] for f in tab.fields(): if not f.ucd: continue if not ucd.check_ucd(f.ucd): continue l2 = [] for u in ucd.parse_ucd(f.ucd): _u = str(u[1]) if not _u in l1: l2.append(_u) l1.extend(l2) return l1
def _def_ucd(word): # TODO: implement 'unknown' UCD # out = OrderedDict() out = list() try: word = word.strip() except: # not a string...tchau! return out if word is None or word == '': return out from astropy.io.votable import ucd _nw = ucd.parse_ucd(word, check_controlled_vocabulary=True, has_colon=True) for namespace, word_ in _nw: _ucd = UCDWord(word_, namespace) # out[_ucd] = None out.append(_ucd) return out
def test_invalid_word(): with pytest.raises(ValueError): ucd.parse_ucd("-pho")
def test_invalid_namespace(): with pytest.raises(ValueError): ucd.parse_ucd("_ivoa:phot.mag", True, True)
def test_too_many_colons(): with pytest.raises(ValueError): ucd.parse_ucd("ivoa:stsci:phot", True, True)
def test_check(): for s, p in examples.items(): assert ucd.parse_ucd(s, True, True) == p assert ucd.check_ucd(s, True, True)
def test_invalid_word(): ucd.parse_ucd("-pho")
def test_invalid_namespace(): ucd.parse_ucd("_ivoa:phot.mag", True, True)
def test_too_many_colons(): ucd.parse_ucd("ivoa:stsci:phot", True, True)