Skip to content

Commit

Permalink
Temporary Troll fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv authored and rubenthoms committed Nov 13, 2024
1 parent 6164958 commit 79277a2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 50 deletions.
67 changes: 18 additions & 49 deletions backend_py/primary/primary/services/sumo_access/grid3d_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ async def get_models_info_arr_async(self, realization: int) -> List[Grid3dInfo]:
bbox = get_bbox_from_sumo_grid_obj(grid_geometry)

# Get the properties for the grid geometry
grid_geometry_name = grid_geometry_name if grid_geometry_name != "Geogrid" else ""
property_info_arr = await self.get_properties_info_arr_async(grid_geometry_name, realization)

grid_model_meta_arr.append(
Expand All @@ -118,12 +119,21 @@ async def get_properties_info_arr_async(
self, grid3d_geometry_name: str, realization: int
) -> List[Grid3dPropertyInfo]:
"""Get metadata for grid properties belonging to a grid geometry"""

grid3d_properties_collection: Grid3dPropertyCollection = Grid3dPropertyCollection(
sumo=self._sumo_client, case_uuid=self._case_uuid, grid3d_geometry_name=grid3d_geometry_name
)
grid3d_properties_collection_filtered = grid3d_properties_collection.filter(
iteration=self._iteration_name, realization=realization
)
if "TROLL" in grid3d_geometry_name:
query = grid3d_properties_collection._add_filter(
name=grid3d_geometry_name, iteration=self._iteration_name, realization=realization
)
grid3d_properties_collection_filtered = Grid3dPropertyCollection(
grid3d_geometry_name, self._sumo_client, self._case_uuid, query, None
)
else:
grid3d_properties_collection_filtered = grid3d_properties_collection.filter(
iteration=self._iteration_name, realization=realization
)

properties_meta: List[Grid3dPropertyInfo] = []
async for property_meta in grid3d_properties_collection_filtered:
Expand All @@ -136,7 +146,11 @@ async def get_properties_info_arr_async(
if t_start and t_end:
iso_string_or_time_interval = f"{t_start}/{t_end}"

property_name = property_meta["data"]["name"]
property_name = (
property_meta["data"]["name"]
if not "TROLL" in grid3d_geometry_name
else property_meta["data"]["tagname"]
)

grid3d_property_meta = Grid3dPropertyInfo(
property_name=property_name,
Expand Down Expand Up @@ -178,51 +192,6 @@ async def is_geometry_shared_async(self, grid3d_geometry_name: str) -> bool:

return True

async def get_geometry_blob_id_async(self, grid3d_geometry_name: str, realization: int) -> str:
"""Get the blob id of a grid geometry"""
grid_geometries_collection: Grid3dGeometryCollection = Grid3dGeometryCollection(
sumo=self._sumo_client, case_uuid=self._case_uuid
)
grid_geometry_as_collection = grid_geometries_collection.filter(
iteration=self._iteration_name,
name=grid3d_geometry_name,
aggregation=False,
realization=realization,
)
grid_geometry_name_as_arr = await grid_geometry_as_collection.names_async
if len(grid_geometry_name_as_arr) > 1:
raise MultipleDataMatchesError(
f"Multiple grid geometries found in case={self._case_uuid}, iteration={self._iteration_name}, grid_geometry_name={grid3d_geometry_name}",
Service.SUMO,
)
grid_geometry = await grid_geometry_as_collection.getitem_async(0)
return grid_geometry.uuid

async def get_property_blob_id_async(self, grid3d_geometry_name: str, property_name: str, realization: int) -> str:
"""Get the uuid of a grid property"""
grid3d_properties_collection: Grid3dPropertyCollection = Grid3dPropertyCollection(
sumo=self._sumo_client, case_uuid=self._case_uuid, grid3d_geometry_name=grid3d_geometry_name
)
grid_property_as_collection = grid3d_properties_collection.filter(
iteration=self._iteration_name,
name=property_name,
aggregation=False,
realization=realization,
)
grid_property_name_as_arr = await grid_property_as_collection.names_async
if len(grid_property_name_as_arr) == 0:
raise NoDataError(
f"No grid property with name {property_name} found in case={self._case_uuid}, iteration={self._iteration_name},realization={realization}, grid_geometry_name={grid3d_geometry_name}",
Service.SUMO,
)
if len(grid_property_name_as_arr) > 1:
raise MultipleDataMatchesError(
f"Multiple grid properties with name {property_name} found in case={self._case_uuid}, iteration={self._iteration_name},realization={realization}, grid_geometry_name={grid3d_geometry_name}",
Service.SUMO,
)
grid_property = await grid_property_as_collection.getitem_async(0)
return grid_property.uuid


def get_dimensions_from_sumo_grid_obj(grid_obj: Grid3dGeometry) -> Grid3dDimensions:
"""Extract the spec from a Sumo GridGeometry object"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ async def get_grid_geometry_and_property_blob_ids_async(
parameter_time_or_interval_str: Optional[str] = None,
) -> Tuple[str, str]:
"""Get the blob ids for both grid geometry and grid property in a case, iteration, and realization"""

# Temporary workarounds for discrepancies in the metadata
grid_name_for_parameters = grid_name
if grid_name == "Geogrid":
grid_name_for_parameters = ""
if "TROLL" in grid_name:
grid_name_for_parameters = parameter_name
parameter_name = grid_name

query: Dict[str, Any] = {
"bool": {
"should": [
Expand All @@ -94,7 +103,7 @@ async def get_grid_geometry_and_property_blob_ids_async(
{"term": {"fmu.iteration.name.keyword": iteration}},
{"term": {"fmu.realization.id": realization}},
{"term": {"data.name.keyword": parameter_name}},
{"term": {"data.tagname.keyword": grid_name}},
{"term": {"data.tagname.keyword": grid_name_for_parameters}},
]
}
},
Expand Down

0 comments on commit 79277a2

Please sign in to comment.