Пример #1
0
def _notError(inst, name, args, kwds):  # PYCHOK no cover
    '''(INTERNAL) Format an error message.
    '''
    n = _DOT_(classname(inst, prefixed=True), _dunder_name(name, name))
    m = _COMMASPACE_.join(
        modulename(c, prefixed=True) for c in inst.__class__.__mro__[1:-1])
    return _COMMASPACE_(unstr(n, *args, **kwds), Fmt.PAREN(_MRO_, m))
Пример #2
0
def _xkwds_Error(_xkwds_func, kwds, name_txt, txt='default'):
    # Helper for _xkwds_get and _xkwds_pop below
    from pygeodesy.streprs import Fmt, pairs
    f = _COMMASPACE_.join(pairs(kwds) + pairs(name_txt))
    f = Fmt.PAREN(_xkwds_func.__name__, f)
    t = _multiple_ if name_txt else _no_
    t = _SPACE_(t, _EQUAL_(_name_, txt), 'kwargs')
    return _AssertionError(f, txt=t)
Пример #3
0
    def toRepr(self, **kwds):  # PYCHOK expected
        '''(INTERNAL) I{Could be overloaded}.

           @kwarg kwds: Optional, keyword arguments.

           @return: C{toStr}() with keyword arguments (as C{str}).
        '''
        t = self.toStr(**kwds).lstrip('([{').rstrip('}])')
        return Fmt.PAREN(self.classname, t)  # XXX (self.named, t)
Пример #4
0
def _callname(name, class_name, self_name, up=1):  # imported by .points
    '''(INTERNAL) Assemble the name for an invokation.
    '''
    n, c = class_name, callername(up=up + 1)
    if c:
        n = _DOT_(n, Fmt.PAREN(c, name))
    if self_name:
        n = _SPACE_(n, repr(self_name))
    return n
Пример #5
0
    def toStr(self, prec=6, sep=_COMMASPACE_, **unused):  # PYCHOK signature
        '''Return this C{Named-Tuple} items as string(s).

           @kwarg prec: The C{float} precision, number of decimal digits (0..9).
                        Trailing zero decimals are stripped for B{C{prec}} values
                        of 1 and above, but kept for negative B{C{prec}} values.
           @kwarg sep: Optional separator to join (C{str}).

           @return: Tuple items (C{str}).
        '''
        return Fmt.PAREN(sep.join(reprs(self, prec=prec)))
Пример #6
0
    def toStr(self, **unused):  # PYCHOK expected
        '''Return this reference frame as a text string.

           @return: This L{RefFrame}'s attributes (C{str}).
        '''
        e = self.ellipsoid
        t = (Fmt.EQUAL(_name_,
                       repr(self.name)), Fmt.EQUAL(_epoch_, self.epoch),
             Fmt.PAREN(Fmt.EQUAL(_ellipsoid_, classname(e)),
                       Fmt.EQUAL(_name_, repr(e.name))))
        return _COMMASPACE_.join(t)
Пример #7
0
    def trilaterate5(
            self,
            distance1,
            point2,
            distance2,
            point3,
            distance3,  # PYCHOK signature
            area=False,
            eps=EPS1,
            radius=R_M,
            wrap=False):
        '''B{Not implemented} for C{B{area}=True} or C{B{wrap}=True}
           and falls back to method C{trilaterate} otherwise.

           @return: A L{Trilaterate5Tuple}C{(min, minPoint, max, maxPoint, n)}
                    with a single trilaterated intersection C{minPoint I{is}
                    maxPoint}, C{min I{is} max} the nearest intersection
                    margin and count C{n = 1}.

           @raise IntersectionError: No intersection, trilateration failed.

           @raise NotImplementedError: Keyword argument C{B{area}=True} or
                                       B{C{wrap}=True} not (yet) supported.

           @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.

           @raise ValueError: Some B{C{points}} coincide or invalid B{C{distance1}},
                              B{C{distance2}}, B{C{distance3}} or B{C{radius}}.
        '''
        if area or wrap:
            from pygeodesy.named import notImplemented
            notImplemented(self, self.trilaterate5, area=area, wrap=wrap)

        t = _trilaterate(self,
                         distance1,
                         self.others(point2=point2),
                         distance2,
                         self.others(point3=point3),
                         distance3,
                         radius=radius,
                         height=None,
                         useZ=True,
                         LatLon=self.classof)
        # ... and handle B{C{eps}} and C{IntersectionError} as
        # method C{.latlonBase.LatLonBase.trilaterate2}
        d = self.distanceTo(t, radius=radius, wrap=wrap)  # PYCHOK distanceTo
        d = abs(distance1 - d), abs(distance2 - d), abs(distance3 - d)
        d = float(min(d))
        if d < eps:  # min is max, minPoint is maxPoint
            return Trilaterate5Tuple(d, t, d, t, 1)  # n = 1
        t = _SPACE_(_no_(_intersection_),
                    Fmt.PAREN(min.__name__, Fmt.f(d, prec=3)))
        raise IntersectionError(area=area, eps=eps, wrap=wrap, txt=t)
Пример #8
0
    def __init__(self, where, **lens_txt):  # txt=None
        '''New L{LenError}.

           @arg where: Object with C{.__name__} attribute
                       (C{class}, C{method}, or C{function}).
           @kwarg lens_txt: Two or more C{name=len(name)} pairs
                            (C{keyword arguments}).
        '''
        from pygeodesy.streprs import Fmt as _Fmt
        x = _xkwds_pop(lens_txt, txt=_invalid_)
        ns, vs = zip(*sorted(lens_txt.items()))
        ns = _COMMASPACE_.join(ns)
        vs = ' vs '.join(map(str, vs))
        t = _SPACE_(_Fmt.PAREN(where.__name__, ns), _len_, vs)
        _ValueError.__init__(self, t, txt=x)
Пример #9
0
 def __call__(self,
              lo,
              hi,
              prec=0,
              lopen=False,
              ropen=False,
              join=_COMMASPACE_):
     '''Return the range as C{"(lo, hi)"}, C{"(lo, hi]"},
        C{"[lo, hi)"} or C{"[lo, hi]"}.
     '''
     from pygeodesy.streprs import Fmt  # PYCHOK re-imported
     r = NN(Fmt.f(lo, prec=prec), join, Fmt.f(hi, prec=prec))
     if lopen:
         r = Fmt.PAREN(r) if ropen else Fmt.LOPEN(r)
     else:
         r = Fmt.ROPEN(r) if ropen else Fmt.SQUARE(r)
     return r
Пример #10
0
def _IsnotError(*nouns, **name_value_Error):  # name=value [, Error=TypeeError]
    '''Create a C{TypeError} for an invalid C{name=value} type.

       @arg nouns: One or more expected class or type names,
                   usually nouns (C{str}).
       @kwarg name_value_Error: One B{C{name=value}} pair and
                                optionally, an B{C{Error=...}}
                                keyword argument to override
                                the default B{C{Error=TypeError}}.

       @return: A C{TypeError} or an B{C{Error}} instance.
    '''
    from pygeodesy.streprs import Fmt as _Fmt
    Error = _xkwds_pop(name_value_Error, Error=TypeError)
    n, v = _xkwds_popitem(name_value_Error) if name_value_Error else (
        _name_value_, MISSING)  # XXX else tuple(...)
    t = _or(*nouns) or _specified_
    if len(nouns) > 1:
        t = _an(t)
    e = Error(_SPACE_(n, _Fmt.PAREN(repr(v)), _not_, t))
    _error_chain(e)
    _error_under(e)
    return e
Пример #11
0
 def _toRepr(self, value):
     '''(INTERNAL) Representation "<name> (<value>)" or "<classname>(<value>)".
     '''
     t = NN(self.name, _SPACE_) if self.name else self.classname
     return Fmt.PAREN(t, value)
Пример #12
0
 def __repr__(self):
     return Fmt.PAREN(self.named, int.__repr__(self))
Пример #13
0
def _error(fun, lat, lon, e):
    '''(INTERNAL) Format an error
    '''
    return _COLONSPACE_(Fmt.PAREN(fun.__name__, fstr((lat, lon))), e)
Пример #14
0
 def toRepr(self, prec=6, fmt=Fmt.F):  # PYCHOK _Named
     '''Like C{repr(dict)} but with C{name} and  C{floats} formatting by C{fstr}.
     '''
     t = pairs(self.items(), prec=prec, fmt=fmt, sep=_EQUAL_)
     return Fmt.PAREN(self.name, _COMMASPACE_.join(sorted(t)))
Пример #15
0
    d = dict((n, (x + r * e) * _Forward_Reverse)
             for n, x, r in zip(_trfNs, X.xform, X.rates))
    t = Transform(**d)
    return t


if __name__ == '__main__':

    from pygeodesy.interns import _COMMA_, _SPACE_, _NL_, _NL_var_

    n, y = date2epoch.__name__, 2020
    for m in range(1, 13):
        for d in (1, _mDays[m]):
            e = date2epoch(y, m, d)
            print(
                _SPACE_(Fmt.PAREN(n, _COMMASPACE_(y, m, d)), Fmt.f(e, prec=3)))

    # __doc__ of this file
    t = [NN] + repr(RefFrames).split(_NL_)
    print(_NL_var_.join(i.strip(_COMMA_) for i in t))

# **) MIT License
#
# Copyright (C) 2016-2021 -- mrJean1 at Gmail -- All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
Пример #16
0
 def __str__(self):
     from pygeodesy.named import classname
     return Fmt.PAREN(classname(self, prefixed=True), NN)
Пример #17
0
def utmupsValidate(coord, falsed=False, MGRS=False, Error=UTMUPSError):
    '''Check a UTM or UPS coordinate.

       @arg coord: The UTM or UPS coordinate (L{Utm}, L{Ups} or C{5+Tuple}).
       @kwarg falsed: C{5+Tuple} easting and northing are falsed (C{bool}).
       @kwarg MGRS: Increase easting and northing ranges (C{bool}).
       @kwarg Error: Optional error to raise, overriding the default
                     (L{UTMUPSError}).

       @return: C{None} if validation passed.

       @raise Error: Validation failed.

       @see: Function L{utmupsValidateOK}.
    '''
    def _en(en, lo, hi, ename):  # U, Error
        try:
            if lo <= float(en) <= hi:
                return
        except (TypeError, ValueError):
            pass
        t = _SPACE_(_outside_, U, _range_, _range_(lo, hi))
        raise Error(ename, en, txt=t)

    if isinstance(coord, (Ups, Utm)):
        hemi = coord.hemisphere
        enMM = coord.falsed
    elif isinstance(coord, (UtmUps5Tuple, UtmUps8Tuple)):
        hemi = coord.hemipole
        enMM = falsed
    else:
        raise _IsnotError(Error=Error,
                          coord=coord,
                          *map1(modulename, Utm, Ups, UtmUps5Tuple,
                                UtmUps8Tuple))
    band = coord.band
    zone = coord.zone

    z, B, h = _to3zBhp(zone, band, hemipole=hemi)

    if z == _UPS_ZONE:  # UPS
        import pygeodesy.ups as u  # PYCHOK expected
        U, M = _UPS_, _UpsMinMax
    else:  # UTM
        import pygeodesy.utm as u  # PYCHOK expected
        U, M = _UTM_, _UtmMinMax

    if MGRS:
        U, s = _MGRS_, _MGRS_TILE
    else:
        s = 0

    i = _NS_.find(h)
    if i < 0 or z < _UTMUPS_ZONE_MIN \
             or z > _UTMUPS_ZONE_MAX \
             or B not in u._Bands:
        t = Fmt.PAREN(U, repr(_SPACE_(NN(Fmt.zone(z), B), h)))
        raise Error(coord=t, zone=zone, band=band, hemisphere=hemi)

    if enMM:
        _en(coord.easting, M.eMin[i] - s, M.eMax[i] + s,
            _easting_)  # PYCHOK .eMax .eMin
        _en(coord.northing, M.nMin[i] - s, M.nMax[i] + s,
            _northing_)  # PYCHOK .nMax .nMin