Changeset 358

Show
Ignore:
Timestamp:
11/19/08 17:35:05 (2 months ago)
Author:
apdavison
Message:

When running without X-windows (e.g. on a cluster), then import pylab will fail for some backends while import matplotlib works, which means you can still create plots and write them to file, even if you can't see them on the screen. I have therefore added a distinction between pylab and matplotlib as separate dependencies.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/__init__.py

    r334 r358  
    4646# messages and the check 
    4747dependencies = {'pylab' : {'website' : 'http://matplotlib.sourceforge.net/', 'is_present' : False, 'check':False}, 
     48                'matplotlib': {'website' : 'http://matplotlib.sourceforge.net/', 'is_present' : False, 'check':False}, 
    4849                'tables': {'website' : 'http://www.pytables.org/moin' , 'is_present' : False, 'check':False}, 
    4950                'psyco' : {'website' : 'http://psyco.sourceforge.net/', 'is_present' : False, 'check':False}, 
     
    6364######################################################### 
    6465 
    65 def get_warning(name): 
     66def get_import_warning(name): 
    6667    return ''' ----------------- Dependency Warning --------------------- 
    6768** %s ** package is not installed.  
     
    6970website : %s 
    7071''' %(name, name, dependencies[name]['website']) 
     72 
     73def get_runtime_warning(name, errmsg): 
     74    return ''' ----------------- Dependency Warning --------------------- 
     75** %s ** package is installed but cannot be imported. The error message is: %s  
     76''' %(name, errmsg) 
    7177 
    7278def check_numpy_version(): 
     
    9298            dependencies[name]['is_present'] = True 
    9399        except ImportError: 
    94             print get_warning(name) 
     100            print get_import_warning(name) 
     101        except RuntimeError, errmsg: 
     102            print get_runtime_warning(name, errmsg) 
    95103        dependencies[name]['check'] = True 
    96104        return dependencies[name]['is_present'] 
  • trunk/src/plotting.py

    r319 r358  
    3434if check_dependency('pylab'): 
    3535    import pylab 
     36if check_dependency('matplotlib'): 
    3637    from matplotlib.figure import Figure 
    3738    from matplotlib.lines import Line2D 
  • trunk/src/signals.py

    r357 r358  
    5151newnum = check_numpy_version() 
    5252 
    53 ENABLE_PLOTS = check_dependency('pylab') 
    54 if ENABLE_PLOTS: 
     53HAVE_PYLAB = check_dependency('pylab') 
     54HAVE_MATPLOTLIB = check_dependency('matplotlib') 
     55if HAVE_PYLAB: 
    5556    import pylab 
    5657else: 
    57     MATPLOTLIB_ERROR = "The pylab package was not detected" 
    58  
     58    PYLAB_ERROR = "The pylab package was not detected" 
     59if not HAVE_MATPLOTLIB: 
     60    MATPLOTLIB_ERROR = "The matplotlib package was not detected" 
    5961 
    6062class SpikeTrain(object): 
     
    427429        spikes = numpy.extract((self.spike_times >= t_start) & (self.spike_times <= t_stop), self.spike_times) 
    428430        subplot = get_display(display) 
    429         if not subplot or not ENABLE_PLOTS
    430             print MATPLOTLIB_ERROR 
     431        if not subplot or not HAVE_PYLAB
     432            print PYLAB_ERROR 
    431433            return 
    432434        else: 
     
    11711173            values, xaxis = numpy.histogram(isis, bins=bins, normed=True) 
    11721174        subplot       = get_display(display) 
    1173         if not subplot or not ENABLE_PLOTS
     1175        if not subplot or not HAVE_PYLAB
    11741176            return values, xaxis 
    11751177        else: 
     
    12651267            values, xaxis = numpy.histogram(cvs, bins=bins, normed=True) 
    12661268        subplot       = get_display(display) 
    1267         if not subplot or not ENABLE_PLOTS
     1269        if not subplot or not HAVE_PYLAB
    12681270            return values, xaxis 
    12691271        else: 
     
    14051407        rates   = self.mean_rates() 
    14061408        subplot = get_display(display) 
    1407         if not subplot or not ENABLE_PLOTS
     1409        if not subplot or not HAVE_PYLAB
    14081410            return rates 
    14091411        else: 
     
    14471449        for idx,id in enumerate(self.id_list()): 
    14481450            spike_hist[idx,:] = self.spiketrains[id].time_histogram(time_bin, normalized) 
    1449         if not subplot or not ENABLE_PLOTS
     1451        if not subplot or not HAVE_PYLAB
    14501452            return spike_hist 
    14511453        else: 
     
    15891591                position = spklist.id2position(id) 
    15901592                activity_map[position] = rates[count] 
    1591             if not subplot or not ENABLE_PLOTS
     1593            if not subplot or not HAVE_PYLAB
    15921594                return activity_map 
    15931595            else: 
     
    15991601                raise Exception("Error, the number of flotting positions does not match the number of cells in the SpikeList") 
    16001602            rates = spklist.mean_rates() 
    1601             if not subplot or not ENABLE_PLOTS
     1603            if not subplot or not HAVE_PYLAB
    16021604                return rates 
    16031605            else: 
     
    16671669            else: 
    16681670                results += analysis.ccf(hist_1,hist_2) 
    1669         if not subplot or not ENABLE_PLOTS
     1671        if not subplot or not HAVE_PYLAB
    16701672            if not averaged: 
    16711673                return results 
     
    17651767                cc_time[s_min] = (Z-X*Y)/numpy.sqrt((X*(1-X))*(Y*(1-Y))) 
    17661768                xaxis[s_min]   = time_bin*idx 
    1767             if not subplot or not ENABLE_PLOTS
     1769            if not subplot or not HAVE_PYLAB
    17681770                return cc_time 
    17691771            else: 
     
    19101912            spk = spk.time_slice(t_start, t_stop) 
    19111913 
    1912         if not subplot or not ENABLE_PLOTS
    1913             print MATPLOTLIB_ERROR 
     1914        if not subplot or not HAVE_PYLAB
     1915            print PYLAB_ERROR 
    19141916        else: 
    19151917            ids, spike_times = spk.convert(format="[ids, times]") 
     
    19641966        if t_start is None: t_start = self.t_start 
    19651967        if t_stop is None:  t_stop  = self.t_stop 
    1966         if not subplot or not ENABLE_PLOTS
    1967             print MATPLOTLIB_ERROR 
     1968        if not subplot or not HAVE_PYLAB
     1969            print PYLAB_ERROR 
    19681970        else: 
    19691971            files        = [] 
     
    22742276        subplot   = get_display(display) 
    22752277        time_axis = self.time_axis()   
    2276         if not subplot or not ENABLE_PLOTS
    2277             print MATPLOTLIB_ERROR 
     2278        if not subplot or not HAVE_PYLAB
     2279            print PYLAB_ERROR 
    22782280        else: 
    22792281            xlabel = "Time (ms)" 
     
    24032405            result = numpy.array(result) 
    24042406             
    2405         if not subplot or not ENABLE_PLOTS
     2407        if not subplot or not HAVE_PYLAB
    24062408            if with_time: 
    24072409                return result, time_axis 
     
    28512853                    subplotcount_all += 1 
    28522854 
    2853         if not figure or not ENABLE_PLOTS
     2855        if not figure or not HAVE_PYLAB
    28542856            return results 
    28552857 
     
    28772879        id_list   = self._AnalogSignalList__sub_id_list(id_list) 
    28782880        time_axis = self.time_axis()   
    2879         if not subplot or not ENABLE_PLOTS
     2881        if not subplot or not HAVE_MATPLOTLIB
    28802882            print MATPLOTLIB_ERROR 
    28812883        else: 
     
    29122914        id_list   = self._AnalogSignalList__sub_id_list(id_list) 
    29132915        time_axis = self.time_axis()   
    2914         if not subplot or not ENABLE_PLOTS
    2915             print MATPLOTLIB_ERROR 
     2916        if not subplot or not HAVE_PYLAB
     2917            print PYLAB_ERROR 
    29162918        else: 
    29172919            xlabel = "Time (ms)" 
     
    29432945        id_list   = self._AnalogSignalList__sub_id_list(id_list) 
    29442946        time_axis = self.time_axis()   
    2945         if not subplot or not ENABLE_PLOTS
    2946             print MATPLOTLIB_ERROR 
     2947        if not subplot or not HAVE_PYLAB
     2948            print PYLAB_ERROR 
    29472949        else: 
    29482950            xlabel = "Time (ms)"