Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions climaf/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
23 changes: 10 additions & 13 deletions climaf/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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')

Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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':
Expand All @@ -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)
#
#
Expand Down Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions scripts/ensemble_time_series_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +29,7 @@
from netCDF4 import netcdftime
except:
import netcdftime

import datetime

# -- Initialize the parser
# --------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -221,6 +219,7 @@


# -- Loop on the netcdf files
from netCDF4 import Dataset,netcdftime,num2date

handles_for_legend = []
dataset_number = 0
Expand Down Expand Up @@ -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)
Comment on lines +250 to +251
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to discard

if not isinstance(elt, datetime.datetime):
if isinstance(elt, netcdftime._netcdftime.DatetimeNoLeap) or isinstance(elt, netcdftime._netcdftime.Datetime360Day):
strdate = str.split(elt.strftime(),' ')[0]
Expand Down