Changeset 295
- Timestamp:
- 11/06/08 11:32:13 (2 months ago)
- Files:
-
- trunk/src/__init__.py (modified) (1 diff)
- trunk/src/analysis.py (modified) (1 diff)
- trunk/src/io.py (modified) (1 diff)
- trunk/src/parameters.py (modified) (1 diff)
- trunk/src/plotting.py (modified) (1 diff)
- trunk/src/random.py (modified) (1 diff)
- trunk/src/signals.py (modified) (1 diff)
- trunk/src/stgen.py (modified) (1 diff)
- trunk/test/test_signals.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/__init__.py
r247 r295 1 1 __all__ = ['analysis', 'parameters', 'plotting', 'sandbox', 'signals', 'stgen', 'utilities', 'io'] 2 2 3 """from tables import __version__ 3 ######################################################### 4 ## ALL DEPENDENCIES SHOULD BE GATHERED HERE FOR CLARITY 5 ######################################################### 6 7 # The nice thing would be to gathered every non standard 8 # dependency here, in order to centralizz the warning 9 # messages and the check 10 dependencies = {'numpy' : {'website' : 'http://numpy.scipy.org/' , 'is_present' : False, 'check':False}, 11 'pylab' : {'website' : 'http://matplotlib.sourceforge.net/', 'is_present' : False, 'check':False}, 12 'tables': {'website' : 'http://www.pytables.org/moin' , 'is_present' : False, 'check':False}, 13 'psyco' : {'website' : 'http://psyco.sourceforge.net/', 'is_present' : False, 'check':False}, 14 'pygsl' : {'website' : 'http://pygsl.sourceforge.net/', 'is_present' : False, 'check':False}, 15 'PIL' : {'website' : 'http://www.pythonware.com/products/pil/', 'is_present':False, 'check':False}, 16 'scipy' : {'website' : 'http://numpy.scipy.org/' , 'is_present' : False, 'check':False}, 17 ## Add here your extensions ### 18 } 19 20 21 22 23 24 25 ######################################################### 26 ## Function to display error messages on the dependencies 27 ######################################################### 28 29 def get_warning(name): 30 return ''' ----------------- Dependency Warning --------------------- 31 ** %s ** package is not installed. 32 To have functions using %s please install the package. 33 website : %s 34 ''' %(name, name, dependencies[name]['website']) 35 36 def check_numpy_version(): 37 import numpy 38 numpy_version = numpy.__version__.split(".")[0:2] 39 numpy_version = float(".".join(numpy_version)) 40 if numpy_version >= 1.2: 41 return True 42 else: 43 return False 4 44 5 45 def check_pytables_version(): 6 46 #v = [int(s) for s in __version__.split('.')] 7 if __version__<= 2: #1.4: #v[0] < 1 or (v[0] == 1 and v[1] < 4):47 if tables.__version__<= 2: #1.4: #v[0] < 1 or (v[0] == 1 and v[1] < 4): 8 48 raise Exception('PyTables version must be >= 1.4, installed version is %s' % __version__) 9 check_pytables_version() 10 """ 49 50 def check_dependency(name): 51 if dependencies[name]['check']: 52 return dependencies[name]['is_present'] 53 else: 54 try: 55 exec("import %s" %name) 56 dependencies[name]['is_present'] = True 57 except ImportError: 58 print get_warning(name) 59 dependencies[name]['check'] = True 60 return dependencies[name]['is_present'] 61 62 63 #for name in dependencies: 64 #if not dependencies[name]['check']: 65 #is_present = check_dependency(name) 66 #dependencies[name]['check'] = True 67 #if is_present: 68 #if name == 'numpy': 69 #newnum = check_numpy_version() 70 #if name == 'pytables': 71 72 73 74 75 76 77 78 79 80 81 11 82 12 83 # Setup fancy logging trunk/src/analysis.py
r215 r295 7 7 """ 8 8 9 import os, numpy 9 import os 10 from NeuroTools.__init__ import check_dependency 11 12 if check_dependency('numpy'): 13 import numpy 14 15 10 16 11 17 def ccf(x, y, axis=None): trunk/src/io.py
r293 r295 1 import numpy, os, logging, cPickle 1 from NeuroTools.__init__ import check_dependency 2 3 import os, logging, cPickle 2 4 DEFAULT_BUFFER_SIZE = 10000 3 5 4 try: 5 import pytable 6 ENABLE_HDF5 = True 7 except ImportError: 8 ENABLE_HDF5 = False 6 if check_dependency('numpy'): 7 import numpy 8 9 9 10 10 trunk/src/parameters.py
r280 r295 7 7 """ 8 8 9 import urllib # to be replaced with srblib9 import urllib, copy, warnings # to be replaced with srblib 10 10 from urlparse import urlparse 11 import copy 12 import warnings 13 import numpy 14 import numpy.random 11 from NeuroTools.__init__ import check_dependency 15 12 from NeuroTools.random import ParameterDist, GammaDist, UniformDist, NormalDist 13 14 if check_dependency('numpy'): 15 import numpy 16 import numpy.random 17 16 18 17 19 def isiterable(x): trunk/src/plotting.py
r291 r295 7 7 8 8 9 import numpy, sys 10 numpy_version = numpy.__version__.split(".")[0:2] 11 numpy_version = float(".".join(numpy_version)) 9 import sys 10 from NeuroTools.__init__ import check_dependency 12 11 13 12 14 13 # Check availability of pylab (essential!) 15 try:14 if check_dependency('pylab'): 16 15 import pylab 17 16 from matplotlib.figure import Figure 18 17 from matplotlib.lines import Line2D 19 18 from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas 20 except ImportError: 21 MATPLOTLIB_ERROR = \ 22 """ 23 ERROR: Matplolib not detected! The module NeuroTools.plotting depends on this package. 24 Please install the Matplotlib package --> http://matplotlib.sourceforge.net/ 25 """ 26 raise Exception(MATPLOTLIB_ERROR) 19 20 21 if check_dependency('numpy'): 22 import numpy 27 23 28 24 # Check availability of PIL 29 try : 25 PILIMAGEUSE = check_dependency('PIL') 26 if PILIMAGEUSE: 30 27 import PIL.Image as Image 31 PILIMAGEUSE = True32 except ImportError:33 PILIMAGE_WARNING = \34 """35 WARNING: Python Imaging Library PIL not detected! Functions that make use of PIL will not be supported!36 """37 PILIMAGEUSE = False38 print PILIMAGE_WARNING39 28 40 29 trunk/src/random.py
r280 r295 1 1 # Classes for specifiying a parameter by a statistical distribution 2 2 3 import numpy 4 import numpy.random 3 from NeuroTools.__init__ import check_dependency 5 4 6 try: 5 if check_dependency('numpy'): 6 import numpy 7 import numpy.random 8 9 have_scipy = check_dependency('scipy') 10 if have_scipy: 7 11 import scipy.stats 8 have_scipy = True 9 except ImportError: 10 warnings.warn('scipy not found. Some distributions will be unable to be realized.', 11 ImportWarning) 12 have_scipy = False 12 13 13 14 14 class ParameterDist(object): trunk/src/signals.py
r293 r295 5 5 """ 6 6 7 import numpy, os, logging, re 7 import os, re 8 from NeuroTools.__init__ import check_dependency, check_numpy_version 8 9 from NeuroTools import analysis 9 10 from NeuroTools.io import * 10 11 from NeuroTools.plotting import get_display, set_axis_limits, set_labels, SimpleMultiplot 11 12 12 numpy_version = numpy.__version__.split(".")[0:2] 13 numpy_version = float(".".join(numpy_version)) 14 15 MATPLOTLIB_ERROR = \ 16 " ----------------- MATPLOTLIB Warning : ---------------------\n \ 17 Matplolib NOT detected so plots will be disabled.\n \ 18 To turn them on, please install the Matplotlib package\n \ 19 --> http://matplotlib.sourceforge.net/" 20 21 PSYCO_ERROR = \ 22 "----------------- PSYCO Warning : ---------------------\n \ 23 Psyco NOT detected. This is an optionnal package that \n \ 24 could slightly speed up some NeuroTools functions.\n \ 25 --> http://psyco.sourceforge.net/" 26 27 28 NUMPY_WARNING = \ 29 " ------------------- NUMPY Warning : -------------------------\n \ 30 You should think about updating your numpy version to\n \ 31 Numpy >= 1.2\n \ 32 --> http://numpy.scipy.org/\n" 33 34 if numpy_version >= 1.2: 35 newnum = True 36 else: 37 newnum = False 38 print NUMPY_WARNING 39 40 try : 41 import pylab 42 ENABLE_PLOTS = True 43 except ImportError: 44 ENABLE_PLOTS = False 45 print MATPLOTLIB_ERROR 46 47 try : 13 if check_dependency('psyco'): 48 14 import psyco 49 15 psyco.full() 50 except ImportError: 51 print PSYCO_ERROR 52 53 54 55 56 16 17 if check_dependency('numpy'): 18 import numpy 19 newnum = check_numpy_version() 20 21 ENABLE_PLOTS = check_dependency('pylab') 22 if ENABLE_PLOTS: 23 import pylab 24 else: 25 MATPLOTLIB_ERROR = "No pylab pacakge have been detected" 57 26 58 27 class SpikeTrain(object): trunk/src/stgen.py
r192 r295 4 4 # TODO make it generate spiketrains? 5 5 6 try: 6 from NeuroTools.__init__ import check_dependency 7 8 have_gsl = check_dependency('pygsl') 9 if have_gsl: 7 10 import pygsl 8 have_gsl = True 9 except ImportError: 10 print "Warning: pygsl not available" 11 have_gsl = False 12 from numpy import array, log 13 import numpy 14 11 12 if check_dependency('numpy'): 13 from numpy import array, log 14 import numpy 15 15 16 16 trunk/test/test_signals.py
r287 r295 5 5 from NeuroTools import signals, io 6 6 import numpy, unittest, os 7 from NeuroTools.signals import numpy_version 8 9 if numpy_version >= 1.2: 10 newnum = True 11 else: 12 newnum = False 7 from NeuroTools.__init__ import check_numpy_version 8 newnum = check_numpy_version() 13 9 14 10 try :

