Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable filter on data.content. #310

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/explorer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ The `SurfaceCollection` object has a filter method and properties for getting fi

surfaces = case.surfaces.filter(iteration="iter-0")

contents = surfaces.contents

surfaces = surfaces.filter(
content=contents[0]
)

names = surfaces.names

surfaces = surfaces.filter(
Expand All @@ -243,7 +249,7 @@ The `SurfaceCollection.filter` method takes the following parameters:

* uuid
* name
* tagname
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional to remove tagname?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, intentional. It is a non-standardized freetext field, which will turn into a major problem down the road. So trying to nudge people away from using it. But it is there, so perhaps it should be in the docs. And it has to be there, because there is no uniqueness without it.

So perhaps this was a bad call 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put tagname back in

* content
* dataformat
* iteration
* realization
Expand Down Expand Up @@ -280,7 +286,7 @@ Example: get aggregated surfaces
We can get list of filter values for the following properties:

* names
* tagnames
* contents
* dataformats
* iterations
* realizations
Expand All @@ -304,6 +310,7 @@ Once we have a `Surface` object we can get surface metadata using properties:

surface = case.surfaces[0]

print(surface.content)
print(surface.uuid)
print(surface.name)
print(surface.tagname)
Expand Down Expand Up @@ -485,6 +492,7 @@ The `SurfaceCollection` class can be used to do on-demand surface aggregations.

surfaces = case.surfaces.filter(
stage="realization",
content="depth",
iteration="iter-0",
name="Valysar Fm.",
tagname="FACIES_Fraction_Channel"
Expand Down
14 changes: 10 additions & 4 deletions examples/explorer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
"# Filter on iteration\n",
"surfs = surfs.filter(iteration=\"iter-0\")\n",
"\n",
"# Get available contents\n",
"print(\"Contents:\", surfs.contents)\n",
"\n",
"# Filter on content\n",
"surfs = surfs.filter(content=\"depth\")\n",
"\n",
"# Get available names\n",
"print(\"Names:\", surfs.names)\n",
"\n",
Expand All @@ -136,18 +142,18 @@
" print(\"Format:\", surf.dataformat)\n",
" print(\"Realization:\", surf.realization)\n",
"\n",
"# Select surface instance\n",
"# Select one surface instance\n",
"surf = surfs[0]\n",
"\n",
"print(\"\\nSelected surface:\")\n",
"print(\"ID:\", surf.uuid)\n",
"print(\"Uuid:\", surf.uuid)\n",
"print(\"Name:\", surf.name)\n",
"print(\"Content:\", surf.content)\n",
"print(\"Tagname:\", surf.tagname)\n",
"print(\"Format:\", surf.dataformat)\n",
"print(\"Iteration:\", surf.iteration)\n",
"print(\"Realization:\", surf.realization)\n",
"print(\"stratigraphic\", surf.stratigraphic)\n",
perolavsvendsen marked this conversation as resolved.
Show resolved Hide resolved
"print(\"vertical domain\", surf.vertical_domain)\n",
"print(\"vertical domain:\", surf.vertical_domain)\n",
"\n",
"# xtgeo.RegularSurface\n",
"reg_surf = surf.to_regular_surface()\n",
Expand Down
5 changes: 5 additions & 0 deletions src/fmu/sumo/explorer/objects/_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def name(self) -> str:
"""Object name"""
return self._get_property(["data", "name"])

@property
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main change in this PR: Add content property to the child object.

def content(self) -> str:
"""Content"""
return self._get_property(["data", "content"])

@property
def tagname(self) -> str:
"""Object tagname"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ def test_case_surfaces_filter(test_case: Case):
assert surf.iteration == "iter-0"
assert surf.name == "Valysar Fm."

# filter on content
non_valid_content_surfs = real_surfs.filter(content="___not_valid")
assert len(non_valid_content_surfs) == 0

real_surfs = real_surfs.filter(content="depth")
assert len(real_surfs) == 56

# filter on tagname
non_valid_tagname_surfs = real_surfs.filter(tagname="___not_valid")
assert len(non_valid_tagname_surfs) == 0
Expand Down