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

Class for variables used for (netcdf) file IO
 
Authors: L. Feng, Edinburgh University
History: v0.9, 2012.10.22
History: v0.95, 2013.02.28 
 
 
Classes:
=============================================================
1. io_var_cl: class for variables used to do file I/O. 
 
 
Functions
============================================================
1. construct_filename: constructure file name 
2. create_var_read_list: create a list of IO var to be read from 
   (netcdf) file
3. create_var_dim_list: create a list of IO var used to define dimension
4. create_var_write_list: create a list of var to be saved into (netcdf) file

 
Modules
       
ESA.util.message_m
numpy
ESA.util.otool_obj
Scientific.IO.NetCDF

 
Classes
       
io_var_cl

 
class io_var_cl
     Class for file io 
 
 Members:
 -----------------------------------------------
 1.  name: <str>:Name of the variable 
 2.  type: <str>: type of the variable
 3.  dimname:<list, t:str>: list if variable  types
 4.  var:   <array>: data 
 5.  varattr: <dict>: attributes
 6.  colno: <int>: column number of the data 
 7.  attr_rd_lst:<list>: the attribute to be read
 8.  dims:<tuple>: shape of the var
 9.  ndim:<integer>: number of the dimension 
10.  mask_val: <float>: filling value for missing or bad data
11.  scale:  <float>: scaling value 
12.  shift:  <float>: shift value 
13.  grd:    <gp_grd_cl>: grid 
 
 
 
Functions:
--------------------------------------------------
1. set_attr_rd_list: set attributes to be read
2. set_dimname: set dimenion names for the variable 
3. set_name: set variable name 
4. set_type: set variable type 
5. set_colno: set column number
6. get_attr: get attribute 
7. set_attr: set attribute
 
8. set_mask: set mask values
9. set_offset: set offset values
10. post_process: re-scale and add shift to the data
11. set_data: set the data set 
12. __getitem__: get var at given index 
13. shape: return shape of the var
14. copy: make a copy of the var
 
15. set_attr: set attributes
16. get_attr: get_attributes
 
  Methods defined here:
__getitem__(self, index)
get value at given index 
 
Inputs:
-----------------------------------------------
1. index:<integer/tuple>: index
 
Returns:
---------------------------------------------------
1. var[index]:<float/array>: values at given index
__init__(self, varname, vartype, vardim, var, varattr={}, colno=-999, attr_rd_lst=[], mask_val=-999.0, scale=1.0, offset=0.0, grd=None)
initialization  
 
Inputs:
------------------------------------------
1.  varname: <str>:Name of the variable 
2.  vartype: <str>: type of the variable
3.  vardim:<list, t:str>: list if variable  types
4.  var:   <array>: data 
5.  varattr: <dict>: attributes
6.  colno: <int>: column number of the data 
7.  attr_rd_lst:<list>: the attribute to be read
8.  mask_val:<float>: filling for bad or missing values
9.  scale:<float>: scaling factor 
10. offset:<float>: offset 
11. grd:<gp_grid_cl>: grid of the data
copy(self)
make a copy 
 
Returns:
1. new_var:<io_var_cl>: a copy of the var
del_attr(self, attr_name)
delete  the attribute
 
Inputs:
----------------------------------
1. attr_name:<str>: name of the attribute
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.
post_process(self, data, new_maskval)
re-scale and add shift to the data 
 
Inputs:
---------------------------------------
1. data:<array>: data  
2. new_mask_val:<float>: new masks for data or missing values
 
Returns:
--------------------------------------------------
1. data: <array>: data after been processed
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
set_attr_rd_list(self, attr_rd_lst)
set list for attributes to be read
 
Inputs:
---------------------------------------
1.  attr_rd_lst:<list>: the attribute to be read
set_colno(self, colno)
set column number 
 
Inputs:
---------------------------------------
1.  colno:<integer>: column of the variable  in the file
set_data(self, data, copy=True)
set the data set  
 
Inputs:
----------------------------
1. data:<array>: data
set_dimname(self, dimname)
set dimension Names
 
Inputs:
---------------------------------------
1.  dimname:<list, t:str>: dimension names
set_grid(self, grd)
setup the grid for the var
set_mask(self, mask_val)
set mask value 
 
Inputs:
---------------------------------------
1.  mask_val:<float>: mask_val
set_name(self, name)
set dimension Names
 
Inputs:
---------------------------------------
1.  name:<str>: name of the var
set_offset(self, offset)
set offset values 
 
 
Inputs:
---------------------------------------
1. offset:<float>: offset
set_scale(self, scale)
set scaling factor 
 
Inputs:
---------------------------------------
1.  scale:<float>: scaling factor
set_type(self, stype)
set dimension Names
 
Inputs:
---------------------------------------
1.  stype:<>: var type
shape(self)
get shape of the data set 
Returns:
---------------------------------------------------
1. dims:<tuple/list>: shape of the var

 
Functions
       
construct_enr_filename(path, flnm, yyyy, dd, mm, enr_yyyy, enr_doy, enr_step, enr_em_st, enr_em_end)
construct file name for ensemble runs
 
Input:
============================================
1. path:<str>: directory
2. flnm:<str>: name 
3. enr_yyyy:<int>: year for ensemble run start 
4. enr_doy:<int>:  doy for ensemble run start
5. enr_step:<int>: step for ensemble run 
7. enr_em_st:<int>: firt one in the ensemble 
8. enr_em_end:<int>: last one in the ensemble 
9. yyyy, dd, mm:<int>: output time 
 
Notes:
1. the default extension will be like: 
STXENRSTEPX.ENXEMSTX-XEMEND.XYYYYXXMMXXDDX
for example:
ST001.EN0001-EN0048.2009.01.01
stands for 
step=1
ensemble member of 0001-0049
yyyyy=2009, mm=1, dd=1
construct_filename(filepath, filenameformat, **keywords)
construction file name use the keywords 
Inputs:
------------------------------------------------
1. filepath:<str>:template for file path 
2. filenameformat:<str>:template for file name
 
3. keywords:<dict>: the parts should be replaced 
 
 
Returns:
-------------------------------------------------
sflnm:<str>: full filename 
 
 
Notes:
--------------------
Keywords should in format of XKEYWORDX
create_var_dim_list(vname_lst, vtype_lst=None, vdata_lst=None)
construct io a list for dimension definition 
 
Inputs:
------------------------------------------
1. vname_lst:<list, t:str>: name of dimensions used in the file 
2. vtype_lst:<list, t:str>: data type of dimension 
3. vdata_lst:<list, t:array>: data of dimension 
 
Outputs:
------------------------------------------
1. var_lst:<list, io_var_cl>: list of dimension  var
create_var_read_list(vname_lst, attr_read_lst=None)
Make a list for IO var to be read from 
 
 
Inputs:
======================================================
1. vname_lst: <list, t:str>: list of variables to read in 
2. attr_read_lst: <list, t:list>: attributes of vars to be read in 
 
 
Returns:
================================================
1, var_lst:<list, io_var_cl>: list of var 
 
Notes:
create_var_write_list(vname_lst, vdim_lst, vtype_lst=None, vdata_lst=None)
construct io avr list for variables to be stored n ensemble fluxes 
 
Inputs:
------------------------------------------
1. vname_lst:<list, t:str>: list of variable names
2. vdim_lst:<list, t:list>: list of dimension names for each variable  (see Note 1)
3. vtype_lst:<list, t:str>: list of variable type
4. vdata_lst:<list, t:array>: list of data
 
1. Outputs:
------------------------------------------
var_lst:<list, io_var_cl>: list of IO var 
 
Notes: 
==========================================================
 
1. if one element in vdim_lst is a string, this element will be converted to a list 
afterm being split using separator ';'