Changeset 2189 in lmdz_wrf
- Timestamp:
- Oct 17, 2018, 7:54:12 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2188 r2189 6784 6784 return newTunits, newTvals 6785 6785 6786 def coincident_CFtimes(tvalB, tunitA, tunitB):6787 """ Function to make coincident times for two different sets of CFtimes6788 tvalB= time values B6789 tunitA= time units times A to which we want to make coincidence6790 tunitB= time units times B6791 >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00',6792 'hours since 1949-12-01 00:00:00')6793 [ 0. 3600. 7200. 10800. 14400. 18000. 21600. 25200. 28800. 32400.]6794 >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00',6795 'hours since 1979-12-01 00:00:00')6796 [ 9.46684800e+08 9.46688400e+08 9.46692000e+08 9.46695600e+086797 9.46699200e+08 9.46702800e+08 9.46706400e+08 9.46710000e+086798 9.46713600e+08 9.46717200e+08]6799 """6800 import datetime as dt6801 fname = 'coincident_CFtimes'6802 6803 trefA = tunitA.split(' ')[2] + ' ' + tunitA.split(' ')[3]6804 trefB = tunitB.split(' ')[2] + ' ' + tunitB.split(' ')[3]6805 tuA = tunitA.split(' ')[0]6806 tuB = tunitB.split(' ')[0]6807 6808 if tuA != tuB:6809 if tuA == 'microseconds':6810 if tuB == 'microseconds':6811 tB = tvalB*1.6812 elif tuB == 'seconds':6813 tB = tvalB*10.e66814 elif tuB == 'minutes':6815 tB = tvalB*60.*10.e66816 elif tuB == 'hours':6817 tB = tvalB*3600.*10.e66818 elif tuB == 'days':6819 tB = tvalB*3600.*24.*10.e66820 else:6821 print errormsg6822 print ' ' + fname + ": combination of time untis: '" + tuA + \6823 "' & '" + tuB + "' not ready !!"6824 quit(-1)6825 elif tuA == 'seconds':6826 if tuB == 'microseconds':6827 tB = tvalB/10.e66828 elif tuB == 'seconds':6829 tB = tvalB*1.6830 elif tuB == 'minutes':6831 tB = tvalB*60.6832 elif tuB == 'hours':6833 tB = tvalB*3600.6834 elif tuB == 'days':6835 tB = tvalB*3600.*24.6836 else:6837 print errormsg6838 print ' ' + fname + ": combination of time untis: '" + tuA + \6839 "' & '" + tuB + "' not ready !!"6840 quit(-1)6841 elif tuA == 'minutes':6842 if tuB == 'microseconds':6843 tB = tvalB/(60.*10.e6)6844 elif tuB == 'seconds':6845 tB = tvalB/60.6846 elif tuB == 'minutes':6847 tB = tvalB*1.6848 elif tuB == 'hours':6849 tB = tvalB*60.6850 elif tuB == 'days':6851 tB = tvalB*60.*24.6852 else:6853 print errormsg6854 print ' ' + fname + ": combination of time untis: '" + tuA + \6855 "' & '" + tuB + "' not ready !!"6856 quit(-1)6857 elif tuA == 'hours':6858 if tuB == 'microseconds':6859 tB = tvalB/(3600.*10.e6)6860 elif tuB == 'seconds':6861 tB = tvalB/3600.6862 elif tuB == 'minutes':6863 tB = tvalB/60.6864 elif tuB == 'hours':6865 tB = tvalB*1.6866 elif tuB == 'days':6867 tB = tvalB*24.6868 else:6869 print errormsg6870 print ' ' + fname + ": combination of time untis: '" + tuA + \6871 "' & '" + tuB + "' not ready !!"6872 quit(-1)6873 elif tuA == 'days':6874 if tuB == 'microseconds':6875 tB = tvalB/(24.*3600.*10.e6)6876 elif tuB == 'seconds':6877 tB = tvalB/(24.*3600.)6878 elif tuB == 'minutes':6879 tB = tvalB/(24.*60.)6880 elif tuB == 'hours':6881 tB = tvalB/24.6882 elif tuB == 'days':6883 tB = tvalB*1.6884 else:6885 print errormsg6886 print ' ' + fname + ": combination of time untis: '" + tuA + \6887 "' & '" + tuB + "' not ready !!"6888 quit(-1)6889 else:6890 print errormsg6891 print ' ' + fname + ": time untis: '" + tuA + "' not ready !!"6892 quit(-1)6893 else:6894 tB = tvalB*1.6895 6896 if trefA != trefB:6897 trefTA = dt.datetime.strptime(trefA, '%Y-%m-%d %H:%M:%S')6898 trefTB = dt.datetime.strptime(trefB, '%Y-%m-%d %H:%M:%S')6899 6900 difft = trefTB - trefTA6901 if searchInlist(difft.keys(), 'total_seconds'):6902 diffv = difft.total_seconds*10.e66903 else:6904 diffv = difft.days*24.*3600.*10.e6 + difft.seconds*10.e6 + difft.microseconds6905 print ' ' + fname + ': different reference refA:',trefTA,'refB',trefTB6906 print ' difference:',difft,':',diffv,'microseconds'6907 6908 if tuA == 'microseconds':6909 tB = tB + diffv6910 elif tuA == 'seconds':6911 tB = tB + diffv/10.e66912 elif tuA == 'minutes':6913 tB = tB + diffv/(60.*10.e6)6914 elif tuA == 'hours':6915 tB = tB + diffv/(3600.*10.e6)6916 elif tuA == 'dayss':6917 tB = tB + diffv/(24.*3600.*10.e6)6918 else:6919 print errormsg6920 print ' ' + fname + ": time untis: '" + tuA + "' not ready !!"6921 quit(-1)6922 6923 return tB6924 6925 6786 def wdismean(pos,val4): 6926 6787 """ Function to compute the mean value weighted to its 4 distances … … 9823 9684 print warnmsg 9824 9685 print ' ' + fname + ": time-units without time '" + tunitB + "' !!" 9825 print " adding: '00:00:00 1"9686 print " adding: '00:00:00" 9826 9687 trefB = tunitB.split(' ')[2] + ' 00:00:00' 9827 9688 tuA = tunitA.split(' ')[0]
Note: See TracChangeset
for help on using the changeset viewer.