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

update README and fix filtering on bool properties #252

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ cases.users
cases.fields

# Apply filters
cases = cases.filter(status=["keep", "offical"], user="peesv", field="Drogon")
cases = cases.filter(status=["keep", "offical"], user="peesv", field="DROGON")

for case in cases:
print(case.id)
print(case.uuid)
print(case.name)

# select case
Expand All @@ -44,21 +44,21 @@ Get objects within a case through `case.[CONTEXT].[OBJECT_TYPE]`.
##### Realized data
```python
# All realized surface objects in case
surfs = case.realization.surfaces
surfs = case.surfaces

# Get filter values
surfs.names
surfs.tagnames
surfs.iterations

# Apply filters
surfs = surfs.filter(name="surface_name", tagname="surface_tagname", iteration=0)
surfs = surfs.filter(name="surface_name", tagname="surface_tagname", iteration="iter-0")

# Get surface
surf = surfs[0]

# Metadata
surf.id
surf.uuid
surf.name
surf.tagname
surf.iteration
Expand All @@ -68,23 +68,24 @@ surf.realization
surf.blob

# Get xtgeo.RegularSurface
%matplotlib inline
reg = surf.to_regular_surface()
reg.quickplot()
```

##### Aggregated data
```python
# All aggregated surfaces in case
surfs = case.aggregation.surfaces
surfs = case.surfaces.filter(aggregation=True)

# Get filter values
surfs.names
surfs.tagnames
surfs.iterations
surfs.operations
surfs.aggregations

# Apply filters
surfs = surfs.filter(name="surface_name", tagname="surface_tagname", iteration=0, operation="mean")
surfs = surfs.filter(name="surface_name", tagname="surface_tagname", iteration="iter-0", aggregation="mean")

# Get surface
surf = surfs[0]
Expand All @@ -94,7 +95,7 @@ surf = surfs[0]
##### Observed data
```python
# All observed surfaces in case
surfs = case.observation.surfaces
surfs = case.surfaces.filter(is_observation=True)

# Get filter values
surfs.names
Expand Down
14 changes: 10 additions & 4 deletions src/fmu/sumo/explorer/objects/_child_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ def _add_filter(
"fmu.context.stage.keyword": stage,
"data.spec.columns.keyword": column,
"_id": uuid,
"data.stratigraphic.keyword": stratigraphic,
"data.vertical_domain.keyword": vertical_domain,
"data.is_observation.keyword": is_observation,
"data.is_prediction.keyword": is_prediction
"data.vertical_domain.keyword": vertical_domain
}

for prop, value in prop_map.items():
Expand All @@ -183,6 +180,15 @@ def _add_filter(
term = "terms" if isinstance(value, list) else "term"
must.append({term: {prop: value}})

bool_prop_map = {
"data.stratigraphic": stratigraphic,
"data.is_observation": is_observation,
"data.is_prediction": is_prediction
}
for prop, value in bool_prop_map.items():
if value is not None:
must.append({"term": {prop: value}})

query = {"bool": {}}

if len(must) > 0:
Expand Down
6 changes: 5 additions & 1 deletion src/fmu/sumo/explorer/objects/surface_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def filter(
stage: Union[str, List[str], bool] = None,
time: TimeFilter = None,
uuid: Union[str, List[str], bool] = None,
is_observation: bool = None,
is_prediction: bool = None
) -> "SurfaceCollection":
"""Filter surfaces
Expand Down Expand Up @@ -216,7 +218,7 @@ def filter(
Get all aggregated surfaces::
surfs = case.surfacse.filter(
surfs = case.surfaces.filter(
aggregation=True
)
Expand All @@ -239,6 +241,8 @@ def filter(
uuid=uuid,
stratigraphic=stratigraphic,
vertical_domain=vertical_domain,
is_observation=is_observation,
is_prediction=is_prediction
)

return SurfaceCollection(self._sumo, self._case_uuid, query, self._pit)
Expand Down
Loading