def __init__(self, *args, **kw): # Accept an optional "epoch" keyword argument. epoch = kw.pop('epoch', None) if epoch is not None: self.epoch = epoch = Date(epoch) if kw: raise TypeError('"epoch" is the only keyword argument' ' you can use during %s instantiation' % (type(self).__name__)) # Interpret a single-argument initialization. if len(args) == 1: a = args[0] if isinstance(a, Body): a = Equatorial(a.a_ra, a.a_dec, epoch=a.a_epoch) for cls in (Equatorial, Ecliptic, Galactic): if isinstance(a, cls): # If the user omitted an "epoch" keyword, then # use the epoch of the other object. if epoch is None: self.epoch = epoch = a.epoch # If we are initialized from another of the same # kind of coordinate and epoch, simply copy the # coordinates and epoch into this new object. if isinstance(self, cls) and epoch == a.epoch: self.set(*a.get()) return # Otherwise, convert. ra, dec = a.to_radec() if epoch != a.epoch: ra, dec = _libastro.precess(a.epoch, epoch, ra, dec) self.from_radec(ra, dec) return raise TypeError( 'a single argument used to initialize %s() must be either' ' a coordinate or a Body, not an %r' % (type(a).__name__, )) # Two arguments are interpreted as (ra, dec) or (lon, lat). elif len(args) == 2: self.set(*args) if epoch is None: self.epoch = epoch = Date(J2000) else: raise TypeError('to initialize %s you must pass either a Body,' ' another coordinate, or two coordinate values,' ' but not: %r' % ( type(self).__name__, args, ))
def __init__(self, *args, **kw): # Accept an optional "epoch" keyword argument. epoch = kw.pop('epoch', None) if epoch is not None: self.epoch = epoch = Date(epoch) if kw: raise TypeError('"epoch" is the only keyword argument' ' you can use during %s instantiation' % (type(self).__name__)) # Interpret a single-argument initialization. if len(args) == 1: a = args[0] if isinstance(a, Body): a = Equatorial(a.a_ra, a.a_dec, epoch = a.a_epoch) for cls in (Equatorial, Ecliptic, Galactic): if isinstance(a, cls): # If the user omitted an "epoch" keyword, then # use the epoch of the other object. if epoch is None: self.epoch = epoch = a.epoch # If we are initialized from another of the same # kind of coordinate and epoch, simply copy the # coordinates and epoch into this new object. if isinstance(self, cls) and epoch == a.epoch: self.set(*a.get()) return # Otherwise, convert. ra, dec = a.to_radec() if epoch != a.epoch: ra, dec = _libastro.precess( a.epoch, epoch, ra, dec ) self.from_radec(ra, dec) return raise TypeError( 'a single argument used to initialize %s() must be either' ' a coordinate or a Body, not an %r' % (type(a).__name__,) ) # Two arguments are interpreted as (ra, dec) or (lon, lat). elif len(args) == 2: self.set(*args) if epoch is None: self.epoch = epoch = Date('2000') else: raise TypeError( 'to initialize %s you must pass either a Body,' ' another coordinate, or two coordinate values,' ' but not: %r' % (type(self).__name__, args,) )