Skip to content

Commit

Permalink
Add parser for OSDU-style well trajectory csv.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed May 10, 2024
1 parent bcb60c4 commit 74c04c9
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ void RiaOsduConnector::requestFileDownloadByFileId( const QString& server, const
{
saveFile( reply, fileId );
}
else
{
qDebug() << "ERROR!!!!!!!!!!!!!!!!!!!!!!!!";
qDebug() << reply->errorString();
}
} );
}

Expand Down Expand Up @@ -668,11 +673,14 @@ void RiaOsduConnector::fileDownloadComplete( const QString& fileId, const QStrin
//--------------------------------------------------------------------------------------------------
std::pair<QString, QString> RiaOsduConnector::requestFileContentsById( const QString& fileId )
{
// TODO: improve this..
QEventLoop loop;
connect( this, SIGNAL( tokenReady( const QString& ) ), &loop, SLOT( quit() ) );
requestToken();
loop.exec();
if ( m_token.isEmpty() )
{
// TODO: improve this..
QEventLoop loop;
connect( this, SIGNAL( tokenReady( const QString& ) ), &loop, SLOT( quit() ) );
requestToken();
loop.exec();
}

qDebug() << "Got token: " << m_token;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "RiaOsduConnector.h"
#include "RiaPreferences.h"

#include "RigWellPath.h"

#include "RiaPreferencesOsdu.h"
#include "RimFileWellPath.h"
#include "RimOilField.h"
Expand All @@ -36,6 +38,8 @@
#include "RiuMainWindow.h"
#include "RiuWellImportWizard.h"

#include "cvfObject.h"

#include <QAction>
#include <QDir>
#include <QFile>
Expand Down Expand Up @@ -128,6 +132,17 @@ void RicWellPathsImportOsduFeature::onActionTriggered( bool isChecked )
wellPath->setFileId( w.fileId );

oilField->wellPathCollection->addWellPath( wellPath );

auto [wellPathGeometry, errorMessage] = RimWellPathCollection::loadWellPathGeometryFromOsdu( m_osduConnector, w.fileId );
if ( wellPathGeometry.notNull() )
{
wellPath->setWellPathGeometry( wellPathGeometry.p() );
}
else
{
qDebug() << "IMPORTING WELL FAILED: " << errorMessage;
}

oilField->wellPathCollection->updateConnectedEditors();
}

Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/FileInterface/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCalculationImporter.h
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCalculationExporter.h
${CMAKE_CURRENT_LIST_DIR}/RifPolygonReader.h
${CMAKE_CURRENT_LIST_DIR}/RifOsduWellPathReader.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand Down Expand Up @@ -191,6 +192,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCalculationImporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCalculationExporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifPolygonReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifOsduWellPathReader.cpp
)

list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
Expand Down
92 changes: 92 additions & 0 deletions ApplicationLibCode/FileInterface/RifOsduWellPathReader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RifOsduWellPathReader.h"

#include "RiaTextStringTools.h"

#include "SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h"

#include "RifCsvUserDataParser.h"

#include "RigWellPath.h"

#include "cvfObject.h"
#include "cvfVector3.h"

#include <QFileInfo>
#include <QTextStream>

std::pair<cvf::ref<RigWellPath>, QString> RifOsduWellPathReader::parseCsv( const QString& content )
{
QString errorMessage;
RifCsvUserDataPastedTextParser parser( content, &errorMessage );

AsciiDataParseOptions parseOptions;
parseOptions.cellSeparator = ",";
parseOptions.decimalSeparator = ".";

std::vector<std::pair<QString, std::vector<double>>> 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<double> 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<cvf::Vec3d> wellPathPoints;
std::vector<double> 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!" };
}
35 changes: 35 additions & 0 deletions ApplicationLibCode/FileInterface/RifOsduWellPathReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <QString>

#include "cvfObject.h"

class RigWellPath;

//==================================================================================================
//
//
//==================================================================================================
class RifOsduWellPathReader
{
public:
static std::pair<cvf::ref<RigWellPath>, QString> parseCsv( const QString& content );
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "RiaTextStringTools.h"
#include "RiaWellNameComparer.h"

#include "RifOsduWellPathReader.h"
#include "RifWellPathFormationsImporter.h"
#include "RifWellPathImporter.h"

Expand Down Expand Up @@ -185,8 +186,15 @@ void RimWellPathCollection::loadDataAndUpdate()
auto osduConnector =
std::make_unique<RiaOsduConnector>( RiuMainWindow::instance(), server, dataParitionId, authority, scopes, clientId );

RigWellPath* wellPathGeometry = loadWellPathGeometryFromOsdu( osduConnector.get(), oWPath->fileId() );
oWPath->setWellPathGeometry( wellPathGeometry );
auto [wellPathGeometry, errorMessage] = loadWellPathGeometryFromOsdu( osduConnector.get(), oWPath->fileId() );
if ( wellPathGeometry.notNull() )
{
oWPath->setWellPathGeometry( wellPathGeometry.p() );
}
else
{
RiaLogging::warning( errorMessage );
}
}

if ( wellPath )
Expand Down Expand Up @@ -1041,10 +1049,11 @@ void RimWellPathCollection::onChildAdded( caf::PdmFieldHandle* containerForNewOb
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigWellPath* RimWellPathCollection::loadWellPathGeometryFromOsdu( RiaOsduConnector* osduConnector, const QString& fileId )
std::pair<cvf::ref<RigWellPath>, QString> RimWellPathCollection::loadWellPathGeometryFromOsdu( RiaOsduConnector* osduConnector,
const QString& fileId )
{
auto [fileContents, errorMessage] = osduConnector->requestFileContentsById( fileId );

qDebug() << "File contents:" << fileContents;
return nullptr;

return RifOsduWellPathReader::parseCsv( fileContents );
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class RimWellPathCollection : public caf::PdmObject

void onChildAdded( caf::PdmFieldHandle* containerForNewObject ) override;

static std::pair<cvf::ref<RigWellPath>, QString> loadWellPathGeometryFromOsdu( RiaOsduConnector* osduConnector, const QString& fileId );

protected:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;

Expand All @@ -156,8 +158,6 @@ class RimWellPathCollection : public caf::PdmObject

static QString unGroupedText();

RigWellPath* loadWellPathGeometryFromOsdu( RiaOsduConnector* osduConnector, const QString& fileId );

private:
std::unique_ptr<RifWellPathImporter> m_wellPathImporter;
std::unique_ptr<RifWellPathFormationsImporter> m_wellPathFormationsImporter;
Expand Down
1 change: 1 addition & 0 deletions ApplicationLibCode/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ set(SOURCE_UNITTEST_FILES
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCalculationIO-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEmReader-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RifPolygonReader-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RifOsduWellPathReader-Test.cpp
)

if(RESINSIGHT_ENABLE_GRPC)
Expand Down
59 changes: 59 additions & 0 deletions ApplicationLibCode/UnitTests/RifOsduWellPathReader-Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "gtest/gtest.h"

#include "RifOsduWellPathReader.h"

#include "RigWellPath.h"

#include "cvfObject.h"

TEST( RifOsduWellPathReader, ParseCsv )
{
std::string fileContent = R"(
MD,TVD,AZIMUTH,INCLINATION,X,Y,GODLEG_SEVERITY,DX,DY,UWI,WELLBORE,CRS,EPSG_CODE
0.0,0.0,1e-10,0.0,68.8767382,33.1345775,0.0,0.0,0.0,WELL NAME #1,WELL NAME #1,WGS84,4326
271.49,271.49,1e-10,0.0,68.8767382,33.1345775,0.0,0.0,0.0,WELL NAME #1,WELL NAME #1,WGS84,4326
306.29,306.29,272.01823962,0.08968724,68.8767375,33.1345774,0.24,-0.06,-0.01,WELL NAME #1,WELL NAME #1,WGS84,4326
336.29,336.29,274.30140794,0.15846019,68.8767368,33.1345775,0.22,-0.12,0.0,WELL NAME #1,WELL NAME #1,WGS84,4326
366.29,366.29,278.8234303,0.09299958,68.8767359,33.1345775,0.23,-0.2,0.0,WELL NAME #1,WELL NAME #1,WGS84,4326
396.29,396.29,272.75661039,0.10458399,68.8767352,33.1345775,0.11,-0.26,0.0,WELL NAME #1,WELL NAME #1,WGS84,4326
426.56,426.29,268.84493373,0.12982945,68.8767347,33.1345775,0.24,-0.3,0.0,WELL NAME #1,WELL NAME #1,WGS84,4326
456.29,456.29,247.08294017,0.24449049,68.8767336,33.1345774,0.58,-0.39,-0.01,WELL NAME #1,WELL NAME #1,WGS84,4326
486.29,486.28,228.45433687,1.77934187,68.876729,33.1345746,1.0,-0.78,-0.33,WELL NAME #1,WELL NAME #1,WGS84,4326
516.29,516.25,234.24032672,3.25969626,68.8767165,33.1345672,1.41,-1.85,-1.15,WELL NAME #1,WELL NAME #1,WGS84,4326
546.29,546.17,235.37605057,5.34499442,68.8766954,33.1345561,3.39,-3.64,-2.39,WELL NAME #1,WELL NAME #1,WGS84,4326
576.29,575.97,233.86086873,7.54998951,68.8766625,33.1345381,1.98,-6.44,-4.4,WELL NAME #1,WELL NAME #1,WGS84,4326
)";

QString fileContentAsQString = QString::fromStdString( fileContent );

auto [wellPath, errorMessage] = RifOsduWellPathReader::parseCsv( fileContentAsQString );
EXPECT_TRUE( wellPath.notNull() );

EXPECT_EQ( 12u, wellPath->wellPathPoints().size() );
EXPECT_EQ( 12u, wellPath->measuredDepths().size() );

cvf::Vec3d point = wellPath->wellPathPoints()[6];
EXPECT_DOUBLE_EQ( 68.8767347, point.x() );
EXPECT_DOUBLE_EQ( 33.1345775, point.y() );
EXPECT_DOUBLE_EQ( -426.29, point.z() );

EXPECT_DOUBLE_EQ( 426.56, wellPath->measuredDepths()[6] );
}

0 comments on commit 74c04c9

Please sign in to comment.