diff --git a/climaf/classes.py b/climaf/classes.py index e5a4a16e..9c64ffa0 100644 --- a/climaf/classes.py +++ b/climaf/classes.py @@ -1055,17 +1055,27 @@ def __init__(self, dic={}, order=None, sortfunc=None): self.crs = self.buildcrs() self.register() - def set_order(self, order, ordered_keylist=None): - ordered_list = [o for o in order] - ordered_list.sort() + #def set_order(self, order, ordered_keylist=None): + # ordered_list = [o for o in order] + # ordered_list.sort() + # if ordered_keylist is None: + # ordered_keylist = [o for o in self] + # ordered_keylist.sort() + # if ordered_list != ordered_keylist: + # raise Climaf_Classes_Error( + # "Labels list (as described by order list) does not match ensemble labels list : %s and %s" % + # (repr(ordered_list), repr(ordered_keylist))) + # self.order = order + def set_order(self,order,ordered_keylist=None): + ordered_list=[ o for o in order ] ; ordered_list.sort() if ordered_keylist is None: - ordered_keylist = [o for o in self] - ordered_keylist.sort() - if ordered_list != ordered_keylist: + ordered_keylist=self.keys() ; ordered_keylist.sort() + if sorted(ordered_list) != sorted(ordered_keylist) : raise Climaf_Classes_Error( - "Labels list (as described by order list) does not match ensemble labels list : %s and %s" % - (repr(ordered_list), repr(ordered_keylist))) - self.order = order + "Order list does not match dict keys list : %s and %s"% + (`ordered_list`,`ordered_keylist`)) + self.order=order + def __setitem__(self, k, v): if not isinstance(k, str): diff --git a/climaf/functions.py b/climaf/functions.py index 9b28340b..8088f2a5 100644 --- a/climaf/functions.py +++ b/climaf/functions.py @@ -52,7 +52,7 @@ def fmul(dat1, dat2): >>> c = '-1' #a constant >>> ds1_times_c = fmul(ds1,c) # ds1 * c """ - if isinstance(dat2, (str, float, int)): + if isinstance(dat2, (str, float, int, np.float32)): c = str(float(dat2)) return ccdo(dat1, operator='mulc,' + c) else: @@ -75,7 +75,7 @@ def fdiv(dat1, dat2): >>> ds1_times_c = fdiv(ds1,c) # ds1 * c """ - if isinstance(dat2, (str, float, int)): + if isinstance(dat2, (str, float, int, np.float32)): c = str(float(dat2)) return ccdo(dat1, operator='divc,' + c) else: @@ -98,9 +98,10 @@ def fadd(dat1, dat2): >>> ds1_plus_c = fadd(ds1,c) # ds1 + c """ - if isinstance(dat2, (str, float, int)): + if isinstance(dat2, (str, float, int, np.float32)): c = str(float(dat2)) return ccdo(dat1, operator='addc,' + c) + else: return ccdo2(dat1, dat2, operator='add') @@ -121,7 +122,7 @@ def fsub(dat1, dat2): >>> ds1_minus_c = fsub(ds1,c) # ds1 - c """ - if isinstance(dat2, (str, float, int)): + if isinstance(dat2, (str, float, int, np.float32)): c = str(float(dat2)) return ccdo(dat1, operator='subc,' + c) else: @@ -268,7 +269,7 @@ def annual_cycle_fast(dat): >>> annual_cycle_dat = annual_cycle(dat) """ - return ccdo_fast(dat, operator="ymonavg") + return ccdo(dat, operator="ymonavg") def clim_average(dat, season): @@ -308,8 +309,6 @@ def clim_average(dat, season): if str(season).upper() == 'DJF': selmonths = '1,2,12' clogger.warning('DJF is actually processed as JF....D. Maybe an issue for short periods !') - if str(season).upper() == "DJFM": - selmonths = '1,2,3,12' if str(season).upper() == 'MAM': selmonths = '3,4,5' if str(season).upper() == 'JJA': @@ -410,8 +409,6 @@ def clim_average_fast(dat, season): if str(season).upper() == 'DJF': selmonths = '1,2,12' clogger.warning('DJF is actually processed as JF....D. Maybe an issue for short periods !') - if str(season).upper() == 'DJFM': - selmonths = '1,2,3,12' if str(season).upper() == 'MAM': selmonths = '3,4,5' if str(season).upper() == 'JJA': @@ -432,7 +429,7 @@ def clim_average_fast(dat, season): selmonths = '4,5,6' if selmonths: - avg = ccdo_fast(scyc, operator='timmean -seltimestep,' + selmonths) + avg = ccdo(scyc, operator='timmean -seltimestep,' + selmonths) # avg = ccdo(scyc,operator='timmean -selmon,'+selmonths) # # @@ -462,15 +459,15 @@ def clim_average_fast(dat, season): if str(season).lower() in ['december', 'dec', '12']: selmonth = '12' if selmonth: - avg = ccdo_fast(scyc, operator='selmon,' + selmonth) + avg = ccdo(scyc, operator='selmon,' + selmonth) # # -- Annual Maximum if str(season).lower() in ['max', 'annual max', 'annual_max']: - avg = ccdo_fast(scyc, operator='timmax') + avg = ccdo(scyc, operator='timmax') # # -- Annual Minimum if str(season).lower() in ['min', 'annual min', 'annual_min']: - avg = ccdo_fast(scyc, operator='timmin') + avg = ccdo(scyc, operator='timmin') # return avg diff --git a/scripts/ensemble_time_series_plot.py b/scripts/ensemble_time_series_plot.py index e0385acb..b1d79a94 100644 --- a/scripts/ensemble_time_series_plot.py +++ b/scripts/ensemble_time_series_plot.py @@ -19,10 +19,8 @@ matplotlib.use('Agg') import matplotlib.pyplot as plt import matplotlib.lines as mlines -import datetime import numpy as np -from netCDF4 import Dataset, num2date - +from netCDF4 import Dataset from climaf.site_settings import atCerfacs if atCerfacs: import netcdftime @@ -31,7 +29,7 @@ from netCDF4 import netcdftime except: import netcdftime - +import datetime # -- Initialize the parser # -------------------------------------------------------------------------------------------------- @@ -221,6 +219,7 @@ # -- Loop on the netcdf files +from netCDF4 import Dataset,netcdftime,num2date handles_for_legend = [] dataset_number = 0 @@ -248,6 +247,8 @@ tvalue = num2date(nctime,units = t_unit,calendar = t_cal) datevar = [] for elt in tvalue: + print 'elt = ',elt + print 'dir(datetime) = ',dir(datetime) if not isinstance(elt, datetime.datetime): if isinstance(elt, netcdftime._netcdftime.DatetimeNoLeap) or isinstance(elt, netcdftime._netcdftime.Datetime360Day): strdate = str.split(elt.strftime(),' ')[0]