Skip to content

Commit

Permalink
Merge branch 'main' into backend-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdp committed Nov 27, 2023
2 parents b42d042 + 3c59974 commit 9482a87
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 454 deletions.
378 changes: 104 additions & 274 deletions backend/poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pandas = {version = "2.0.1", extras = ["performance"]}
httpx = "^0.24.0"
psutil = "^5.9.5"
vtk = "^9.2.6"
fmu-sumo = "^0.5.4"
sumo-wrapper-python = "^0.4.1"
fmu-sumo = "1.0.3"
sumo-wrapper-python = "1.0.6"
azure-monitor-opentelemetry = "^1.1.0"


Expand Down
120 changes: 0 additions & 120 deletions backend/src/services/sumo_access/dev_sumo_access_test_driver.py

This file was deleted.

4 changes: 2 additions & 2 deletions backend/src/services/sumo_access/grid_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def get_grid_geometry(self, grid_name: str, realization: int) -> xtgeo.Gri
)
stream = self._sumo_client.get(f"/objects('{geometry_blob_id}')/blob")
print(f"{grid_name} {realization} {geometry_blob_id} in {round(timer.lap_s(),2)}s")
grid_geom = xtgeo.grid_from_file(BytesIO(stream))
grid_geom = xtgeo.grid_from_file(BytesIO(stream.content))

return grid_geom

Expand All @@ -58,7 +58,7 @@ async def get_grid_parameter(
)
stream = self._sumo_client.get(f"/objects('{parameter_blob_id}')/blob")
print(f"{grid_name} {grid_parameter_name} {realization} {parameter_blob_id} in {round(timer.lap_s(),2)}s")
grid_param = xtgeo.gridproperty_from_file(BytesIO(stream))
grid_param = xtgeo.gridproperty_from_file(BytesIO(stream.content))
return grid_param

async def grids_have_equal_nxnynz(self, grid_name: str) -> bool:
Expand Down
32 changes: 16 additions & 16 deletions backend/src/services/sumo_access/queries/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@

async def get_stratigraphic_column_identifier(sumo_client: SumoClient, case_id: str) -> str:
"""Get stratigraphic column identifier for a case (assuming unique for all objects)"""
response = await sumo_client.get_async(
"/search",
query=f"_sumo.parent_object:{case_id}",
size=1,
select="masterdata.smda.stratigraphic_column.identifier",
)

hits = response["hits"]["hits"]
params = {
"query": f"_sumo.parent_object:{case_id}",
"size": 1,
"select": "masterdata.smda.stratigraphic_column.identifier",
}
response = await sumo_client.get_async("/search", params)
result = response.json()
hits = result["hits"]["hits"]
return hits[0]["_source"]["masterdata"]["smda"]["stratigraphic_column"]["identifier"]


async def get_field_identifiers(sumo_client: SumoClient, case_id: str) -> List[str]:
"""Get field identifiers for a case (assuming unique for all objects)"""
response = await sumo_client.get_async(
"/search",
query=f"_sumo.parent_object:{case_id}",
size=1,
select="masterdata.smda.field.identifier",
)

hits = response["hits"]["hits"]
params = {
"query": f"_sumo.parent_object:{case_id}",
"size": 1,
"select": "masterdata.smda.field.identifier",
}
response = await sumo_client.get_async("/search", params)
result = response.json()
hits = result["hits"]["hits"]
fields = hits[0]["_source"]["masterdata"]["smda"]["field"]
return [field["identifier"] for field in fields]
98 changes: 58 additions & 40 deletions backend/src/services/sumo_access/queries/cpgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

async def get_grid_names(sumo_client: SumoClient, case_id: str, iteration: str) -> List[str]:
"""Get a list of grid names for a case and iteration"""
query = {
payload = {
"size": 0,
"query": {
"bool": {
Expand All @@ -25,7 +25,7 @@ async def get_grid_names(sumo_client: SumoClient, case_id: str, iteration: str)
}
},
}
response = await sumo_client.post_async("/search", json=query)
response = await sumo_client.post_async("/search", json=payload)

result = response.json()
grid_names = result.get("aggregations").get("grid_names").get("buckets")
Expand All @@ -38,7 +38,7 @@ async def get_grid_geometry_checksums(
sumo_client: SumoClient, case_id: str, iteration: str, grid_name: str
) -> List[str]:
"""Get a list of checksums for a grid geometry in a case and iteration"""
query = {
payload = {
"size": 0,
"query": {
"bool": {
Expand All @@ -59,7 +59,7 @@ async def get_grid_geometry_checksums(
}
},
}
response = sumo_client.post_async("/search", json=query)
response = sumo_client.post_async("/search", json=payload)

result = response.json()
checksums = result.get("aggregations").get("checksums").get("buckets")
Expand All @@ -75,18 +75,25 @@ async def get_grid_geometry_blob_id(
grid_name: str,
) -> str:
"""Get the blob id for a given grid geometry in a case, iteration and realization"""
response = await sumo_client.get_async(
"/search",
query=f"_sumo.parent_object:{case_id} AND \
class.keyword:cpgrid AND \
fmu.iteration.name:{iteration} AND \
fmu.realization.id:{realization} AND \
data.name.keyword:{grid_name}",
size=1000,
select="_id",
)

hits = response["hits"]["hits"]
payload = {
"query": {
"bool": {
"must": [
{"match": {"_sumo.parent_object.keyword": case_id}},
{"match": {"class": "cpgrid"}},
{"match": {"fmu.iteration.name": iteration}},
{"match": {"fmu.realization.id": realization}},
{"match": {"data.name.keyword": grid_name}},
]
}
},
"size": 1,
}
response = await sumo_client.post_async("/search", json=payload)

result = response.json()
hits = result["hits"]["hits"]
print(hits)
if len(hits) != 1:
raise ValueError(f"Expected 1 hit, got {len(hits)}")
return [hit["_id"] for hit in hits][0]
Expand All @@ -101,19 +108,25 @@ async def get_grid_parameter_blob_id(
parameter_name: str,
) -> str:
"""Get the blob id for a given grid parameter in a case, iteration and realization""" ""
response = await sumo_client.get_async(
"/search",
query=f"_sumo.parent_object:{case_id} AND \
class.keyword:cpgrid_property AND \
fmu.iteration.name:{iteration} AND \
fmu.realization.id:{realization} AND \
data.name.keyword:{parameter_name} AND \
data.tagname.keyword:{grid_name}",
size=1000,
select="_id",
)

hits = response["hits"]["hits"]
payload = {
"query": {
"bool": {
"must": [
{"match": {"_sumo.parent_object.keyword": case_id}},
{"match": {"class": "cpgrid_property"}},
{"match": {"fmu.iteration.name": iteration}},
{"match": {"fmu.realization.id": realization}},
{"match": {"data.name.keyword": parameter_name}},
{"match": {"data.tagname.keyword": grid_name}},
]
}
},
"size": 1,
}
response = await sumo_client.post_async("/search", json=payload)

result = response.json()
hits = result["hits"]["hits"]

if len(hits) != 1:
raise ValueError(f"Expected 1 hit, got {len(hits)}")
Expand Down Expand Up @@ -158,18 +171,23 @@ async def get_nx_ny_nz_for_ensemble_grids(
sumo_client: SumoClient, case_uuid: str, iteration: str, grid_name: str
) -> List[List[int]]:
"""Get a list of nxnynz for all realizations of a grid model in a case and iteration"""
payload = {
"query": {
"bool": {
"must": [
{"match": {"_sumo.parent_object.keyword": case_uuid}},
{"match": {"class": "cpgrid"}},
{"match": {"fmu.iteration.name": iteration}},
{"match": {"data.name.keyword": grid_name}},
]
}
},
"size": 1000,
}

response = await sumo_client.get_async(
"/search",
query=f"_sumo.parent_object:{case_uuid} AND \
class.keyword:cpgrid AND \
fmu.iteration.name:{iteration} AND \
data.name.keyword:{grid_name}",
size=1000,
select="data",
)

hits = response["hits"]["hits"]
response = await sumo_client.post_async("/search", json=payload)
result = response.json()
hits = result["hits"]["hits"]

nxnynz = []
for hit in hits:
Expand Down

0 comments on commit 9482a87

Please sign in to comment.