mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Working Correlation Plot prototype
This commit is contained in:
@@ -45,6 +45,8 @@
|
||||
#include "RimAnnotationTextAppearance.h"
|
||||
#include "RimCellRangeFilterCollection.h"
|
||||
#include "RimCommandObject.h"
|
||||
#include "RimCorrelationPlot.h"
|
||||
#include "RimCorrelationPlotCollection.h"
|
||||
#include "RimEclipseCaseCollection.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimFlowPlotCollection.h"
|
||||
@@ -331,7 +333,7 @@ bool RiaApplication::openFile( const QString& fileName )
|
||||
}
|
||||
else if ( fileType & RiaDefines::ANY_ECLIPSE_FILE )
|
||||
{
|
||||
loadingSucceded = RicImportGeneralDataFeature::openEclipseFilesFromFileNames( QStringList{fileName}, true );
|
||||
loadingSucceded = RicImportGeneralDataFeature::openEclipseFilesFromFileNames( QStringList{ fileName }, true );
|
||||
lastUsedDialogTag = RiaDefines::defaultDirectoryLabel( fileType );
|
||||
}
|
||||
|
||||
@@ -1546,6 +1548,7 @@ void RiaApplication::loadAndUpdatePlotData()
|
||||
RimGridCrossPlotCollection* gcpColl = nullptr;
|
||||
RimSaturationPressurePlotCollection* sppColl = nullptr;
|
||||
RimAnalysisPlotCollection* alsColl = nullptr;
|
||||
RimCorrelationPlotCollection* corrColl = nullptr;
|
||||
RimMultiPlotCollection* gpwColl = nullptr;
|
||||
|
||||
if ( m_project->mainPlotCollection() )
|
||||
@@ -1586,6 +1589,10 @@ void RiaApplication::loadAndUpdatePlotData()
|
||||
{
|
||||
alsColl = m_project->mainPlotCollection()->analysisPlotCollection();
|
||||
}
|
||||
if ( m_project->mainPlotCollection->correlationPlotCollection() )
|
||||
{
|
||||
corrColl = m_project->mainPlotCollection()->correlationPlotCollection();
|
||||
}
|
||||
if ( m_project->mainPlotCollection()->multiPlotCollection() )
|
||||
{
|
||||
gpwColl = m_project->mainPlotCollection()->multiPlotCollection();
|
||||
@@ -1602,6 +1609,7 @@ void RiaApplication::loadAndUpdatePlotData()
|
||||
plotCount += gcpColl ? gcpColl->gridCrossPlots().size() : 0;
|
||||
plotCount += sppColl ? sppColl->plots().size() : 0;
|
||||
plotCount += alsColl ? alsColl->plots().size() : 0;
|
||||
plotCount += corrColl ? corrColl->plots().size() : 0;
|
||||
plotCount += gpwColl ? gpwColl->multiPlots().size() : 0;
|
||||
|
||||
if ( plotCount > 0 )
|
||||
@@ -1686,6 +1694,15 @@ void RiaApplication::loadAndUpdatePlotData()
|
||||
}
|
||||
}
|
||||
|
||||
if ( corrColl )
|
||||
{
|
||||
for ( const auto& corrPlot : corrColl->plots() )
|
||||
{
|
||||
corrPlot->loadDataAndUpdate();
|
||||
plotProgress.incrementProgress();
|
||||
}
|
||||
}
|
||||
|
||||
if ( gpwColl )
|
||||
{
|
||||
for ( const auto& multiPlot : gpwColl->multiPlots() )
|
||||
@@ -1807,7 +1824,7 @@ bool RiaApplication::generateCode( const QString& fileName, QString* errMsg )
|
||||
|
||||
std::vector<std::shared_ptr<const caf::PdmObject>> commandObjects;
|
||||
|
||||
QStringList excludedClassNames{"TestCommand1", "TC2"}; // See RifCommandCore-Text.cpp
|
||||
QStringList excludedClassNames{ "TestCommand1", "TC2" }; // See RifCommandCore-Text.cpp
|
||||
|
||||
auto allObjects = caf::PdmMarkdownBuilder::createAllObjects( caf::PdmDefaultObjectFactory::instance() );
|
||||
for ( auto classObject : allObjects )
|
||||
|
||||
@@ -889,6 +889,14 @@ const QString& RiaPreferences::timeFormat() const
|
||||
return m_timeFormat();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaPreferences::dateTimeFormat() const
|
||||
{
|
||||
return QString( "%1 %2" ).arg( m_dateFormat() ).arg( m_timeFormat() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -93,6 +93,7 @@ public:
|
||||
|
||||
const QString& dateFormat() const;
|
||||
const QString& timeFormat() const;
|
||||
QString dateTimeFormat() const;
|
||||
|
||||
bool searchPlotTemplateFoldersRecursively() const;
|
||||
QStringList plotTemplateFolders() const;
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
|
||||
#include "gsl/statistics/gsl_statistics_double.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -49,3 +51,53 @@ const QString RiaStatisticsTools::replacePercentileByPValueText( const QString&
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaStatisticsTools::pearsonCorrelation( const std::vector<double>& xValues, const std::vector<double>& yValues )
|
||||
{
|
||||
#ifdef OWN_IMPLEMENTATION
|
||||
const double eps = 1.0e-8;
|
||||
if ( xValues.size() != yValues.size() ) return 0.0;
|
||||
if ( xValues.empty() ) return 0.0;
|
||||
|
||||
size_t sampleSize = xValues.size();
|
||||
|
||||
double meanX = 0.0, meanY = 0.0;
|
||||
for ( size_t i = 0; i < sampleSize; ++i )
|
||||
{
|
||||
meanX += xValues[i];
|
||||
meanY += yValues[i];
|
||||
}
|
||||
meanX /= sampleSize;
|
||||
meanY /= sampleSize;
|
||||
|
||||
double sumNumerator = 0.0;
|
||||
double sumxDiffSquared = 0.0, sumyDiffSquared = 0.0;
|
||||
for ( size_t i = 0; i < sampleSize; ++i )
|
||||
{
|
||||
double xDiff = xValues[i] - meanX;
|
||||
double yDiff = yValues[i] - meanY;
|
||||
sumNumerator += xDiff * yDiff;
|
||||
sumxDiffSquared += xDiff * xDiff;
|
||||
sumyDiffSquared += yDiff * yDiff;
|
||||
}
|
||||
|
||||
if ( sumxDiffSquared < eps && sumyDiffSquared < eps ) return 1.0;
|
||||
if ( sumxDiffSquared < eps || sumyDiffSquared < eps ) return 0.0;
|
||||
|
||||
return sumNumerator / ( std::sqrt( sumxDiffSquared ) * std::sqrt( sumyDiffSquared ) );
|
||||
#else
|
||||
return gsl_stats_correlation( xValues.data(), 1, yValues.data(), 1, xValues.size() );
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaStatisticsTools::spearmanCorrelation( const std::vector<double>& xValues, const std::vector<double>& yValues )
|
||||
{
|
||||
std::vector<double> work( 2 * xValues.size() );
|
||||
return gsl_stats_spearman( xValues.data(), 1, yValues.data(), 1, xValues.size(), work.data() );
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
class QString;
|
||||
|
||||
@@ -48,4 +50,8 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static double pearsonCorrelation( const std::vector<double>& xValues, const std::vector<double>& yValues );
|
||||
|
||||
static double spearmanCorrelation( const std::vector<double>& xValues, const std::vector<double>& yValues );
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user