# Copyright 2018 United Kingdom Research and Innovation# Copyright 2018 The University of Manchester## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.## Authors:# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txtimportnumpyfrom.data_containerimportDataContainer
[docs]classVectorData(DataContainer):'''DataContainer to contain 1D array'''@propertydefgeometry(self):returnself._geometry@geometry.setterdefgeometry(self,val):self._geometry=val@propertydefdimension_labels(self):ifhasattr(self,'geometry'):returnself.geometry.dimension_labelsreturnself._dimension_labels@dimension_labels.setterdefdimension_labels(self,val):ifhasattr(self,'geometry'):self.geometry.dimension_labels=valself._dimension_labels=valdef__init__(self,array=None,**kwargs):self.geometry=kwargs.get('geometry',None)dtype=kwargs.get('dtype',numpy.float32)ifself.geometryisNone:ifarrayisNone:raiseValueError('Please specify either a geometry or an array')else:from.vector_geometryimportVectorGeometryiflen(array.shape)>1:raiseValueError('Incompatible size: expected 1D got {}'.format(array.shape))out=arrayself.geometry=VectorGeometry(array.shape[0],**kwargs)self.length=self.geometry.lengthelse:self.length=self.geometry.lengthifarrayisNone:out=numpy.zeros((self.length,),dtype=dtype)else:ifself.length==array.shape[0]:out=arrayelse:raiseValueError('Incompatible size: expecting {} got {}'.format((self.length,),array.shape))deep_copy=True# need to pass the geometry, othewise Nonesuper(VectorData,self).__init__(out,deep_copy,self.geometry.dimension_labels,geometry=self.geometry)