[Scipy-svn] r2791 - trunk/Lib/sandbox/timeseries

scipy-svn@scip... scipy-svn@scip...
Wed Feb 28 15:46:33 CST 2007


Author: mattknox_ca
Date: 2007-02-28 15:46:29 -0600 (Wed, 28 Feb 2007)
New Revision: 2791

Modified:
   trunk/Lib/sandbox/timeseries/tcore.py
Log:
moved some functions over to "extras.py"

Modified: trunk/Lib/sandbox/timeseries/tcore.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tcore.py	2007-02-28 21:46:10 UTC (rev 2790)
+++ trunk/Lib/sandbox/timeseries/tcore.py	2007-02-28 21:46:29 UTC (rev 2791)
@@ -16,7 +16,6 @@
 from scipy.interpolate import fitpack
 
 import maskedarray as MA
-from maskedarray import masked, nomask, getmask
 
 from cseries import TSER_CONSTANTS
 
@@ -143,60 +142,6 @@
         raise ValueError("Invalid frequency: %s " % str(freq))    
 fmtFreq = check_freqstr
         
-#class DateSpec:
-#    "Fake data type for date variables."
-#    def __init__(self, freq):
-#        self.freq = fmtFreq(freq)
-#        
-#    def __hash__(self): 
-#        return hash(self.freq)
-#    
-#    def __eq__(self, other):
-#        if hasattr(other, "freq"): 
-#            return self.freq == other.freq
-#        else: 
-#            return False
-#    def __str__(self): 
-#        return "Date(%s)" % str(self.freq) 
-#
-## define custom numpy types.
-## Note: A more robust approach would register these as actual valid numpy types
-## this is just a hack for now
-#numpy.dateA = DateSpec("Annual")
-#numpy.dateB = DateSpec("Business")
-#numpy.dateD = DateSpec("Daily")
-#numpy.dateH = DateSpec("Hourly")
-#numpy.dateM = DateSpec("Monthly")
-#numpy.dateQ = DateSpec("Quarterly")
-#numpy.dateS = DateSpec("Secondly")
-#numpy.dateT = DateSpec("Minutely")
-#numpy.dateW = DateSpec("Weekly")
-#numpy.dateU = DateSpec("Undefined")
-#
-#
-#freq_type_mapping = {'A': numpy.dateA,
-#                     'B': numpy.dateB,
-#                     'D': numpy.dateD,
-#                     'H': numpy.dateH,
-#                     'M': numpy.dateM,
-#                     'Q': numpy.dateQ,
-#                     'S': numpy.dateS,
-#                     'T': numpy.dateT,
-#                     'W': numpy.dateW,
-#                     'U': numpy.dateU,
-#                     }
-#        
-#def freqToType(freq):
-#    "Returns the Date dtype corresponding to the given frequency."
-#    return freq_type_mapping[fmtFreq(freq)]
-#
-#def isDateType(dtype):
-#    "Returns True whether the argument is the dtype of a Date."
-#    #TODO: That looks messy. We should simplify that
-#    if len([x for x in freq_type_mapping.values() if x == dtype]) > 0: 
-#        return True
-#    else: 
-#        return False
 
 #####---------------------------------------------------------------------------
 #---- --- Misc functions ---
@@ -219,90 +164,3 @@
     else:
         return flatten_sequence(args)
         
-
-#####---------------------------------------------------------------------------
-#---- --- Functions for filling in masked values in a masked array ---
-#####---------------------------------------------------------------------------
-
-def forward_fill(marr, maxgap=None):
-    """forward_fill(marr, maxgap=None)
-
-Forward fill masked values in a 1-d array when there are <= maxgap
-consecutive masked values. If maxgap is None, then forward fill all
-masked values."""
-
-    if numeric.ndim(marr) > 1:
-        raise ValueError,"The input array should be 1D only!"
-
-    marr = MA.array(marr, copy=True)
-    if getmask(marr) is nomask or marr.size == 0:
-        return marr
-
-    currGap = 0
-
-    if maxgap is not None:
-        for i in range(1, marr.size):
-            if marr._mask[i]:
-                currGap += 1
-                if currGap <= maxgap and not marr._mask[i-1]:
-                    marr._data[i] = marr._data[i-1]
-                    marr._mask[i] = False
-                elif currGap == maxgap + 1:
-                    marr._mask[i-maxgap:i] = True
-            else:
-                currGap = 0               
-    else:
-        for i in range(1, marr.size):
-            if marr._mask[i] and not marr._mask[i-1]:
-                marr._data[i] = marr._data[i-1]
-                marr._mask[i] = False
-    return marr
-
-
-def backward_fill(marr, maxgap=None):
-    """backward_fill(marr, maxgap=None)
-
-backward fill masked values in a 1-d array when there are <= maxgap
-consecutive masked values. If maxgap is None, then backward fill all
-masked values."""
-    return forward_fill(marr[::-1], maxgap=maxgap)[::-1]
-    
-
-def interp_masked1d(marr, kind='linear'):
-    """interp_masked1d(marr, king='linear')
-
-Interpolate masked values in marr according to method kind.
-kind must be one of 'constant', 'linear', 'cubic', quintic'
-"""
-    if numeric.ndim(marr) > 1: 
-        raise ValueError("array must be 1 dimensional!")
-    #
-    marr = MA.array(marr, copy=True)
-    if getmask(marr) is nomask: 
-        return marr
-    #
-    unmaskedIndices = (~marr._mask).nonzero()[0]
-    if unmaskedIndices.size < 2: 
-        return marr
-    #    
-    kind = kind.lower()
-    if kind == 'constant': 
-        return forward_fill(marr)
-    try:
-        k = {'linear' : 1,
-             'cubic' : 3,
-             'quintic' : 5}[kind.lower()]
-    except KeyError:
-        raise ValueError("Unsupported interpolation type.")
-    
-    first_unmasked, last_unmasked = MA.extras.flatnotmasked_edges(marr)
-    
-    vals = marr.data[unmaskedIndices]
-    
-    tck = fitpack.splrep(unmaskedIndices, vals, k=k)
-    
-    maskedIndices = marr._mask.nonzero()[0]
-    interpIndices = maskedIndices[(maskedIndices > first_unmasked) & \
-                                  (maskedIndices < last_unmasked)]
-    marr[interpIndices] = fitpack.splev(interpIndices, tck).astype(marr.dtype)
-    return marr



More information about the Scipy-svn mailing list