Changeset 538 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 29, 2015, 7:43:26 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r535 r538 2958 2958 return timeinf 2959 2959 2960 def date_juliandate(rdate): 2961 """ Function to transform from a standard date to a matrix julian day based one 2962 rdate= `datetime' object to transform 2960 def date_juliandate(refyr, TOTsecs): 2961 """ Function to transform from a total quantity of seconds since the 2962 beginning of a year to 360 days / year calendar 2963 TOTsecs= total number of seconds 2963 2964 """ 2964 import datetime as dt2965 2966 2965 fname = 'date_juliandate' 2967 2966 2968 jday = int(rdate.timetuple().tm_yday) 2969 rldate[0] = int(rdate.year) 2970 rldate[1] = jday/30 + 1 2971 rldate[2] = jday - (rldate[1]-1)*30 2972 rldate[3] = int(rdate.hour) 2973 rldate[4] = int(rdate.second) 2974 rldate[5] = int(rdate.minute) 2975 2976 if rldate[2] < 0: 2977 print errormsg 2978 print ' ' + fname + ': wrong date', rdate, 'it gives a negative', \ 2979 rldate[2],'day!!' 2967 secsYear = 3600*24*30*12. 2968 secsMonth = 3600*24*30. 2969 secsDay = 3600*24. 2970 secsHour = 3600. 2971 secsMinute = 60. 2972 2973 rldate = np.zeros((6), dtype=int) 2974 rldate[0] = refyr 2975 if TOTsecs > secsYear: 2976 rldate[0] = refyr + int(TOTsecs/secsYear) + 1 2977 TOTsecs = TOTsecs - int(TOTsecs/secsYear)*secsYear 2978 2979 if np.mod(TOTsecs,secsMonth) == 0: 2980 rldate[1] = int(TOTsecs/secsMonth) 2981 else: 2982 rldate[1] = int(TOTsecs/secsMonth) + 1 2983 TOTsecs = TOTsecs - int(TOTsecs/secsMonth)*secsMonth 2984 2985 if np.mod(TOTsecs,secsDay) == 0: 2986 rldate[2] = int(TOTsecs/secsDay) 2987 else: 2988 rldate[2] = int(TOTsecs/secsDay) + 1 2989 TOTsecs = TOTsecs - int(TOTsecs/secsDay)*secsDay 2990 2991 if np.mod(TOTsecs,secsHour) == 0: 2992 rldate[3] = int(TOTsecs/secsHour) 2993 else: 2994 rldate[3] = int(TOTsecs/secsHour) + 1 2995 TOTsecs = TOTsecs - int(TOTsecs/secsHour)*secsHour 2996 2997 if np.mod(TOTsecs,secsMinute) == 0: 2998 rldate[4] = int(TOTsecs/secsMinute) 2999 else: 3000 rldate[4] = int(TOTsecs/secsMinute) + 1 3001 TOTsecs = TOTsecs - int(TOTsecs/secsMinute)*secsMinute 3002 3003 rldate[5] = TOTsecs 3004 3005 # print refyr,TOTsecs,':',rldate 3006 # quit() 2980 3007 2981 3008 return rldate … … 2994 3021 """ 2995 3022 import datetime as dt 3023 fname = 'CFtimes_datetime' 2996 3024 2997 3025 times = ncfile.variables[tname] … … 3001 3029 if not searchInlist(attvar, 'units'): 3002 3030 print errormsg 3003 print ' CFtimes_datetime: "time" does not have attribute: "units"'3031 print ' ' + fname + ": '" + tname + "' does not have attribute: 'units'" 3004 3032 quit(-1) 3005 3033 else: … … 3022 3050 realdates = np.zeros((dimt, 6), dtype=int) 3023 3051 3052 secsDay=3600*24. 3053 3024 3054 # Checking calendar! 3025 3055 ## 3026 3056 y360 = False 3027 daycal360 = ['earth_360d', '360d', '360days' ]3057 daycal360 = ['earth_360d', '360d', '360days', '360_day'] 3028 3058 if searchInlist(attvar, 'calendar'): 3029 3059 calendar = times.getncattr('calendar') … … 3045 3075 if tunits == 'weeks': 3046 3076 for it in range(dimt): 3047 realdate = refdate + dt.timedelta(weeks=float(times[it])) 3048 realdates[it,:] = date_juliandate(realdate) 3077 deltat = dt.timedelta(weeks=float(times[it])) 3078 Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000. 3079 realdates[it,:] = date_juliandate(refdate.year,Tsecs) 3049 3080 elif tunits == 'days': 3050 3081 for it in range(dimt): 3051 realdate = refdate + dt.timedelta(days=float(times[it])) 3052 realdates[it,:] = date_juliandate(realdate) 3082 deltat = dt.timedelta(days=float(times[it])) 3083 Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000. 3084 realdates[it,:] = date_juliandate(refdate.year,Tsecs) 3053 3085 elif tunits == 'hours': 3054 3086 for it in range(dimt): 3055 realdate = refdate + dt.timedelta(hours=float(times[it])) 3056 realdates[it,:] = date_juliandate(realdate) 3087 realdate = dt.timedelta(hours=float(times[it])) 3088 Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000. 3089 realdates[it,:] = date_juliandate(refdate.year,Tsecs) 3057 3090 elif tunits == 'minutes': 3058 3091 for it in range(dimt): 3059 realdate = refdate + dt.timedelta(minutes=float(times[it])) 3060 realdates[it,:] = date_juliandate(realdate) 3092 realdate = dt.timedelta(minutes=float(times[it])) 3093 Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000. 3094 realdates[it,:] = date_juliandate(refdate.year,Tsecs) 3061 3095 elif tunits == 'seconds': 3062 3096 for it in range(dimt): 3063 realdate = refdate + dt.timedelta(seconds=float(times[it])) 3064 realdates[it,:] = date_juliandate(realdate) 3097 realdate = dt.timedelta(seconds=float(times[it])) 3098 Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000. 3099 realdates[it,:] = date_juliandate(refdate.year,Tsecs) 3065 3100 elif tunits == 'miliseconds': 3066 3101 for it in range(dimt): 3067 realdate = refdate + dt.timedelta(miliseconds=float(times[it])) 3068 realdates[it,:] = date_juliandate(realdate) 3102 realdate = dt.timedelta(miliseconds=float(times[it])) 3103 Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000. 3104 realdates[it,:] = date_juliandate(refdate.year,Tsecs) 3069 3105 else: 3070 3106 print errormsg … … 16202 16238 slicevar.append(ddt) 16203 16239 16204 #print ddt,d1,d2,mattimes[ddt,:],'var:',slicevar,'new:',slicenewvar16240 print ddt,d1,d2,mattimes[ddt,:],'var:',slicevar,'new:',slicenewvar 16205 16241 16206 16242 newvarv[tuple(slicenewvar)] = oVn[tuple(slicevar)]
Note: See TracChangeset
for help on using the changeset viewer.