def __init__(self, component_descriptor: ComponentDescriptor, ld: LogicalData, template_attribute: TemplateAttribute, ): super().__init__(component_descriptor) if self.component_descriptor.has_attribute_L: self.label = RepCode.IDENT(ld) else: self.label = template_attribute.label if self.component_descriptor.has_attribute_C: self.count = RepCode.UVARI(ld) else: self.count = template_attribute.count if self.component_descriptor.has_attribute_R: self.rep_code = RepCode.USHORT(ld) else: self.rep_code = template_attribute.rep_code if self.component_descriptor.has_attribute_U: self.units = RepCode.UNITS(ld) else: self.units = template_attribute.units if self.component_descriptor.has_attribute_V: self.value = [RepCode.code_read(self.rep_code, ld) for _i in range(self.count)] else: self.value = template_attribute.value
def read(self, ld: LogicalData, frame_number: int) -> None: """Reads the Logical Data into the numpy frame at the specified frame number. This is currently RP66V1 specific. In future designs this can be sub-classed by format (LAS, LIS, RP66V1 etc.) """ # if len(self.array) == 0: # raise ExceptionFrameChannel(f'FrameChannelDLIS.read() array is not initialised.') if frame_number >= len(self.array): raise ExceptionFrameChannel( f'FrameChannelDLIS.read() frame number {frame_number} is > than array size {len(self.array)}.' ) for dim in self.numpy_indexes(frame_number): # dim is a tuple of length self.rank + 1 value = RepCode.code_read(self.rep_code, ld) self.array[dim] = value
def test_code_read_raises(): with pytest.raises(RepCode.ExceptionRepCode) as err: RepCode.code_read(0, None) assert err.value.args[0] == 'Unsupported Representation code 0'
def test_code_read(rc, ld, expected): assert RepCode.code_read(rc, ld) == expected