ESA.util.gp_grid_m
index
/home/lfeng/otool/ESA/util/gp_grid_m.py

generic class for grid used by numerical models.  
   
    Authors: L. Feng, Edinburgh University
    History: v0.9, 2012.06.30
    History: v0.95, 2012.08.23
    this module defines grid class for high-dimension fields
 
 
Classes:
===================================================
1. gp_grid_cl: grid 
 
 
Functions:
=====================================================
1.  coordinate_sample_index: Generate (0,1) (i.e, low-high) 
----list for the corners around a  given point in a high-dimension space. 
    
2. build_grid_from_matrix: convert a matrix into a gridded data set.

 
Modules
       
ESA.util.gp_axis_m
ESA.util.message_m
numpy
copy
ESA.util.otool_obj

 
Classes
       
gp_grid_cl

 
class gp_grid_cl
    grid class
 
 
Members:
------------------------------------------------------
1. ndim:<int>: number of the dimensions. 
2. dims:<list>: shape of the grid 
3. __axis_dict:<dictionary>: dictionary for id of gp_axis
4. axis_lst:<list>: list of the axises
5. attr_dict:<dictionary>: dictionary for the attributes
 
 
Functions:
------------------------------------------------------
1. __init__: initialize the class
2. __getitem__: overide index function to return axis. 
3. set_attr:  set attribute
4. get_attr:  get attribute
5. allocate_point: find grid corners surrounding a given point.  
6. allocate_point_subspace: find grid corners surrounding a point given in a subplace
 
7. update_axis: replace or add axis to the grid 
 
8. get_axis_ids: get IDs for given axis names
 
9. get_value_at_point: interpolate data field to a point defined at the grid (N-d) space. 
 
10. get_profile: interploate profiles of data field to a point defined at (N-1)-d space
 
  Methods defined here:
__getitem__(self, ax_id)
get axis  
 
Inputs:
--------------------------------
1. ax_id:<integer/str>: Id for the axis to be found
 
Returns:
----------------------------------
1, gax:<gp_axis_cl>: axis if the ax_id is valid
__init__(self, gp_axis_lst, **keywords)
initialize grid 
Inputs:
1. gp_axis_lst:<list>:list of gp_axis for definition of the grid.
2. keywords:<dict>: attributes
 
Notes:
----------------------------------------------------
each axis in gp_axis_lst  is expected have different names
allocate_point(self, p)
find grid points around a given point, and  
calculate their weights according to the distances from this point.  
 
Inputs:
----------------------------------------------------------------
1. p:<array, (nax,)>: the coordiantes of the given point.  
 
Returns:
-------------------------------------------------------------------
1. grd_pt_lst: <list, t:tuple>: list of the index of the surrounding grid points.
---If the dimension size nax is n, the length of grd_pt_lst is 2^n, 
with each element being an array of size n. 
        
2. grd_wgt_lst: <list, t:float>: Weights of the the surrounding points,         
---which are calculated from their distances from the point.
allocate_point_subspace(self, p, axis_id_lst)
find grid points around a given point, and  
calculate their weights according to the distances from this point.  
 
Inputs:
----------------------------------------------------------------
1. p:<array, (nuse,)>: the coordiantes of the given point.  
2. axis_id_lst:<list, t:integer>: the use the index
 
Returns:
-------------------------------------------------------------------
1. grd_pt_lst: <list, t:tuple>: list of the index of the surrounding grid points.
---If the dimension size nax is n, the length of grd_pt_lst is 2^n, 
with each element being an array of size n with coordinate [:] for axis=axis_id
 
        
2. grd_wgt_lst: <list, t:float>: Weights of the the surrounding points,         
---which are calculated from their distances from the point.
copy(self)
make a copy of itself
copy_attr_dict(self)
get one copy of the attr_dict
get_attr(self, attr_name)
find the attribute
 
Inputs:
----------------------------------
1. attr_name:<str>: name of the attribute
 
Returns:
------------------------------------------
1. attr: <obj>: if the attribute exists.
get_axis(self, ax_id)
wrapper for __getitem__
 
Inputs:
--------------------------------
1. ax_id:<integer/str>: Id for the axis to be found
 
Returns:
----------------------------------
1, gax:<gp_axis_cl>: axis if the ax_id is valid
get_axis_ids(self, axis_name_lst)
Find id for given names 
 
Inputs:
----------------------------------------------------------------
1. axis_name_lst:<list, t:str>: the names
 
Returns:
------------------------------------------
1. axis_id_lst:<list,t:integer>: the index
get_profile(self, p, field, axis_id_lst)
extract profile at a  given 'horizontal location'
 
Inputs:
----------------------------------------------------------------
1. p:<array, (nuse,)>: the sub coordiantes of the given points.  
2. field:<array, dims>: gridded data 
3. axis_id_lst:<integer>: index of the axis, where the axises to be used
 
Returns:
---------------------------------------------------------------
 
1. profile:<array, ...>: the profile at the locations
get_value_at_point(self, p, field)
calculate value at a given p by interpolating the 
gridded data (field) at surrounding grid points
 
Inputs:
----------------------------------------------------------------
1. p:<array, (nax,)>: the coordiantes of the given point.  
2. field:<array, (nx, ny, nz, ...)>:gridded data
 
 
Returns:
----------------------------------------------------------------
val:<float>: values at point p
set_attr(self, attr_name, attr_value)
set attribute
Inputs:
----------------------------
1. attr_name:<str>: name of the attribute
2. attr_value:<obj>: the value of the attribute
shape(self)
Return the shape of the grid
size(self, ax_id=None)
Return size along one direction or total size of the grid 
 
Inputs:
--------------------------------
1. ax_id:<integer/str>: Id for the axis to be found
 
Returns:
1. nsize:<integer>: the size of axis if axis_id is provided, or the total size if no ax_id is specified.
update_axis(self, gp_axis)
add or replace axis 
 
Inputs:
--------------------------------------------------
1. gp_axis:<gp_axis_cl>: class to be added or replaced
        
Output:
-------------------------------------------------
2. gax:<gp_axis>: axis if the Id is correct

 
Functions
       
build_grid_from_matrix(ax_name_lst, ax_colno_lst, data, zname=None, zval=None, mask_val=-999.0)
convert a matrix into a gridded data set
 
 
Inputs:
-----------------------------------------------------
1. ax_name_lst:<list, t:str>: axis names
2. ax_colno_lst:<list, t:integer>: columns of the axis in the table 
3. data:<array, (nrow, ncol>: data
--- if (zname and zval) are given,   data is supposed to be in the column of 
--- [ax_1, ax_2, ax_3,.., ax_n, z1, z2, z3, ...]
 
---if (zname and zval) are not given, data is supposed to be in the form of 
--- [ax_1, ax_2, ax_3, ...,ax_n, val]
 
4. zname:<str>: name of the z-axis ('vertical' axis)
5. zval:<array>:  z ('vertical') data: 
 
 
 
Returns:
--------------------------------------------
1. grd:<gp_grd_cl>: the grid defined by  [ax_name_lst, yname]
2. data:<array, (nrow, nax)>: gridded data
coordinate_sample_index(n)
Generate (0,1) (i.e, low-high) list for the corners around a 
given point in a high-dimension space. These indexes can be 
used to sample the (left-right) boundary pairs of the point along each directions. 
 
Inputs:
----------------------------------------------
1. n:<int>: dimension number of the space (==the number of left-right boundary pairs)
 
Returns:
----------------------------------------------
1. cor_lst:<list>: list of the (0,1)  for the surrounding corners of 
---a point in a N-dimensional space. 
For example,  in a 2D space, cor_lst=[[0,0], [0,1], [1,0], [1,1]] for four corners.