def to_python(self,value): '''get python value from serialized place''' if isinstance(value,str) or isinstance(value,unicode): try: return Dec_coord.fromStr(value) except: raise ValidationError("Invalid input for Declination:"+str(value)) elif isinstance(value, Dec_coord) or value is None: return value else: raise TypeError("unable to convert to Dec_coord")
def to_python(self, value): '''get python value from serialized place''' if isinstance(value, str) or isinstance(value, unicode): try: return Dec_coord.fromStr(value) except: raise ValidationError("Invalid input for Declination:" + str(value)) elif isinstance(value, Dec_coord) or value is None: return value else: raise TypeError("unable to convert to Dec_coord")
def parse_first_coords(coord_file): """parse the coordinates of the first object in the coordinate file and return a Coords object""" with open(coord_file) as cf: line = cf.readline() while line and (line.isspace() or line.startswith("#")): # skip over blank lines and comments line = cf.readline() if not line: raise Exception("Unable to parse coordinates") # TODO use better exception type rastr, decstr = line.split()[0:2] # assume seperationg by whitespace and no internal whitespace ra = RA_coord.fromStr(rastr) dec = Dec_coord.fromStr(decstr) return Coords(ra, dec)
def parse_first_coords(coord_file): '''parse the coordinates of the first object in the coordinate file and return a Coords object''' with open(coord_file) as cf: line = cf.readline() while line and (line.isspace() or line.startswith('#')): #skip over blank lines and comments line = cf.readline() if not line: raise Exception( "Unable to parse coordinates") #TODO use better exception type rastr, decstr = line.split()[ 0:2] #assume seperationg by whitespace and no internal whitespace ra = RA_coord.fromStr(rastr) dec = Dec_coord.fromStr(decstr) return Coords(ra, dec)
def compress(self, data_list): '''compress field into RA_coord''' if not data_list or data_list == [None, None, None]: return None return Dec_coord(*data_list)