mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 06:38:13 -05:00
#13841 Python: Add available_properties API for regular surfaces
This commit is contained in:
1 parent
288f9a4a44
commit
b707c4588b
7 files changed
+107
-1
No files matched your search
@@ -415,6 +415,19 @@ std::vector<float> RimRegularSurface::getProperty( const QString& key ) const
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RimRegularSurface::propertyNames() const
|
||||
{
|
||||
std::vector<QString> names;
|
||||
for ( const auto& [key, value] : m_properties )
|
||||
{
|
||||
names.push_back( key );
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -42,7 +42,8 @@ public:
|
||||
void setProperty( const QString& key, const std::vector<float>& values );
|
||||
void setPropertyAsDepth( const QString& key );
|
||||
|
||||
std::vector<float> getProperty( const QString& key ) const;
|
||||
std::vector<float> getProperty( const QString& key ) const;
|
||||
std::vector<QString> propertyNames() const;
|
||||
|
||||
int nx() const;
|
||||
int ny() const;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "RimRegularSurface.h"
|
||||
#include "RimSurfaceCollection.h"
|
||||
#include "RimcDataContainerString.h"
|
||||
|
||||
#include "RifSurfaceExporter.h"
|
||||
|
||||
@@ -138,3 +139,36 @@ std::expected<caf::PdmObjectHandle*, QString> RimcRegularSurface_setPropertyAsDe
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimRegularSurface, RimcRegularSurface_propertyNames, "PropertyNames" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimcRegularSurface_propertyNames::RimcRegularSurface_propertyNames( caf::PdmObjectHandle* self )
|
||||
: PdmObjectMethod( self, PdmObjectMethod::NullPointerType::NULL_IS_INVALID, PdmObjectMethod::ResultType::PERSISTENT_FALSE )
|
||||
{
|
||||
CAF_PDM_InitObject( "Property Names", "", "", "Property Names." );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimcRegularSurface_propertyNames::execute()
|
||||
{
|
||||
RimRegularSurface* surface = self<RimRegularSurface>();
|
||||
if ( !surface ) return std::unexpected( "No surface found" );
|
||||
|
||||
auto dataObject = new RimcDataContainerString();
|
||||
dataObject->m_stringValues = surface->propertyNames();
|
||||
|
||||
return dataObject;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimcRegularSurface_propertyNames::classKeywordReturnedType() const
|
||||
{
|
||||
return RimcDataContainerString::classKeywordStatic();
|
||||
}
|
||||
@@ -75,3 +75,17 @@ public:
|
||||
private:
|
||||
caf::PdmField<QString> m_name;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimcRegularSurface_propertyNames : public caf::PdmObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimcRegularSurface_propertyNames( caf::PdmObjectHandle* self );
|
||||
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
QString classKeywordReturnedType() const override;
|
||||
};
|
||||
+4
@@ -83,5 +83,9 @@ if resinsight is not None:
|
||||
f"Retrieved {len(wave_values)} wave property values, min={min(wave_values):.2f}, max={max(wave_values):.2f}"
|
||||
)
|
||||
|
||||
# List available properties
|
||||
props = s.available_properties()
|
||||
print(f"Available properties: {props}")
|
||||
|
||||
# Use the wave as depth for the surface
|
||||
s.set_property_as_depth("wave")
|
||||
@@ -25,6 +25,17 @@ def set_property(self: RegularSurface, name: str, values: List[float]) -> None:
|
||||
self.set_property_from_key(name=name, value_key=key)
|
||||
|
||||
|
||||
@add_method(RegularSurface)
|
||||
def available_properties(self: RegularSurface) -> List[str]:
|
||||
"""Gets the list of available property names on a regular surface.
|
||||
|
||||
Returns:
|
||||
List[str]: Names of all properties set on this surface.
|
||||
"""
|
||||
result = self.property_names()
|
||||
return result.values
|
||||
|
||||
|
||||
@add_method(RegularSurface)
|
||||
def get_property(self: RegularSurface, name: str) -> List[float]:
|
||||
"""Gets a property from a regular surface.
|
||||
|
||||
@@ -106,6 +106,35 @@ def test_get_property(rips_instance, initialize_test):
|
||||
s.get_property("non_existent_property")
|
||||
|
||||
|
||||
def test_available_properties(rips_instance, initialize_test):
|
||||
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
|
||||
c = rips_instance.project.load_case(path=case_path)
|
||||
assert len(c.grids()) == 1
|
||||
|
||||
surface_collection = rips_instance.project.descendants(rips.SurfaceCollection)[0]
|
||||
|
||||
nx = 5
|
||||
ny = 4
|
||||
s = surface_collection.new_regular_surface(nx=nx, ny=ny)
|
||||
|
||||
# Empty property list initially
|
||||
props = s.available_properties()
|
||||
assert props == []
|
||||
|
||||
# Property names after setting one property
|
||||
s.set_property("prop_a", [float(i) for i in range(nx * ny)])
|
||||
props = s.available_properties()
|
||||
assert "prop_a" in props
|
||||
assert len(props) == 1
|
||||
|
||||
# Property names persist after setting multiple properties
|
||||
s.set_property("prop_b", [float(i) for i in range(nx * ny)])
|
||||
props = s.available_properties()
|
||||
assert len(props) == 2
|
||||
assert "prop_a" in props
|
||||
assert "prop_b" in props
|
||||
|
||||
|
||||
def test_create_regular_surface_invalid_values(rips_instance, initialize_test):
|
||||
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
|
||||
c = rips_instance.project.load_case(path=case_path)
|
||||
|
||||
Reference in new issue
Block a user