Skip to main content

CIM query utilities

Project description

PyPI version Python Versions License: MIT Code style: black codecov

CIMSPARQL Query CIM data using sparql

This Python package provides functionality for reading/parsing cim data from either xml files or GraphDB into Python memory as pandas dataframes.

The package provides a set of predefined functions/queries to load CIM data such generator or branch data, though the user can easiliy extend or define their own queries.

Usage

Load data using predefined functions/queries

>>> from cimsparql.graphdb import GraphDBClient
>>> from cimsparql.url import service
>>> gdbc = GraphDBClient(service(repo='<repo>', server=127.0.0.1:7200))
>>> ac_lines = gdbc.ac_lines(limit=3)
>>> print(ac_lines[['name', 'x', 'r', 'bch']])
         name       x       r       bch
0  <branch 1>  1.9900  0.8800  0.000010
1  <branch 2>  1.9900  0.8800  0.000010
2  <branch 3>  0.3514  0.1733  0.000198

In the example above the client will query repo "" in the default server GraphDB for AC line values.

Inspect/view predefined queries

To see the actual sparql use the dry_run option:

>>> from cimsparql.queries import ac_line_query
>>> print(ac_line_query(limit=3, dry_run=True))

The resulting string contains all the prefix's available in the Graphdb repo making it easier to copy and past to graphdb. Note that the prefixes are not required in the user specified quires described below.

The dry_run option is available for all the predefined queries.

Load data using user specified queries

>>> query = 'SELECT ?mrid where { ?mrid rdf:type cim:ACLineSegment } limit 2'
>>> query_result = gdbc.get_table(query)
>>> print(query_result)

List of available repos at the server

>>> from cimsparql.url import GraphDbConfig
>>> print(GraphDbConfig().repos)

Prefix and namespace

Available namespace for current graphdb client (gdbc in the examples above), which can be used in queries (such as rdf and cim) can by found by

>>> print(gdbc.ns)
{'wgs': 'http://www.w3.org/2003/01/geo/wgs84_pos#',
 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
 'owl': 'http://www.w3.org/2002/07/owl#',
 'cim': 'http://iec.ch/TC57/2010/CIM-schema-cim15#',
 'gn': 'http://www.geonames.org/ontology#',
 'xsd': 'http://www.w3.org/2001/XMLSchema#',
 'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
 'SN': 'http://www.statnett.no/CIM-schema-cim15-extension#',
 'ALG': 'http://www.alstom.com/grid/CIM-schema-cim15-extension#'}

Project details


Release history Release notifications | RSS feed

This version

1.9.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cimsparql-1.9.1.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cimsparql-1.9.1-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file cimsparql-1.9.1.tar.gz.

File metadata

  • Download URL: cimsparql-1.9.1.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.12 Linux/5.13.0-1022-azure

File hashes

Hashes for cimsparql-1.9.1.tar.gz
Algorithm Hash digest
SHA256 2cb59f612cf6fa75b2c3a354e80bdf85b412e5feff9c1795a031bb10062c39ec
MD5 22a6c90ae0bfbf5a28bed187f35ee22c
BLAKE2b-256 88cc73b5b3e8f8c6edf7a6b843c086c2ec5edf7bff8b037e88a9586b0359bf64

See more details on using hashes here.

File details

Details for the file cimsparql-1.9.1-py3-none-any.whl.

File metadata

  • Download URL: cimsparql-1.9.1-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.12 Linux/5.13.0-1022-azure

File hashes

Hashes for cimsparql-1.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a4084e471842305897bc059ab9a7d0076333289a1e844124ea436db76bd89bf8
MD5 54a899eb5290c3d69507f0bb20b5c5d6
BLAKE2b-256 ff1f91e051af79f0dc4a9d3c0f7876a60b112ec71e1553770d210bed11bc5149

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page