示例#1
0
    def toLatLon(self, LatLon, datum=None, **LatLon_kwds):
        '''Convert this WM coordinate to a geodetic point.

           @arg LatLon: Ellipsoidal class to return the geodetic
                        point (C{LatLon}).
           @kwarg datum: Optional datum for ellipsoidal or C{None}
                         for spherical B{C{LatLon}} (C{Datum}).
           @kwarg LatLon_kwds: Optional, additional B{C{LatLon}}
                               keyword arguments.

           @return: Point of this WM coordinate (B{C{LatLon}}).

           @raise TypeError: If B{C{LatLon}} and B{C{datum}} are
                             incompatible or if B{C{datum}} is
                             invalid or not ellipsoidal.

           @example:

           >>> w = Wm(448251.795, 5411932.678)
           >>> from pygeodesy import sphericalTrigonometry as sT
           >>> ll = w.toLatLon(sT.LatLon)  # 43°39′11.58″N, 004°01′36.17″E
        '''
        e = issubclassof(LatLon, _LLEB)
        if e and datum:
            kwds = _xkwds(LatLon_kwds, datum=datum)
        elif not (e or datum):  # and LatLon
            kwds = LatLon_kwds
            datum = None
        else:
            raise _TypeError(LatLon=LatLon, datum=datum)

        r = self.latlon2(datum=datum)
        r = LatLon(r.lat, r.lon, **kwds)
        return self._xnamed(r)
示例#2
0
    def __imul__(self, other):
        '''Multiply this instance by a scalar or an other instance.

           @arg other: L{Fsum} instance or C{scalar}.

           @return: This instance, updated (L{Fsum}).

           @raise TypeError: Invalid B{C{other}} type.

           @see: Method L{Fsum.fmul}.
        '''
        if isscalar(other):
            self.fmul(other)
        elif isinstance(other, Fsum):
            ps = list(other._ps)  # copy
            if ps:
                s = self.fcopy()
                self.fmul(ps.pop())
                while ps:  # self += s * ps.pop()
                    p = s.fcopy()
                    p.fmul(ps.pop())
                    self.fadd(p._ps)
            else:
                self._ps = []  # zero
                self._fsum2_ = None
        else:
            raise _TypeError(_SPACE_(self, '*=', repr(other)))
        return self
示例#3
0
    def __mod__(self, arg, **unused):
        '''Regular C{%} operator.

           @arg arg: A C{scalar} value to be formatted (either
                     the C{scalar}, or a 1-tuple C{(scalar,)},
                     or 2-tuple C{(prec, scalar)}.

           @raise TypeError: Non-scalar B{C{arg}} value.

           @raise ValueError: Invalid B{C{arg}}.
        '''
        def _error(arg):
            n = _DOT_(Fstr.__name__, self.name or self)
            return _SPACE_(n, _PERCENT_, repr(arg))

        prec = 6  # default std %f and %F
        if isinstance(arg, (tuple, list)):
            n = len(arg)
            if n == 1:
                arg = arg[0]
            elif n == 2:
                prec, arg = arg
            else:
                raise _ValueError(_error(arg))

        if not isscalar(arg):
            raise _TypeError(_error(arg))
        return self(arg, prec=prec)
示例#4
0
 def __delattr__(self, name):
     if name in self._Names_:
         raise _TypeError('del',
                          _dot_(self.classname, name),
                          txt=_immutable_)
     elif name in (_name_, _name):
         _Named.__setattr__(self, name,
                            '')  # XXX _Named.name.fset(self, '')
     else:
         tuple.__delattr__(self, name)
示例#5
0
 def __setattr__(self, name, value):
     if name in self._Names_:
         raise _TypeError(_dot_(self.classname, name),
                          value,
                          txt=_immutable_)
     elif name in (_name_, _name):
         _Named.__setattr__(self, name,
                            value)  # XXX _Named.name.fset(self, value)
     else:
         tuple.__setattr__(self, name, value)
示例#6
0
def _ll2datum(ll, datum, name):
    '''(INTERNAL) Convert datum if needed.
    '''
    if datum not in (None, ll.datum):
        try:
            ll = ll.convertDatum(datum)
        except AttributeError:
            raise _TypeError(name,
                             ll,
                             txt=_item_ps(_no_convertDatum_, datum.name))
    return ll
示例#7
0
 def freduce(f, iterable, *start):
     '''For missing C{functools.reduce}.
     '''
     if start:
         r = v = start[0]
     else:
         r, v = 0, MISSING
     for v in iterable:
         r = f(r, v)
     if v is MISSING:
         raise _TypeError(iterable=(), start=MISSING)
     return r
示例#8
0
 def __setattr__(self, name, value):
     '''Set attribute or item B{C{name}} to B{C{value}}.
     '''
     if name in self._Names_:
         raise _TypeError(_DOT_(self.classname, name),
                          value,
                          txt=_immutable_)
     elif name in (_name_, _name):
         _Named.__setattr__(self, name,
                            value)  # XXX _Named.name.fset(self, value)
     else:
         tuple.__setattr__(self, name, value)
示例#9
0
 def __new__(cls, *args):
     '''New L{_NamedTuple} initialized with B{C{positional}} arguments.
     '''
     self = tuple.__new__(cls, args)
     ns = self._Names_
     if not (isinstance(ns, tuple) and len(ns) > 1):  # XXX > 0
         raise _TypeError(_dot_(self.classname, _Names_), ns)
     if len(ns) != len(args) or not ns:
         raise LenError(cls, args=len(args), ns=len(ns))
     if _name_ in ns:
         t = unstr(_dot_(self.classname, _Names_), *ns)
         raise _NameError(_name_, _name_, txt=t)
     return self
示例#10
0
 def _latlon3(self, LatLon, datum):
     '''(INTERNAL) Convert cached LatLon
     '''
     ll = self._latlon
     if LatLon is None:
         if datum and datum != ll.datum:
             raise _TypeError(latlon=ll,
                              txt=_item_ps(_no_convertDatum_, datum.name))
         return _xnamed(LatLonDatum3Tuple(ll.lat, ll.lon, ll.datum),
                        ll.name)
     else:
         _xsubclassof(_LLEB, LatLon=LatLon)
         ll = _xnamed(LatLon(ll.lat, ll.lon, datum=ll.datum), ll.name)
         return _ll2datum(ll, datum, _LatLon_)
示例#11
0
    def __delattr__(self, name):
        '''Delete an attribute by B{C{name}}.

           @note: Items can not be deleted.
        '''
        if name in self._Names_:
            raise _TypeError(_del_,
                             _DOT_(self.classname, name),
                             txt=_immutable_)
        elif name in (_name_, _name):
            _Named.__setattr__(self, name,
                               NN)  # XXX _Named.name.fset(self, NN)
        else:
            tuple.__delattr__(self, name)
示例#12
0
    def _validate(self, _OK=False):  # see .EcefMatrix
        '''(INTERNAL) One-time check of C{_Names_} and C{_Units_}
           for each C{_NamedUnit} I{sub-class separately}.
        '''
        ns = self._Names_
        if not (isinstance(ns, tuple) and len(ns) > 1):  # XXX > 0
            raise _TypeError(_DOT_(self.classname, _Names_), ns)
        for i, n in enumerate(ns):
            if not _xvalid(n, _OK=_OK):
                t = Fmt.SQUARE(_Names_, i)
                raise _ValueError(_DOT_(self.classname, t), n)

        us = self._Units_
        if not isinstance(us, tuple):
            raise _TypeError(_DOT_(self.classname, _Units_), us)
        if len(us) != len(ns):
            raise LenError(self.__class__, _Units_=len(us), _Names_=len(ns))
        for i, u in enumerate(us):
            if not (u is None or callable(u)):
                t = Fmt.SQUARE(_Units_, i)
                raise _TypeError(_DOT_(self.classname, t), u)

        self.__class__._validated = True
示例#13
0
    def others(self, other, name=_other_, up=1):  # see .points.LatLon_.others
        '''Check this and an other instance for type compatiblility.

           @arg other: The other instance (any C{type}).
           @kwarg name: Optional, name for other (C{str}).
           @kwarg up: Number of call stack frames up (C{int}).

           @raise TypeError: Mismatch of the B{C{other}} and this
                             C{class} or C{type}.
        '''
        if not (isinstance(self, other.__class__)
                or isinstance(other, self.__class__)):
            n = _callname(name,
                          classname(self, prefixed=True),
                          self.name,
                          up=up + 1)
            raise _TypeError(name, other, txt=_incompatible(n))
示例#14
0
    def __iadd__(self, other):
        '''Add a scalar or an other instance to this instance.

           @arg other: L{Fsum} instance or C{scalar}.

           @return: This instance, updated (L{Fsum}).

           @raise TypeError: Invalid B{C{other}} type.

           @see: Method L{Fsum.fadd}.
        '''
        if isscalar(other):
            self.fadd_(other)
        elif other is self:
            self.fmul(2)
        elif isinstance(other, Fsum):
            self.fadd(other._ps)
        else:
            raise _TypeError(_SPACE_(self, '+=', repr(other)))
        return self
示例#15
0
    def __isub__(self, other):
        '''Subtract a scalar or an other instance from this instance.

           @arg other: L{Fsum} instance or C{scalar}.

           @return: This instance, updated (L{Fsum}).

           @raise TypeError: Invalid B{C{other}} type.

           @see: Method L{Fsum.fadd}.
        '''
        if isscalar(other):
            self.fadd_(-other)
        elif other is self:
            self._ps = []  # zero
            self._fsum2_ = None
        elif isinstance(other, Fsum):
            self.fadd(-p for p in other._ps)
        else:
            raise _TypeError(_SPACE_(self, '-=', repr(other)))
        return self
示例#16
0
def _xotherError(inst, other, name=_other_, up=1):
    '''(INTERNAL) Return a C{_TypeError} for an incompatible, named C{other}.
    '''
    n = _callname(name, classname(inst, prefixed=True), inst.name, up=up + 1)
    return _TypeError(name, other, txt=_incompatible(n))
示例#17
0
 def __setattr__(self, attr, value):  # PYCHOK no cover
     from pygeodesy.errors import _TypeError
     t = _EQUALSPACED_(self._DOT_(attr), value)
     raise _TypeError(t, txt=_immutable_)
示例#18
0
def _2epoch(epoch):  # imported by .ellipsoidalBase
    '''(INTERNAL) Validate an C{epoch}.
    '''
    if isscalar(epoch) and epoch > 0:  # XXX 1970?
        return _F(epoch)
    raise _TypeError(epoch=epoch, txt=_not_scalar_)