Download OW polygons from a specific polygon set via DSIS¶
This notebook provides a simple workflow for sending a request to DSIS using the dsis-client library developed by Equinor.
The following steps are covered:
- Authenticate to DSIS using an
.env_dsisfile with the required configuration and credentials. - Construct and execute a query requesting polygons belonging to a specific polygon set.
- Visualize the results returned by the query.
For more information about the required content of the .env_dsis file, please contact the SDD-SID team, or the DSIS team in Equinor.
from dotenv import load_dotenv
import os
from typing import Any
from shapely.geometry import Polygon
import matplotlib.pyplot as plt
import json
from dsis_client import DSISClient, DSISConfig, QueryBuilder, Environment
Authenticate and connect to DSIS¶
We provide all the required configuration and credentials via the .env_dsis file. Make sure to modify the config logic below if you are, e.g., fetching secrets from a key vault through this notebook.
load_dotenv(".env_dsis")
True
config = DSISConfig(
environment=Environment.DEV,
tenant_id=os.getenv("tenant_id"),
client_id=os.getenv("client_id"),
client_secret=os.getenv("client_secret"),
access_app_id=os.getenv("resource_id"),
dsis_username=os.getenv("dsis_function_key"),
dsis_password=os.getenv("dsis_password"),
subscription_key_dsauth=os.getenv("subscription_key_dsauth"),
subscription_key_dsdata=os.getenv("subscription_key_dsdata"),
dsis_site=os.getenv("dsis_site"),
)
dsis_client = DSISClient(config)
if dsis_client.test_connection():
print("✓ Connected to DSIS API")
✓ Connected to DSIS API
Build and execute a query¶
Next, we specify the name and version of the OW model we plan to use, along with the database, project, and the object ID of the data we want to download. In this notebook, we download polygons (MappingPolygon objects) that belong to a specific polygon set (MappingPolygonSet). The OBJECT_ID corresponds to the ID of the polygon set we use as a filter.
MODEL_NAME = "OpenWorksCommonModel"
MODEL_VERSION = "5000107"
DISTRICT = "BG4FROST"
PROJECT = "VOLVE_PUBLIC"
OBJECT_ID = 2326
# Helper function which might be incorporated in the dsis-client library in the future
def build_district_id(database: str, *, model_name: str) -> str:
"""Build DSIS district_id from database name.
DSIS uses different district-id conventions for different models.
Examples:
- OpenWorksCommonModel: OpenWorksCommonModel_OW_<DB>-OW_<DB>
- OpenWorks native models (e.g., OW5000): OpenWorks_OW_<DB>_SingleSource-OW_<DB>
"""
if model_name == "OpenWorksCommonModel":
return f"OpenWorksCommonModel_OW_{database}-OW_{database}"
return f"OpenWorks_OW_{database}_SingleSource-OW_{database}"
query = (
QueryBuilder(
model_name=MODEL_NAME,
model_version=MODEL_VERSION,
district_id=build_district_id(DISTRICT, model_name=MODEL_NAME),
project=PROJECT,
)
.schema("MappingPolygon")
.filter(f"mappingpolygonset_native_uid eq '{OBJECT_ID}'")
)
We execute the query and print out the first element from the list returned in the response from DSIS. This element correponds to a single polygon.
query_results: list[dict[str, Any]] = list(dsis_client.execute_query(query))
print(json.dumps(query_results[0], indent=4))
{
"datum": 0,
"color": null,
"data": {
"x_coord": [
435259.53,
435219.94,
435181.06,
435163.38,
435115.3,
435096.22,
435070.06,
435025.53,
434991.6,
434966.84,
434945.62,
434932.3,
434908.28,
434889.88,
434869.53,
434858.94,
434834.2,
434876.47,
434901.9,
434912.5,
434930.06,
434949.16,
434977.44,
435019.16,
435045.3,
435074.3,
435103.28,
435135.1,
435154.2,
435172.6,
435210.75,
435251.75,
435332.8,
435323.88,
435259.53
],
"y_coord": [
6479503.5,
6479501,
6479502,
6479498.5,
6479473,
6479458,
6479444.5,
6479436,
6479427,
6479411.5,
6479391,
6479360.5,
6479337.5,
6479317,
6479264,
6479212.5,
6479213,
6479324,
6479349.5,
6479383.5,
6479407,
6479430,
6479444.5,
6479449,
6479461.5,
6479475,
6479488,
6479500.5,
6479512.5,
6479514,
6479512.5,
6479514,
6479553.5,
6479532.5,
6479503.5
],
"z_value": [
2714.2354,
2706.7893,
2710.5122,
2712.498,
2708.0303,
2699.9636,
2698.7224,
2694.8875,
2689.3088,
2678.9573,
2694.8872,
2669.4739,
2665.755,
2655.2175,
2644.0637,
2657.885,
2669.9177,
2687.9622,
2684.0286,
2694.6104,
2704.185,
2730.044,
2730.6758,
2729.59,
2731.5488,
2730.58,
2730.8381,
2732.686,
2733.5469,
2731.9626,
2721.061,
2727.19,
2759.8435,
2727.6838,
2714.2354
],
"throw_direction": []
},
"datum_unit": "meters",
"no_data_value": null,
"polygon_set_data_type": "FAULT",
"polygon_set_name": "2014_Volve_Hugin_Base",
"remark": null,
"polygon_seq_no": 71,
"update_user_id": null,
"xy_unit": "meters",
"z_domain_qualifier": null,
"polygon_type": "EXCLUSIVE",
"alternate_uid": "{\"polygon_set_id\":2326,\"poly_seq_no\":71}",
"create_date": "2018-05-15T14:05:46.000",
"spatial": {
"geo_type": "LINESTRING",
"x": [
"435259.53125",
"435219.9375",
"435181.0625",
"435163.375",
"435115.3125",
"435096.21875",
"435070.0625",
"435025.53125",
"434991.59375",
"434966.84375",
"434945.625",
"434932.3125",
"434908.28125",
"434889.875",
"434869.53125",
"434858.9375",
"434834.1875",
"434876.46875",
"434901.90625",
"434912.5",
"434930.0625",
"434949.15625",
"434977.4375",
"435019.15625",
"435045.3125",
"435074.3125",
"435103.28125",
"435135.09375",
"435154.1875",
"435172.59375",
"435210.75",
"435251.75",
"435332.8125",
"435323.875",
"435259.53125"
],
"y": [
"6479503.5",
"6479501.0",
"6479502.0",
"6479498.5",
"6479473.0",
"6479458.0",
"6479444.5",
"6479436.0",
"6479427.0",
"6479411.5",
"6479391.0",
"6479360.5",
"6479337.5",
"6479317.0",
"6479264.0",
"6479212.5",
"6479213.0",
"6479324.0",
"6479349.5",
"6479383.5",
"6479407.0",
"6479430.0",
"6479444.5",
"6479449.0",
"6479461.5",
"6479475.0",
"6479488.0",
"6479500.5",
"6479512.5",
"6479514.0",
"6479512.5",
"6479514.0",
"6479553.5",
"6479532.5",
"6479503.5"
],
"z": [
"2714.2353515625",
"2706.789306640625",
"2710.51220703125",
"2712.498046875",
"2708.0302734375",
"2699.963623046875",
"2698.722412109375",
"2694.887451171875",
"2689.308837890625",
"2678.957275390625",
"2694.88720703125",
"2669.473876953125",
"2665.7548828125",
"2655.217529296875",
"2644.063720703125",
"2657.885009765625",
"2669.917724609375",
"2687.962158203125",
"2684.028564453125",
"2694.6103515625",
"2704.18505859375",
"2730.0439453125",
"2730.67578125",
"2729.590087890625",
"2731.548828125",
"2730.580078125",
"2730.838134765625",
"2732.68603515625",
"2733.546875",
"2731.962646484375",
"2721.06103515625",
"2727.18994140625",
"2759.843505859375",
"2727.683837890625",
"2714.2353515625"
],
"x_unit": "dega",
"y_unit": "dega",
"z_unit": "ms",
"x_unittype": "project coordinate",
"y_unittype": "project coordinate",
"z_unittype": "seismic time"
},
"area": 11269.828,
"depth_domain": "TIME",
"create_user_id": "KKSU",
"native_uid": "{\"polygon_set_id\":2326,\"poly_seq_no\":71}",
"crs": "ST_ED50_UTM31N_P23031_T1133",
"z_value_unit": "ms",
"mappingpolygonset_native_uid": "2326",
"fault": "UNKNOWN",
"num_points": 35,
"poly_z_value_unit": "ms",
"data_source": "STAT",
"update_date": null,
"area_unit": "m2",
"unit_desc": "ms",
"poly_z_value": null
}
Finally, we can plot all the polygons returned by DSIS using the query above.
fig, ax = plt.subplots(figsize=(6, 6))
# Plot each polygon from query_results
for i, result in enumerate(query_results):
spatial = result["spatial"]
x_coords = [float(x) for x in spatial["x"]]
y_coords = [float(y) for y in spatial["y"]]
polygon = Polygon(zip(x_coords, y_coords))
x, y = polygon.exterior.xy
ax.plot(x, y, linewidth=0.5)
ax.fill(x, y, alpha=0.3)
ax.set_aspect("equal")
ax.grid(True)
ax.set_xlabel("X")
ax.set_ylabel("Y")
plt.xticks(rotation=-70)
plt.tight_layout()
plt.show()