Python: Update well log import API to accept measured depth and multiple channels

- Updated Python API to accept measured_depth list and channel_data dictionary
- Modified C++ GRPC implementation to handle CSV-formatted channel mappings
- Replaced single values parameter with dictionary of channels
- Added comprehensive validation for all input parameters
- Updated parameter name from channel_keys_json to channel_keys_csv
- Enhanced tests to cover 16 different scenarios including edge cases
- Updated example to demonstrate new dictionary-based API functionality
This commit is contained in:
Kristian Bendiksen committed 2025-09-04 09:04:56 +02:00
1 parent 8089739add
commit 160cb71168
16 files changed
+1211 -126

No files matched your search

@@ -34,6 +34,8 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimWellLogFileDataLoader.h
${CMAKE_CURRENT_LIST_DIR}/RimOsduWellLogDataLoader.h
${CMAKE_CURRENT_LIST_DIR}/RimImportedWellLog.h
${CMAKE_CURRENT_LIST_DIR}/RimImportedWellLogData.h
${CMAKE_CURRENT_LIST_DIR}/RimWellLogChannelData.h
)
set(SOURCE_GROUP_SOURCE_FILES
@@ -74,6 +76,8 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimWellLogFileDataLoader.cpp
${CMAKE_CURRENT_LIST_DIR}/RimOsduWellLogDataLoader.cpp
${CMAKE_CURRENT_LIST_DIR}/RimImportedWellLog.cpp
${CMAKE_CURRENT_LIST_DIR}/RimImportedWellLogData.cpp
${CMAKE_CURRENT_LIST_DIR}/RimWellLogChannelData.cpp
)
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
@@ -18,10 +18,12 @@
#include "RimImportedWellLog.h"
#include "Well/RigImportedWellLogData.h"
#include "RimImportedWellLogData.h"
#include "RimWellLogChannel.h"
#include "RimWellPath.h"
#include "Well/RigImportedWellLogData.h"
#include "RiaFieldHandleTools.h"
#include "cafPdmFieldScriptingCapability.h"
@@ -41,6 +43,9 @@ RimImportedWellLog::RimImportedWellLog()
CAF_PDM_InitScriptableField( &m_name, "Name", QString(), "Name" );
m_name.uiCapability()->setUiReadOnly( true );
CAF_PDM_InitFieldNoDefault( &m_wellLogData, "WellLogData", "Well Log Data" );
m_wellLogData.uiCapability()->setUiTreeChildrenHidden( true );
setDeletable( true );
}
@@ -65,8 +70,8 @@ QString RimImportedWellLog::name() const
//--------------------------------------------------------------------------------------------------
QString RimImportedWellLog::wellName() const
{
RimWellPath* wellPath = firstAncestorOrThisOfType<RimWellPath>();
if ( wellPath )
if ( RimWellPath* wellPath = firstAncestorOrThisOfType<RimWellPath>() )
{
return wellPath->name();
}
@@ -78,15 +83,46 @@ QString RimImportedWellLog::wellName() const
//--------------------------------------------------------------------------------------------------
RigWellLogData* RimImportedWellLog::wellLogData()
{
return m_wellLogData.p();
return m_cachedRigData.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimImportedWellLog::setWellLogData( RigImportedWellLogData* wellLogData )
void RimImportedWellLog::setWellLogData( RimImportedWellLogData* wellLogData )
{
m_wellLogData = wellLogData;
// Clear cached Rig data when setting new PDM data
m_cachedRigData = nullptr;
if ( wellLogData )
{
// Create temporary Rig data to update channels
m_cachedRigData = wellLogData->createRigData();
updateChannelsFromWellLogData( m_cachedRigData.p() );
}
else
{
m_wellLogChannels.deleteChildren();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimImportedWellLog::updateChannelsFromWellLogData( RigImportedWellLogData* wellLogData )
{
m_wellLogChannels.deleteChildren();
if ( !wellLogData ) return;
QStringList wellLogNames = wellLogData->wellLogChannelNames();
for ( int logIdx = 0; logIdx < wellLogNames.size(); logIdx++ )
{
RimWellLogChannel* wellLog = new RimWellLogChannel();
wellLog->setName( wellLogNames[logIdx] );
m_wellLogChannels.push_back( wellLog );
}
}
//--------------------------------------------------------------------------------------------------
@@ -97,10 +133,11 @@ std::vector<std::pair<double, double>>
{
if ( unitString ) *unitString = QString();
if ( !m_wellLogData.notNull() ) return {};
RigWellLogData* wld = wellLogData();
if ( !wld ) return {};
std::vector<double> depths = m_wellLogData->depthValues();
std::vector<double> values = m_wellLogData->values( channelName );
std::vector<double> depths = wld->depthValues();
std::vector<double> values = wld->values( channelName );
std::vector<std::pair<double, double>> depthValuePairs;
if ( depths.size() == values.size() )
@@ -114,10 +151,23 @@ std::vector<std::pair<double, double>>
return depthValuePairs;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimImportedWellLog::initAfterRead()
{
// Create cached Rig data from PDM data when loading from project file
if ( m_wellLogData() && !m_cachedRigData.notNull() )
{
m_cachedRigData = m_wellLogData()->createRigData();
updateChannelsFromWellLogData( m_cachedRigData.p() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimImportedWellLog::userDescriptionField()
{
return &m_name;
}
}
@@ -20,12 +20,14 @@
#include "RimWellLog.h"
#include "cafPdmChildField.h"
#include "cafPdmField.h"
#include "cvfObject.h"
#include <QString>
class RigImportedWellLogData;
class RimImportedWellLogData;
class RimWellPath;
//==================================================================================================
@@ -44,15 +46,20 @@ public:
QString wellName() const override;
RigWellLogData* wellLogData() override;
void setWellLogData( RigImportedWellLogData* wellLogData );
void setWellLogData( RimImportedWellLogData* wellLogData );
std::vector<std::pair<double, double>>
findMdAndChannelValuesForWellPath( const RimWellPath& wellPath, const QString& channelName, QString* unitString = nullptr ) override;
private:
void initAfterRead() override;
caf::PdmFieldHandle* userDescriptionField() override;
void updateChannelsFromWellLogData( RigImportedWellLogData* wellLogData );
private:
cvf::ref<RigImportedWellLogData> m_wellLogData;
caf::PdmField<QString> m_name;
};
// PDM-based data storage for project file persistence
caf::PdmChildField<RimImportedWellLogData*> m_wellLogData;
caf::PdmField<QString> m_name;
cvf::ref<RigImportedWellLogData> m_cachedRigData;
};
@@ -0,0 +1,181 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 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 "RimImportedWellLogData.h"
#include "RimWellLogChannelData.h"
#include "Well/RigImportedWellLogData.h"
CAF_PDM_SOURCE_INIT( RimImportedWellLogData, "ImportedWellLogData" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimImportedWellLogData::RimImportedWellLogData()
{
CAF_PDM_InitObject( "Imported Well Log Data", "", "", "Imported Well Log Data" );
CAF_PDM_InitField( &m_depthValues, "DepthValues", {}, "Depth Values" );
CAF_PDM_InitField( &m_tvdMslValues, "TvdMslValues", {}, "TVD MSL Values" );
CAF_PDM_InitField( &m_tvdRkbValues, "TvdRkbValues", {}, "TVD RKB Values" );
CAF_PDM_InitFieldNoDefault( &m_channelDataObjects, "ChannelDataObjects", "Channel Data Objects" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimImportedWellLogData::setDepthValues( const std::vector<double>& depths )
{
m_depthValues = depths;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimImportedWellLogData::setTvdMslValues( const std::vector<double>& tvdMsl )
{
m_tvdMslValues = tvdMsl;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimImportedWellLogData::setTvdRkbValues( const std::vector<double>& tvdRkb )
{
m_tvdRkbValues = tvdRkb;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimImportedWellLogData::setChannelData( const QString& name, const std::vector<double>& values )
{
// Check if channel already exists
for ( RimWellLogChannelData* channelData : m_channelDataObjects )
{
if ( channelData->name() == name )
{
channelData->setValues( values );
return;
}
}
// Create new channel data object
RimWellLogChannelData* channelData = new RimWellLogChannelData();
channelData->setName( name );
channelData->setValues( values );
m_channelDataObjects.push_back( channelData );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double> RimImportedWellLogData::depthValues() const
{
return m_depthValues();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double> RimImportedWellLogData::tvdMslValues() const
{
return m_tvdMslValues();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double> RimImportedWellLogData::tvdRkbValues() const
{
return m_tvdRkbValues();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QString> RimImportedWellLogData::channelNames() const
{
std::vector<QString> names;
for ( const RimWellLogChannelData* channelData : m_channelDataObjects )
{
names.push_back( channelData->name() );
}
return names;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double> RimImportedWellLogData::channelValues( const QString& name ) const
{
for ( const RimWellLogChannelData* channelData : m_channelDataObjects )
{
if ( channelData->name() == name )
{
return channelData->values();
}
}
return {};
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimImportedWellLogData::hasTvdMslValues() const
{
return !m_tvdMslValues().empty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimImportedWellLogData::hasTvdRkbValues() const
{
return !m_tvdRkbValues().empty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigImportedWellLogData> RimImportedWellLogData::createRigData() const
{
cvf::ref<RigImportedWellLogData> rigData = new RigImportedWellLogData();
// Set depth values
rigData->setDepthValues( m_depthValues() );
// Set TVD values if present
if ( hasTvdMslValues() )
{
rigData->setTvdMslValues( m_tvdMslValues() );
}
if ( hasTvdRkbValues() )
{
rigData->setTvdRkbValues( m_tvdRkbValues() );
}
// Set channel data
for ( const RimWellLogChannelData* channelData : m_channelDataObjects )
{
rigData->setChannelData( channelData->name(), channelData->values() );
}
return rigData;
}
@@ -0,0 +1,66 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 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 "cafPdmChildArrayField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cvfObject.h"
#include <QString>
#include <vector>
class RigImportedWellLogData;
class RimWellLogChannelData;
//==================================================================================================
/// PDM class for storing imported well log data that can be persisted to project files
//==================================================================================================
class RimImportedWellLogData : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimImportedWellLogData();
// Setters for data
void setDepthValues( const std::vector<double>& depths );
void setTvdMslValues( const std::vector<double>& tvdMsl );
void setTvdRkbValues( const std::vector<double>& tvdRkb );
void setChannelData( const QString& name, const std::vector<double>& values );
// Getters for data
std::vector<double> depthValues() const;
std::vector<double> tvdMslValues() const;
std::vector<double> tvdRkbValues() const;
std::vector<QString> channelNames() const;
std::vector<double> channelValues( const QString& name ) const;
bool hasTvdMslValues() const;
bool hasTvdRkbValues() const;
// Method to produce RigImportedWellLogData from PDM data
cvf::ref<RigImportedWellLogData> createRigData() const;
private:
caf::PdmField<std::vector<double>> m_depthValues;
caf::PdmField<std::vector<double>> m_tvdMslValues;
caf::PdmField<std::vector<double>> m_tvdRkbValues;
caf::PdmChildArrayField<RimWellLogChannelData*> m_channelDataObjects;
};
@@ -0,0 +1,64 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 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 "RimWellLogChannelData.h"
CAF_PDM_SOURCE_INIT( RimWellLogChannelData, "WellLogChannelData" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogChannelData::RimWellLogChannelData()
{
CAF_PDM_InitObject( "Well Log Channel Data", "", "", "Well Log Channel Data" );
CAF_PDM_InitField( &m_name, "Name", QString(), "Name" );
CAF_PDM_InitField( &m_values, "Values", {}, "Values" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogChannelData::setName( const QString& name )
{
m_name = name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimWellLogChannelData::name() const
{
return m_name();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogChannelData::setValues( const std::vector<double>& values )
{
m_values = values;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double> RimWellLogChannelData::values() const
{
return m_values();
}
@@ -0,0 +1,46 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 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 "cafPdmField.h"
#include "cafPdmObject.h"
#include <QString>
#include <vector>
//==================================================================================================
/// PDM class for storing individual channel data (name and values) for well logs
//==================================================================================================
class RimWellLogChannelData : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimWellLogChannelData();
void setName( const QString& name );
QString name() const;
void setValues( const std::vector<double>& values );
std::vector<double> values() const;
private:
caf::PdmField<QString> m_name;
caf::PdmField<std::vector<double>> m_values;
};