[Scipy-svn] r3326 - trunk/scipy/sandbox/timeseries

scipy-svn@scip... scipy-svn@scip...
Tue Sep 18 18:22:36 CDT 2007


Author: mattknox_ca
Date: 2007-09-18 18:22:21 -0500 (Tue, 18 Sep 2007)
New Revision: 3326

Removed:
   trunk/scipy/sandbox/timeseries/tcore.py
Modified:
   trunk/scipy/sandbox/timeseries/__init__.py
   trunk/scipy/sandbox/timeseries/tdates.py
   trunk/scipy/sandbox/timeseries/tseries.py
Log:
removed tcore.py and moved its functions into the areas where they are actually used

Modified: trunk/scipy/sandbox/timeseries/__init__.py
===================================================================
--- trunk/scipy/sandbox/timeseries/__init__.py	2007-09-18 20:49:42 UTC (rev 3325)
+++ trunk/scipy/sandbox/timeseries/__init__.py	2007-09-18 23:22:21 UTC (rev 3326)
@@ -1,19 +1,5 @@
 """TimeSeries
-
-
-__author__ = "Pierre GF Gerard-Marchant  & Matt Knox ($Author$)"
-__version__ = '1.0'
-__revision__ = "$Revision$"
-__date__     = '$Date$'
 
-import tcore
-from tcore import *
-import tdates
-from tdates import *
-import tseries
-from tseries import *
-import tmulti
-from tmulti import *
 :author: Pierre GF Gerard-Marchant & Matt Knox
 :contact: pierregm_at_uga_dot_edu - mattknox_ca_at_hotmail_dot_com
 :version: $Id$
@@ -25,9 +11,6 @@
 __revision__ = "$Revision$"
 __date__     = '$Date$'
 
-# initialize python callbacks for C code
-import tcore
-from tcore import *
 import const
 import tdates
 from tdates import *

Deleted: trunk/scipy/sandbox/timeseries/tcore.py
===================================================================
--- trunk/scipy/sandbox/timeseries/tcore.py	2007-09-18 20:49:42 UTC (rev 3325)
+++ trunk/scipy/sandbox/timeseries/tcore.py	2007-09-18 23:22:21 UTC (rev 3326)
@@ -1,58 +0,0 @@
-"""
-A collection of tools for timeseries
-
-:author: Pierre GF Gerard-Marchant & Matt Knox
-:contact: pierregm_at_uga_dot_edu - mattknox_ca_at_hotmail_dot_com
-:version: $Id$
-"""
-__author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)"
-__version__ = '1.0'
-__revision__ = "$Revision$"
-__date__     = '$Date$'
-
-import numpy
-import numpy.core.numeric as numeric
-
-import maskedarray as MA
-
-#####---------------------------------------------------------------------------
-#---- --- Generic functions ---
-#####---------------------------------------------------------------------------
-def first_unmasked_val(a):
-    "Returns the first unmasked value in a 1d maskedarray."
-    (i,j) = MA.extras.flatnotmasked_edges(a)
-    return a[i]
-
-def last_unmasked_val(a):
-    "Returns the last unmasked value in a 1d maskedarray."
-    (i,j) = MA.extras.flatnotmasked_edges(a)
-    return a[j]
-
-def reverse_dict(d):
-    "Reverses the keys and values of a dictionary."
-    alt = []
-    tmp = [alt.extend([(w,k) for w in v]) for (k,v) in d.iteritems()]
-    return dict(alt)
-
-
-
-#####---------------------------------------------------------------------------
-#---- --- Misc functions ---
-#####---------------------------------------------------------------------------
-#http://aspn.activestate.com/ASPN/Mail/Message/python-tutor/2302348
-def flatten_sequence(iterable):
-    """Flattens a compound of nested iterables."""
-    itm = iter(iterable)
-    for elm in itm:
-        if hasattr(elm,'__iter__') and not isinstance(elm, basestring):
-            for f in flatten_sequence(elm):
-                yield f
-        else:
-            yield elm
-
-def flatargs(*args):
-    "Flattens the arguments."
-    if not hasattr(args, '__iter__'):
-        return args
-    else:
-        return flatten_sequence(args)

Modified: trunk/scipy/sandbox/timeseries/tdates.py
===================================================================
--- trunk/scipy/sandbox/timeseries/tdates.py	2007-09-18 20:49:42 UTC (rev 3325)
+++ trunk/scipy/sandbox/timeseries/tdates.py	2007-09-18 23:22:21 UTC (rev 3326)
@@ -29,10 +29,10 @@
 
 from parser import DateFromString, DateTimeFromString
 
-import tcore as corelib
 import const as _c
 import cseries
 
+# initialize python callbacks for C code
 cseries.set_callback_DateFromString(DateFromString)
 cseries.set_callback_DateTimeFromString(DateTimeFromString)
 
@@ -396,9 +396,28 @@
     #......................................................
     def find_dates(self, *dates):
         "Returns the indices corresponding to given dates, as an array."
+
+        #http://aspn.activestate.com/ASPN/Mail/Message/python-tutor/2302348
+        def flatten_sequence(iterable):
+            """Flattens a compound of nested iterables."""
+            itm = iter(iterable)
+            for elm in itm:
+                if hasattr(elm,'__iter__') and not isinstance(elm, basestring):
+                    for f in flatten_sequence(elm):
+                        yield f
+                else:
+                    yield elm
+
+        def flatargs(*args):
+            "Flattens the arguments."
+            if not hasattr(args, '__iter__'):
+                return args
+            else:
+                return flatten_sequence(args)
+
         ifreq = self.freq
         c = numpy.zeros(self.shape, bool_)
-        for d in corelib.flatargs(*dates):
+        for d in flatargs(*dates):
             if d.freq != ifreq:
                 d = d.asfreq(ifreq)
             c += (self == d.value)
@@ -685,37 +704,6 @@
 if __name__ == '__main__':
     import maskedarray.testutils
     from maskedarray.testutils import assert_equal
-#    if 0:
-#        dlist = ['2007-%02i' % i for i in range(1,5)+range(7,13)]
-#        mdates = date_array_fromlist(dlist, 'M')
-#        # Using an integer
-#        assert_equal(mdates[0].value, 24073)
-#        assert_equal(mdates[-1].value, 24084)
-#        # Using a date
-#        lag = mdates.find_dates(mdates[0])
-#        print mdates[lag]
-#        assert_equal(mdates[lag], mdates[0])
-#    if 0:
-#        hodie = today('D')
-#        D = DateArray(today('D'))
-#        assert_equal(D.freq, 6000)
-#    if 0:
-#        freqs = [x[0] for x in corelib.freq_dict.values() if x[0] != 'U']
-#        print freqs
-#        for f in freqs:
-#            print f
-#            today = thisday(f)
-#            assert(Date(freq=f, value=today.value) == today)
-#    if 0:
-#        D = date_array(freq='U', start_date=Date('U',1), length=10)
-#    if 0:
-#        dlist = ['2007-01-%02i' % i for i in (1,2,4,5,7,8,10,11,13)]
-#        ords = numpy.fromiter((DateTimeFromString(s).toordinal() for s in dlist),
-#                               float_)
-#    if 0:
-#        "Tests the automatic sorting of dates."
-#        D = date_array_fromlist(dlist=['2006-01','2005-01','2004-01'],freq='M')
-#        assert_equal(D.view(ndarray), [24037, 24049, 24061])
 
     if 1:
         dlist = ['2007-%02i' % i for i in range(1,5)+range(7,13)]

Modified: trunk/scipy/sandbox/timeseries/tseries.py
===================================================================
--- trunk/scipy/sandbox/timeseries/tseries.py	2007-09-18 20:49:42 UTC (rev 3325)
+++ trunk/scipy/sandbox/timeseries/tseries.py	2007-09-18 23:22:21 UTC (rev 3326)
@@ -31,7 +31,6 @@
     filled, getmask, getmaskarray, hsplit, make_mask_none, mask_or, make_mask, \
     masked_array
 
-import tcore as corelib
 import const as _c
 
 import tdates
@@ -54,6 +53,7 @@
 'day_of_week','day_of_year','day','month','quarter','year',
 'hour','minute','second',
 'tofile','asrecords','flatten', 'check_observed',
+'first_unmasked_val', 'last_unmasked_val'
            ]
 
 
@@ -68,9 +68,19 @@
                'MAXIMUM': ['MAX','MAXIMUM','HIGH'],
                'MINIMUM': ['MIN','MINIMUM','LOW']}
 
+def first_unmasked_val(a):
+    "Returns the first unmasked value in a 1d maskedarray."
+    (i,j) = MA.extras.flatnotmasked_edges(a)
+    return a[i]
+
+def last_unmasked_val(a):
+    "Returns the last unmasked value in a 1d maskedarray."
+    (i,j) = MA.extras.flatnotmasked_edges(a)
+    return a[j]
+
 obs_dict = {"UNDEFINED":None,
-            "BEGINNING": corelib.first_unmasked_val,
-            "ENDING": corelib.last_unmasked_val,
+            "BEGINNING": first_unmasked_val,
+            "ENDING": last_unmasked_val,
             "AVERAGED": MA.average,
             "SUMMED": MA.sum,
             "MAXIMUM": MA.maximum,
@@ -82,8 +92,15 @@
     for al in aliases:
         alias_obs_dict[al] = obs_dict[ob]
 obs_dict.update(alias_obs_dict)
-fmtobs_revdict = corelib.reverse_dict(fmtobs_dict)
 
+def _reverse_dict(d):
+    "Reverses the keys and values of a dictionary."
+    alt = []
+    tmp = [alt.extend([(w,k) for w in v]) for (k,v) in d.iteritems()]
+    return dict(alt)
+
+fmtobs_revdict = _reverse_dict(fmtobs_dict)
+
 def fmtObserv(obStr):
     "Converts a possible 'Observed' string into acceptable values."
     if obStr is None:



More information about the Scipy-svn mailing list