Exemplo n.º 1
0
    def test_fmt_docval_args_no_docval(self):
        """ Test that fmt_docval_args raises an error when run on function without docval """
        def method1(self, **kwargs):
            pass

        with self.assertRaisesRegex(ValueError, r"no docval found on .*method1.*"):
            fmt_docval_args(method1, {})
Exemplo n.º 2
0
 def __init__(self, **kwargs):
     description, emission_lambda = popargs("description",
                                            "emission_lambda", kwargs)
     pargs, pkwargs = fmt_docval_args(
         super(OpticalChannel, self).__init__, kwargs)
     super(OpticalChannel, self).__init__(*pargs, **pkwargs)
     self.description = description
     self.emission_lambda = emission_lambda
Exemplo n.º 3
0
Arquivo: base.py Projeto: CINPLA/pynwb
    def __init__(self, **kwargs):
        """Create a TimeSeries object
        """
        pargs, pkwargs = fmt_docval_args(super(TimeSeries, self).__init__, kwargs)
        super(TimeSeries, self).__init__(*pargs, **pkwargs)
        keys = ("resolution",
                "comments",
                "description",
                "conversion",
                "unit",
                "control",
                "control_description")
        for key in keys:
            val = kwargs.get(key)
            if val is not None:
                setattr(self, key, val)

        data = getargs('data', kwargs)
        self.fields['data'] = data
        if isinstance(data, TimeSeries):
            data.__add_link('data_link', self)
            self.fields['num_samples'] = data.num_samples
        elif isinstance(data, AbstractDataChunkIterator):
            self.fields['num_samples'] = -1
        elif isinstance(data, DataIO):
            this_data = data.data
            if isinstance(this_data, AbstractDataChunkIterator):
                self.fields['num_samples'] = -1
            else:
                self.fields['num_samples'] = len(this_data)
        elif data is None:
            self.fields['num_samples'] = 0
        else:
            self.fields['num_samples'] = len(data)

        timestamps = kwargs.get('timestamps')
        starting_time = kwargs.get('starting_time')
        rate = kwargs.get('rate')
        if timestamps is not None:
            if rate is not None:
                raise ValueError('Specifying rate and timestamps is not supported.')
            if starting_time is not None:
                raise ValueError('Specifying starting_time and timestamps is not supported.')
            self.fields['timestamps'] = timestamps
            self.timestamps_unit = 'Seconds'
            self.interval = 1
            if isinstance(timestamps, TimeSeries):
                timestamps.__add_link('timestamp_link', self)
        elif rate is not None:
            self.rate = rate
            if starting_time is not None:
                self.starting_time = starting_time
                self.starting_time_unit = 'Seconds'
            else:
                self.starting_time = 0.0
        else:
            raise TypeError("either 'timestamps' or 'rate' must be specified")
Exemplo n.º 4
0
 def __init__(self, **kwargs):
     device, description, excitation_lambda, location = popargs(
         'device', 'description', 'excitation_lambda', 'location', kwargs)
     pargs, pkwargs = fmt_docval_args(super(OptogeneticStimulusSite, self).__init__, kwargs)
     super(OptogeneticStimulusSite, self).__init__(*pargs, **pkwargs)
     self.device = device
     self.description = description
     self.excitation_lambda = excitation_lambda
     self.location = location
Exemplo n.º 5
0
 def __init__(self, **kwargs):
     data, field_of_view, unit, dimension = popargs('data', 'field_of_view',
                                                    'unit', 'dimension',
                                                    kwargs)
     pargs, pkwargs = fmt_docval_args(super(AxisMap, self).__init__, kwargs)
     super(AxisMap, self).__init__(*pargs, **pkwargs)
     self.data = data
     self.field_of_view = field_of_view
     self.unit = unit
     self.dimension = dimension
Exemplo n.º 6
0
 def __init__(self, **kwargs):
     data, bits_per_pixel, dimension, format, field_of_view = popargs(
         'data', 'bits_per_pixel', 'dimension', 'format', 'field_of_view',
         kwargs)
     pargs, pkwargs = fmt_docval_args(super(AImage, self).__init__, kwargs)
     super(AImage, self).__init__(*pargs, **pkwargs)
     self.data = data
     self.bits_per_pixel = bits_per_pixel
     self.dimension = format
     self.field_of_view = field_of_view
Exemplo n.º 7
0
 def __init__(self, **kwargs):
     field_of_view, imaging_plane, pmt_gain, scan_line_rate = popargs(
         'field_of_view', 'imaging_plane', 'pmt_gain', 'scan_line_rate',
         kwargs)
     pargs, pkwargs = fmt_docval_args(
         super(TwoPhotonSeries, self).__init__, kwargs)
     super(TwoPhotonSeries, self).__init__(*pargs, **pkwargs)
     self.field_of_view = field_of_view
     self.imaging_plane = imaging_plane
     self.pmt_gain = pmt_gain
     self.scan_line_rate = scan_line_rate
Exemplo n.º 8
0
 def test_fmt_docval_args(self):
     """ Test that fmt_docval_args works """
     test_kwargs = {
         'arg1': 'a string',
         'arg2': 1,
         'arg3': True,
     }
     rec_args, rec_kwargs = fmt_docval_args(self.test_obj.basic_add2_kw, test_kwargs)
     exp_args = ['a string', 1]
     self.assertListEqual(rec_args, exp_args)
     exp_kwargs = {'arg3': True}
     self.assertDictEqual(rec_kwargs, exp_kwargs)
Exemplo n.º 9
0
 def __init__(self, **kwargs):
     imaging_plane, reference_images = popargs('imaging_plane',
                                               'reference_images', kwargs)
     if kwargs.get('name') is None:
         kwargs['name'] = imaging_plane.name
     columns, colnames = getargs('columns', 'colnames', kwargs)
     pargs, pkwargs = fmt_docval_args(
         super(PlaneSegmentation, self).__init__, kwargs)
     super(PlaneSegmentation, self).__init__(*pargs, **pkwargs)
     self.imaging_plane = imaging_plane
     if isinstance(reference_images, ImageSeries):
         reference_images = (reference_images, )
     self.reference_images = reference_images
Exemplo n.º 10
0
 def test_fmt_docval_args_allow_extra(self):
     """ Test that fmt_docval_args works """
     test_kwargs = {
         'arg1': 'a string',
         'arg2': 1,
         'arg3': True,
         'hello': 'abc',
         'list': ['abc', 1, 2, 3]
     }
     rec_args, rec_kwargs = fmt_docval_args(self.test_obj.basic_add2_kw_allow_extra, test_kwargs)
     exp_args = ['a string', 1]
     self.assertListEqual(rec_args, exp_args)
     exp_kwargs = {'arg3': True, 'hello': 'abc', 'list': ['abc', 1, 2, 3]}
     self.assertDictEqual(rec_kwargs, exp_kwargs)
Exemplo n.º 11
0
 def __init__(self, **kwargs):
     slice, seal, description, location, resistance, filtering, initial_access_resistance, device = popargs(
         'slice', 'seal', 'description', 'location', 'resistance',
         'filtering', 'initial_access_resistance', 'device', kwargs)
     pargs, pkwargs = fmt_docval_args(
         super(IntracellularElectrode, self).__init__, kwargs)
     super(IntracellularElectrode, self).__init__(*pargs, **pkwargs)
     self.slice = slice
     self.seal = seal
     self.description = description
     self.location = location
     self.resistance = resistance
     self.filtering = filtering
     self.initial_access_resistance = initial_access_resistance
     self.device = device
Exemplo n.º 12
0
 def __init__(self, **kwargs):
     axis_1_phase_map, axis_1_power_map, axis_2_phase_map, axis_2_power_map, axis_descriptions, \
         focal_depth_image, sign_map, vasculature_image = popargs(
             'axis_1_phase_map', 'axis_1_power_map', 'axis_2_phase_map', 'axis_2_power_map',
             'axis_descriptions', 'focal_depth_image', 'sign_map', 'vasculature_image', kwargs)
     pargs, pkwargs = fmt_docval_args(
         super(ImagingRetinotopy, self).__init__, kwargs)
     super(ImagingRetinotopy, self).__init__(*pargs, **pkwargs)
     self.axis_1_phase_map = axis_1_phase_map
     self.axis_1_power_map = axis_1_power_map
     self.axis_2_phase_map = axis_2_phase_map
     self.axis_2_power_map = axis_2_power_map
     self.axis_descriptions = axis_descriptions
     self.focal_depth_image = focal_depth_image
     self.sign_map = sign_map
     self.vasculature_image = vasculature_image
Exemplo n.º 13
0
 def __init__(self, **kwargs):
     kwargs['name'] = 'subject'
     pargs, pkwargs = fmt_docval_args(super(Subject, self).__init__, kwargs)
     super(Subject, self).__init__(*pargs, **pkwargs)
     self.age = getargs('age', kwargs)
     self.description = getargs('description', kwargs)
     self.genotype = getargs('genotype', kwargs)
     self.sex = getargs('sex', kwargs)
     self.species = getargs('species', kwargs)
     self.subject_id = getargs('subject_id', kwargs)
     self.weight = getargs('weight', kwargs)
     date_of_birth = getargs('date_of_birth', kwargs)
     if date_of_birth and date_of_birth.tzinfo is None:
         self.date_of_birth = _add_missing_timezone(date_of_birth)
     else:
         self.date_of_birth = date_of_birth
Exemplo n.º 14
0
 def __init__(self, **kwargs):
     optical_channel, description, device, excitation_lambda, imaging_rate, \
         indicator, location, manifold, conversion, unit, reference_frame = popargs(
             'optical_channel', 'description', 'device', 'excitation_lambda',
             'imaging_rate', 'indicator', 'location', 'manifold', 'conversion',
             'unit', 'reference_frame', kwargs)
     pargs, pkwargs = fmt_docval_args(
         super(ImagingPlane, self).__init__, kwargs)
     super(ImagingPlane, self).__init__(*pargs, **pkwargs)
     self.optical_channel = optical_channel if isinstance(
         optical_channel, list) else [optical_channel]
     self.description = description
     self.device = device
     self.excitation_lambda = excitation_lambda
     self.imaging_rate = imaging_rate
     self.indicator = indicator
     self.location = location
     self.manifold = manifold
     self.conversion = conversion
     self.unit = unit
     self.reference_frame = reference_frame
Exemplo n.º 15
0
 def _func(self, **kwargs):
     cargs, ckwargs = fmt_docval_args(container_type.__init__, kwargs)
     ret = container_type(*cargs, **ckwargs)
     getattr(self, add_name)(ret)
     return ret
Exemplo n.º 16
0
 def __init__(self, **kwargs):
     args, kwargs = fmt_docval_args(LinkSpec.__init__, kwargs)
     super(NWBLinkSpec, self).__init__(*args, **kwargs)
Exemplo n.º 17
0
 def __init__(self, **kwargs):
     args, kwargs = fmt_docval_args(AttributeSpec.__init__, kwargs)
     super(NWBAttributeSpec, self).__init__(*args, **kwargs)
Exemplo n.º 18
0
 def __init__(self, **kwargs):
     ''' Create a NWBNamespaceBuilder '''
     args, vargs = fmt_docval_args(NamespaceBuilder.__init__, kwargs)
     kwargs['namespace_cls'] = NWBNamespace
     super(NWBNamespaceBuilder, self).__init__(*args, **kwargs)
     self.include_namespace(CORE_NAMESPACE)
Exemplo n.º 19
0
 def __init__(self, **kwargs):
     rois = popargs('rois', kwargs)
     pargs, pkwargs = fmt_docval_args(
         super(RoiResponseSeries, self).__init__, kwargs)
     super(RoiResponseSeries, self).__init__(*pargs, **pkwargs)
     self.rois = rois
Exemplo n.º 20
0
    def __init__(self, **kwargs):
        pargs, pkwargs = fmt_docval_args(super(NWBFile, self).__init__, kwargs)
        pkwargs['name'] = 'root'
        super(NWBFile, self).__init__(*pargs, **pkwargs)
        self.__session_description = getargs('session_description', kwargs)
        self.__identifier = getargs('identifier', kwargs)

        self.__session_start_time = getargs('session_start_time', kwargs)
        if self.__session_start_time.tzinfo is None:
            self.__session_start_time = _add_missing_timezone(
                self.__session_start_time)

        self.__timestamps_reference_time = getargs('timestamps_reference_time',
                                                   kwargs)
        if self.__timestamps_reference_time is None:
            self.__timestamps_reference_time = self.__session_start_time
        elif self.__timestamps_reference_time.tzinfo is None:
            raise ValueError(
                "'timestamps_reference_time' must be a timezone-aware datetime object."
            )

        self.__file_create_date = getargs('file_create_date', kwargs)
        if self.__file_create_date is None:
            self.__file_create_date = datetime.now(tzlocal())
        if isinstance(self.__file_create_date, datetime):
            self.__file_create_date = [self.__file_create_date]
        self.__file_create_date = list(
            map(_add_missing_timezone, self.__file_create_date))

        self.acquisition = getargs('acquisition', kwargs)
        self.analysis = getargs('analysis', kwargs)
        self.stimulus = getargs('stimulus', kwargs)
        self.stimulus_template = getargs('stimulus_template', kwargs)
        self.keywords = getargs('keywords', kwargs)

        self.processing = getargs('processing', kwargs)
        epochs = getargs('epochs', kwargs)
        if epochs is not None:
            if epochs.name != 'epochs':
                raise ValueError("NWBFile.epochs must be named 'epochs'")
            self.epochs = epochs
        self.epoch_tags = getargs('epoch_tags', kwargs)

        trials = getargs('trials', kwargs)
        if trials is not None:
            self.trials = trials
        invalid_times = getargs('invalid_times', kwargs)
        if invalid_times is not None:
            self.invalid_times = invalid_times
        units = getargs('units', kwargs)
        if units is not None:
            self.units = units

        self.electrodes = getargs('electrodes', kwargs)
        self.electrode_groups = getargs('electrode_groups', kwargs)
        self.devices = getargs('devices', kwargs)
        self.ic_electrodes = getargs('ic_electrodes', kwargs)
        self.imaging_planes = getargs('imaging_planes', kwargs)
        self.ogen_sites = getargs('ogen_sites', kwargs)
        self.intervals = getargs('intervals', kwargs)
        self.subject = getargs('subject', kwargs)
        self.sweep_table = getargs('sweep_table', kwargs)
        self.lab_meta_data = getargs('lab_meta_data', kwargs)

        recommended = [
            'experimenter',
            'experiment_description',
            'session_id',
            'lab',
            'institution',
            'data_collection',
            'notes',
            'pharmacology',
            'protocol',
            'related_publications',
            'slices',
            'source_script',
            'source_script_file_name',
            'surgery',
            'virus',
            'stimulus_notes',
        ]
        for attr in recommended:
            setattr(self, attr, kwargs.get(attr, None))

        if getargs('source_script', kwargs) is None and getargs(
                'source_script_file_name', kwargs) is not None:
            raise ValueError(
                "'source_script' cannot be None when 'source_script_file_name' is set"
            )
Exemplo n.º 21
0
Arquivo: ogen.py Projeto: CINPLA/pynwb
 def __init__(self, **kwargs):
     site = popargs('site', kwargs)
     pargs, pkwargs = fmt_docval_args(
         super(OptogeneticSeries, self).__init__, kwargs)
     super(OptogeneticSeries, self).__init__(*pargs, **pkwargs)
     self.site = site
Exemplo n.º 22
0
    def __init__(self, **kwargs):
        pargs, pkwargs = fmt_docval_args(super(NWBFile, self).__init__, kwargs)
        pkwargs['name'] = 'root'
        super(NWBFile, self).__init__(*pargs, **pkwargs)
        self.fields['session_description'] = getargs('session_description',
                                                     kwargs)
        self.fields['identifier'] = getargs('identifier', kwargs)

        self.fields['session_start_time'] = getargs('session_start_time',
                                                    kwargs)
        if self.fields['session_start_time'].tzinfo is None:
            self.fields['session_start_time'] = _add_missing_timezone(
                self.fields['session_start_time'])

        self.fields['timestamps_reference_time'] = getargs(
            'timestamps_reference_time', kwargs)
        if self.fields['timestamps_reference_time'] is None:
            self.fields['timestamps_reference_time'] = self.fields[
                'session_start_time']
        elif self.fields['timestamps_reference_time'].tzinfo is None:
            raise ValueError(
                "'timestamps_reference_time' must be a timezone-aware datetime object."
            )

        self.fields['file_create_date'] = getargs('file_create_date', kwargs)
        if self.fields['file_create_date'] is None:
            self.fields['file_create_date'] = datetime.now(tzlocal())
        if isinstance(self.fields['file_create_date'], datetime):
            self.fields['file_create_date'] = [self.fields['file_create_date']]
        self.fields['file_create_date'] = list(
            map(_add_missing_timezone, self.fields['file_create_date']))

        fieldnames = [
            'acquisition',
            'analysis',
            'stimulus',
            'stimulus_template',
            'keywords',
            'processing',
            'epoch_tags',
            'electrodes',
            'electrode_groups',
            'devices',
            'ic_electrodes',
            'imaging_planes',
            'ogen_sites',
            'intervals',
            'subject',
            'sweep_table',
            'lab_meta_data',
            'epochs',
            'trials',
            'invalid_times',
            'units',
            'scratch',
            'experimenter',
            'experiment_description',
            'session_id',
            'lab',
            'institution',
            'data_collection',
            'notes',
            'pharmacology',
            'protocol',
            'related_publications',
            'slices',
            'source_script',
            'source_script_file_name',
            'surgery',
            'virus',
            'stimulus_notes',
        ]
        for attr in fieldnames:
            setattr(self, attr, kwargs.get(attr, None))

        if getargs('source_script', kwargs) is None and getargs(
                'source_script_file_name', kwargs) is not None:
            raise ValueError(
                "'source_script' cannot be None when 'source_script_file_name' is set"
            )

        self.__obj = None