ESA.enkf.run_desc_file_m
index
/home/lfeng/otool/ESA/enkf/run_desc_file_m.py

Functions for creating and  reading  configuration for ensemble runs
 
    Authors: L. Feng, Edinburgh University
    History: v0.9, 2012.06.28
    History: v0.95, 2013.02.15
 
Functions
=================================================
 
1. open_enr_desc_file: set up class file_desc_cl for file access
2. read_enr_desc_file: read enr_desc   data into class file_desc_cl
3. close_enr_desc_file: delete class file_desc_cl
4. get_enr_desc_table: get enr_desc_table_lst at given time
5. write_enr_desc_colum_heads: write out the column names etc
6. write_enr_desc_colum_val: write out the column values
7. open_enr_desc_file_write: open one new run description file 
8. close_new_enr_desc_file: close a new run description file

 
Modules
       
ESA.util.message_m
numpy
ESA.util.otool_descfile_io
ESA.util.otool_obj
ESA.util.otool_var_io
ESA.util.time_module

 
Functions
       
add_enr_desc_data(fdesc, ref, **keywords)
add table for ensemble configurations  to data_lst in fdesc
 
Inputs:
=====================================
1. fdesc:<grdfile_io_cl>: class for file access
2. ref:<str/numeric>: reference for data sets read from file 
3. keywords:<dict>: extra parameters
 
Returns:
=====================================
1. idx:<int>: index of the data set with reference =ref.
close_enr_desc_file(fdesc)
Close fdesc file 
 
Inputs:
--------------------------------------------------
1. fdesc:<file_desc_cl>: class for file access
 
Returns:
---------------------------------------------
1. None
close_new_enr_desc_file(fl)
close file 
Inputs;
---------------------------------
1. fl:<file>: file handle
get_enr_desc_file_ref(yyyy, mm, dd, **keywords)
check file reference
 
for enremble configuration. By default 
the reference number is year 
 
Inputs:
----------------------------------------------------
1. yyyy:<array, (ntime,)>: year
2. mm: <array, (ntime,)>: month
3. dd:<array, (ntime,)>: dd
4. keywords:<dict>: extra information
 
Returns:
------------------------------------------------------
1. ref:<int>: reference number 
--- by default, the reference number is year
get_enr_desc_table(fdesc, oyyyy, omm, odd, **keywords)
read run description  data table at a given point (such year)
 
Inputs:
---------------------------------------
1. fdesc:<grdfile_io_cl>: file access 
2. oyyyy:<int>: year
3. omm: <int>: month 
4. odd:<int>: day (for future use)
 
6. keywords:<dict>: extra inputs
---Reserved Entries
 
Returns:
 
================================================
1. fdesc.data_lst:<list, t:recarray>:class for runs covering given date
open_enr_desc_file(flnm, datapath, yyyy, mm, dd, **fio_keywords)
construct fdesc to read ensemble run configurations data
 
 
Inputs:
==============================================
1. flnm:<str>: format for filename
2. datapath:<str>: file path
3. yyyy:<array, (ntime,)>: year
4. mm: <array, (ntime,)>: month
5. dd:<array, (ntime,)>: dd
6. fio_keywords:<dict>: extra inputs 
---Reserved keywords:
--->fl_colnm_lst: <list>:  list of all column names in the file 
--->sel_colnm_lst: <list>: list of the names for column to be read
--->colnm_dict:<dict>: dictionary for translating column names
--->delim: <str>: separator. 
--->data_start:<int>: starting line number of the data section 
--->header_start:<int>: line number of header section
 
 
Returns:
=============================================
1. fdesc:<file_desc_cl>: class for file access
open_enr_desc_file_write(flnm)
open a new file 
 
Inputs:
-----------------------------------------------
1. flnm:<str>: file name 
 
Returns:
-----------------------------------------------
1. fl:<file>: file handle
open_enr_desc_write(flnm, datapath, yyyy, mm, dd, **fio_keywords)
read_enr_desc_file(fdesc, **fio_keywords)
Read ensemble configurations as table into fdesc.data_lst
    
Inputs:
--------------------------------------------------
1. fdesc:<file_desc_cl>: class for file access
2. fio_keywords:<dict>: extra inputs for file read write
---Reserved words:
--->fl_colnm_lst: list of all column names in the file 
--->sel_colnm_lst: list of the names for column to be read
--->colnm_dict:<dict>: dictionary for translating column names
 
Returns:
-------------------------------------
1. ndata:<int>: length of fdesc.dtable 
 
 
Notes:
-------------------------------------
1. data will be stored as recarray by fdesc.dtable
write_enr_desc_colum_heads(fl, colnm_lst=['step', 'mem_st', 'mem_end', 'year_st', 'year_end', 'doy_st', 'doy_end', 'flnm', 'output_name', 'index_method'], max_nmlen=20)
write out the column names
 
Inputs:
-----------------------------------------------------------
1. fl:<file>: handle to file 
2. colnm_lst:<list, t:str>: list of column names
3. max_nmlen:<int>: maximum length of column name
 
Returns:
----------------------------------
1. fl:<file>: file object
write_enr_desc_colum_val(fl, col_vals, coltype_lst=['i4', 'i4', 'i4', 'i4', 'i4', 'i4', 'i4', 'S40', 'S40', 'i4'])
write out the column values
Inputs:
--------------------------------------------------------
1. fl:<file>: handle to run description file
2. col_vals:<list/array>: value of each column
 
Returns:
-----------------------------------------------------------
1. fl:<file>: file handle

 
Data
        def_delim = ','
def_enr_data_start = '000'
def_enr_header_start = 0
enr_datapath = '/XYYYYX/'
enr_desc_colnm_dict = {'doy_end': 'doy_end', 'doy_st': 'doy_st', 'flnm': 'flnm_ems', 'mem_end': 'mem_end', 'mem_st': 'mem_st', 'output_name': 'flnm_mod', 'step': 'step', 'year_end': 'year_end', 'year_st': 'year_st'}
enr_desc_coltype_lst = ['i4', 'i4', 'i4', 'i4', 'i4', 'i4', 'i4', 'S40', 'S40', 'i4']
enr_desc_column_lst = ['step', 'mem_st', 'mem_end', 'year_st', 'year_end', 'doy_st', 'doy_end', 'flnm', 'output_name', 'index_method']
enr_desc_flnm_format = 'enr_desc_XYYYYX.dat'