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

module for time conversions.  
 
Authors: L. Feng, Edinburgh University
History: v0.9, 2012.04.01
History: v0.95, 2012.08.21
 
Functions:
=====================================================
1. days_in_year: number of days in each year
2. day_of_year:  day of year for calender date
3. get_doy: a wrapper for day_of_year
4. tai85_to_utc:  convert a time in tai85 format to UTC string.
5. doy_to_utc:    convert day of year to utc string. 
6. doy_to_time_array: convert day of year to calendar date (yyyy, mm, dd)
7. utc_to_time_array(utc): convert the utc string to the list of (yyyy, mm, dd, hh, mi, sec)
8. time_array_to_utc: convert yyyy, mm, dd, hh, mi, sec to utc string
9. convert yyyy, mm, dd, hh, mi, sec to tau (i.e, hours since 1985.01.01, 00:00)
10.tau_to_time_array(tau): convert tau (i.e, hours since 1985.01.01, 00:00) to  yyyy, mm, dd, hh, mi, sec 
11. next_doy: get day of year for current time + n days 
12. get_ut_loc_time_slot: get indexes for UT time series which fall within the local time slot

 
Modules
       
datetime
numpy
pylab

 
Functions
       
day_of_year(yyyy, mm, dd)
get the days in a given year for calender date
 
Input: 
-------------------------------------------
1. yyyy, mm, dd:<integer>:year, month and day 
 
Returns:
---------------------------------------------
1.  days in year
days_in_year(yyyy)
get the days in a given year for calender date
 
Input: 
-------------------------------------------
1. yyyy, mm, dd:<integer>:year, month and day 
 
Returns:
---------------------------------------------
1.  days in year
doy_to_tai85(doy, sec=0, yyyy=2004)
convert the day of year to tai85 format 
(i.e., Seconds since 1985-01-01 00:00:00)
 
Inputs:
1. doy:<integer>: Day of year
2. sec:<integer>: Seconds in the day
3. yyyy: <integer>: Year
 
Returns:
---------------------------------------------
1. tai85:  in seconds
doy_to_time_array(doy, yyyy=2005)
convert day of year to calendar date (yyyy, mm, dd)
 
Inputs:
1. doy:<integer>: Day of year
2. yyyy: <integer>: Year
 
Returns:
---------------------------------------------
1. yyyy, mm, dd:<integer>: year, month and day
doy_to_utc(doy, sec=0, yyyy=2004)
convert day of year to utc string
    
Inputs:
1. doy:<integer>: Day of year
2. sec:<integer>: Seconds in the day
3. yyyy: <integer>: Year
 
Returns:
---------------------------------------------
1. utc: the time in utc format yyyy-mm-dd hh:mm:ss
get_doy(yyyy, mm, dd)
get the days in a given year for calender date
(wrapper for day_of_year)
 
Input: 
----------------------------
1. yyyy, mm, dd:<integer>:year, month and day 
 
Returns:
---------------------------------------------
1.  days in year
get_tau(yyyy, mm, dd, hh=0, mi=0, sec=0)
convert yyyy, mm, dd, hh, mi, sec to tau (i.e, hours since 1985.01.01, 00:00)
 
Inputs:
1. yyyy, mm, dd, hh, mi, sec:<integer>: year, month, day, hour, minute and second
    
Outputs:
1. tau:<float>: Hours since 1985.01.01, 00:00
get_ut_loc_time_slot(lt_st, lt_end, day_time_grid, lon, day_length=86400.0)
get indexes for UT time series which fall within the local time slot
 
Inputs:
1.lt_st, lt_end:<numeric>: local time periods. 
2.day_time_grid:<array>: UT time series
3.lon:<array>: longitudes of the locations. 
4. day_length:<float>: the length of day in seconds or hours. 
The unit should be consistent with day_time_grid and the local time period.
 
 
Returns:
-----------------------------------------
1. usd_idx:<array>:the index for the UT time series which fall within the local time
between ls_st and lt_end
next_doy(yyyy_in, doy_in, days=1, return_ymd=False)
get date  for current time + n days later
 
Inputs:
-----------------------------------------
 
1.yyyy_in, doy_in:<integer>: current year and day of year
2.days:<integer>: day increment
3.return_ymd:<T/F>: if ture, year, month and day will be returned 
 
Returns:
-----------------------------------------
1.yyyy, doy:<integer>: year and day, If return_ymd==False, 
 
or 
1. yyyy, mm, dd:<integer>:year, month and day, If return_ymd==True.
tai85_to_utc(tai85)
convert a time in tai85 format to UTC string 
Inputs: 
----------------------------------------
1. tai85:<integer>: Seconds since 1985-01-01 00:00:00
 
Returns:
---------------------------------------------
1. utc: <string>: time in utc format (yyyy-mm-dd hh:mi:ss)
 
 
Notes:
Time_leap is done in a hard (hand) way
tau_to_time_array(tau)
convert tau (i.e, hours since 1985.01.01, 00:00) to  yyyy, mm, dd, hh, mi, sec 
 
Inputs:
-----------------------------------------------------------
1. tau:<float>: Hours since 1985.01.01, 00:00
 
Returns:
-----------------------------------------
1. yyyy, mm, dd, hh, mi, sec:<integer>: year, month, day, hour, minute and second
time_array_to_utc(yyyy, mm, dd, hh=0, mi=0, sec=0)
convert yyyy, mm, dd, hh, mi, sec to utc string
 
Inputs:
1. yyyy, mm, dd, hh, mi, sec:<integer>: year, month, day, hour, minute and second
    
Returns:
-----------------------------------------
1. utc: the time in utc format yyyy-mm-dd hh:mm:ss
utc_to_tai85(utc)
convert utc string to tai85 format 
(i.e., Seconds since 1985-01-01 00:00:00)
 
Inputs:
--------------------------------------------
1. utc: utc time in yyyy-mm-dd hh:mi:ss
 
Returns:
---------------------------------------------
1. tai85: <integer> seconds since
utc_to_time_array(utc)
convert the utc string to yyyy, mm, dd, hh, mi, sec
 
Inputs:
 
1. utc:<string>: the time in utc format yyyy-mm-dd hh:mm:ss
 
 
Returns:
-----------------------------------------
1. yyyy, mm, dd, hh, mi, sec:<integer>: year, month, day, hour, minute, seconds

 
Data
        TAI0 = datetime.datetime(1985, 1, 1, 0, 0)
def_yyyy = 2004
second_leap = 0