mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Correlation Matrix Plot
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimAbstractCorrelationPlot.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlot.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationMatrixPlot.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimParameterResultCrossPlot.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlotCollection.h
|
||||
)
|
||||
@@ -9,6 +10,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlotCollection.h
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimAbstractCorrelationPlot.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlot.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationMatrixPlot.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimParameterResultCrossPlot.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlotCollection.cpp
|
||||
)
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiaSummaryCurveDefinition.h"
|
||||
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
|
||||
#include "RimAnalysisPlotDataEntry.h"
|
||||
#include "RimEnsembleCurveSet.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryAddress.h"
|
||||
@@ -24,26 +26,23 @@ CAF_PDM_ABSTRACT_SOURCE_INIT( RimAbstractCorrelationPlot, "AbstractCorrelationPl
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimAbstractCorrelationPlot::RimAbstractCorrelationPlot()
|
||||
: m_selectMultipleVectors( false )
|
||||
{
|
||||
CAF_PDM_InitObject( "Abstract Correlation Plot", ":/CorrelationPlot16x16.png", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_ensemble, "Ensemble", "Ensemble", "", "", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_selectedVarsUiField, "SelectedVariableDisplayVar", "Vector", "", "", "" );
|
||||
m_selectedVarsUiField.xmlCapability()->disableIO();
|
||||
m_selectedVarsUiField.uiCapability()->setUiEditorTypeName( caf::PdmUiLineEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_summaryAddressUiField, "SelectedVariableDisplayVar", "Vector", "", "", "" );
|
||||
m_summaryAddressUiField.xmlCapability()->disableIO();
|
||||
m_summaryAddressUiField.uiCapability()->setUiEditorTypeName( caf::PdmUiLineEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_summaryAddress, "SummaryAddress", "Summary Address", "", "", "" );
|
||||
m_summaryAddress.uiCapability()->setUiHidden( true );
|
||||
m_summaryAddress.uiCapability()->setUiTreeChildrenHidden( true );
|
||||
CAF_PDM_InitFieldNoDefault( &m_analysisPlotDataSelection, "AnalysisPlotData", "", "", "", "" );
|
||||
m_analysisPlotDataSelection.uiCapability()->setUiTreeChildrenHidden( true );
|
||||
m_analysisPlotDataSelection.uiCapability()->setUiTreeHidden( true );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_pushButtonSelectSummaryAddress, "SelectAddress", "", "", "", "" );
|
||||
caf::PdmUiPushButtonEditor::configureEditorForField( &m_pushButtonSelectSummaryAddress );
|
||||
m_pushButtonSelectSummaryAddress.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
m_pushButtonSelectSummaryAddress = false;
|
||||
|
||||
m_summaryAddress = new RimSummaryAddress;
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_timeStep, "TimeStep", "Time Step", "", "", "" );
|
||||
m_timeStep.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() );
|
||||
|
||||
@@ -70,19 +69,28 @@ void RimAbstractCorrelationPlot::fieldChangedByUi( const caf::PdmFieldHandle* ch
|
||||
if ( changedField == &m_pushButtonSelectSummaryAddress )
|
||||
{
|
||||
RiuSummaryVectorSelectionDialog dlg( nullptr );
|
||||
RimSummaryCaseCollection* candidateEnsemble = m_ensemble;
|
||||
RifEclipseSummaryAddress candicateAddress = m_summaryAddress->address();
|
||||
|
||||
dlg.hideSummaryCases();
|
||||
dlg.setEnsembleAndAddress( candidateEnsemble, candicateAddress );
|
||||
if ( m_selectMultipleVectors )
|
||||
{
|
||||
dlg.enableMultiSelect( true );
|
||||
}
|
||||
|
||||
dlg.setCaseAndAddress( nullptr, RifEclipseSummaryAddress() );
|
||||
dlg.setCurveSelection( curveDefinitions() );
|
||||
|
||||
if ( dlg.exec() == QDialog::Accepted )
|
||||
{
|
||||
auto curveSelection = dlg.curveSelection();
|
||||
if ( !curveSelection.empty() )
|
||||
{
|
||||
m_summaryAddress->setAddress( curveSelection[0].summaryAddress() );
|
||||
|
||||
std::vector<RiaSummaryCurveDefinition> summaryVectorDefinitions = dlg.curveSelection();
|
||||
m_analysisPlotDataSelection.deleteAllChildObjects();
|
||||
for ( const RiaSummaryCurveDefinition& vectorDef : summaryVectorDefinitions )
|
||||
{
|
||||
auto plotEntry = new RimAnalysisPlotDataEntry();
|
||||
plotEntry->setFromCurveDefinition( vectorDef );
|
||||
m_analysisPlotDataSelection.push_back( plotEntry );
|
||||
}
|
||||
this->loadDataAndUpdate();
|
||||
this->updateConnectedEditors();
|
||||
}
|
||||
@@ -95,11 +103,6 @@ void RimAbstractCorrelationPlot::fieldChangedByUi( const caf::PdmFieldHandle* ch
|
||||
this->loadDataAndUpdate();
|
||||
this->updateConnectedEditors();
|
||||
}
|
||||
else if ( changedField == &m_ensemble )
|
||||
{
|
||||
this->loadDataAndUpdate();
|
||||
this->updateConnectedEditors();
|
||||
}
|
||||
else if ( changedField == &m_showPlotTitle || changedField == &m_useAutoPlotTitle || changedField == &m_description )
|
||||
{
|
||||
this->updatePlotTitle();
|
||||
@@ -136,38 +139,14 @@ QList<caf::PdmOptionItemInfo>
|
||||
{
|
||||
QList<caf::PdmOptionItemInfo> options = RimPlot::calculateValueOptions( fieldNeedingOptions, useOptionsOnly );
|
||||
|
||||
if ( fieldNeedingOptions == &m_ensemble )
|
||||
if ( fieldNeedingOptions == &m_timeStep )
|
||||
{
|
||||
RimProject* project = RiaApplication::instance()->project();
|
||||
std::vector<RimSummaryCaseCollection*> summaryCaseCollections;
|
||||
project->descendantsIncludingThisOfType( summaryCaseCollections );
|
||||
for ( auto summaryCaseCollection : summaryCaseCollections )
|
||||
std::set<time_t> allTimeSteps = allAvailableTimeSteps();
|
||||
for ( time_t timeStep : allTimeSteps )
|
||||
{
|
||||
if ( summaryCaseCollection->isEnsemble() )
|
||||
{
|
||||
options.push_back( caf::PdmOptionItemInfo( summaryCaseCollection->name(), summaryCaseCollection ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( fieldNeedingOptions == &m_summaryAddressUiField )
|
||||
{
|
||||
if ( m_ensemble )
|
||||
{
|
||||
RimEnsembleCurveSet::appendOptionItemsForSummaryAddresses( &options, m_ensemble );
|
||||
}
|
||||
}
|
||||
else if ( fieldNeedingOptions == &m_timeStep )
|
||||
{
|
||||
QString dateTimeFormat = RiaApplication::instance()->preferences()->dateTimeFormat();
|
||||
if ( m_ensemble )
|
||||
{
|
||||
std::set<time_t> allTimeSteps = allAvailableTimeSteps();
|
||||
for ( time_t timeStep : allTimeSteps )
|
||||
{
|
||||
QDateTime dateTime = QDateTime::fromTime_t( timeStep );
|
||||
QString timestepString = dateTime.toString( Qt::ISODate );
|
||||
options.push_back( caf::PdmOptionItemInfo( timestepString, dateTime ) );
|
||||
}
|
||||
QDateTime dateTime = QDateTime::fromTime_t( timeStep );
|
||||
QString timestepString = dateTime.toString( Qt::ISODate );
|
||||
options.push_back( caf::PdmOptionItemInfo( timestepString, dateTime ) );
|
||||
}
|
||||
}
|
||||
return options;
|
||||
@@ -180,19 +159,102 @@ std::set<time_t> RimAbstractCorrelationPlot::allAvailableTimeSteps()
|
||||
{
|
||||
std::set<time_t> timeStepUnion;
|
||||
|
||||
for ( RimSummaryCase* sumCase : m_ensemble->allSummaryCases() )
|
||||
RiaSummaryCurveDefinitionAnalyser* analyserOfSelectedCurveDefs = getOrCreateSelectedCurveDefAnalyser();
|
||||
for ( RimSummaryCaseCollection* ensemble : analyserOfSelectedCurveDefs->m_ensembles )
|
||||
{
|
||||
const std::vector<time_t>& timeSteps = sumCase->summaryReader()->timeSteps( m_summaryAddress->address() );
|
||||
|
||||
for ( time_t t : timeSteps )
|
||||
{
|
||||
timeStepUnion.insert( t );
|
||||
}
|
||||
const std::set<time_t>& timeSteps = ensemble->ensembleTimeSteps();
|
||||
timeStepUnion.insert( timeSteps.begin(), timeSteps.end() );
|
||||
}
|
||||
|
||||
return timeStepUnion;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RiaSummaryCurveDefinition> RimAbstractCorrelationPlot::curveDefinitions() const
|
||||
{
|
||||
std::vector<RiaSummaryCurveDefinition> curveDefs;
|
||||
for ( auto dataEntry : m_analysisPlotDataSelection )
|
||||
{
|
||||
curveDefs.push_back( dataEntry->curveDefinition() );
|
||||
}
|
||||
|
||||
return curveDefs;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaSummaryCurveDefinitionAnalyser* RimAbstractCorrelationPlot::getOrCreateSelectedCurveDefAnalyser()
|
||||
{
|
||||
if ( !m_analyserOfSelectedCurveDefs )
|
||||
{
|
||||
m_analyserOfSelectedCurveDefs = std::unique_ptr<RiaSummaryCurveDefinitionAnalyser>(
|
||||
new RiaSummaryCurveDefinitionAnalyser( this->curveDefinitions() ) );
|
||||
}
|
||||
|
||||
return m_analyserOfSelectedCurveDefs.get();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<RifEclipseSummaryAddress> RimAbstractCorrelationPlot::addresses()
|
||||
{
|
||||
std::set<RifEclipseSummaryAddress> addresses;
|
||||
|
||||
RiaSummaryCurveDefinitionAnalyser* analyserOfSelectedCurveDefs = getOrCreateSelectedCurveDefAnalyser();
|
||||
|
||||
for ( RimSummaryCaseCollection* ensemble : analyserOfSelectedCurveDefs->m_ensembles )
|
||||
{
|
||||
const std::set<RifEclipseSummaryAddress>& caseAddrs = ensemble->ensembleSummaryAddresses();
|
||||
addresses.insert( caseAddrs.begin(), caseAddrs.end() );
|
||||
}
|
||||
|
||||
return addresses;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<RimSummaryCaseCollection*> RimAbstractCorrelationPlot::ensembles()
|
||||
{
|
||||
RiaSummaryCurveDefinitionAnalyser* analyserOfSelectedCurveDefs = getOrCreateSelectedCurveDefAnalyser();
|
||||
return analyserOfSelectedCurveDefs->m_ensembles;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<EnsembleParameter> RimAbstractCorrelationPlot::ensembleParameters()
|
||||
{
|
||||
std::set<EnsembleParameter> ensembleParms;
|
||||
|
||||
RiaSummaryCurveDefinitionAnalyser* analyserOfSelectedCurveDefs = getOrCreateSelectedCurveDefAnalyser();
|
||||
|
||||
for ( RimSummaryCaseCollection* ensemble : analyserOfSelectedCurveDefs->m_ensembles )
|
||||
{
|
||||
std::vector<EnsembleParameter> parameters = ensemble->alphabeticEnsembleParameters();
|
||||
ensembleParms.insert( parameters.begin(), parameters.end() );
|
||||
}
|
||||
return ensembleParms;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
EnsembleParameter RimAbstractCorrelationPlot::ensembleParameter( const QString& ensembleParameterName )
|
||||
{
|
||||
std::set<EnsembleParameter> ensembleParms = ensembleParameters();
|
||||
for ( const EnsembleParameter& eParam : ensembleParms )
|
||||
{
|
||||
if ( eParam.name == ensembleParameterName ) return eParam;
|
||||
}
|
||||
|
||||
return EnsembleParameter();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -313,3 +375,25 @@ time_t RimAbstractCorrelationPlot::timeDiff( time_t lhs, time_t rhs )
|
||||
}
|
||||
return rhs - lhs;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimAbstractCorrelationPlot::selectedVarsText() const
|
||||
{
|
||||
QString vectorNames;
|
||||
if ( m_analyserOfSelectedCurveDefs )
|
||||
{
|
||||
for ( const std::string& quantityName : m_analyserOfSelectedCurveDefs->m_quantityNames )
|
||||
{
|
||||
vectorNames += QString::fromStdString( quantityName ) + ", ";
|
||||
}
|
||||
|
||||
if ( !vectorNames.isEmpty() )
|
||||
{
|
||||
vectorNames.chop( 2 );
|
||||
}
|
||||
}
|
||||
|
||||
return vectorNames;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
|
||||
#include "cafPdmPtrField.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
class RiaSummaryCurveDefinition;
|
||||
class RiaSummaryCurveDefinitionAnalyser;
|
||||
class RimAnalysisPlotDataEntry;
|
||||
class RimSummaryAddress;
|
||||
|
||||
class RimAbstractCorrelationPlot : public RimPlot
|
||||
@@ -47,7 +52,14 @@ protected:
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly ) override;
|
||||
|
||||
std::set<time_t> allAvailableTimeSteps();
|
||||
std::set<time_t> allAvailableTimeSteps();
|
||||
std::vector<RiaSummaryCurveDefinition> curveDefinitions() const;
|
||||
RiaSummaryCurveDefinitionAnalyser* getOrCreateSelectedCurveDefAnalyser();
|
||||
|
||||
std::set<RifEclipseSummaryAddress> addresses();
|
||||
std::set<RimSummaryCaseCollection*> ensembles();
|
||||
std::set<EnsembleParameter> ensembleParameters();
|
||||
EnsembleParameter ensembleParameter( const QString& ensembleParameterName );
|
||||
|
||||
// RimViewWindow overrides
|
||||
QWidget* viewWidget() override;
|
||||
@@ -84,15 +96,20 @@ protected:
|
||||
|
||||
static time_t timeDiff( time_t lhs, time_t rhs );
|
||||
|
||||
QString selectedVarsText() const;
|
||||
|
||||
protected:
|
||||
QPointer<RiuQwtPlotWidget> m_plotWidget;
|
||||
std::unique_ptr<RiaSummaryCurveDefinitionAnalyser> m_analyserOfSelectedCurveDefs;
|
||||
QPointer<RiuQwtPlotWidget> m_plotWidget;
|
||||
|
||||
bool m_selectMultipleVectors;
|
||||
|
||||
// Fields
|
||||
caf::PdmPtrField<RimSummaryCaseCollection*> m_ensemble;
|
||||
caf::PdmChildField<RimSummaryAddress*> m_summaryAddress;
|
||||
caf::PdmField<RifEclipseSummaryAddress> m_summaryAddressUiField;
|
||||
caf::PdmField<bool> m_pushButtonSelectSummaryAddress;
|
||||
caf::PdmField<QDateTime> m_timeStep;
|
||||
caf::PdmChildArrayField<RimAnalysisPlotDataEntry*> m_analysisPlotDataSelection;
|
||||
|
||||
caf::PdmField<QString> m_selectedVarsUiField;
|
||||
caf::PdmField<bool> m_pushButtonSelectSummaryAddress;
|
||||
caf::PdmField<QDateTime> m_timeStep;
|
||||
|
||||
caf::PdmField<bool> m_showPlotTitle;
|
||||
caf::PdmField<bool> m_useAutoPlotTitle;
|
||||
|
||||
@@ -0,0 +1,482 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020 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 "RimCorrelationMatrixPlot.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaColorTools.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiaStatisticsTools.h"
|
||||
#include "RiuPlotMainWindowTools.h"
|
||||
#include "RiuQwtLinearScaleEngine.h"
|
||||
#include "RiuQwtPlotTools.h"
|
||||
#include "RiuQwtPlotWidget.h"
|
||||
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
|
||||
#include "RimDerivedSummaryCase.h"
|
||||
#include "RimEnsembleCurveSet.h"
|
||||
#include "RimPlotAxisProperties.h"
|
||||
#include "RimPlotAxisPropertiesInterface.h"
|
||||
#include "RimPlotDataFilterCollection.h"
|
||||
#include "RimRegularLegendConfig.h"
|
||||
#include "RimSummaryAddress.h"
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryCaseCollection.h"
|
||||
#include "RimSummaryPlotAxisFormatter.h"
|
||||
|
||||
#include "cafPdmUiComboBoxEditor.h"
|
||||
#include "cafPdmUiTreeOrdering.h"
|
||||
|
||||
#include "cvfScalarMapper.h"
|
||||
|
||||
#include "qwt_plot_marker.h"
|
||||
#include "qwt_scale_draw.h"
|
||||
#include "qwt_text.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimCorrelationMatrixPlot, "CorrelationMatrixPlot" );
|
||||
|
||||
class TextScaleDraw : public QwtScaleDraw
|
||||
{
|
||||
public:
|
||||
TextScaleDraw( const std::map<size_t, QString>& tickLabels )
|
||||
: m_tickLabels( tickLabels )
|
||||
{
|
||||
}
|
||||
|
||||
QwtText label( double value ) const override
|
||||
{
|
||||
size_t intValue = static_cast<size_t>( value + 0.25 );
|
||||
auto it = m_tickLabels.find( intValue );
|
||||
return it != m_tickLabels.end() ? it->second : "";
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<size_t, QString> m_tickLabels;
|
||||
};
|
||||
|
||||
class CorrelationMatrixRowOrColumn
|
||||
{
|
||||
public:
|
||||
CorrelationMatrixRowOrColumn( const QString& label,
|
||||
const std::vector<double>& values,
|
||||
const std::vector<QString>& entryLabels )
|
||||
: m_label( label )
|
||||
, m_values( values )
|
||||
, m_entryLabels( entryLabels )
|
||||
, m_correlationSum( 0.0 )
|
||||
{
|
||||
bool anyValid = false;
|
||||
for ( auto value : values )
|
||||
{
|
||||
if ( RiaCurveDataTools::isValidValue( value, false ) )
|
||||
{
|
||||
m_correlationSum += value * value;
|
||||
anyValid = true;
|
||||
}
|
||||
}
|
||||
if ( !anyValid ) m_correlationSum = std::numeric_limits<double>::infinity();
|
||||
}
|
||||
|
||||
QString m_label;
|
||||
std::vector<double> m_values;
|
||||
std::vector<QString> m_entryLabels;
|
||||
double m_correlationSum;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCorrelationMatrixPlot::RimCorrelationMatrixPlot()
|
||||
: RimAbstractCorrelationPlot()
|
||||
{
|
||||
CAF_PDM_InitObject( "Correlation Plot", ":/CorrelationMatrixPlot16x16.png", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_correlationFactor, "CorrelationFactor", "Correlation Factor", "", "", "" );
|
||||
m_correlationFactor.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() );
|
||||
CAF_PDM_InitField( &m_showAbsoluteValues, "CorrelationAbsValues", true, "Show Absolute Values", "", "", "" );
|
||||
CAF_PDM_InitField( &m_sortByValues, "CorrelationSorting", true, "Sort Matrix by Values", "", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_legendConfig, "LegendConfig", "", "", "", "" );
|
||||
m_legendConfig = new RimRegularLegendConfig();
|
||||
m_legendConfig->setAutomaticRanges( -1.0, 1.0, -1.0, 1.0 );
|
||||
|
||||
m_selectMultipleVectors = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCorrelationMatrixPlot::~RimCorrelationMatrixPlot()
|
||||
{
|
||||
removeMdiWindowFromMdiArea();
|
||||
|
||||
cleanupBeforeClose();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCorrelationMatrixPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
||||
const QVariant& oldValue,
|
||||
const QVariant& newValue )
|
||||
{
|
||||
RimAbstractCorrelationPlot::fieldChangedByUi( changedField, oldValue, newValue );
|
||||
if ( changedField == &m_correlationFactor || changedField == &m_showAbsoluteValues || changedField == &m_sortByValues )
|
||||
{
|
||||
this->updateLegend();
|
||||
this->loadDataAndUpdate();
|
||||
this->updateConnectedEditors();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCorrelationMatrixPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
||||
{
|
||||
caf::PdmUiGroup* correlationGroup = uiOrdering.addNewGroup( "Correlation Factor Settings" );
|
||||
correlationGroup->add( &m_correlationFactor );
|
||||
correlationGroup->add( &m_showAbsoluteValues );
|
||||
correlationGroup->add( &m_sortByValues );
|
||||
|
||||
caf::PdmUiGroup* curveDataGroup = uiOrdering.addNewGroup( "Summary Vector" );
|
||||
m_selectedVarsUiField = selectedVarsText();
|
||||
|
||||
curveDataGroup->add( &m_selectedVarsUiField );
|
||||
curveDataGroup->add( &m_pushButtonSelectSummaryAddress, { false, 1, 0 } );
|
||||
curveDataGroup->add( &m_timeStep );
|
||||
|
||||
caf::PdmUiGroup* plotGroup = uiOrdering.addNewGroup( "Plot Settings" );
|
||||
plotGroup->add( &m_showPlotTitle );
|
||||
plotGroup->add( &m_useAutoPlotTitle );
|
||||
plotGroup->add( &m_description );
|
||||
m_description.uiCapability()->setUiReadOnly( m_useAutoPlotTitle() );
|
||||
RimPlot::defineUiOrdering( uiConfigName, *plotGroup );
|
||||
|
||||
uiOrdering.skipRemainingFields( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<caf::PdmOptionItemInfo>
|
||||
RimCorrelationMatrixPlot::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly )
|
||||
{
|
||||
QList<caf::PdmOptionItemInfo> options =
|
||||
RimAbstractCorrelationPlot::calculateValueOptions( fieldNeedingOptions, useOptionsOnly );
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCorrelationMatrixPlot::onLoadDataAndUpdate()
|
||||
{
|
||||
updateMdiWindowVisibility();
|
||||
|
||||
m_selectedVarsUiField = selectedVarsText();
|
||||
|
||||
m_analyserOfSelectedCurveDefs = std::unique_ptr<RiaSummaryCurveDefinitionAnalyser>(
|
||||
new RiaSummaryCurveDefinitionAnalyser( this->curveDefinitions() ) );
|
||||
|
||||
if ( m_plotWidget )
|
||||
{
|
||||
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotBarChart );
|
||||
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotScale );
|
||||
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotItem );
|
||||
|
||||
createMatrix();
|
||||
|
||||
m_plotWidget->insertLegend( nullptr );
|
||||
m_plotWidget->updateLegend();
|
||||
|
||||
this->updateAxes();
|
||||
this->updatePlotTitle();
|
||||
m_plotWidget->scheduleReplot();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCorrelationMatrixPlot::childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField )
|
||||
{
|
||||
this->loadDataAndUpdate();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCorrelationMatrixPlot::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering,
|
||||
QString uiConfigName /*= "" */ )
|
||||
{
|
||||
uiTreeOrdering.add( m_legendConfig() );
|
||||
uiTreeOrdering.skipRemainingChildren( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCorrelationMatrixPlot::updateAxes()
|
||||
{
|
||||
if ( !m_plotWidget ) return;
|
||||
|
||||
m_plotWidget->setAxisScaleEngine( QwtPlot::yLeft, new RiuQwtLinearScaleEngine );
|
||||
m_plotWidget->setAxisTitleText( QwtPlot::yLeft, "Result Vector" );
|
||||
m_plotWidget->setAxisTitleEnabled( QwtPlot::yLeft, true );
|
||||
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::yLeft, 11, 7, false, Qt::AlignCenter );
|
||||
m_plotWidget->setAxisLabelsAndTicksEnabled( QwtPlot::yLeft, true, false );
|
||||
m_plotWidget->setAxisRange( QwtPlot::yLeft, 0.0, (double)m_resultLabels.size() + 1 );
|
||||
m_plotWidget->setAxisScaleDraw( QwtPlot::yLeft, new TextScaleDraw( m_resultLabels ) );
|
||||
m_plotWidget->setMajorAndMinorTickIntervalsAndRange( QwtPlot::yLeft,
|
||||
1.0,
|
||||
0.0,
|
||||
0.5,
|
||||
(double)m_resultLabels.size() - 0.5,
|
||||
0.0,
|
||||
m_resultLabels.size() );
|
||||
|
||||
auto scaleDraw = new TextScaleDraw( m_paramLabels );
|
||||
scaleDraw->setLabelRotation( 30.0 );
|
||||
m_plotWidget->setAxisScaleDraw( QwtPlot::xBottom, scaleDraw );
|
||||
|
||||
m_plotWidget->setAxisScaleEngine( QwtPlot::xBottom, new RiuQwtLinearScaleEngine );
|
||||
m_plotWidget->setAxisTitleText( QwtPlot::xBottom, "Ensemble Parameter" );
|
||||
m_plotWidget->setAxisTitleEnabled( QwtPlot::xBottom, true );
|
||||
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::xBottom, 11, 6, false, Qt::AlignCenter | Qt::AlignTop );
|
||||
m_plotWidget->setAxisLabelsAndTicksEnabled( QwtPlot::xBottom, true, false );
|
||||
m_plotWidget->setAxisRange( QwtPlot::xBottom, 0.0, (double)m_paramLabels.size() + 1 );
|
||||
// m_plotWidget->setAutoTickIntervalCounts( QwtPlot::xBottom, m_paramLabels.size(), m_paramLabels.size() );
|
||||
m_plotWidget->setMajorAndMinorTickIntervalsAndRange( QwtPlot::xBottom,
|
||||
1.0,
|
||||
0.0,
|
||||
0.5,
|
||||
(double)m_paramLabels.size() - 0.5,
|
||||
0.0,
|
||||
(double)m_paramLabels.size() );
|
||||
|
||||
m_plotWidget->setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignRight );
|
||||
}
|
||||
|
||||
void eraseInvalidEntries( std::vector<CorrelationMatrixRowOrColumn>& matrix )
|
||||
{
|
||||
matrix.erase( std::remove_if( matrix.begin(),
|
||||
matrix.end(),
|
||||
[]( auto entry ) {
|
||||
return !RiaCurveDataTools::isValidValue( entry.m_correlationSum, false );
|
||||
} ),
|
||||
matrix.end() );
|
||||
}
|
||||
|
||||
void sortEntries( std::vector<CorrelationMatrixRowOrColumn>& matrix )
|
||||
{
|
||||
std::sort( matrix.begin(),
|
||||
matrix.end(),
|
||||
[]( const CorrelationMatrixRowOrColumn& lhs, const CorrelationMatrixRowOrColumn& rhs ) {
|
||||
return lhs.m_correlationSum > rhs.m_correlationSum;
|
||||
} );
|
||||
}
|
||||
|
||||
std::vector<CorrelationMatrixRowOrColumn> transpose( const std::vector<CorrelationMatrixRowOrColumn>& matrix )
|
||||
{
|
||||
std::vector<CorrelationMatrixRowOrColumn> transposedMatrix;
|
||||
for ( size_t rowIdx = 0u; rowIdx < matrix[0].m_values.size(); ++rowIdx )
|
||||
{
|
||||
QString label = matrix[0].m_entryLabels[rowIdx];
|
||||
std::vector<double> values;
|
||||
std::vector<QString> entryLabels;
|
||||
for ( size_t colIdx = 0u; colIdx < matrix.size(); ++colIdx )
|
||||
{
|
||||
values.push_back( matrix[colIdx].m_values[rowIdx] );
|
||||
entryLabels.push_back( matrix[colIdx].m_label );
|
||||
}
|
||||
transposedMatrix.push_back( CorrelationMatrixRowOrColumn( label, values, entryLabels ) );
|
||||
}
|
||||
return transposedMatrix;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCorrelationMatrixPlot::createMatrix()
|
||||
{
|
||||
time_t selectedTimestep = m_timeStep().toTime_t();
|
||||
|
||||
m_paramLabels.clear();
|
||||
m_resultLabels.clear();
|
||||
|
||||
auto curveDefs = curveDefinitions();
|
||||
if ( curveDefs.empty() ) return;
|
||||
|
||||
std::vector<CorrelationMatrixRowOrColumn> correlationMatrixColumns;
|
||||
|
||||
for ( EnsembleParameter parameter : ensembleParameters() )
|
||||
{
|
||||
if ( parameter.isNumeric() && parameter.isValid() )
|
||||
{
|
||||
bool anyValidResults = false;
|
||||
std::vector<double> correlations;
|
||||
std::vector<QString> resultLabels;
|
||||
|
||||
for ( auto curveDef : curveDefs )
|
||||
{
|
||||
double correlation = std::numeric_limits<double>::infinity();
|
||||
|
||||
auto ensemble = curveDef.ensemble();
|
||||
auto address = curveDef.summaryAddress();
|
||||
|
||||
QString resultLabel = curveDef.curveDefinitionText();
|
||||
|
||||
if ( ensemble )
|
||||
{
|
||||
std::vector<double> caseValuesAtTimestep;
|
||||
std::vector<double> parameterValues;
|
||||
|
||||
for ( size_t caseIdx = 0u; caseIdx < ensemble->allSummaryCases().size(); ++caseIdx )
|
||||
{
|
||||
auto summaryCase = ensemble->allSummaryCases()[caseIdx];
|
||||
RifSummaryReaderInterface* reader = summaryCase->summaryReader();
|
||||
if ( reader )
|
||||
{
|
||||
std::vector<double> values;
|
||||
double closestValue = std::numeric_limits<double>::infinity();
|
||||
time_t closestTimeStep = 0;
|
||||
if ( reader->values( address, &values ) )
|
||||
{
|
||||
const std::vector<time_t>& timeSteps = reader->timeSteps( address );
|
||||
for ( size_t i = 0; i < timeSteps.size(); ++i )
|
||||
{
|
||||
if ( timeDiff( timeSteps[i], selectedTimestep ) <
|
||||
timeDiff( selectedTimestep, closestTimeStep ) )
|
||||
{
|
||||
closestValue = values[i];
|
||||
closestTimeStep = timeSteps[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( closestValue != std::numeric_limits<double>::infinity() )
|
||||
{
|
||||
caseValuesAtTimestep.push_back( closestValue );
|
||||
double paramValue = parameter.values[caseIdx].toDouble();
|
||||
parameterValues.push_back( paramValue );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( parameterValues.empty() ) continue;
|
||||
|
||||
if ( m_correlationFactor == CorrelationFactor::PEARSON )
|
||||
{
|
||||
correlation = RiaStatisticsTools::pearsonCorrelation( parameterValues, caseValuesAtTimestep );
|
||||
}
|
||||
else
|
||||
{
|
||||
correlation = RiaStatisticsTools::spearmanCorrelation( parameterValues, caseValuesAtTimestep );
|
||||
}
|
||||
|
||||
if ( RiaCurveDataTools::isValidValue( correlation, false ) )
|
||||
{
|
||||
if ( m_showAbsoluteValues() ) correlation = std::abs( correlation );
|
||||
anyValidResults = true;
|
||||
}
|
||||
}
|
||||
correlations.push_back( correlation );
|
||||
resultLabels.push_back( resultLabel );
|
||||
}
|
||||
if ( anyValidResults )
|
||||
{
|
||||
correlationMatrixColumns.push_back(
|
||||
CorrelationMatrixRowOrColumn( parameter.name, correlations, resultLabels ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eraseInvalidEntries( correlationMatrixColumns );
|
||||
if ( m_sortByValues() ) sortEntries( correlationMatrixColumns );
|
||||
|
||||
auto correlationMatrixRows = transpose( correlationMatrixColumns );
|
||||
|
||||
eraseInvalidEntries( correlationMatrixRows );
|
||||
if ( m_sortByValues() ) sortEntries( correlationMatrixRows );
|
||||
|
||||
for ( size_t rowIdx = 0u; rowIdx < correlationMatrixRows.size(); ++rowIdx )
|
||||
{
|
||||
for ( size_t colIdx = 0u; colIdx < correlationMatrixRows[rowIdx].m_values.size(); ++colIdx )
|
||||
{
|
||||
double correlation = correlationMatrixRows[rowIdx].m_values[colIdx];
|
||||
auto label = QString( "%1" ).arg( correlation, 0, 'f', 2 );
|
||||
cvf::Color3ub color = m_legendConfig->scalarMapper()->mapToColor( correlation );
|
||||
QColor qColor( color.r(), color.g(), color.b() );
|
||||
QwtPlotItem* rectangle = RiuQwtPlotTools::createBoxShape( label,
|
||||
(double)colIdx,
|
||||
(double)colIdx + 1.0,
|
||||
(double)rowIdx,
|
||||
(double)rowIdx + 1,
|
||||
qColor );
|
||||
QwtText textLabel( label );
|
||||
cvf::Color3f contrastColor = RiaColorTools::contrastColor( cvf::Color3f( color ) );
|
||||
textLabel.setColor( RiaColorTools::toQColor( contrastColor ) );
|
||||
QFont font = textLabel.font();
|
||||
font.setPixelSize( RiaFontCache::pointSizeToPixelSize( 7 ) );
|
||||
textLabel.setFont( font );
|
||||
QwtPlotMarker* marker = new QwtPlotMarker();
|
||||
marker->setLabel( textLabel );
|
||||
marker->setXValue( colIdx + 0.5 );
|
||||
marker->setYValue( rowIdx + 0.5 );
|
||||
rectangle->attach( m_plotWidget );
|
||||
marker->attach( m_plotWidget );
|
||||
m_paramLabels[colIdx] = correlationMatrixRows[rowIdx].m_entryLabels[colIdx];
|
||||
}
|
||||
m_resultLabels[rowIdx] = correlationMatrixRows[rowIdx].m_label;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCorrelationMatrixPlot::updatePlotTitle()
|
||||
{
|
||||
if ( m_useAutoPlotTitle )
|
||||
{
|
||||
m_description = QString( "%1 Matrix for Parameters vs Result Vectors" ).arg( m_correlationFactor().uiText() );
|
||||
}
|
||||
m_plotWidget->setPlotTitle( m_description );
|
||||
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle && isMdiWindow() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCorrelationMatrixPlot::updateLegend()
|
||||
{
|
||||
if ( m_showAbsoluteValues )
|
||||
{
|
||||
m_legendConfig->setAutomaticRanges( -1.0, 1.0, -1.0, 1.0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_legendConfig->setAutomaticRanges( 0.0, 1.0, 0.0, 1.0 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020 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 "RimCorrelationPlot.h"
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
class RimRegularLegendConfig;
|
||||
class RimSummaryAddress;
|
||||
class RiuGroupedBarChartBuilder;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimCorrelationMatrixPlot : public RimAbstractCorrelationPlot
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
using CorrelationFactor = RimCorrelationPlot::CorrelationFactor;
|
||||
using CorrelationFactorEnum = RimCorrelationPlot::CorrelationFactorEnum;
|
||||
|
||||
public:
|
||||
RimCorrelationMatrixPlot();
|
||||
~RimCorrelationMatrixPlot() override;
|
||||
|
||||
private:
|
||||
// Overridden PDM methods
|
||||
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly ) override;
|
||||
|
||||
void onLoadDataAndUpdate() override;
|
||||
|
||||
void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override;
|
||||
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override;
|
||||
|
||||
void updateAxes() override;
|
||||
|
||||
// Private methods
|
||||
void createMatrix();
|
||||
void updatePlotTitle() override;
|
||||
void updateLegend() override;
|
||||
|
||||
private:
|
||||
caf::PdmField<CorrelationFactorEnum> m_correlationFactor;
|
||||
caf::PdmField<bool> m_showAbsoluteValues;
|
||||
caf::PdmField<bool> m_sortByValues;
|
||||
caf::PdmChildField<RimRegularLegendConfig*> m_legendConfig;
|
||||
|
||||
std::map<size_t, QString> m_paramLabels;
|
||||
std::map<size_t, QString> m_resultLabels;
|
||||
};
|
||||
@@ -110,8 +110,8 @@ void RimCorrelationPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrder
|
||||
}
|
||||
|
||||
caf::PdmUiGroup* curveDataGroup = uiOrdering.addNewGroup( "Summary Vector" );
|
||||
curveDataGroup->add( &m_ensemble );
|
||||
curveDataGroup->add( &m_summaryAddressUiField );
|
||||
|
||||
curveDataGroup->add( &m_selectedVarsUiField );
|
||||
curveDataGroup->add( &m_pushButtonSelectSummaryAddress, { false, 1, 0 } );
|
||||
curveDataGroup->add( &m_timeStep );
|
||||
|
||||
@@ -119,6 +119,8 @@ void RimCorrelationPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrder
|
||||
plotGroup->add( &m_showPlotTitle );
|
||||
plotGroup->add( &m_useAutoPlotTitle );
|
||||
plotGroup->add( &m_description );
|
||||
RimPlot::defineUiOrdering( uiConfigName, *plotGroup );
|
||||
|
||||
m_description.uiCapability()->setUiReadOnly( m_useAutoPlotTitle() );
|
||||
uiOrdering.skipRemainingFields( true );
|
||||
}
|
||||
@@ -142,9 +144,12 @@ void RimCorrelationPlot::onLoadDataAndUpdate()
|
||||
{
|
||||
updateMdiWindowVisibility();
|
||||
|
||||
m_summaryAddressUiField = m_summaryAddress->address();
|
||||
m_analyserOfSelectedCurveDefs = std::unique_ptr<RiaSummaryCurveDefinitionAnalyser>(
|
||||
new RiaSummaryCurveDefinitionAnalyser( this->curveDefinitions() ) );
|
||||
|
||||
if ( m_plotWidget )
|
||||
m_selectedVarsUiField = selectedVarsText();
|
||||
|
||||
if ( m_plotWidget && m_analyserOfSelectedCurveDefs )
|
||||
{
|
||||
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotBarChart );
|
||||
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotScale );
|
||||
@@ -198,18 +203,18 @@ void RimCorrelationPlot::addDataToChartBuilder( RiuGroupedBarChartBuilder& chart
|
||||
{
|
||||
time_t selectedTimestep = m_timeStep().toTime_t();
|
||||
|
||||
if ( !m_ensemble ) return;
|
||||
|
||||
if ( !m_summaryAddress ) return;
|
||||
|
||||
std::vector<EnsembleParameter> ensembleParameters = m_ensemble->variationSortedEnsembleParameters();
|
||||
if ( ensembles().empty() ) return;
|
||||
if ( addresses().empty() ) return;
|
||||
|
||||
std::vector<double> caseValuesAtTimestep;
|
||||
std::map<QString, std::vector<double>> parameterValues;
|
||||
|
||||
for ( size_t caseIdx = 0u; caseIdx < m_ensemble->allSummaryCases().size(); ++caseIdx )
|
||||
auto ensemble = *ensembles().begin();
|
||||
auto address = *addresses().begin();
|
||||
|
||||
for ( size_t caseIdx = 0u; caseIdx < ensemble->allSummaryCases().size(); ++caseIdx )
|
||||
{
|
||||
auto summaryCase = m_ensemble->allSummaryCases()[caseIdx];
|
||||
auto summaryCase = ensemble->allSummaryCases()[caseIdx];
|
||||
|
||||
RifSummaryReaderInterface* reader = summaryCase->summaryReader();
|
||||
if ( !reader ) continue;
|
||||
@@ -220,9 +225,9 @@ void RimCorrelationPlot::addDataToChartBuilder( RiuGroupedBarChartBuilder& chart
|
||||
|
||||
double closestValue = std::numeric_limits<double>::infinity();
|
||||
time_t closestTimeStep = 0;
|
||||
if ( reader->values( m_summaryAddress->address(), &values ) )
|
||||
if ( reader->values( address, &values ) )
|
||||
{
|
||||
const std::vector<time_t>& timeSteps = reader->timeSteps( m_summaryAddress->address() );
|
||||
const std::vector<time_t>& timeSteps = reader->timeSteps( address );
|
||||
for ( size_t i = 0; i < timeSteps.size(); ++i )
|
||||
{
|
||||
if ( timeDiff( timeSteps[i], selectedTimestep ) < timeDiff( selectedTimestep, closestTimeStep ) )
|
||||
@@ -236,7 +241,7 @@ void RimCorrelationPlot::addDataToChartBuilder( RiuGroupedBarChartBuilder& chart
|
||||
{
|
||||
caseValuesAtTimestep.push_back( closestValue );
|
||||
|
||||
for ( auto parameter : ensembleParameters )
|
||||
for ( auto parameter : ensembleParameters() )
|
||||
{
|
||||
if ( parameter.isNumeric() && parameter.isValid() )
|
||||
{
|
||||
@@ -281,9 +286,7 @@ void RimCorrelationPlot::updatePlotTitle()
|
||||
{
|
||||
if ( m_useAutoPlotTitle )
|
||||
{
|
||||
m_description = QString( "%1 for %2" )
|
||||
.arg( m_correlationFactor().uiText() )
|
||||
.arg( QString::fromStdString( m_summaryAddressUiField().uiText() ) );
|
||||
m_description = QString( "%1 for %2" ).arg( m_correlationFactor().uiText() ).arg( m_selectedVarsUiField );
|
||||
}
|
||||
m_plotWidget->setPlotTitle( m_description );
|
||||
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle && isMdiWindow() );
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "RimCorrelationPlotCollection.h"
|
||||
|
||||
#include "RimCorrelationMatrixPlot.h"
|
||||
#include "RimCorrelationPlot.h"
|
||||
#include "RimParameterResultCrossPlot.h"
|
||||
|
||||
@@ -49,7 +50,19 @@ RimCorrelationPlot* RimCorrelationPlotCollection::createCorrelationPlot()
|
||||
RimCorrelationPlot* plot = new RimCorrelationPlot();
|
||||
plot->setAsPlotMdiWindow();
|
||||
|
||||
// plot->enableAutoPlotTitle( true );
|
||||
m_correlationPlots.push_back( plot );
|
||||
|
||||
return plot;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCorrelationMatrixPlot* RimCorrelationPlotCollection::createCorrelationMatrixPlot()
|
||||
{
|
||||
RimCorrelationMatrixPlot* plot = new RimCorrelationMatrixPlot();
|
||||
plot->setAsPlotMdiWindow();
|
||||
|
||||
m_correlationPlots.push_back( plot );
|
||||
|
||||
return plot;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
class RimAbstractCorrelationPlot;
|
||||
class RimCorrelationPlot;
|
||||
class RimCorrelationMatrixPlot;
|
||||
class RimParameterResultCrossPlot;
|
||||
|
||||
//==================================================================================================
|
||||
@@ -38,6 +39,7 @@ public:
|
||||
~RimCorrelationPlotCollection() override;
|
||||
|
||||
RimCorrelationPlot* createCorrelationPlot();
|
||||
RimCorrelationMatrixPlot* createCorrelationMatrixPlot();
|
||||
RimParameterResultCrossPlot* createParameterResultCrossPlot();
|
||||
void removePlot( RimAbstractCorrelationPlot* CorrelationPlot );
|
||||
|
||||
|
||||
@@ -93,9 +93,10 @@ void RimParameterResultCrossPlot::fieldChangedByUi( const caf::PdmFieldHandle* c
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimParameterResultCrossPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
||||
{
|
||||
m_selectedVarsUiField = selectedVarsText();
|
||||
|
||||
caf::PdmUiGroup* curveDataGroup = uiOrdering.addNewGroup( "Summary Vector" );
|
||||
curveDataGroup->add( &m_ensemble );
|
||||
curveDataGroup->add( &m_summaryAddressUiField );
|
||||
curveDataGroup->add( &m_selectedVarsUiField );
|
||||
curveDataGroup->add( &m_pushButtonSelectSummaryAddress, { false, 1, 0 } );
|
||||
curveDataGroup->add( &m_timeStep );
|
||||
|
||||
@@ -106,6 +107,8 @@ void RimParameterResultCrossPlot::defineUiOrdering( QString uiConfigName, caf::P
|
||||
plotGroup->add( &m_showPlotTitle );
|
||||
plotGroup->add( &m_useAutoPlotTitle );
|
||||
plotGroup->add( &m_description );
|
||||
RimPlot::defineUiOrdering( uiConfigName, *plotGroup );
|
||||
|
||||
m_description.uiCapability()->setUiReadOnly( m_useAutoPlotTitle() );
|
||||
uiOrdering.skipRemainingFields( true );
|
||||
}
|
||||
@@ -120,12 +123,9 @@ QList<caf::PdmOptionItemInfo>
|
||||
RimAbstractCorrelationPlot::calculateValueOptions( fieldNeedingOptions, useOptionsOnly );
|
||||
if ( fieldNeedingOptions == &m_ensembleParameter )
|
||||
{
|
||||
if ( m_ensemble )
|
||||
for ( const auto& param : ensembleParameters() )
|
||||
{
|
||||
for ( const auto& param : m_ensemble->variationSortedEnsembleParameters() )
|
||||
{
|
||||
options.push_back( caf::PdmOptionItemInfo( param.uiName(), param.name ) );
|
||||
}
|
||||
options.push_back( caf::PdmOptionItemInfo( param.uiName(), param.name ) );
|
||||
}
|
||||
}
|
||||
return options;
|
||||
@@ -138,9 +138,12 @@ void RimParameterResultCrossPlot::onLoadDataAndUpdate()
|
||||
{
|
||||
updateMdiWindowVisibility();
|
||||
|
||||
m_summaryAddressUiField = m_summaryAddress->address();
|
||||
m_analyserOfSelectedCurveDefs = std::unique_ptr<RiaSummaryCurveDefinitionAnalyser>(
|
||||
new RiaSummaryCurveDefinitionAnalyser( this->curveDefinitions() ) );
|
||||
|
||||
if ( m_plotWidget )
|
||||
m_selectedVarsUiField = selectedVarsText();
|
||||
|
||||
if ( m_plotWidget && m_analyserOfSelectedCurveDefs )
|
||||
{
|
||||
m_plotWidget->insertLegend( nullptr );
|
||||
m_plotWidget->updateLegend();
|
||||
@@ -160,7 +163,7 @@ void RimParameterResultCrossPlot::updateAxes()
|
||||
{
|
||||
if ( !m_plotWidget ) return;
|
||||
|
||||
m_plotWidget->setAxisTitleText( QwtPlot::yLeft, QString::fromStdString( m_summaryAddressUiField().uiText() ) );
|
||||
m_plotWidget->setAxisTitleText( QwtPlot::yLeft, m_selectedVarsUiField );
|
||||
m_plotWidget->setAxisTitleEnabled( QwtPlot::yLeft, true );
|
||||
m_plotWidget->setAxisAutoScale( QwtPlot::yLeft, true );
|
||||
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::yLeft, 11, 11, false, Qt::AlignCenter );
|
||||
@@ -178,19 +181,22 @@ void RimParameterResultCrossPlot::createPoints()
|
||||
{
|
||||
time_t selectedTimestep = m_timeStep().toTime_t();
|
||||
|
||||
if ( !m_ensemble ) return;
|
||||
caf::ColorTable colorTable = RiaColorTables::categoryPaletteColors();
|
||||
|
||||
if ( !m_summaryAddress ) return;
|
||||
if ( ensembles().empty() ) return;
|
||||
if ( addresses().empty() ) return;
|
||||
|
||||
EnsembleParameter ensembleParameter = m_ensemble->ensembleParameter( m_ensembleParameter );
|
||||
if ( !( ensembleParameter.isNumeric() && ensembleParameter.isValid() ) ) return;
|
||||
auto ensemble = *ensembles().begin();
|
||||
auto address = *addresses().begin();
|
||||
EnsembleParameter parameter = ensembleParameter( m_ensembleParameter );
|
||||
if ( !( parameter.isNumeric() && parameter.isValid() ) ) return;
|
||||
|
||||
for ( size_t caseIdx = 0u; caseIdx < m_ensemble->allSummaryCases().size(); ++caseIdx )
|
||||
for ( size_t caseIdx = 0u; caseIdx < ensemble->allSummaryCases().size(); ++caseIdx )
|
||||
{
|
||||
std::vector<double> caseValuesAtTimestep;
|
||||
std::vector<double> parameterValues;
|
||||
|
||||
auto summaryCase = m_ensemble->allSummaryCases()[caseIdx];
|
||||
auto summaryCase = ensemble->allSummaryCases()[caseIdx];
|
||||
|
||||
RifSummaryReaderInterface* reader = summaryCase->summaryReader();
|
||||
if ( !reader ) continue;
|
||||
@@ -201,9 +207,9 @@ void RimParameterResultCrossPlot::createPoints()
|
||||
|
||||
double closestValue = std::numeric_limits<double>::infinity();
|
||||
time_t closestTimeStep = 0;
|
||||
if ( reader->values( m_summaryAddress->address(), &values ) )
|
||||
if ( reader->values( address, &values ) )
|
||||
{
|
||||
const std::vector<time_t>& timeSteps = reader->timeSteps( m_summaryAddress->address() );
|
||||
const std::vector<time_t>& timeSteps = reader->timeSteps( address );
|
||||
for ( size_t i = 0; i < timeSteps.size(); ++i )
|
||||
{
|
||||
if ( timeDiff( timeSteps[i], selectedTimestep ) < timeDiff( selectedTimestep, closestTimeStep ) )
|
||||
@@ -216,18 +222,15 @@ void RimParameterResultCrossPlot::createPoints()
|
||||
if ( closestValue != std::numeric_limits<double>::infinity() )
|
||||
{
|
||||
caseValuesAtTimestep.push_back( closestValue );
|
||||
double paramValue = ensembleParameter.values[caseIdx].toDouble();
|
||||
double paramValue = parameter.values[caseIdx].toDouble();
|
||||
parameterValues.push_back( paramValue );
|
||||
|
||||
RiuQwtPlotCurve* plotCurve = new RiuQwtPlotCurve;
|
||||
plotCurve->setSamplesFromXValuesAndYValues( parameterValues, caseValuesAtTimestep, false );
|
||||
plotCurve->setAppearance( RiuQwtPlotCurve::STYLE_NONE,
|
||||
RiuQwtPlotCurve::INTERPOLATION_POINT_TO_POINT,
|
||||
0,
|
||||
QColor( Qt::red ) );
|
||||
RiuQwtSymbol* symbol = new RiuQwtSymbol( RiuQwtSymbol::SYMBOL_ELLIPSE, "" );
|
||||
QwtPlotCurve* plotCurve = new QwtPlotCurve;
|
||||
plotCurve->setSamples( parameterValues.data(), caseValuesAtTimestep.data(), (int)parameterValues.size() );
|
||||
plotCurve->setStyle( QwtPlotCurve::NoCurve );
|
||||
RiuQwtSymbol* symbol = new RiuQwtSymbol( RiuQwtSymbol::SYMBOL_DIAMOND, "" );
|
||||
symbol->setSize( 12, 12 );
|
||||
symbol->setColor( QColor( Qt::red ) );
|
||||
symbol->setColor( colorTable.cycledQColor( caseIdx ) );
|
||||
plotCurve->setSymbol( symbol );
|
||||
plotCurve->attach( m_plotWidget );
|
||||
}
|
||||
@@ -241,9 +244,7 @@ void RimParameterResultCrossPlot::updatePlotTitle()
|
||||
{
|
||||
if ( m_useAutoPlotTitle )
|
||||
{
|
||||
m_description = QString( "Cross Plot %1 x %2" )
|
||||
.arg( m_ensembleParameter )
|
||||
.arg( QString::fromStdString( m_summaryAddressUiField().uiText() ) );
|
||||
m_description = QString( "Cross Plot %1 x %2" ).arg( m_ensembleParameter ).arg( m_selectedVarsUiField() );
|
||||
}
|
||||
m_plotWidget->setPlotTitle( m_description );
|
||||
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle && isMdiWindow() );
|
||||
|
||||
Reference in New Issue
Block a user