pytesmo.grid package

Submodules

pytesmo.grid.grids module

Created on Aug 26, 2013

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

class pytesmo.grid.grids.BasicGrid(lon, lat, gpis=None, subset=None, setup_kdTree=True, shape=None)[source]

Bases: object

Grid that just has lat,lon coordinates and can find the nearest neighbour. It can also yield the gpi, lat, lon information in order.

Parameters:

lon : numpy.array

longitudes of the points in the grid

lat : numpy.array

latitudes of the points in the grid

gpis : numpy.array, optional

if the gpi numbers are in a different order than the lon and lat arrays an array containing the gpi numbers can be given

subset : numpy.array, optional

if the active part of the array is only a subset of all the points then the subset array which is a index into lon and lat can be given here

setup_kdTree : boolean, optional

if set (default) then the kdTree for nearest neighbour search will be built on initialization

shape : tuple, optional

if given the grid can be reshaped into the given shape this indicates that it is a regular grid and fills the attributes self.londim and self.latdim which define the grid only be the meridian coordinates(self.londim) and the coordinates of the circles of latitude(self.latdim). The shape has to be given as (latdim, londim)

Attributes

arrlon numpy.array array of all longitudes of the grid
arrlat numpy.array array of all latitudes of the grid
n_gpi int number of gpis in the grid
gpidirect boolean if true the gpi number is equal to the index of arrlon and arrlat
gpis numpy.array gpi number for elements in arrlon and arrlat gpi[i] is located at arrlon[i],arrlat[i]
subset numpy.array if given then this contains the indices of a subset of the grid. This can be used if only a part of a grid is interesting for a application. e.g. land points, or only a specific country
allpoints boolean if False only a subset of the grid is active
activearrlon numpy.array array of longitudes that are active, is defined by arrlon[subset] if a subset is given otherwise equal to arrlon
activearrlat numpy.array array of latitudes that are active, is defined by arrlat[subset] if a subset is given otherwise equal to arrlat
activegpis numpy.array array of gpis that are active, is defined by gpis[subset] if a subset is given otherwise equal to gpis
issplit boolean if True then the array was split in n parts with the self.split function
kdTree object grid.nearest_neighbor.findGeoNN object for nearest neighbor search
shape tuple, optional if given during initialization then this is the shape the grid can be reshaped to this only makes sense for regular lat,lon grids
latdim numpy.array, optional if shape is given this attribute has contains all latitudes that make up the regular lat,lon grid
londim numpy.array, optional if shape is given this attribute has contains all longitudes that make up the regular lat,lon grid

Methods

calc_lut(other, max_dist=inf, into_subset=False)[source]

takes other BasicGrid or CellGrid objects and computes a lookup table between them. the lut will have the size of self.n_gpis and will for every grid point have the nearest index into other.arrlon etc.

Parameters:

other : grid object

to which to calculate the lut to

max_dist : float, optional

maximum allowed distance in meters

into_subset : boolean, optional

if set the returned lut will have the index into the subset if the other grid is a subset of a grid. Example: if e.g. ind_l is used for the warp_grid some datasets will be given as arrays with len(ind_l) elements. These datasets can not be indexed with gpi numbers but have to be indexed with indices into the subset

find_nearest_gpi(lon, lat, max_dist=inf)[source]

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

Parameters:

lon : float

longitude of point

lat : float

latitude of point

Returns:

gpi : long

grid point index

distance : float

distance of gpi to given lon, lat At the moment not on a great circle but in spherical cartesian coordinates

get_grid_points(*args)[source]

Returns all active grid points

Parameters:

n : int, optional

if the grid is split in n parts using the split function then this function will only return the nth part of the grid

Returns:

gpis : numpy.array

arrlon : numpy.array

arrlat :numpy.array :

gpi2lonlat(gpi)[source]

Longitude and Latitude for given GPI.

Parameters:

gpi : int32

Grid Point Index.

Returns:

lon : float

Longitude (deg) of GPI.

lat : float

grid_points(*args)[source]

Yields all grid points in order

Parameters:

n : int, optional

if the grid is split in n parts using the split function then this iterator will only iterate of the nth part of the grid

Returns:

gpi : long

grid point index

lon : float

longitude of gpi

lat : float

longitude of gpi

split(n)[source]

function splits the grid into n parts this changes not function but grid_points() which takes the argument n and will only iterate through this part of the grid

Parameters:

n : int

number of parts the grid should be split into

unite()[source]

unites a split array, so that it can be iterated over as a whole again

class pytesmo.grid.grids.CellGrid(lon, lat, cells, gpis=None, subset=None)[source]

Bases: pytesmo.grid.grids.BasicGrid

Grid that has lat,lon coordinates as well as cell informatin. It can find nearest neighbour. It can also yield the gpi, lat, lon, cell information in cell order. This is important if the data on the grid is saved in cell files on disk as we can go through all grid points with optimized IO performance

Parameters:

lon : numpy.array

longitudes of the points in the grid

lat : numpy.array

latitudes of the points in the grid

cells : numpy.array

of same shape as lon and lat, containing the cell number of each gpi

gpis : numpy.array, optional

if the gpi numbers are in a different order than the lon and lat arrays an array containing the gpi numbers can be given

subset : numpy.array, optional

if the active part of the array is only a subset of all the points then the subset array which is a index into lon, lat and cells can be given here

Attributes

arrcell numpy.array array of cell number with same shape as arrlon,arrlat
activearrcell numpy.array array of longitudes that are active, is defined by arrlon[subset] if a subset is given otherwise equal to arrlon

Methods

get_cells()[source]

function to get all cell numbers of the grid

Returns:

cells : numpy.array

unique cell numbers

get_grid_points(*args)[source]

Returns all active grid points

Parameters:

n : int, optional

if the grid is split in n parts using the split function then this function will only return the nth part of the grid

Returns:

gpis : numpy.array

arrlon : numpy.array

arrlat :numpy.array :

cells : numpy.array

gpi2cell(gpi)[source]

Cell for given GPI.

Parameters:

gpi : int32

Grid Point Index.

Returns:

cell : int

Cell number of GPI.

grid_points_for_cell(cell)[source]

get all grid points for a given cell number

Parameters:

cell : int

cell number

Returns:

gpis : numpy.array

gpis belonging to cell

split(n)[source]

function splits the grid into n parts this changes not function but grid_points() which takes the argument n and will only iterate through this part of the grid

Parameters:

n : int

number of parts the grid should be split into

exception pytesmo.grid.grids.GridDefinitionError[source]

Bases: exceptions.Exception

exception pytesmo.grid.grids.GridIterationError[source]

Bases: exceptions.Exception

pytesmo.grid.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, max_dist=inf)[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

Module contents

Table Of Contents

Previous topic

pytesmo package

Next topic

pytesmo.io package

This Page