[Scipy-svn] r2552 - in trunk/Lib/sandbox/timeseries: . build build/lib.linux-x86_64-2.4 build/lib.linux-x86_64-2.4/timeseries build/temp.linux-x86_64-2.4 examples src tests

scipy-svn at scipy.org scipy-svn at scipy.org
Sun Jan 14 16:39:29 CST 2007


Author: pierregm
Date: 2007-01-14 16:39:15 -0600 (Sun, 14 Jan 2007)
New Revision: 2552

Added:
   trunk/Lib/sandbox/timeseries/.project
   trunk/Lib/sandbox/timeseries/CHANGELOG
   trunk/Lib/sandbox/timeseries/MANIFEST
   trunk/Lib/sandbox/timeseries/build/
   trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/
   trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/timeseries/
   trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/timeseries/__init__.py
   trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/timeseries/tcore.py
   trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/timeseries/tdates.py
   trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/timeseries/tseries.py
   trunk/Lib/sandbox/timeseries/build/temp.linux-x86_64-2.4/
   trunk/Lib/sandbox/timeseries/build/temp.linux-x86_64-2.4/src/
   trunk/Lib/sandbox/timeseries/tcore.py
   trunk/Lib/sandbox/timeseries/tdates.py
   trunk/Lib/sandbox/timeseries/tests/test_dates.py
   trunk/Lib/sandbox/timeseries/tests/test_timeseries.py
   trunk/Lib/sandbox/timeseries/tseries.py
Removed:
   trunk/Lib/sandbox/timeseries/corelib.py
   trunk/Lib/sandbox/timeseries/mtimeseries/
   trunk/Lib/sandbox/timeseries/timeseries.py
   trunk/Lib/sandbox/timeseries/tsdate.py
Modified:
   trunk/Lib/sandbox/timeseries/
   trunk/Lib/sandbox/timeseries/__init__.py
   trunk/Lib/sandbox/timeseries/examples/
   trunk/Lib/sandbox/timeseries/examples/example.py
   trunk/Lib/sandbox/timeseries/src/
Log:
cf changelog


Property changes on: trunk/Lib/sandbox/timeseries
___________________________________________________________________
Name: svn:ignore
   + sandbox


Added: trunk/Lib/sandbox/timeseries/.project
===================================================================
--- trunk/Lib/sandbox/timeseries/.project	2007-01-14 21:25:20 UTC (rev 2551)
+++ trunk/Lib/sandbox/timeseries/.project	2007-01-14 22:39:15 UTC (rev 2552)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>scipy_svn_timeseries</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.python.pydev.PyDevBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.python.pydev.pythonNature</nature>
+	</natures>
+</projectDescription>

Copied: trunk/Lib/sandbox/timeseries/CHANGELOG (from rev 2488, trunk/Lib/sandbox/timeseries/mtimeseries/CHANGELOG)
===================================================================
--- trunk/Lib/sandbox/timeseries/mtimeseries/CHANGELOG	2007-01-04 16:42:30 UTC (rev 2488)
+++ trunk/Lib/sandbox/timeseries/CHANGELOG	2007-01-14 22:39:15 UTC (rev 2552)
@@ -0,0 +1,15 @@
+#2007-01-14 : Code reorganization:
+#           : - Moved Matt's initial version to archived_version
+#           : - Moved Pierre's version to base
+#           : tdates
+#           : - Fixed a bug w/ definition of months and weeks
+#           : - Renamed dateOf to asfreq + use cseries
+#2007-01-04 : tsdate
+#           : - Corrected a bug w/ Date.__init__ and 'B' freq
+#2007-01-03 : tseries 
+#           : - Allowed endpoints adjustment after convert
+#           : - Put the estimation of the data length in its own function.
+#           : - Added a timestep compatibility check.
+#           : - The variables in a multi-series correspond now to the last axis.
+#           : - Blocked transpose/swapaxes, temporarily.
+#           : - Speed-up fill_missing_dates
\ No newline at end of file

Added: trunk/Lib/sandbox/timeseries/MANIFEST
===================================================================
--- trunk/Lib/sandbox/timeseries/MANIFEST	2007-01-14 21:25:20 UTC (rev 2551)
+++ trunk/Lib/sandbox/timeseries/MANIFEST	2007-01-14 22:39:15 UTC (rev 2552)
@@ -0,0 +1,8 @@
+setup.py
+./__init__.py
+./corelib.py
+./cseries.c
+./shiftingarray.py
+./timeseries.py
+./tsdate.py
+./examples/example.py

Modified: trunk/Lib/sandbox/timeseries/__init__.py
===================================================================
--- trunk/Lib/sandbox/timeseries/__init__.py	2007-01-14 21:25:20 UTC (rev 2551)
+++ trunk/Lib/sandbox/timeseries/__init__.py	2007-01-14 22:39:15 UTC (rev 2552)
@@ -1,3 +0,0 @@
-from timeseries import *
-from tsdate import *
-from corelib import *


Property changes on: trunk/Lib/sandbox/timeseries/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Date 
Author 
Revision
Id

Added: trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/timeseries/__init__.py
===================================================================

Added: trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/timeseries/tcore.py
===================================================================
--- trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/timeseries/tcore.py	2007-01-14 21:25:20 UTC (rev 2551)
+++ trunk/Lib/sandbox/timeseries/build/lib.linux-x86_64-2.4/timeseries/tcore.py	2007-01-14 22:39:15 UTC (rev 2552)
@@ -0,0 +1,157 @@
+import numpy
+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)
+
+
+
+#####---------------------------------------------------------------------------
+#---- --- Option conversion ---
+#####---------------------------------------------------------------------------
+obs_dict = {"UNDEFINED":None,
+            "UNDEF":None,
+            "BEGIN": first_unmasked_val,
+            "BEGINNING": first_unmasked_val,
+            "END": last_unmasked_val,
+            "ENDING": last_unmasked_val,
+            "AVERAGED": MA.average,
+            "AVERAGE": MA.average,
+            "MEAN": MA.average,
+            "SUMMED": MA.sum,
+            "SUM": MA.sum,
+            "MAXIMUM": MA.maximum,
+            "MAX": MA.maximum,
+            "MINIMUM": MA.minimum,
+            "MIN": MA.minimum,
+            }
+obsDict = obs_dict
+#
+def fmtObserv(obStr):
+    "Converts a possible 'Observed' string into acceptable values."
+    if obStr is None:
+        return None
+    elif obStr.upper() in obs_dict.keys():
+        return obStr.upper()    
+    else:
+        raise ValueError("Invalid value for observed attribute: %s " % str(obStr))
+
+
+fmtfreq_dict = {'A': ['ANNUAL','ANNUALLY','YEAR','YEARLY'],
+                'B': ['BUSINESS','BUSINESSLYT'],
+                'D': ['DAY','DAILY',],
+                'H': ['HOUR','HOURLY',],
+                'M': ['MONTH','MONTHLY',],
+                'Q': ['QUARTER','QUARTERLY',],
+                'S': ['SECOND','SECONDLY',],
+                'T': ['MINUTE','MINUTELY',],
+                'W': ['WEEK','WEEKLY',],
+                'U': ['UNDEF','UNDEFINED'],
+                }
+fmtfreq_revdict = reverse_dict(fmtfreq_dict)
+
+def fmtFreq (freqStr):
+    "Converts a possible 'frequency' string to acceptable values."
+    if freqStr is None:
+        return None    
+    elif freqStr.upper() in fmtfreq_dict.keys():
+        return freqStr[0].upper()
+    elif freqStr.upper() in fmtfreq_revdict.keys():
+        return fmtfreq_revdict[freqStr.upper()]
+    else:
+        raise ValueError("Invalid frequency: %s " % str(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):
+    return freq_type_mapping[fmtFreq(freq)]
+
+def isDateType(dtype):
+    #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: 
+        r