Ejemplo n.º 1
0
 def _getAggregationDS(self):
     nm = '{0}/{1}'.format(self._rootDir, self.saveDataFileName)
     try:
         self._aggregationDS = DataStorage.open(nm, 'a')
         return self._aggregationDS
     except IOError as e:
         return None
Ejemplo n.º 2
0
 def _saveAllOptions(self):
     '''Save the iterated options.'''
     iterFileName = self.outputDir() + '/iterparams.h5'
     log_info('root.submitters', 'Saving parameter iteration data: {0}'.format(iterFileName))
     iterOut = DataStorage.open(iterFileName, 'w')
     iterOut['items'] = self._ac.optionList()
     iterOut.close()
Ejemplo n.º 3
0
 def _getAggregationDS(self):
     nm = '{0}/{1}'.format(self._rootDir, self.saveDataFileName)
     try:
         self._aggregationDS = DataStorage.open(nm, 'a')
         return self._aggregationDS
     except IOError as e:
         return None
Ejemplo n.º 4
0
 def _saveAllOptions(self):
     '''Save the iterated options.'''
     iterFileName = self.outputDir() + '/iterparams.h5'
     log_info('root.submitters',
              'Saving parameter iteration data: {0}'.format(iterFileName))
     iterOut = DataStorage.open(iterFileName, 'w')
     iterOut['items'] = self._ac.optionList()
     iterOut.close()
Ejemplo n.º 5
0
def getBumpCurrentSlope(simLabel, threshold=0):
    fileName = 'bump_slope_data/bump_slope_detailed_noise_{0}.h5'.format(simLabel)
    msg = 'Loading bump vs. current slope from \'{0}\''.format(fileName)
    log_info('getBumpCurrentlope (detailed)', msg)
    ds = DataStorage.open(fileName, 'r')
    slopes = ds['lineFitSlope'].flatten()
    ds.close()
    slopes[slopes < threshold] = np.nan
    return slopes
Ejemplo n.º 6
0
 def _retrieve_slopes(self, file_name, flatten):
     '''Retrieve the slopes from a file ``file_name``.'''
     ds = DataStorage.open(file_name, 'r')
     slopes = ds['lineFitSlope']
     if flatten:
         slopes = slopes.flatten()
     ds.close()
     slopes[slopes < self.threshold] = np.nan
     return slopes
Ejemplo n.º 7
0
 def _retrieve_slopes(self, file_name, flatten):
     '''Retrieve the slopes from a file ``file_name``.'''
     ds = DataStorage.open(file_name, 'r')
     slopes = ds['lineFitSlope']
     if flatten:
         slopes = slopes.flatten()
     ds.close()
     slopes[slopes < self.threshold] = np.nan
     return slopes
Ejemplo n.º 8
0
 def _open_iter_file(self):
     '''Open the iteration metadata file for this parameter space.'''
     fname = "{0}/iterparams.h5".format(self._rootDir)
     try:
         ds = DataStorage.open(fname, 'r')
     except IOError as e:
         job2DLogger.error("Could not open the metadata file. Check that "
                           "the file exists:\n\t%s", fname)
         raise e
     return ds
Ejemplo n.º 9
0
def getBumpCurrentSlope(simLabel, threshold=0):
    fileName = 'bump_slope_data/bump_slope_detailed_noise_{0}.h5'.format(
        simLabel)
    msg = 'Loading bump vs. current slope from \'{0}\''.format(fileName)
    log_info('getBumpCurrentlope (detailed)', msg)
    ds = DataStorage.open(fileName, 'r')
    slopes = ds['lineFitSlope'].flatten()
    ds.close()
    slopes[slopes < threshold] = np.nan
    return slopes
Ejemplo n.º 10
0
 def _open_iter_file(self):
     '''Open the iteration metadata file for this parameter space.'''
     fname = "{0}/iterparams.h5".format(self._rootDir)
     try:
         ds = DataStorage.open(fname, 'r')
     except IOError as e:
         job2DLogger.error(
             "Could not open the metadata file. Check that "
             "the file exists:\n\t%s", fname)
         raise e
     return ds
Ejemplo n.º 11
0
    def saveSpikes(self, fileName):
        '''
        Save all the simulated spikes that have been recorded into a file.

        Parameters
        ----------
        fileName : string
            Path and name of the file
        '''
        out = DataStorage.open(fileName, 'w')
        d = self.getSpikes()  # FIXME: what is d?
        out.close()
Ejemplo n.º 12
0
    def saveData(self):
        output_fname = "{0}/{1}noise_sigma{2}_output.h5".format(
            self.no.output_dir, self.no.fileNamePrefix,
            int(self.no.noise_sigma))

        out = self.getNetParams()
        out['stateMon_e']   = nest.GetStatus(self.stateMon_e)
        out['stateMon_i']   = nest.GetStatus(self.stateMon_i)
        self.fixStateMon(out['stateMon_e'])
        self.fixStateMon(out['stateMon_i'])

        d = DataStorage.open(output_fname, 'w')
        d.update(out)
        d.close()
Ejemplo n.º 13
0
 def _loadData(self):
     if (self._dataLoaded):
         return
     try:
         trialSetLogger.debug("Opening " + self._fileName)
         self._ds = DataStorage.open(self._fileName, self._fileMode)
         DataSpace.__init__(self, self._ds['trials'], key='trials')
     except (IOError, KeyError) as e:
         self._ds = None
         msg =  "Could not open file {0}. Creating an empty DataSet instead."
         trialSetLogger.warn(msg.format(self._fileName))
         trialSetLogger.warn("Error message: {0}".format(str(e)))
         DataSpace.__init__(self, [], key='trials')
     self._dataLoaded = True
Ejemplo n.º 14
0
 def _loadData(self):
     if (self._dataLoaded):
         return
     try:
         trialSetLogger.debug("Opening " + self._fileName)
         self._ds = DataStorage.open(self._fileName, self._fileMode)
         DataSpace.__init__(self, self._ds['trials'], key='trials')
     except (IOError, KeyError) as e:
         self._ds = None
         msg = "Could not open file {0}. Creating an empty DataSet instead."
         trialSetLogger.warn(msg.format(self._fileName))
         trialSetLogger.warn("Error message: {0}".format(str(e)))
         DataSpace.__init__(self, [], key='trials')
     self._dataLoaded = True
Ejemplo n.º 15
0
    def saveAll(self, fileName):
        '''
        Save all the simulated data that has been recorded into a file.

        Parameters
        ----------
        fileName : string
            Path and name of the file
        '''
        out = DataStorage.open(fileName, 'w')
        d = self.getAllData()
        for key, val in d.iteritems():
            out[key] = val
        out.close()
Ejemplo n.º 16
0
    def saveData(self):
        output_fname = "{0}/{1}noise_sigma{2}_output.h5".format(
            self.no.output_dir, self.no.fileNamePrefix,
            int(self.no.noise_sigma))

        out = self.getNetParams()
        out['stateMon_e'] = nest.GetStatus(self.stateMon_e)
        out['stateMon_i'] = nest.GetStatus(self.stateMon_i)
        self.fixStateMon(out['stateMon_e'])
        self.fixStateMon(out['stateMon_i'])

        d = DataStorage.open(output_fname, 'w')
        d.update(out)
        d.close()
Ejemplo n.º 17
0
    def saveIterParams(self,
                       iterParams,
                       dimension_labels,
                       dimensions,
                       fileName='iterparams.h5',
                       dry_run=False):
        '''
        Save iterated parameters.

        .. todo::
            Check the consistency of iterParams, dimension_labels and
            dimensions.

        Parameters
        ----------
        iterParams : dict
            A dictionary of iterated parameters. {<name> : np.ndarray}
        dimension_labels : list or tuple of strings
            Labels of the dimensions. These have to reflect ``iterParams``.
        dimensions : list of ints
            Dimension for each label, must be the same length as
            ``dimension_labels``.
        fileName : str, optional
            An output file name, with an extension supported by the data_storage
            package.
        dry_run : bool
            If ``True`` perform only the dry run.
        '''
        if ((dimension_labels is not None and dimensions is not None)
                and len(dimension_labels) != len(dimensions)):
            raise ValueError("len(dimension_labels) != len(dimensions)")

        filePath = os.path.join(self.outputDir(), fileName)
        log_info('root.submitters',
                 'Saving parameter iteration data to: {0}'.format(filePath))
        if dry_run:
            log_info('root.submitters', 'Dry run: not performing the save '
                     'actually.')
        else:
            o = DataStorage.open(filePath, 'w')
            o['iterParams'] = iterParams
            if dimension_labels is not None:
                o['dimension_labels'] = list(dimension_labels)
            if dimensions is not None:
                o['dimensions'] = list(dimensions)
            o.close()
Ejemplo n.º 18
0
    def saveIterParams(self, iterParams, dimension_labels, dimensions,
                       fileName='iterparams.h5', dry_run=False):
        '''
        Save iterated parameters.

        .. todo::
            Check the consistency of iterParams, dimension_labels and
            dimensions.

        Parameters
        ----------
        iterParams : dict
            A dictionary of iterated parameters. {<name> : np.ndarray}
        dimension_labels : list or tuple of strings
            Labels of the dimensions. These have to reflect ``iterParams``.
        dimensions : list of ints
            Dimension for each label, must be the same length as
            ``dimension_labels``.
        fileName : str, optional
            An output file name, with an extension supported by the data_storage
            package.
        dry_run : bool
            If ``True`` perform only the dry run.
        '''
        if ((dimension_labels is not None and dimensions is not None) and
            len(dimension_labels) != len(dimensions)):
            raise ValueError("len(dimension_labels) != len(dimensions)")

        filePath = os.path.join(self.outputDir(), fileName)
        log_info('root.submitters',
                 'Saving parameter iteration data to: {0}'.format(filePath))
        if dry_run:
            log_info('root.submitters', 'Dry run: not performing the save '
                     'actually.')
        else:
            o = DataStorage.open(filePath, 'w')
            o['iterParams'] = iterParams
            if dimension_labels is not None:
                o['dimension_labels'] = list(dimension_labels)
            if dimensions is not None:
                o['dimensions'] = list(dimensions)
            o.close()
Ejemplo n.º 19
0
def print_data(args):
    '''Print data from a file or directory containing the parameter sweep.

    Parameters
    ----------
    args : argparse.Namespace
        Arguments obtained from ``argparse.Argumentparser``.

    Returns
    -------
    errno : int
        Error number.
    '''
    data = DataStorage.open(args.path, 'r')
    dataset_path = split_data_path(args.data)
    if len(dataset_path) == 0:
        print_data_type(data)
    else:
        print_data_type(data.get_item_chained(dataset_path))

    return Errnum.success
    def plot(self, *args, **kwargs):
        myc= self._get_class_config()
        tLimits = [5.e3, 6e3]


        fig = self._get_final_fig(self.myc['fig_size'])
        gs = gridspec.GridSpec(3, 1, height_ratios=(2.5, 1, 1))

        data = DataStorage.open(self.myc['data_file'], 'r')
        trial_data = data['trials'][0]
        events_e = trial_data['spikeMon_e']['events']
        ESpikes = PopulationSpikes(trial_data['net_attr']['net_Ne'],
                                   events_e['senders'],
                                   events_e['times'])
        events_i = trial_data['spikeMon_i']['events']
        ISpikes = PopulationSpikes(trial_data['net_attr']['net_Ni'],
                                   events_i['senders'],
                                   events_i['times'])

        # EI Raster
        ax_raster = fig.add_subplot(gs[0, 0])
        rasters.plotEIRaster(
            ESpikes, ISpikes,
            ylabelPos=self.myc['ylabelPos'],
            tLimits=tLimits,
            markersize=self.config['scale_factor']*self.myc['markersize'],
            yticks=True,
            sigmaTitle=False,
            ann_EI=False,
            scaleBar=125, scaleX=.8, scaleY=-.05, scaleText='ms',
            scaleTextYOffset=.03, scaleHeight=.01,
            rasterized=False,
            reshape_senders=False)

        # EI rates
        ax_erates = fig.add_subplot(gs[1, 0])
        ax_irates = fig.add_subplot(gs[2, 0])
        rasters.plot_avg_firing_rate_spikes(ESpikes,
                                            ylabelPos=self.myc['ylabelPos'],
                                            color='red',
                                            tLimits=tLimits,
                                            ax=ax_erates,
                                            dt=.5,
                                            winLen=2.)
        rasters.plot_avg_firing_rate_spikes(ISpikes,
                                            ylabelPos=self.myc['ylabelPos'],
                                            color='blue',
                                            tLimits=tLimits,
                                            ax=ax_irates,
                                            dt=.5,
                                            winLen=2.)

        gsl = .12
        gsb = .02
        gsr = .95
        gst = .95
        #fig.text(0.01, gst, 'B', size=16, weight='bold',
        #         va='bottom', ha='left')
        gs.update(left=gsl, bottom=gsb, right=gsr, top=gst, hspace=.2)

        ax_theta = fig.add_axes(Bbox.from_extents(gsl, gst - .015,
                                                    gsr, gst + .01))
        t = np.arange(tLimits[0], tLimits[1]+self.dt, self.dt)
        theta = self.const + .5 * (1. +
                np.cos(2*np.pi*self.freq*1e-3*t - np.pi)) * (1 - self.const)
        ax_theta.fill_between(t, theta, edgecolor='None',
                                color=self.myc['theta_color'])
        ax_theta.set_xlim([tLimits[0], tLimits[1]])
        ax_theta.set_ylim(-.02, 1.02)
        ax_theta.axis('off')

        plt.savefig(self.get_fname('pastoll_et_al_rasters.pdf'), dpi=300,
                    transparent=True)
        plt.close(fig)
'''Main simulation run: Only export E and I connections.'''
from __future__ import absolute_import, print_function, division

from grid_cell_model.models.parameters import getOptParser
from grid_cell_model.models.gc_net_nest import BasicGridCellNetwork
from grid_cell_model.models.seeds import TrialSeedGenerator
from simtools.storage import DataStorage


parser = getOptParser()
(o, args) = parser.parse_args()

output_fname = "{0}/{1}job{2:05}_output.h5".format(o.output_dir,
                                                   o.fileNamePrefix, o.job_num)
d = DataStorage.open(output_fname, 'w')
seed_gen = TrialSeedGenerator(int(o.master_seed))

out = []
overalT = 0.
################################################################################
for trial_idx in range(o.ntrials):
    print("\n\t\tStarting trial no. {0}\n".format(trial_idx))
    seed_gen.set_generators(trial_idx)
    d['master_seed'] = int(o.master_seed)
    d['invalidated'] = 1

    ei_net = BasicGridCellNetwork(o, simulationOpts=None)

    ei_net.endConstruction()
    ei_net.beginSimulation()
Ejemplo n.º 22
0
    def plot(self, *args, **kwargs):
        myc = self._get_class_config()
        tLimits = [5.e3, 6e3]

        fig = self._get_final_fig(self.myc['fig_size'])
        gs = gridspec.GridSpec(3, 1, height_ratios=(2.5, 1, 1))

        data = DataStorage.open(self.myc['data_file'], 'r')
        trial_data = data['trials'][0]
        events_e = trial_data['spikeMon_e']['events']
        ESpikes = PopulationSpikes(trial_data['net_attr']['net_Ne'],
                                   events_e['senders'], events_e['times'])
        events_i = trial_data['spikeMon_i']['events']
        ISpikes = PopulationSpikes(trial_data['net_attr']['net_Ni'],
                                   events_i['senders'], events_i['times'])

        # EI Raster
        ax_raster = fig.add_subplot(gs[0, 0])
        rasters.plotEIRaster(ESpikes,
                             ISpikes,
                             ylabelPos=self.myc['ylabelPos'],
                             tLimits=tLimits,
                             markersize=self.config['scale_factor'] *
                             self.myc['markersize'],
                             yticks=True,
                             sigmaTitle=False,
                             ann_EI=False,
                             scaleBar=125,
                             scaleX=.8,
                             scaleY=-.05,
                             scaleText='ms',
                             scaleTextYOffset=.03,
                             scaleHeight=.01,
                             rasterized=False,
                             reshape_senders=False)

        # EI rates
        ax_erates = fig.add_subplot(gs[1, 0])
        ax_irates = fig.add_subplot(gs[2, 0])
        rasters.plot_avg_firing_rate_spikes(ESpikes,
                                            ylabelPos=self.myc['ylabelPos'],
                                            color='red',
                                            tLimits=tLimits,
                                            ax=ax_erates,
                                            dt=.5,
                                            winLen=2.)
        rasters.plot_avg_firing_rate_spikes(ISpikes,
                                            ylabelPos=self.myc['ylabelPos'],
                                            color='blue',
                                            tLimits=tLimits,
                                            ax=ax_irates,
                                            dt=.5,
                                            winLen=2.)

        gsl = .12
        gsb = .02
        gsr = .95
        gst = .95
        #fig.text(0.01, gst, 'B', size=16, weight='bold',
        #         va='bottom', ha='left')
        gs.update(left=gsl, bottom=gsb, right=gsr, top=gst, hspace=.2)

        ax_theta = fig.add_axes(
            Bbox.from_extents(gsl, gst - .015, gsr, gst + .01))
        t = np.arange(tLimits[0], tLimits[1] + self.dt, self.dt)
        theta = self.const + .5 * (1. + np.cos(2 * np.pi * self.freq * 1e-3 *
                                               t - np.pi)) * (1 - self.const)
        ax_theta.fill_between(t,
                              theta,
                              edgecolor='None',
                              color=self.myc['theta_color'])
        ax_theta.set_xlim([tLimits[0], tLimits[1]])
        ax_theta.set_ylim(-.02, 1.02)
        ax_theta.axis('off')

        plt.savefig(self.get_fname('pastoll_et_al_rasters.pdf'),
                    dpi=300,
                    transparent=True)
        plt.close(fig)
Ejemplo n.º 23
0
def open_storage(tmpdir, file_name, mode):
    '''Open the data storage in a temporary directory.'''
    return DataStorage.open(str(tmpdir.join('test_basic_types.h5')), mode)
Ejemplo n.º 24
0
    stats_visitor_e.visitDictDataSet(dummy_data_set)
    ac_visitor.visitDictDataSet(dummy_data_set)

    # Clean the state monitor
    data['stateMonF_e'] = [data['stateMonF_e'][0]]

    return data


parser          = getOptParser()
(options, args) = parser.parse_args()

output_fname = "{0}/{1}job{2:05}_output.h5".format(options.output_dir,
                                                   options.fileNamePrefix,
                                                   options.job_num)
d = DataStorage.open(output_fname, 'a')
if "trials" not in d.keys():
    d['trials'] = []

seed_gen = TrialSeedGenerator(int(options.master_seed))

overalT = 0.

###############################################################################
for trial_idx in range(len(d['trials']), options.ntrials):
    print("\n\t\tStarting trial no. {0}\n".format(trial_idx))
    seed_gen.set_generators(trial_idx)
    d['master_seed'] = int(options.master_seed)
    d['invalidated'] = 1
    try:
        ei_net = BasicGridCellNetwork(options, simulationOpts=None)