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 __init__(self, ld: LogicalData): ld_index = ld.index component_descriptor = ComponentDescriptor(ld.read()) if not component_descriptor.is_set_group: raise ExceptionEFLRSet(f'Component Descriptor does not represent a set but a {component_descriptor.type}.') self.type: bytes = RepCode.IDENT(ld) self.name: bytes = ComponentDescriptor.CHARACTERISTICS_AND_COMPONENT_FORMAT_SET_MAP['N'].global_default if component_descriptor.has_set_N: self.name = RepCode.IDENT(ld) self.logical_data_consumed = ld.index - ld_index
def __init__(self, lr_type: int, ld: File.LogicalData): self.lr_type: int = lr_type # [RP66V1 Section 3.3 Indirectly Formatted Logical Record] self.object_name: RepCode.ObjectName = RepCode.OBNAME(ld) # [RP66V1 Section 5.6.1 Frames] self.frame_number = RepCode.UVARI(ld) self.preamble_length = ld.index self.remain = ld.remain # Frame numbers start from 1 but there are many observed cases of IFLRs that have a 0 frame number and zero # remaining data. Here we only warn if the frame number is zero and the remaining data is non-zero. # We warn rather than raising in the spirit of optimism. if self.frame_number == 0 and self.remain != 0: logger.warning( f'Frame number needs to be >= 1, not {self.frame_number} [RP66V1 Section 5.6.1 Frames] (there is data remaining)' )
def test_Object(eflr_data: DataForEFLR): eflr_data.rewind() template = EFLR.Template() template.read(eflr_data.template) obj = EFLR.Object(eflr_data.object, template) assert obj.name == RepCode.ObjectName(O=0, C=0, I=b'TIME') assert eflr_data.object.remain == 1 # Object byte terminates template
def test_log_pass_write_XML(): log_pass = _log_pass() ostream = io.StringIO() xml_stream = XmlWrite.XmlStream(ostream) iflr_map = { RepCode.ObjectName(O=11, C=0, I=b'0B'): [], } TotalDepth.RP66V1.IndexXML.log_pass_to_XML(log_pass, iflr_map, xml_stream) # print(ostream.getvalue()) expected = """ <LogPass count="1"> <FrameArray C="0" I="0B" O="11" description="" x_axis="DEPT" x_units="0.1 in"> <Channels count="9"> <Channel C="0" I="DEPT" O="11" count="1" dimensions="1" long_name="MWD Tool Measurement Depth" rep_code="2" units="0.1 in"/> <Channel C="0" I="INC" O="11" count="1" dimensions="1" long_name="Inclination" rep_code="2" units="deg"/> <Channel C="0" I="AZI" O="11" count="1" dimensions="1" long_name="Azimuth" rep_code="2" units="deg"/> <Channel C="0" I="MTTVD" O="11" count="1" dimensions="1" long_name="MWD Tool Measurement TVD" rep_code="2" units="m"/> <Channel C="0" I="SECT" O="11" count="1" dimensions="1" long_name="Section" rep_code="2" units="m"/> <Channel C="0" I="RCN" O="11" count="1" dimensions="1" long_name="Rectangular Co-ordinates North" rep_code="2" units="m"/> <Channel C="0" I="RCE" O="11" count="1" dimensions="1" long_name="Rectangular Co-ordinates East" rep_code="2" units="m"/> <Channel C="0" I="DLSEV" O="11" count="1" dimensions="1" long_name="Dog-leg Severity" rep_code="2" units="deg/30m"/> <Channel C="0" I="TLTS" O="11" count="1" dimensions="1" long_name="Tool Temperature Static" rep_code="2" units="degC"/> </Channels> <IFLR count="0"> <FrameNumbers count="0" rle_len="0"/> <LRSH count="0" rle_len="0"/> <Xaxis count="0" rle_len="0"/> </IFLR> </FrameArray> </LogPass>""" assert ostream.getvalue() == expected
def test_logical_index_logical_file_iflr_position_map(): fobj = io.BytesIO(test_data.BASIC_FILE) with LogicalFile.LogicalIndex(fobj) as logical_index: assert len(logical_index) == 1 logical_file = logical_index.logical_files[0] # pprint.pprint(logical_file.iflr_position_map) expected_key = RepCode.ObjectName(O=2, C=0, I=b'50') assert list(logical_file.iflr_position_map.keys()) == [expected_key]
def len_input_bytes(self) -> int: """The number of RP66V1 bytes to read for one frame of this channel.""" try: return self.count * RepCode.rep_code_fixed_length(self.rep_code) except RepCode.ExceptionRepCode as err: raise ExceptionFrameChannel( f'len_input_bytes() on variable length Rep Code {self.rep_code}' ) from err
def test_log_pass_frame_channels_from_RP66V1_file(): log_pass = _log_pass() frame_array = log_pass[FRAME_ARRAY_IDENT] assert len(frame_array) == 9 # print(list(frame_array.keys())) expected = [ RepCode.ObjectName(O=11, C=0, I=b'DEPT'), RepCode.ObjectName(O=11, C=0, I=b'INC'), RepCode.ObjectName(O=11, C=0, I=b'AZI'), RepCode.ObjectName(O=11, C=0, I=b'MTTVD'), RepCode.ObjectName(O=11, C=0, I=b'SECT'), RepCode.ObjectName(O=11, C=0, I=b'RCN'), RepCode.ObjectName(O=11, C=0, I=b'RCE'), RepCode.ObjectName(O=11, C=0, I=b'DLSEV'), RepCode.ObjectName(O=11, C=0, I=b'TLTS'), ] assert list(frame_array.keys()) == expected
def test_iflr_ctor_zero_not_empty(): ld = File.LogicalData(IFLR_ZERO_NOT_EMPTY) iflr = IFLR.IndirectlyFormattedLogicalRecord(1, ld) assert iflr.lr_type == 1 assert iflr.object_name == RepCode.ObjectName(O=11, C=0, I=b'0B') assert iflr.frame_number == 0 assert iflr.preamble_length == 6 assert iflr.remain == 36 assert iflr.remain == ld.remain
def test_iflr_ctor(frame_number, by): ld = File.LogicalData(by) iflr = IFLR.IndirectlyFormattedLogicalRecord(1, ld) assert iflr.lr_type == 1 assert iflr.object_name == RepCode.ObjectName(O=11, C=0, I=b'0B') assert iflr.frame_number == frame_number assert iflr.preamble_length == 6 assert iflr.remain == 36 assert iflr.remain == ld.remain
def test_frame_channel_numpy_indexes(dimensions, frame_number, expected): channel = LogPass.FrameChannel( ident=RepCode.ObjectName(O=11, C=0, I=b'DEPT'), long_name=b'Depth of measurement', rep_code=2, units=b'm', dimensions=dimensions, ) # print(channel.numpy_indexes(frame_number)) assert list(channel.numpy_indexes(frame_number)) == expected
def test_ObjectName_ctor_lt_false(): object_name = RepCode.ObjectName(1, 2, b'') with pytest.raises(TypeError) as err: object_name < 1 assert err.value.args[ 0] == "'<' not supported between instances of 'ObjectName' and 'int'" with pytest.raises(TypeError) as err: 1 < object_name assert err.value.args[ 0] == "'<' not supported between instances of 'int' and 'ObjectName'"
def test_read_iflr_partial(): log_pass = _log_pass() frame_array: LogPass.FrameArray = log_pass[FRAME_ARRAY_IDENT] channels = { RepCode.ObjectName(O=11, C=0, I=b'DEPT'), RepCode.ObjectName(O=11, C=0, I=b'INC'), RepCode.ObjectName(O=11, C=0, I=b'SECT'), } frame_array.init_arrays_partial(len(IFLR_BYTES), channels) for f, by in enumerate(IFLR_BYTES): iflr, logical_data = _iflr_and_logical_data_from_bytes(by) frame_array.read_partial(logical_data, f, channels) assert str(frame_array.channels[0].array) == """[[ 75197.] [154724.] [234606.] [311024.] [381102.] [386839.] [428193.] [447720.]]""" assert str(frame_array.channels[1].array) == """[[0.50002027] [0.50002027] [0.7500017 ] [0.50002027] [0.99998325] [0.9699998 ] [0.9699998 ] [0.69999975]]""" assert str(frame_array.channels[2].array) == """[]""" assert str(frame_array.channels[3].array) == """[]""" assert str(frame_array.channels[4].array) == """[[0.833423] [2.596255] [4.809544] [6.92684 ] [9.256786] [9.268364] [7.632412] [6.981416]]""" assert str(frame_array.channels[5].array) == """[]""" assert str(frame_array.channels[6].array) == """[]""" assert str(frame_array.channels[7].array) == """[]""" assert str(frame_array.channels[8].array) == """[]"""
def frame_channel_from_RP66V1(channel_object: EFLR.Object) -> FrameChannel: """Create a file format agnostic FrameChannel from an EFLR.Object (row) in a `CHANNEL` EFLR.""" return FrameChannel( ident=channel_object.name, long_name=channel_object[b'LONG-NAME'].value[0] if channel_object[b'LONG-NAME'].value is not None else b'', rep_code=channel_object[b'REPRESENTATION-CODE'].value[0], units=channel_object[b'UNITS'].value[0] if channel_object[b'UNITS'].value is not None else b'', dimensions=channel_object[b'DIMENSION'].value, # TODO: Replace this with the np.dtype directly np_dtype=RepCode.numpy_dtype(channel_object[b'REPRESENTATION-CODE'].value[0]) )
def test_eflr_channel_obnames(): ld = File.LogicalData(BYTES_CHANNEL) channels = EFLR.ExplicitlyFormattedLogicalRecord( Types.EFLR_PUBLIC_SET_TYPE_TO_CODE_MAP[b'CHANNEL'], ld) channel_obnames = [obj.name for obj in channels.objects] # print(channel_obnames) assert channel_obnames == [ RepCode.ObjectName(O=11, C=0, I=b'DEPT'), RepCode.ObjectName(O=11, C=0, I=b'INC'), RepCode.ObjectName(O=11, C=0, I=b'AZI'), RepCode.ObjectName(O=11, C=0, I=b'MTTVD'), RepCode.ObjectName(O=11, C=0, I=b'SECT'), RepCode.ObjectName(O=11, C=0, I=b'RCN'), RepCode.ObjectName(O=11, C=0, I=b'RCE'), RepCode.ObjectName(O=11, C=0, I=b'DLSEV'), RepCode.ObjectName(O=11, C=0, I=b'TLTS'), ]
def test_eflr_frame_channels(): ld = File.LogicalData(BYTES_FRAME) frame = EFLR.ExplicitlyFormattedLogicalRecord( Types.EFLR_PUBLIC_SET_TYPE_TO_CODE_MAP[b'FRAME'], ld) obj = frame[0] channels = obj[b'CHANNELS'].value assert len(channels) == 9 assert channels == [ RepCode.ObjectName(O=11, C=0, I=b'DEPT'), RepCode.ObjectName(O=11, C=0, I=b'INC'), RepCode.ObjectName(O=11, C=0, I=b'AZI'), RepCode.ObjectName(O=11, C=0, I=b'MTTVD'), RepCode.ObjectName(O=11, C=0, I=b'SECT'), RepCode.ObjectName(O=11, C=0, I=b'RCN'), RepCode.ObjectName(O=11, C=0, I=b'RCE'), RepCode.ObjectName(O=11, C=0, I=b'DLSEV'), RepCode.ObjectName(O=11, C=0, I=b'TLTS') ]
def test_logical_index_logical_file_iflr_position_map_x_axis_summary(): fobj = io.BytesIO(test_data.BASIC_FILE) with LogicalFile.LogicalIndex(fobj) as logical_index: assert len(logical_index) == 1 logical_file = logical_index.logical_files[0] # pprint.pprint(logical_file.iflr_position_map) expected_key = RepCode.ObjectName(O=2, C=0, I=b'50') assert list(logical_file.iflr_position_map.keys()) == [expected_key] x_axis = logical_file.iflr_position_map[expected_key] assert len(x_axis) == 649 assert x_axis.summary.min == 2889.4 assert x_axis.summary.max == 2954.199999999941 assert x_axis.summary.count == 649
def test_logical_index_logical_file_iflr_position_map_x_axis_summary_spacing(): fobj = io.BytesIO(test_data.BASIC_FILE) with LogicalFile.LogicalIndex(fobj) as logical_index: assert len(logical_index) == 1 logical_file = logical_index.logical_files[0] # pprint.pprint(logical_file.iflr_position_map) expected_key = RepCode.ObjectName(O=2, C=0, I=b'50') assert list(logical_file.iflr_position_map.keys()) == [expected_key] x_axis = logical_file.iflr_position_map[expected_key] assert x_axis.summary.spacing.min == 0.09999999999990905 assert x_axis.summary.spacing.max == 0.09999999999990905 assert x_axis.summary.spacing.mean == 0.09999999999990905 assert x_axis.summary.spacing.median == 0.09999999999990905 assert x_axis.summary.spacing.std == 0.0
def test_logical_index_logical_file_iflr_position_map_x_axis_summary_spacing_counts( ): fobj = io.BytesIO(test_data.BASIC_FILE) with LogicalFile.LogicalIndex(fobj) as logical_index: assert len(logical_index) == 1 logical_file = logical_index.logical_files[0] # pprint.pprint(logical_file.iflr_position_map) expected_key = RepCode.ObjectName(O=2, C=0, I=b'50') assert list(logical_file.iflr_position_map.keys()) == [expected_key] x_axis = logical_file.iflr_position_map[expected_key] assert x_axis.summary.spacing.counts.norm == 648 assert x_axis.summary.spacing.counts.dupe == 0 assert x_axis.summary.spacing.counts.skip == 0 assert x_axis.summary.spacing.counts.back == 0
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 __init__(self, ld: LogicalData, template: Template): component_descriptor = ComponentDescriptor(ld.read()) if not component_descriptor.is_object: raise ExceptionEFLRObject( f'Component Descriptor does not represent a object but a {component_descriptor.type}.' ) self.name: RepCode.ObjectName = RepCode.OBNAME(ld) self.attrs: typing.List[typing.Union[AttributeBase, None]] = [] self.attr_label_map: typing.Dict[bytes, int] = {} index: int = 0 while True: component_descriptor = ComponentDescriptor(ld.read()) if not component_descriptor.is_attribute_group: raise ExceptionEFLRObject( f'Component Descriptor does not represent a attribute but a {component_descriptor.type}.' ) if template[index].component_descriptor.is_invariant_attribute: self.attrs.append(template[index]) elif template[index].component_descriptor.is_absent_attribute: self.attrs.append(None) else: # TODO: Check the attribute label is the same as the template. Reference [RP66V1 Section 4.5] self.attrs.append( Attribute(component_descriptor, ld, template[index])) if ld.remain == 0 or ComponentDescriptor(ld.peek()).is_object: break # next_component_descriptor = ComponentDescriptor(ld.peek()) # if next_component_descriptor.is_object: # break index += 1 while len(self.attrs) < len(template): self.attrs.append(template[len(self.attrs)]) if len(template) != len(self.attrs): raise ExceptionEFLRObject( f'Template specifies {len(template)} attributes but Logical Data has {len(self.attrs)}' ) # Now populate self.attr_label_map for a, attr in enumerate(self.attrs): if attr is None: label = template.attrs[a].label else: label = attr.label # TODO: Assert that the attribute label is the same as the template. Reference [RP66V1 Section 4.5] if label in self.attr_label_map: raise ExceptionEFLRObjectDuplicateLabel( f'Duplicate Attribute label {label}') self.attr_label_map[label] = a
# Data from PRASLIN-1_MWD_SUITE1_RUN1_HDS1-L_SURVEY_0MD-2125MD_EOS.dlis # 9 channels and 83 frames but here are just the frames [1:9] BYTES_EFLR_CHANNEL = b'\xf8\x07CHANNEL\x0259<\tLONG-NAME\x00\x14<\nPROPERTIES\x00\x14<\x13REPRESENTATION-CODE\x00\x0e<\x05UNITS\x00\x14<\tDIMENSION\x00\x0e<\x04AXIS\x00\x17<\rELEMENT-LIMIT\x00\x0e<\x06SOURCE\x00\x18<\tRELOG-NUM\x00\x0ep\x0b\x00\x04DEPT)\x01\x1aMWD Tool Measurement Depth\x00)\x01\x00\x00\x00\x02)\x01\x060.1 in)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x00p\x0b\x00\x03INC)\x01\x0bInclination\x00)\x01\x00\x00\x00\x02)\x01\x03deg)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x00p\x0b\x00\x03AZI)\x01\x07Azimuth\x00)\x01\x00\x00\x00\x02)\x01\x03deg)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x00p\x0b\x00\x05MTTVD)\x01\x18MWD Tool Measurement TVD\x00)\x01\x00\x00\x00\x02)\x01\x01m)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x00p\x0b\x00\x04SECT)\x01\x07Section\x00)\x01\x00\x00\x00\x02)\x01\x01m)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x00p\x0b\x00\x03RCN)\x01\x1eRectangular Co-ordinates North\x00)\x01\x00\x00\x00\x02)\x01\x01m)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x00p\x0b\x00\x03RCE)\x01\x1dRectangular Co-ordinates East\x00)\x01\x00\x00\x00\x02)\x01\x01m)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x00p\x0b\x00\x05DLSEV)\x01\x10Dog-leg Severity\x00)\x01\x00\x00\x00\x02)\x01\x07deg/30m)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x00p\x0b\x00\x04TLTS)\x01\x17Tool Temperature Static\x00)\x01\x00\x00\x00\x02)\x01\x04degC)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x01\x00)\x01\x00\x00\x00\x00' BYTES_EFLR_FRAME = b'\xf8\x05FRAME\x0260<\x0bDESCRIPTION\x00\x14<\x08CHANNELS\x00\x17<\nINDEX-TYPE\x00\x14<\tDIRECTION\x00\x14>\x07SPACING\x00\x02\x060.1 in<\tENCRYPTED\x00\x0e>\tINDEX-MIN\x00\x02\x060.1 in>\tINDEX-MAX\x00\x02\x060.1 inp\x0b\x00\x020B\x00)\t\x0b\x00\x04DEPT\x0b\x00\x03INC\x0b\x00\x03AZI\x0b\x00\x05MTTVD\x0b\x00\x04SECT\x0b\x00\x03RCN\x0b\x00\x03RCE\x0b\x00\x05DLSEV\x0b\x00\x04TLTS)\x01\x0eBOREHOLE-DEPTH\x00+\x01\x060.1 in\x00\x00\x00\x00)\x01\x00\x00\x00\x00+\x01\x060.1 in\x00\x00\x00\x00+\x01\x060.1 inILJ\xb0' # NOTE: Missing first IFLR as is seems to be all nulls. IFLR_BYTES = [ b'\x0b\x00\x020B\x02G\x92\xde\x80?\x00\x01T\x00\x00\x00\x00C>\xffa?U[6?U[6\x00\x00\x00\x00=\xa1\xee\x7f\xc4y\xd0\x00', b'\x0b\x00\x020B\x03H\x17\x19\x00?\x00\x01T\x00\x00\x00\x00C\xc4~\xb4@&)\x0b@&)\x0b\x00\x00\x00\x00\x00\x00\x00\x00\xc4y\xd0\x00', b'\x0b\x00\x020B\x04He\x1b\x80?@\x00\x1d\x00\x00\x00\x00D\x14\xf8,@\x99\xe7\xc9@\x99\xe7\xc9\x00\x00\x00\x00=\x1a\xe4!\xc4y\xd0\x00', b'\x0b\x00\x020B\x05H\x97\xde\x00?\x00\x01T\x00\x00\x00\x00DE}\xd2@\xdd\xa8\xac@\xdd\xa8\xac\x00\x00\x00\x00=\x1a\xe4!\xc4y\xd0\x00', b'\x0b\x00\x020B\x06H\xba\x15\xc0?\x7f\xfe\xe7\x00\x00\x00\x00Dq\xfc\xcfA\x14\x1b\xccA\x14\x1b\xcc\x00\x00\x00\x00=\xac~\r\xc4y\xd0\x00', b'\x0b\x00\x020B\x07H\xbc\xe2\xe0?xQ\xe8CHp\xa4Du\xa1=A\x14K8A\x14K8\xbd0mP@\x7fp7BI\x93&', b'\x0b\x00\x020B\x08H\xd1\x14 ?xQ\xe8CMs3D\x87\xf1k@\xf4<\xb8@\xf4<\xb8\xbf<R\xf8<\xc5"XBa\xabQ', b"\x0b\x00\x020B\tH\xda\x9d\x00?33/CN.\x14D\x8e$s@\xdfg\xc3@\xdfg\xc3\xbf\x86]}>'6FBi\xb3h", ] FRAME_ARRAY_IDENT = RepCode.ObjectName(O=11, C=0, I=b'0B') @pytest.mark.parametrize( 'by', ( BYTES_EFLR_CHANNEL, BYTES_EFLR_FRAME, ) ) def test_logical_data_constructs(by): File.LogicalData(by) @pytest.mark.parametrize( 'lr_type, by', ( (3, BYTES_EFLR_CHANNEL),
def test_log_pass_frame_channel_numpy_indexes(): log_pass = _log_pass() frame_array = log_pass[FRAME_ARRAY_IDENT] channel = frame_array[RepCode.ObjectName(O=11, C=0, I=b'DEPT')] assert list(channel.numpy_indexes(0)) == [(0, 0)]
def test_numpy_dtype(rc, expected): assert RepCode.numpy_dtype(rc) == expected
def seek(self, ld: LogicalData) -> None: """Increments the logical data without reading any values into the array.""" if len(self.array) != 0: raise ExceptionFrameChannel('seek() on empty array. This seems like a logical error.') ld.seek(RepCode.rep_code_fixed_length(self.rep_code) * self.count)
def test_example_iflr_process(): log_pass: LogPass.LogPass = _create_log_pass() # ObjectName(O=11, C=0, I=b'0B') frame_array: LogPass.FrameArray = log_pass[RepCode.ObjectName( 11, 0, b'0B')] frame_array.init_arrays(len(BYTES_IFLR)) # print() for frame_number, by in enumerate(BYTES_IFLR): ld = File.LogicalData(by) _iflr = IFLR.IndirectlyFormattedLogicalRecord(0, ld) # frame_array.read_x_axis(ld, frame_number=0) frame_array.read(ld, frame_number=frame_number) # print(frame_array) # print() expected = [ # X axis np.array([ [0.], [75197.], [154724.], [234606.], [311024.], [381102.], [386839.], [428193.], [447720.], [466339.], [489547.], [500559.], [523772.], [538638.], [542417.], [550409.], ]), np.array([ [0.], [0.50002027], [0.50002027], [0.7500017], [0.50002027], [0.99998325], [0.9699998], [0.9699998], [0.69999975], [1.0600001], [0.9699998], [0.8800001], [0.78999996], [1.7599998], [2.2000003], [2.9], ], ), np.array([ [0.], [0.], [0.], [0.], [0.], [0.], [200.44], [205.45], [206.18], [208.69], [202.7], [200.93], [255.77002], [243.87], [241.15], [240.7], ]), np.array([ [0.], [190.99757], [392.98987], [595.8777], [789.96594], [967.95013], [982.51935], [1087.5443], [1137.139], [1184.4233], [1243.3641], [1271.3306], [1330.2852], [1368.0354], [1377.6296], [1397.9094], ]), np.array([ [0.], [0.833423], [2.596255], [4.809544], [6.92684], [9.256786], [9.268364], [7.632412], [6.981416], [6.338459], [5.399805], [4.980779], [4.457969], [4.138596], [3.98476], [3.54544], ]), np.array([ [0.], [0.833423], [2.596255], [4.809544], [6.92684], [9.256786], [9.268364], [7.632412], [6.981416], [6.338459], [5.399805], [4.980779], [4.457969], [4.138596], [3.98476], [3.54544], ]), np.array([ [0.], [0.], [0.], [0.], [0.], [0.], [-0.043073], [-0.735641], [-1.049728], [-1.387169], [-1.841496], [-2.009587], [-2.565323], [-3.338264], [-3.632012], [-4.421124], ]), np.array([ [-9.9925000e+02], [7.9068176e-02], [0.0000000e+00], [3.7815217e-02], [3.7815217e-02], [8.4224798e-02], [3.9912241e+00], [2.4064228e-02], [1.6329297e-01], [2.3032904e-01], [7.0473805e-02], [1.0141353e-01], [3.9362201e-01], [7.9411954e-01], [1.4060384e+00], [1.0347618e+00], ]), np.array([ [-999.25], [-999.25], [-999.25], [-999.25], [-999.25], [-999.25], [50.3937], [56.4173], [58.4252], [58.4252], [62.4409], [62.4409], [62.4409], [62.4409], [62.4409], [58.4252], ]), ] for c, channel in enumerate(frame_array.channels): # print(channel.array) # np.testing.assert_array_almost_equal(channel.array, expected[c]) assert str(channel.array) == str(expected[c])
def test_ExplicitlyFormattedLogicalRecord_objects(ld): ld.rewind() eflr = EFLR.ExplicitlyFormattedLogicalRecord(3, ld) assert len(eflr.template) == 5 assert len(eflr.objects) == 3 ## Object #1 obj_index: int = 0 assert eflr.objects[0].name == RepCode.ObjectName(0, 0, b'TIME') assert len(eflr.objects[0].attrs) == len(eflr.template) # Attribute 0 attr_index = 0 assert eflr.objects[obj_index].attrs[attr_index].label == b'LONG-NAME' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['OBNAME'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [ RepCode.ObjectName(0, 0, b'1') ] # Attribute 1 attr_index = 1 assert eflr.objects[obj_index].attrs[attr_index].label == b'ELEMENT-LIMIT' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['UVARI'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [1] # Attribute 2 attr_index = 2 assert eflr.objects[obj_index].attrs[ attr_index].label == b'REPRESENTATION-CODE' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['USHORT'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [ RepCode.REP_CODE_STR_TO_INT['FSINGL'] ] # Attribute 3 attr_index = 3 assert eflr.objects[obj_index].attrs[attr_index].label == b'UNITS' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['IDENT'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [b'S'] # Attribute 4 attr_index = 4 assert eflr.objects[obj_index].attrs[attr_index].label == b'DIMENSION' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['UVARI'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [1] ## Object #2 obj_index: int = 1 assert eflr.objects[0].name == RepCode.ObjectName(0, 0, b'TIME') assert len(eflr.objects[0].attrs) == len(eflr.template) # Attribute 0 attr_index = 0 assert eflr.objects[obj_index].attrs[attr_index].label == b'LONG-NAME' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['OBNAME'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [ RepCode.ObjectName(0, 0, b'2') ] # Attribute 1 attr_index = 1 assert eflr.objects[obj_index].attrs[attr_index].label == b'ELEMENT-LIMIT' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['UVARI'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [1] # Attribute 2 attr_index = 2 assert eflr.objects[obj_index].attrs[ attr_index].label == b'REPRESENTATION-CODE' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['USHORT'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [ RepCode.REP_CODE_STR_TO_INT['FDOUBL'] ] # Attribute 3 attr_index = 3 assert eflr.objects[obj_index].attrs[attr_index].label == b'UNITS' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['IDENT'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [b'PSI'] # Attribute 4 attr_index = 4 assert eflr.objects[obj_index].attrs[attr_index].label == b'DIMENSION' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['UVARI'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [1] ## Object #3 obj_index: int = 2 assert eflr.objects[0].name == RepCode.ObjectName(0, 0, b'TIME') assert len(eflr.objects[0].attrs) == len(eflr.template) # Attribute 0 attr_index = 0 assert eflr.objects[obj_index].attrs[attr_index].label == b'LONG-NAME' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['OBNAME'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [ RepCode.ObjectName(0, 0, b'3') ] # Attribute 1 attr_index = 1 assert eflr.objects[obj_index].attrs[attr_index].label == b'ELEMENT-LIMIT' assert eflr.objects[obj_index].attrs[attr_index].count == 2 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['UVARI'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [8, 20] # Attribute 2 attr_index = 2 assert eflr.objects[obj_index].attrs[ attr_index].label == b'REPRESENTATION-CODE' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['USHORT'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' # See above for: NOTE: [RP66V1 Error] assert eflr.objects[obj_index].attrs[attr_index].value == [ RepCode.REP_CODE_STR_TO_INT['SNORM'] ] # Attribute 3 attr_index = 3 assert eflr.objects[obj_index].attrs[attr_index].label == b'UNITS' assert eflr.objects[obj_index].attrs[attr_index].count == 1 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['IDENT'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value is None # Attribute 4 attr_index = 4 assert eflr.objects[obj_index].attrs[attr_index].label == b'DIMENSION' assert eflr.objects[obj_index].attrs[attr_index].count == 2 assert eflr.objects[obj_index].attrs[ attr_index].rep_code == RepCode.REP_CODE_STR_TO_INT['UVARI'] assert eflr.objects[obj_index].attrs[attr_index].units == b'' assert eflr.objects[obj_index].attrs[attr_index].value == [8, 10]
def test_code_read(rc, ld, expected): assert RepCode.code_read(rc, ld) == expected
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_numpy_dtype_raises(): with pytest.raises(RepCode.ExceptionRepCode) as err: RepCode.numpy_dtype(0) assert err.value.args[0] == 'Unsupported Representation code 0'