From ebd86c940046fc93fbdfd9156104cf12491efef6 Mon Sep 17 00:00:00 2001 From: "kristjan.vilgo" Date: Mon, 3 May 2021 23:35:14 +0300 Subject: [PATCH] 1. Added examples to README.md 2. Simplified publication API --- OPDM/OPDM_SOAP_API.py | 9 ++-- README.md | 95 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/OPDM/OPDM_SOAP_API.py b/OPDM/OPDM_SOAP_API.py index a22cc84..80fd461 100644 --- a/OPDM/OPDM_SOAP_API.py +++ b/OPDM/OPDM_SOAP_API.py @@ -30,9 +30,8 @@ import urllib3 - def get_element(element_path, xmltree): - element = xmltree.find(element_path, namespaces = xmltree.nsmap) + element = xmltree.find(element_path, namespaces=xmltree.nsmap) return element @@ -221,7 +220,7 @@ def execute_operation(self, operation_xml): response = self.client.service.ExecuteOperation(operation_xml, _soapheaders=self.create_saml_header()) return response - def publication_request(self, content_type, file_path_or_file_object): + def publication_request(self, file_path_or_file_object, content_type="CGMES"): """PublicationRequest(dataset: ns0:opdeFileDto) -> return: ns0:resultDto, ns0:opdeFileDto(id: xsd:string, type: xsd:string, content: xsd:base64Binary)""" @@ -242,7 +241,7 @@ def publication_request(self, content_type, file_path_or_file_object): return response - def query_object(self, object_type="IGM", metadata_dict = "", components = [], dependencies = []): + def query_object(self, object_type="IGM", metadata_dict="", components=[], dependencies=[]): """ objec_type ->IGM, CGM, BDS metadata_dict_example = {'pmd:cgmesProfile': 'SV', 'pmd:scenarioDate': '2018-12-07T00:30:00+01:00', 'pmd:timeHorizon': '1D'} @@ -480,7 +479,7 @@ def publication_cancel_subscription(self, subscription_id): # Model submission example file_path = r"\\elering.sise\teenused\NMM\data\ACG\Generated Cases Archive\20190713T1530Z__ELERING_EQ_001.zip" -response = service.publication_request("CGMES", file_path) +response = service.publication_request(file_path) print(etree.tostring(response, pretty_print=True).decode()) diff --git a/README.md b/README.md index fd0f81a..cdc2f36 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,95 @@ # OPDM -Python API for OPDM +Python implementation of OPDM SOAP API. OPDM is used to exchange Electrical Grid Models between ENTSO-E TSO-s and RSC-s + +# Installation + + pip install opdm-api + +or + + pip install --user opdm-api + +or + + python -m pip install --user opdm-api + + +# Usage + +## Initialise + import opdm-api + + service = opdm-api.create_client("https://opdm.elering.sise:8443", username="user", password="pass") + +## Upload File +### Upload a file + response = service.publication_request(file_path_or_objet) + +### Upload all files in a directory + import glob + imort os + + for file_name in glob.glob1(direcotry_path, "*.zip"): + service.publication_request(os.path.join(direcotry_path, file_name)) + +## Get File Upload/Publication Report + publication_report = get_profile_publication_report(model_ID) + +or + + publication_report = get_profile_publication_report(filename="uploaded_file_name.zip") + +## Subscribe for Model publications +### Get available Publications + available_publications = service.publication_list() + +### Subscribe for BDS +*available publications: BDS, IGM, CGM* + + response = service.publication_subscribe("BDS") + +### Subscribe for all IGM-s except RT + + time_horizons = [f"{item:02d}" for item in list(range(1,32))] + ["ID", "1D", "2D", "YR"] + for time_horizon in time_horizons: + print(f"Adding subscription for {time_horizon}") + response = service.publication_subscribe("IGM", subscription_id=f"IGM-{time_horizon}", metadata_dict={'pmd:timeHorizon': time_horizon}) + print(response) + +## Cancel Subscription + response = publication_cancel_subscription(subscription_id) + +## Query Data +### Model +*Model consists of multiple files* + + query_id, response = service.query_object(object_type = "IGM", metadata_dict = {'pmd:scenarioDate': '2019-07-28T00:30:00', 'pmd:timeHorizon': '1D'}) + +### File + + query_id, response = service.query_profile('pmd:timeHorizon': '1D', 'pmd:cgmesProfile': 'SV'}) + +### Create nice table of returned Query responses + + import pandas + + pandas.set_option("display.max_rows", 12) + pandas.set_option("display.max_columns", 10) + pandas.set_option("display.width", 1500) + pandas.set_option('display.max_colwidth', -1) + + print(pandas.DataFrame(response['sm:QueryResult']['sm:part'][1:])) + +## Download a File +### Download to OPDM Client and return local path to the file + response = service.get_content(file_UUID) + print(response['sm:GetContentResult']['sm:part'][1]['opdm:Profile']['opde:Content']) + +### Download and Save file + response = service.get_content(file_UUID, return_payload=True) + with open(f"{file_UUID}.zip", 'wb') as cgmes_file: + report_file.write(response['sm:GetContentResult']['sm:part'][1]['opdm:Profile']['opde:Content']) + + + +