Changeset 447 in lmdz_wrf for trunk/tools
- Timestamp:
- May 28, 2015, 5:29:26 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r438 r447 14727 14727 14728 14728 #selvar('x@lon,y@lat,time@time,shan@int', '/home/lluis/PY/test.nc', 'var') 14729 14730 def coincident_CFtimes(tvalB, tunitA, tunitB): 14731 """ Function to make coincident times for two different sets of CFtimes 14732 tvalB= time values B 14733 tunitA= time units times A to which we want to make coincidence 14734 tunitB= time units times B 14735 >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00', 14736 'hours since 1949-12-01 00:00:00') 14737 [ 0. 3600. 7200. 10800. 14400. 18000. 21600. 25200. 28800. 32400.] 14738 >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00', 14739 'hours since 1979-12-01 00:00:00') 14740 [ 9.46684800e+08 9.46688400e+08 9.46692000e+08 9.46695600e+08 14741 9.46699200e+08 9.46702800e+08 9.46706400e+08 9.46710000e+08 14742 9.46713600e+08 9.46717200e+08] 14743 """ 14744 import datetime as dt 14745 fname = 'coincident_CFtimes' 14746 14747 trefA = tunitA.split(' ')[2] + ' ' + tunitA.split(' ')[3] 14748 trefB = tunitB.split(' ')[2] + ' ' + tunitB.split(' ')[3] 14749 tuA = tunitA.split(' ')[0] 14750 tuB = tunitB.split(' ')[0] 14751 14752 if tuA != tuB: 14753 if tuA == 'microseconds': 14754 if tuB == 'microseconds': 14755 tB = tvalB*1. 14756 elif tuB == 'seconds': 14757 tB = tvalB*10.e6 14758 elif tuB == 'minutes': 14759 tB = tvalB*60.*10.e6 14760 elif tuB == 'hours': 14761 tB = tvalB*3600.*10.e6 14762 elif tuB == 'days': 14763 tB = tvalB*3600.*24.*10.e6 14764 else: 14765 print errormsg 14766 print ' ' + fname + ": combination of time untis: '" + tuA + \ 14767 "' & '" + tuB + "' not ready !!" 14768 quit(-1) 14769 elif tuA == 'seconds': 14770 if tuB == 'microseconds': 14771 tB = tvalB/10.e6 14772 elif tuB == 'seconds': 14773 tB = tvalB*1. 14774 elif tuB == 'minutes': 14775 tB = tvalB*60. 14776 elif tuB == 'hours': 14777 tB = tvalB*3600. 14778 elif tuB == 'days': 14779 tB = tvalB*3600.*24. 14780 else: 14781 print errormsg 14782 print ' ' + fname + ": combination of time untis: '" + tuA + \ 14783 "' & '" + tuB + "' not ready !!" 14784 quit(-1) 14785 elif tuA == 'minutes': 14786 if tuB == 'microseconds': 14787 tB = tvalB/(60.*10.e6) 14788 elif tuB == 'seconds': 14789 tB = tvalB/60. 14790 elif tuB == 'minutes': 14791 tB = tvalB*1. 14792 elif tuB == 'hours': 14793 tB = tvalB*60. 14794 elif tuB == 'days': 14795 tB = tvalB*60.*24. 14796 else: 14797 print errormsg 14798 print ' ' + fname + ": combination of time untis: '" + tuA + \ 14799 "' & '" + tuB + "' not ready !!" 14800 quit(-1) 14801 elif tuA == 'hours': 14802 if tuB == 'microseconds': 14803 tB = tvalB/(3600.*10.e6) 14804 elif tuB == 'seconds': 14805 tB = tvalB/3600. 14806 elif tuB == 'minutes': 14807 tB = tvalB/60. 14808 elif tuB == 'hours': 14809 tB = tvalB*1. 14810 elif tuB == 'days': 14811 tB = tvalB*24. 14812 else: 14813 print errormsg 14814 print ' ' + fname + ": combination of time untis: '" + tuA + \ 14815 "' & '" + tuB + "' not ready !!" 14816 quit(-1) 14817 elif tuA == 'days': 14818 if tuB == 'microseconds': 14819 tB = tvalB/(24.*3600.*10.e6) 14820 elif tuB == 'seconds': 14821 tB = tvalB/(24.*3600.) 14822 elif tuB == 'minutes': 14823 tB = tvalB/(24.*60.) 14824 elif tuB == 'hours': 14825 tB = tvalB/24. 14826 elif tuB == 'days': 14827 tB = tvalB*1. 14828 else: 14829 print errormsg 14830 print ' ' + fname + ": combination of time untis: '" + tuA + \ 14831 "' & '" + tuB + "' not ready !!" 14832 quit(-1) 14833 else: 14834 print errormsg 14835 print ' ' + fname + ": time untis: '" + tuA + "' not ready !!" 14836 quit(-1) 14837 else: 14838 tB = tvalB*1. 14839 14840 if trefA != trefB: 14841 trefTA = dt.datetime.strptime(trefA, '%Y-%m-%d %H:%M:%S') 14842 trefTB = dt.datetime.strptime(trefB, '%Y-%m-%d %H:%M:%S') 14843 14844 difft = trefTB - trefTA 14845 diffv = difft.days*24.*3600.*10.e6 + difft.seconds*10.e6 + difft.microseconds 14846 print ' ' + fname + ': different reference refA:',trefTA,'refB',trefTB 14847 print ' difference:',difft,':',diffv,'microseconds' 14848 14849 if tuA == 'microseconds': 14850 tB = tB + diffv 14851 elif tuA == 'seconds': 14852 tB = tB + diffv/10.e6 14853 elif tuA == 'minutes': 14854 tB = tB + diffv/(60.*10.e6) 14855 elif tuA == 'hours': 14856 tB = tB + diffv/(3600.*10.e6) 14857 elif tuA == 'dayss': 14858 tB = tB + diffv/(24.*3600.*10.e6) 14859 else: 14860 print errormsg 14861 print ' ' + fname + ": time untis: '" + tuA + "' not ready !!" 14862 quit(-1) 14863 14864 return tB 14865 14866 14729 14867 #quit() 14730 14868
Note: See TracChangeset
for help on using the changeset viewer.