///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2024 Equinor ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RifOsduWellPathReader.h" #include #include #include #include #include #include #include "RiaLogging.h" #include "RiaTextStringTools.h" #include "RifAsciiDataParseOptions.h" #include "RifByteArrayArrowRandomAccessFile.h" #include "RifCsvUserDataParser.h" #include "RigWellPath.h" #include "cvfObject.h" #include "cvfVector3.h" #include #include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::pair, QString> RifOsduWellPathReader::parseCsv( const QString& content ) { QString errorMessage; RifCsvUserDataPastedTextParser parser( content, &errorMessage ); RifAsciiDataParseOptions parseOptions; parseOptions.cellSeparator = ","; parseOptions.decimalSeparator = "."; std::vector>> readValues; if ( parser.parse( parseOptions ) ) { for ( auto s : parser.tableData().columnInfos() ) { if ( s.dataType != Column::NUMERIC ) continue; QString columnName = QString::fromStdString( s.columnName() ); bool isNumber = false; auto value = columnName.toDouble( &isNumber ); std::vector values = s.values; if ( isNumber ) { values.insert( values.begin(), value ); } readValues.push_back( { columnName, values } ); } } const int MD_INDEX = 0; const int TVD_INDEX = 1; const int X_INDEX = 4; const int Y_INDEX = 5; if ( readValues.size() == 10 ) { const size_t firstSize = readValues[MD_INDEX].second.size(); if ( ( firstSize == readValues[TVD_INDEX].second.size() ) && ( firstSize == readValues[X_INDEX].second.size() ) && ( firstSize == readValues[Y_INDEX].second.size() ) ) { std::vector wellPathPoints; std::vector measuredDepths; for ( size_t i = 0; i < firstSize; i++ ) { cvf::Vec3d point( readValues[X_INDEX].second[i], readValues[Y_INDEX].second[i], -readValues[TVD_INDEX].second[i] ); double md = readValues[MD_INDEX].second[i]; wellPathPoints.push_back( point ); measuredDepths.push_back( md ); } return { new RigWellPath( wellPathPoints, measuredDepths ), "" }; } } return { nullptr, "Oh no!" }; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::pair, QString> RifOsduWellPathReader::readWellPathData( const QByteArray& content ) { // Function to convert an entire column to std::vector auto convertColumnToVector = []( const std::shared_ptr& column ) -> std::vector { auto convertChunkToVector = []( const std::shared_ptr& array ) -> std::vector { std::vector result; auto double_array = std::static_pointer_cast( array ); result.resize( double_array->length() ); for ( int64_t i = 0; i < double_array->length(); ++i ) { result[i] = double_array->Value( i ); } return result; }; CAF_ASSERT( column->type()->id() == arrow::Type::DOUBLE ); std::vector result; // Iterate over each chunk in the column for ( int i = 0; i < column->num_chunks(); ++i ) { std::shared_ptr chunk = column->chunk( i ); std::vector chunk_vector = convertChunkToVector( chunk ); result.insert( result.end(), chunk_vector.begin(), chunk_vector.end() ); } return result; }; arrow::MemoryPool* pool = arrow::default_memory_pool(); std::shared_ptr input = std::make_shared( content ); // Open Parquet file reader std::unique_ptr arrow_reader; if ( !parquet::arrow::OpenFile( input, pool, &arrow_reader ).ok() ) { return { nullptr, "Unable to read parquet data." }; } // Read entire file as a single Arrow table std::shared_ptr table; if ( !arrow_reader->ReadTable( &table ).ok() ) { return { nullptr, "Unable to read parquet table." }; } const std::string MD = "MD"; const std::string TVD = "TVD"; const std::string X = "X"; const std::string Y = "Y"; std::vector columnNames = { MD, TVD, X, Y }; std::map> readValues; for ( std::string columnName : columnNames ) { std::shared_ptr column = table->GetColumnByName( columnName ); if ( column->type()->id() == arrow::Type::DOUBLE ) { std::vector columnVector = convertColumnToVector( column ); RiaLogging::debug( QString( "Column name: %1. Size: %2" ).arg( QString::fromStdString( columnName ) ).arg( columnVector.size() ) ); readValues[columnName] = columnVector; } } const size_t firstSize = readValues[MD].size(); if ( ( firstSize == readValues[TVD].size() ) && ( firstSize == readValues[X].size() ) && ( firstSize == readValues[Y].size() ) ) { std::vector wellPathPoints; std::vector measuredDepths; for ( size_t i = 0; i < firstSize; i++ ) { cvf::Vec3d point( readValues[X][i], readValues[Y][i], -readValues[TVD][i] ); double md = readValues[MD][i]; wellPathPoints.push_back( point ); measuredDepths.push_back( md ); } return { cvf::make_ref( wellPathPoints, measuredDepths ), "" }; } return { nullptr, "" }; }