grid Package

nearest_neighbor Module

Created on Jul 30, 2013

@author: Christoph Paulik christoph.paulik@geo.tuwien.ac.at

class pytesmo.grid.nearest_neighbor.findGeoNN(lon, lat, R=6370997.0, grid=False, kd_tree_name='pykdtree')[source]

Bases: object

class that takes lat,lon coordinates, transformes them to cartesian (X,Y,Z) coordinates and provides a interface to scipy.spatial.kdTree as well as pykdtree if installed

Parameters :

lon : numpy.array or list

longitudes of the points in the grid

lat : numpy.array or list

latitudes of the points in the grid

R : float, optional

Radius of the earth to use for calculating 3D coordinates

grid : boolean, optional

if True then lon and lat are assumed to be the coordinates of a grid and will be used in numpy.meshgrid to get coordinates for all grid points

kd_tree_name : string, optional

name of kdTree implementation to use, either ‘pykdtree’ to use pykdtree or ‘scipy’ to use scipy.spatial.kdTree Fallback is always scipy if any other string is given or if pykdtree is not installed. standard is pykdtree since it is faster

Attributes

R float earth radius to use in computation of x,y,z coordinates
coords numpy.array 3D array of cartesian x,y,z coordinates
kd_tree_name: string   name of kdTree implementation to use, either ‘pykdtree’ to use pykdtree or ‘scipy’ to use scipy.spatial.kdTree Fallback is always scipy if any other string is given or if pykdtree is not installed
kdtree: object   kdTree object that is built only once and saved in this attribute

Methods

find_nearest_index(lon, lat)[source]

finds nearest index, builds kdTree if it does not yet exist

Parameters :

lon : float, list or numpy.array

longitude of point

lat : float, list or numpy.array

latitude of point

Returns :

d : float, numpy.array

distances of query coordinates to the nearest grid point, distance is given in cartesian coordinates and is not the great circle distance at the moment. This should be OK for most applications that look for the nearest neighbor which should not be hundreds of kilometers away.

ind : int, numpy.array

indices of nearest neighbor

index_lon : numpy.array, optional

if self.grid is True then return index into lon array of grid definition

index_lat : numpy.array, optional

if self.grid is True then return index into lat array of grid definition

Table Of Contents

Previous topic

pytesmo Package

Next topic

io Package

This Page