def add_roi(self, **kwargs): """Add a Region Of Interest (ROI) data to this""" pixel_mask, voxel_mask, image_mask = popargs('pixel_mask', 'voxel_mask', 'image_mask', kwargs) if image_mask is None and pixel_mask is None and voxel_mask is None: raise ValueError("Must provide 'image_mask' and/or 'pixel_mask'") rkwargs = dict(kwargs) if image_mask is not None: rkwargs['image_mask'] = image_mask if pixel_mask is not None: rkwargs['pixel_mask'] = pixel_mask if voxel_mask is not None: rkwargs['voxel_mask'] = voxel_mask return super(PlaneSegmentation, self).add_row(**rkwargs)
def __init__(self, **kwargs): name, data, electrodes = popargs('name', 'data', 'electrodes', kwargs) timestamps = getargs('timestamps', kwargs) if not (isinstance(data, TimeSeries) and isinstance(timestamps, TimeSeries)): if not (isinstance(data, DataChunkIterator) and isinstance(timestamps, DataChunkIterator)): if len(data) != len(timestamps): raise Exception( 'Must provide the same number of timestamps and spike events' ) else: # TODO: add check when we have DataChunkIterators pass super(SpikeEventSeries, self).__init__(name, data, electrodes, **kwargs)
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
def __init__(self, **kwargs): # get the inputs electrodes, description, times, features = popargs( 'electrodes', 'description', 'times', 'features', kwargs) # Validate the shape of the inputs # Validate event times compared to features shape_validators = [] shape_validators.append(assertEqualShape(data1=features, data2=times, axes1=0, axes2=0, name1='feature_shape', name2='times', ignore_undetermined=True)) # Validate electrodes compared to features shape_validators.append(assertEqualShape(data1=features, data2=electrodes, axes1=1, axes2=0, name1='feature_shape', name2='electrodes', ignore_undetermined=True)) # Valided description compared to features shape_validators.append(assertEqualShape(data1=features, data2=description, axes1=2, axes2=0, name1='feature_shape', name2='description', ignore_undetermined=True)) # Raise an error if any of the shapes do not match raise_error = False error_msg = "" for sv in shape_validators: raise_error |= not sv.result if not sv.result: error_msg += sv.message + "\n" if raise_error: raise ValueError(error_msg) # Initialize the object super(FeatureExtraction, self).__init__(**kwargs) self.electrodes = electrodes self.description = description self.times = list(times) self.features = features
def __init__(self, **kwargs): columns = kwargs['columns'] if columns is None: taxon_id, rep_idx, taxa_table = popargs('taxon_id', 'rep_idx', 'taxa_table', kwargs) if not isinstance(taxon_id, VectorData): taxon_id = VectorData('taxon_id', 'NCBI accession', data=taxon_id) if not isinstance(rep_idx, VectorData): if taxa_table is None: raise ValueError('taxa_table must be provided if writing') rep_idx = DynamicTableRegion('rep_idx', rep_idx, 'representative taxon', taxa_table) kwargs['columns'] = [taxon_id, rep_idx] call_docval_func(super().__init__, kwargs)
def __init__(self, **kwargs): metric, source_timeseries, bands = popargs('metric', 'source_timeseries', 'bands', kwargs) super(DecompositionSeries, self).__init__(**kwargs) self.source_timeseries = source_timeseries if self.source_timeseries is None: warnings.warn( "It is best practice to set `source_timeseries` if it is present to document " "where the DecompositionSeries was derived from. (Optional)") self.metric = metric if bands is None: bands = DynamicTable( "bands", "data about the frequency bands that the signal was decomposed into" ) self.bands = bands
def __init__(self, **kwargs): metric, source_timeseries, bands, source_channels = popargs( 'metric', 'source_timeseries', 'bands', 'source_channels', kwargs) super(DecompositionSeries, self).__init__(**kwargs) self.source_timeseries = source_timeseries self.source_channels = source_channels if self.source_timeseries is None and self.source_channels is None: warnings.warn( "Neither source_timeseries nor source_channels is present in DecompositionSeries. It is " "recommended to indicate the source timeseries if it is present, or else to link to the " "corresponding source_channels. (Optional)") self.metric = metric if bands is None: bands = DynamicTable( "bands", "data about the frequency bands that the signal was decomposed into" ) self.bands = bands
def __init__(self, **kwargs): bits_per_pixel, dimension, external_file, starting_frame, format, device = popargs( 'bits_per_pixel', 'dimension', 'external_file', 'starting_frame', 'format', 'device', kwargs) call_docval_func(super(ImageSeries, self).__init__, kwargs) if external_file is None and self.data is None: raise ValueError( "Must supply either external_file or data to %s '%s'." % (self.__class__.__name__, self.name)) self.bits_per_pixel = bits_per_pixel self.dimension = dimension self.external_file = external_file if external_file is not None: self.starting_frame = starting_frame else: self.starting_frame = None self.format = format self.device = device
def add_interval(self, **kwargs): tags, timeseries = popargs('tags', 'timeseries', kwargs) start_time, stop_time = getargs('start_time', 'stop_time', kwargs) rkwargs = dict(kwargs) if tags is not None: if isinstance(tags, str): tags = [s.strip() for s in tags.split(",") if not s.isspace()] rkwargs['tags'] = tags if not (timeseries is None or (isinstance(timeseries, (tuple, list)) and len(timeseries) == 0)): if isinstance(timeseries, TimeSeries): timeseries = [timeseries] tmp = list() for ts in timeseries: idx_start, count = self.__calculate_idx_count(start_time, stop_time, ts) tmp.append((idx_start, count, ts)) timeseries = tmp rkwargs['timeseries'] = timeseries return super(TimeIntervals, self).add_row(**rkwargs)
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) call_docval_func(super().__init__, kwargs) warnings.warn( "The ImagingRetinotopy class currently cannot be written to or read from a file. " "This is a known bug and will be fixed in a future release of PyNWB." ) 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
def load_namespaces(self, **kwargs): ''' Load cached namespaces from a file. ''' namespace_catalog, path, namespaces, file_obj = popargs('namespace_catalog', 'path', 'namespaces', 'file', kwargs) if file_obj is None: raise ValueError("'file' argument must be supplied to load_namespaces.") if path is not None and file_obj is not None: # consistency check if os.path.abspath(file_obj.filename) != os.path.abspath(path): msg = ("You argued '%s' as this object's path, but supplied a file with filename: %s" % (path, file_obj.filename)) raise ValueError(msg) return self.__load_namespaces(namespace_catalog, namespaces, file_obj)
def __init__(self, **kwargs): name, data, electrode, gain = popargs('name', 'data', 'electrode', 'gain', kwargs) unit = 'amperes' capacitance_fast, capacitance_slow, resistance_comp_bandwidth, resistance_comp_correction, \ resistance_comp_prediction, whole_cell_capacitance_comp, whole_cell_series_resistance_comp = popargs( 'capacitance_fast', 'capacitance_slow', 'resistance_comp_bandwidth', 'resistance_comp_correction', 'resistance_comp_prediction', 'whole_cell_capacitance_comp', 'whole_cell_series_resistance_comp', kwargs) super(VoltageClampSeries, self).__init__(name, data, unit, electrode, gain, **kwargs) self.capacitance_fast = capacitance_fast self.capacitance_slow = capacitance_slow self.resistance_comp_bandwidth = resistance_comp_bandwidth self.resistance_comp_correction = resistance_comp_correction self.resistance_comp_prediction = resistance_comp_prediction self.whole_cell_capacitance_comp = whole_cell_capacitance_comp self.whole_cell_series_resistance_comp = whole_cell_series_resistance_comp
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) call_docval_func(super(ImagingPlane, self).__init__, kwargs) 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
def __init__(self, **kwargs): path, mode, manager, extensions, load_namespaces, file_obj, comm, driver =\ popargs('path', 'mode', 'manager', 'extensions', 'load_namespaces', 'file', 'comm', 'driver', kwargs) if load_namespaces: if manager is not None: warn("loading namespaces from file - ignoring 'manager'") if extensions is not None: warn( "loading namespaces from file - ignoring 'extensions' argument" ) # namespaces are not loaded when creating an NWBHDF5IO object in write mode if 'w' in mode or mode == 'x': raise ValueError( "cannot load namespaces from file when writing to it") tm = get_type_map() super(NWBHDF5IO, self).load_namespaces(tm, path, file=file_obj, driver=driver) manager = BuildManager(tm) # XXX: Leaving this here in case we want to revert to this strategy for # loading cached namespaces # ns_catalog = NamespaceCatalog(NWBGroupSpec, NWBDatasetSpec, NWBNamespace) # super(NWBHDF5IO, self).load_namespaces(ns_catalog, path) # tm = TypeMap(ns_catalog) # tm.copy_mappers(get_type_map()) else: if manager is not None and extensions is not None: raise ValueError( "'manager' and 'extensions' cannot be specified together") elif extensions is not None: manager = get_manager(extensions=extensions) elif manager is None: manager = get_manager() super(NWBHDF5IO, self).__init__(path, manager=manager, mode=mode, file=file_obj, comm=comm, driver=driver)
def __init__(self, **kwargs): seq_table, taxa_table, genome_table, distances, tree, tree_graph = popargs( 'seq_table', 'taxa_table', 'genome_table', 'distances', 'tree', 'tree_graph', kwargs) call_docval_func(super().__init__, {'name': 'root'}) self.seq_table = seq_table self.taxa_table = taxa_table self.genome_table = genome_table self.tree_graph = tree_graph self.distances = distances self.tree = tree self._sanity = False self._sanity_features = 5 self._labels = None self.__indices = None self.__n_outputs = None self.__n_emb_components = self.taxa_table['embedding'].data.shape[ 1] if 'embedding' in self.taxa_table else 0 self.set_label_key('id') self.__rev = False self.__get_kwargs = dict()
def __init__(self, **kwargs): name, data, unit, electrode, gain = popargs('name', 'data', 'unit', 'electrode', 'gain', kwargs) if unit != 'amperes': warnings.warn( "Unit for %s '%s' is ignored and will be set to 'amperes' as per NWB 2.1.0." % (self.__class__.__name__, name)) unit = 'amperes' capacitance_fast, capacitance_slow, resistance_comp_bandwidth, resistance_comp_correction, \ resistance_comp_prediction, whole_cell_capacitance_comp, whole_cell_series_resistance_comp = popargs( 'capacitance_fast', 'capacitance_slow', 'resistance_comp_bandwidth', 'resistance_comp_correction', 'resistance_comp_prediction', 'whole_cell_capacitance_comp', 'whole_cell_series_resistance_comp', kwargs) super().__init__(name, data, unit, electrode, gain, **kwargs) self.capacitance_fast = capacitance_fast self.capacitance_slow = capacitance_slow self.resistance_comp_bandwidth = resistance_comp_bandwidth self.resistance_comp_correction = resistance_comp_correction self.resistance_comp_prediction = resistance_comp_prediction self.whole_cell_capacitance_comp = whole_cell_capacitance_comp self.whole_cell_series_resistance_comp = whole_cell_series_resistance_comp
def __init__(self, **kwargs): optical_channel, description, device, excitation_lambda, imaging_rate, \ indicator, location, manifold, conversion, unit, reference_frame, origin_coords, origin_coords_unit, \ grid_spacing, grid_spacing_unit = popargs( 'optical_channel', 'description', 'device', 'excitation_lambda', 'imaging_rate', 'indicator', 'location', 'manifold', 'conversion', 'unit', 'reference_frame', 'origin_coords', 'origin_coords_unit', 'grid_spacing', 'grid_spacing_unit', kwargs) call_docval_func(super(ImagingPlane, self).__init__, kwargs) 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 if manifold is not None: warnings.warn( "The 'manifold' argument is deprecated in favor of 'origin_coords' and 'grid_spacing'.", DeprecationWarning) if conversion != 1.0: warnings.warn( "The 'conversion' argument is deprecated in favor of 'origin_coords' and 'grid_spacing'.", DeprecationWarning) if unit != 'meters': warnings.warn( "The 'unit' argument is deprecated in favor of 'origin_coords_unit' and 'grid_spacing_unit'.", DeprecationWarning) self.manifold = manifold self.conversion = conversion self.unit = unit self.reference_frame = reference_frame self.origin_coords = origin_coords self.origin_coords_unit = origin_coords_unit self.grid_spacing = grid_spacing self.grid_spacing_unit = grid_spacing_unit
def __init__(self, **kwargs): name, data, electrode, gain = popargs('name', 'data', 'electrode', 'gain', kwargs) unit = 'volts' super(VoltageClampStimulusSeries, self).__init__(name, data, unit, electrode, gain, **kwargs)
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) call_docval_func(super().__init__, kwargs) 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
def __init__(self, **kwargs): test_attr = popargs('test_attr', kwargs) super(MyTestMetaData, self).__init__(**kwargs) self.test_attr = test_attr
def __init__(self, **kwargs): name, description, images = popargs('name', 'description', 'images', kwargs) super(Images, self).__init__(name, **kwargs) self.description = description self.images = images
def __init__(self, **kwargs): genotypes_table = popargs('genotypes_table', kwargs) call_docval_func(super().__init__, kwargs) self.genotypes_table = genotypes_table
def method(self, **kwargs): return popargs('arg1', kwargs)
def __init__(self, **kwargs): path, mode, manager, extensions, load_namespaces, file_obj, comm =\ popargs('path', 'mode', 'manager', 'extensions', 'load_namespaces', 'file', 'comm', kwargs) # root group self.__rgroup = file_obj chunk_store = getattr(file_obj, 'chunk_store', None) if chunk_store is not None: try: filename = getattr(chunk_store.source, 'path', None) if filename is None: filename = chunk_store.source.name except: filename = None if filename is None: filename = f'{type(file_obj.store).__name__}' self.__rgroup.filename = filename file_obj = self.__set_rgroup(file_obj) self.__built = dict() # keep track of each builder for each dataset/group/link for each file self.__read = dict() # keep track of which files have been read. Key is the filename value is the builder self.__file = file_obj if load_namespaces: if manager is not None: warn("loading namespaces from file - ignoring 'manager'") if extensions is not None: warn("loading namespaces from file - ignoring 'extensions' argument") # namespaces are not loaded when creating an NWBZARRHDF5IO object in write mode if 'w' in mode or mode == 'x': raise ValueError("cannot load namespaces from file when writing to it") tm = get_type_map() self.load_namespaces(tm, path, file=file_obj) manager = BuildManager(tm) # XXX: Leaving this here in case we want to revert to this strategy for # loading cached namespaces # ns_catalog = NamespaceCatalog(NWBGroupSpec, NWBDatasetSpec, NWBNamespace) # super(NWBZARRHDF5IO, self).load_namespaces(ns_catalog, path) # tm = TypeMap(ns_catalog) # tm.copy_mappers(get_type_map()) else: if manager is not None and extensions is not None: raise ValueError("'manager' and 'extensions' cannot be specified together") elif extensions is not None: manager = get_manager(extensions=extensions) elif manager is None: manager = get_manager() self.logger = logging.getLogger('%s.%s' % (self.__class__.__module__, self.__class__.__qualname__)) if file_obj is not None: if path is None: path = file_obj.filename elif os.path.abspath(file_obj.filename) != os.path.abspath(path): msg = 'You argued %s as this object\'s path, ' % path msg += 'but supplied a file with filename: %s' % file_obj.filename raise ValueError(msg) elif path is None: TypeError("Must supply either 'path' or 'file' arg to HDF5IO.") if file_obj is None and not os.path.exists(path) and (mode == 'r' or mode == 'r+'): msg = "Unable to open file %s in '%s' mode. File does not exist." % (path, mode) raise UnsupportedOperation(msg) if file_obj is None and os.path.exists(path) and (mode == 'w-' or mode == 'x'): msg = "Unable to open file %s in '%s' mode. File already exists." % (path, mode) raise UnsupportedOperation(msg) if manager is None: manager = BuildManager(TypeMap(NamespaceCatalog())) elif isinstance(manager, TypeMap): manager = BuildManager(manager) # TO DO # self._HDF5IO__comm = comm self._HDF5IO__mode = mode self._HDF5IO__path = path self._HDF5IO__file = file_obj super(_HDF5IO, self).__init__(manager, source=path) self._HDF5IO__ref_queue = deque() # a queue of the references that need to be added self._HDF5IO__dci_queue = deque() # a queue of DataChunkIterators that need to be exhausted
def test_last_arg_not_dict(self): kwargs = {'a': 1, 'b': None} msg = 'Last argument must be a dict' with self.assertRaisesWith(ValueError, msg): popargs(kwargs, 'a')
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
def test_arg_not_found_many_args(self): kwargs = {'a': 1, 'b': None} msg = "Argument not found in dict: 'c'" with self.assertRaisesWith(ValueError, msg): popargs('a', 'c', kwargs)
def __init__(self, **kwargs): call_docval_func(super(ProcessingModule, self).__init__, kwargs) self.description = popargs('description', kwargs) self.data_interfaces = popargs('data_interfaces', kwargs)
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
def __init__(self, **kwargs): self._arg1, self._arg2, self._arg3, self._arg4 = popargs( 'arg1', 'arg2', 'arg3', 'arg4', kwargs)