Add action for downloading and parsing well log from OSDU Wellbore DDMS.

This commit is contained in:
Kristian Bendiksen
2024-05-27 11:24:00 +02:00
parent 5be47b3d2c
commit 23d716754e
20 changed files with 1094 additions and 46 deletions

View File

@@ -98,6 +98,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RifPolygonReader.h
${CMAKE_CURRENT_LIST_DIR}/RifOsduWellPathReader.h
${CMAKE_CURRENT_LIST_DIR}/RifAsciiDataParseOptions.h
${CMAKE_CURRENT_LIST_DIR}/RifByteArrayArrowRandomAccessFile.h
)
set(SOURCE_GROUP_SOURCE_FILES
@@ -194,6 +195,8 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCalculationExporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifPolygonReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifOsduWellPathReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifOsduWellLogReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifByteArrayArrowRandomAccessFile.cpp
)
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@@ -0,0 +1,107 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RifByteArrayArrowRandomAccessFile.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifByteArrayArrowRandomAccessFile::RifByteArrayArrowRandomAccessFile( const QByteArray& data )
: m_data( data )
, m_position( 0 )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
arrow::Result<int64_t> RifByteArrayArrowRandomAccessFile::ReadAt( int64_t position, int64_t nbytes, void* out )
{
if ( nbytes > 0 )
{
memcpy( out, m_data.data() + position, static_cast<size_t>( nbytes ) );
m_position += nbytes;
}
return nbytes;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
arrow::Result<std::shared_ptr<arrow::Buffer>> RifByteArrayArrowRandomAccessFile::ReadAt( int64_t position, int64_t nbytes )
{
return std::make_shared<arrow::Buffer>( (const uint8_t*)m_data.data() + position, nbytes );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
arrow::Result<int64_t> RifByteArrayArrowRandomAccessFile::Read( int64_t nbytes, void* out )
{
return ReadAt( m_position, nbytes, out );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
arrow::Result<std::shared_ptr<arrow::Buffer>> RifByteArrayArrowRandomAccessFile::Read( int64_t nbytes )
{
return ReadAt( m_position, nbytes );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
arrow::Result<int64_t> RifByteArrayArrowRandomAccessFile::GetSize()
{
return m_data.size();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
arrow::Result<int64_t> RifByteArrayArrowRandomAccessFile::Tell() const
{
return m_position;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
arrow::Status RifByteArrayArrowRandomAccessFile::Seek( int64_t position )
{
m_position = position;
return arrow::Status::OK();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
arrow::Status RifByteArrayArrowRandomAccessFile::Close()
{
m_closed = true;
return arrow::Status::OK();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifByteArrayArrowRandomAccessFile::closed() const
{
return m_closed;
}

View File

@@ -0,0 +1,61 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <arrow/csv/api.h>
#include <arrow/io/api.h>
#include <arrow/scalar.h>
#include <arrow/util/cancel.h>
#include <parquet/arrow/reader.h>
#include <QByteArray>
#include <memory>
//==================================================================================================
///
//==================================================================================================
class RifByteArrayArrowRandomAccessFile : public arrow::io::RandomAccessFile
{
public:
RifByteArrayArrowRandomAccessFile( const QByteArray& data );
arrow::Result<int64_t> ReadAt( int64_t position, int64_t nbytes, void* out ) override;
arrow::Result<std::shared_ptr<arrow::Buffer>> ReadAt( int64_t position, int64_t nbytes ) override;
arrow::Result<int64_t> Read( int64_t nbytes, void* out ) override;
arrow::Result<std::shared_ptr<arrow::Buffer>> Read( int64_t nbytes ) override;
arrow::Result<int64_t> GetSize() override;
arrow::Result<int64_t> Tell() const override;
arrow::Status Seek( int64_t position ) override;
arrow::Status Close() override;
bool closed() const override;
private:
const QByteArray& m_data;
bool m_closed;
int64_t m_position;
};

View File

@@ -0,0 +1,105 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RifOsduWellLogReader.h"
#include "RifByteArrayArrowRandomAccessFile.h"
#include "cafAssert.h"
#include <iostream>
#include <vector>
#include <arrow/array/array_primitive.h>
#include <arrow/csv/api.h>
#include <arrow/io/api.h>
#include <arrow/scalar.h>
#include <arrow/util/cancel.h>
#include <parquet/arrow/reader.h>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<cvf::ref<RigOsduWellLogData>, QString> RifOsduWellLogReader::readWellLogData( const QByteArray& contents )
{
// Function to convert an entire column to std::vector<double>
auto convertColumnToVector = []( const std::shared_ptr<arrow::ChunkedArray>& column ) -> std::vector<double>
{
auto convertChunkToVector = []( const std::shared_ptr<arrow::Array>& array ) -> std::vector<double>
{
std::vector<double> result;
auto double_array = std::static_pointer_cast<arrow::DoubleArray>( 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<double> result;
// Iterate over each chunk in the column
for ( int i = 0; i < column->num_chunks(); ++i )
{
std::shared_ptr<arrow::Array> chunk = column->chunk( i );
std::vector<double> 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<arrow::io::RandomAccessFile> input = std::make_shared<RifByteArrayArrowRandomAccessFile>( contents );
// Open Parquet file reader
std::unique_ptr<parquet::arrow::FileReader> 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<arrow::Table> table;
if ( !arrow_reader->ReadTable( &table ).ok() )
{
return { nullptr, "Unable to read parquet table." };
}
auto logData = cvf::make_ref<RigOsduWellLogData>();
for ( std::string columnName : table->ColumnNames() )
{
std::shared_ptr<arrow::ChunkedArray> column = table->GetColumnByName( columnName );
if ( column->type()->id() == arrow::Type::DOUBLE )
{
std::vector<double> columnVector = convertColumnToVector( column );
logData->setValues( QString::fromStdString( columnName ), columnVector );
}
}
logData->finalizeData();
return { logData, "" };
}

View File

@@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RigOsduWellLogData.h"
#include "cvfObject.h"
#include <QByteArray>
#include <QString>
//==================================================================================================
//
//
//==================================================================================================
class RifOsduWellLogReader
{
public:
static std::pair<cvf::ref<RigOsduWellLogData>, QString> readWellLogData( const QByteArray& contents );
};