Example #1
0
def geoidHeight2(lat, lon, model=0, timeout=2.0):
    '''Get the C{NAVD88} geoid height at an C{NAD83} location.

       @arg lat: Latitude (C{degrees}).
       @arg lon: Longitude (C{degrees}).
       @kwarg model: Optional, geoid model ID (C{int}).
       @kwarg timeout: Optional, query timeout (seconds).

       @return: An L{GeoidHeight2Tuple}C{(height, model_name)}
                or C{(None, "error"}) in case of errors.

       @raise ValueError: Invalid B{C{timeout}}.

       @note: The returned C{height} is C{None} if B{C{lat}} or B{C{lon}} is
              invalid or outside the C{Conterminous US (CONUS)}, if the
              B{C{model}} was invalid, if conversion failed or if the
              query timed out.  The C{error} is the C{HTTP-, IO-, SSL-,
              Type-, URL-} or C{ValueError} as a string (C{str}).

       @see: U{NOAA National Geodetic Survey
             <https://www.NGS.NOAA.gov/INFO/geodesy.shtml>},
             U{Geoid<https://www.NGS.NOAA.gov/web_services/geoid.shtml>},
             U{USGS10mElev.py<https://Gist.GitHub.com/pyRobShrk>}, module
             L{geoids}, classes L{GeoidG2012B}, L{GeoidKarney} and
             L{GeoidPGM}.
    '''
    try:
        j = _qURL('https://Geodesy.NOAA.gov/api/geoid/ght',
                  ('lat=%.6F' % (Lat(lat), ), 'lon=%.6F' %
                   (Lon(lon), ), 'model=%s' % (model, ) if model else ''),
                  timeout=Scalar(timeout, name='timeout'))  # PYCHOK 5
        if j[:1] == '{' and j[-1:] == '}' and j.find('"error":') > 0:
            d = _json(j)
            if isinstance(d.get('error', 'N/A'), float):
                h = d.get('geoidHeight', None)
                if h is not None:
                    m = _str(d.get('geoidModel', 'N/A'))
                    return GeoidHeight2Tuple(h, m)
            e = 'geoidHeight'
        else:
            e = 'JSON'
        e = 'no %s "%s"' % (e, clips(j, limit=256, white=' '))
    except (HTTPError, IOError, TypeError, ValueError) as x:
        e = repr(x)
    e = _error(geoidHeight2, lat, lon, e)
    return GeoidHeight2Tuple(None, e)
Example #2
0
def geoidHeight2(lat, lon, model=0, timeout=2.0):
    '''Get the C{NAVD88} geoid height at an C{NAD83} location.

       @param lat: Latitude (C{degrees}).
       @param lon: Longitude (C{degrees}).
       @keyword model: Optional, geoid model ID (C{int}).
       @keyword timeout: Optional, query timeout (seconds).

       @return: 2-Tuple (C{height, model_name}) in (C{meter, str})
                or C{(None, error}).

       @note: The returned C{height} is C{None} if I{lat} or I{lon} is
              invalid or outside the C{Conterminous US (CONUS)}, if the
              I{model} was invalid, if conversion failed or if the
              query timed out.  The C{error} is the C{HTTP-, IO-, SSL-,
              Type-, URL-} or C{ValueError} as a string (C{str}).

       @see: U{NOAA National Geodetic Survey
             <http://www.NGS.NOAA.gov/INFO/geodesy.shtml>},
             U{Geoid<http://www.NGS.NOAA.gov/web_services/geoid.shtml>},
             U{USGS10mElev.py<http://Gist.GitHub.com/pyRobShrk>}, module
             L{geoids}, classes L{GeoidG2012B}, L{GeoidKarney} and
             L{GeoidPGM}.
    '''
    try:
        j = _qURL('http://Geodesy.NOAA.gov/api/geoid/ght',
                  ('lat=%.6f' % (lat, ), 'lon=%.6f' % (lon, ), 'model=%s' %
                   (model, ) if model else ''),
                  timeout=float(timeout))  # PYCHOK 5
        if j[:1] == '{' and j[-1:] == '}' and j.find('"error":') > 0:
            d = _json(j)
            if isinstance(d.get('error', 'N/A'), float):
                h = d.get('geoidHeight', None)
                if h is not None:
                    return h, _str(d.get('geoidModel', 'N/A'))
            e = 'geoidHeight'
        else:
            e = 'JSON'
        e = 'no %s "%s"' % (e, clipStr(j, limit=256, white=' '))
    except (IOError, TypeError, ValueError) as x:
        e = repr(x)
    return None, _error(geoidHeight2, lat, lon, e)
Example #3
0
File: rpc.py Project: reorx/Docky
    def login(self, email, password):
        if self._authed:
            return self._auth_token

        data = {'email': email, 'password': password}
        data_s = 'json=' + _json(data)
        call_url = 'http://%s%s%s' % (self._domain, self._port_s, self.LOGIN_URL)
        req = urllib2.Request(url=call_url, data=data_s, headers=self.BASIC_HEADER)
        resp = self._fetch(req)

        try:
            cookie = BaseCookie(resp.headers['set-cookie'])
        except KeyError:
            cookie = BaseCookie(resp.headers['Set-Cookie'])

        self._auth_token = cookie[self.SESSION_COOKIE_NAME].value
        self._authed = True
        self.user = _dic(resp.read())

        print 'self._auth_token: ', self._auth_token
        return self._auth_token
Example #4
0
def geoidHeight2(lat, lon, model=0, timeout=2.0):
    '''Get the C{NAVD88} geoid height at an C{NAD83} location.

       @param lat: Latitude (C{degrees}).
       @param lon: Longitude (C{degrees}).
       @keyword model: Optional, geoid model ID (C{int}).
       @keyword timeout: Optional, query timeout (seconds).

       @return: 2-Tuple (height, model_name) in (C{meter}, C{str}) or
                (C{None}, I{<error>}).

       @note: The returned height is C{None} if I{lat} or I{lon} is
              invalid or outside the C{Conterminous US (CONUS)}, if
              the I{model} was invalid, if conversion failed or if
              the query timed out.  The I{<error>} is the C{HTTP-,
              IO-, SSL-, Type-, URL-} or C{ValueError} as C{str}.

       @see: U{NOAA National Geodetic Survery
             <http://www.NGS.NOAA.gov/INFO/geodesy.shtml>} and
             U{Geoid<http://www.NGS.NOAA.gov/web_services/geoid.shtml>}
    '''
    try:
        d = _json(
            _qURL('http://Geodesy.NOAA.gov/api/geoid/ght',
                  'lat=%.6f' % (lat, ),
                  'lon=%.6f' % (lon, ),
                  'model=%d' % (model, ) if model else '',
                  timeout=float(timeout)))

        e = d.get('error', 'N/A')
        if isinstance(e, float):
            h = d.get('geoidHeight', None)
            if h is not None:
                return h, d.get('geoidModel', 'N/A')

        raise ValueError(e)
    except (IOError, TypeError, ValueError) as x:
        return None, _error(geoidHeight2, lat, lon, x)
Example #5
0
def _get_message(msg):
    "Returns a list-of-one-string payload for returning from handlers."
    return [_json(dict(message=msg), separators=(',', ':'))]