def write_well_information_to_las( logical_file: LogicalFile.LogicalFile, frame_array: typing.Union[LogPass.FrameArray, None], frame_slice: typing.Union[Slice.Slice, Slice.Sample], ostream: typing.TextIO, ) -> None: """Writes the well information section. Reference: ``[LAS2.0 Las2_Update_Feb2017.pdf Section 5.4 ~W (Well Information)]`` """ # Tuple of (units, value, description) las_map: typing.Dict[str, UnitValueDescription] = extract_well_information_from_origin(logical_file) _add_start_stop_step_to_dictionary(logical_file, frame_array, frame_slice, las_map) eflr: EFLR.ExplicitlyFormattedLogicalRecord for _lrsh_position, eflr in logical_file.eflrs: if eflr.set.type in DLIS_TO_WELL_INFORMATION_LAS_EFLR_MAPPING: bytes_index_map: typing.Dict[bytes, int] = EFLR.reduced_object_map(eflr) for row_key in DLIS_TO_WELL_INFORMATION_LAS_EFLR_MAPPING[eflr.set.type]: if row_key in bytes_index_map: obj = eflr[bytes_index_map[row_key]] # ORIGIN is only key/value so does not have LONG-NAME # PARAMETER does have LONG-NAME units = obj[b'VALUES'].units.decode('ascii') value = stringify.stringify_object_by_type(obj[b'VALUES'].value).strip() descr = stringify.stringify_object_by_type(obj[b'LONG-NAME'].value).strip() # NOTE: Overwriting is possible here. las_map[row_key.decode('ascii')] = UnitValueDescription(units, value, descr) table = [ ['#MNEM.UNIT', 'DATA', 'DESCRIPTION',], ['#----.----', '----', '-----------',], ] for k in WELL_INFORMATION_KEYS: if k in las_map: row = [f'{k:4}.{las_map[k].unit:4}', f'{las_map[k].value}', f': {las_map[k].description}',] else: row = [f'{k:4}.{"":4}', '', ':'] table.append(row) rows = data_table.format_table(table, pad=' ', left_flush=True) ostream.write('~Well Information Section\n') for row in rows: ostream.write(row) ostream.write('\n')
def test_ExplicitlyFormattedLogicalRecord_reduced_object_map(): ld = LogicalData(LOGICAL_BYTES_FROM_STANDARD) eflr = EFLR.ExplicitlyFormattedLogicalRecord(3, ld) result = EFLR.reduced_object_map(eflr) # print(result) assert result == {b'TIME': 0, b'PRESSURE': 1, b'PAD-ARRAY': 2}