glm Python library
Project description
# glm [![PyPI](https://img.shields.io/pypi/v/glm.svg)](https://pypi.python.org/pypi/glm) [![Python version compatibility status](https://img.shields.io/pypi/pyversions/glm.svg)](https://pypi.python.org/pypi/glm) [![Build Status](https://travis-ci.com/NREL/glm.svg?branch=master)](https://travis-ci.com/NREL/glm)
A fast [GridLAB-D](https://github.com/gridlab-d/gridlab-d) to JSON (and back) parser.
- Fast GLM to JSON converter.
- Supports nested objects, schedules, definitions, directives, modules, includes and clock objects
- Fast JSON to GLM converter.
- Native support for Python, returns nested dictionaries.
![](./docs/img/python-example.png)
- Descriptive error messages when unable to parse a GridLAB-D model file.
![](./docs/img/error-example.png)
- Tested on all examples in the GridLAB-D source repository.
## Install
Go to the [latest releases page](https://github.com/NREL/glm/releases/latest) for the Python or the CLI for various operating systems.
### Python
You can pip install the package from PyPI or using the wheel (files with extension .whl) after downloading it or directly from the URL from the releases page.
The following installs the latest glm package for Windows, MacOSX or Linux from PyPI.
This will work for Python2 or Python3.
```
pip install glm
```
### CLI
If you want to use the CLI, you can unzip the file from the releases page for your operating system.
There will be two executables in the folder, `glm2json` and `json2glm`.
On Windows, you may have to rename the files to add the `.exe` at the end of the executable in order to run it from a Windows CMD prompt.
You will be able to run it from a Git Bash prompt without renaming it.
You can use the following commands to download and unzip the files on the respective operating systems.
**Windows**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
curl -LO "https://github.com/NREL/glm/releases/download/$VERSION/glm-windows-amd64.zip"
unzip glm-windows-amd64.zip
```
**OSX**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
curl -LO "https://github.com/NREL/glm/releases/download/$VERSION/glm-osx-amd64.tar.xz"
tar -zxvf glm-osx-amd64.tar.xz
```
**Linux**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
curl -LO "https://github.com/NREL/glm/releases/download/$VERSION/glm-linux-amd64.tar.xz"
tar -zxvf glm-linux-amd64.tar.xz
```
The contents of the compressed archive will contain a command line executable, and a module that can be imported into Python.
## Documentation
You can use this from the command line as follows:
```
Usage:
glm2json [required&optional-params]
Convert from glm/json to json/glm
Options(opt-arg sep :|=|spc):
-h, --help write this help to stdout
--version bool false write version to stdout
-p=, --pathToFile= string REQUIRED set pathToFile
--pretty bool false set pretty
```
```
./glm2json --path-to-file ./tests/data/4node.glm --pretty ✔ 10397 18:20:47
{
"clock": {
"timestamp": "2000-01-01 0:00:00",
"timezone": "EST+5EDT"
},
"includes": [],
"objects": [
{
"name": "overhead_line_conductor:100",
"attributes": {
"name": "PhaseCond",
"geometric_mean_radius": "0.0244 ft",
"resistance": "0.306"
},
"children": []
},
{
"name": "overhead_line_conductor:101",
"attributes": {
"name": "NeutralCond",
"geometric_mean_radius": "0.00814 ft",
"resistance": "0.592"
},
"children": []
},
{
"name": "line_spacing:200",
"attributes": {
"name": "LineSpacing",
"distance_AB": "2.5",
"distance_BC": "4.5",
"distance_AC": "7.0",
"distance_AN": "5.656",
"distance_BN": "4.272",
"distance_CN": "5.0"
},
"children": []
},
{
"name": "line_configuration:1",
"attributes": {
"name": "LineConf",
"conductor_A": "PhaseCond",
"conductor_B": "PhaseCond",
"conductor_C": "PhaseCond",
"conductor_N": "NeutralCond",
"spacing": "LineSpacing"
},
"children": []
},
{
"name": "overhead_line",
"attributes": {
"name": "Line1",
"phases": "ABCN",
"from": "Node1",
"to": "Node2",
"length": "2000 ft",
"configuration": "LineConf",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "overhead_line",
"attributes": {
"name": "Line2",
"phases": "ABCN",
"from": "Node3",
"to": "Node4",
"length": "2500 ft",
"configuration": "LineConf",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "node",
"attributes": {
"name": "Node1",
"phases": "ABCN",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "node",
"attributes": {
"name": "Node2",
"phases": "ABCN",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "node",
"attributes": {
"name": "Node3",
"phases": "ABCN",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "node",
"attributes": {
"name": "Node4",
"phases": "ABCN",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "tape.recorder",
"attributes": {
"interval": "4.0",
"parent": "network_node2",
"limit": "21600",
"file": "./csv_output/network_node2.csv",
"property": "measured_real_power, measured_real_energy, voltage_A, voltage_B, voltage_C"
},
"children": []
}
],
"modules": [
{
"name": "powerflow",
"attributes": {}
},
{
"name": "tape",
"attributes": {}
}
],
"directives": [],
"definitions": [],
"schedules": []
}
```
## Issues
Feel free to open an issue if something is not working as expected.
## Developer Guide
- Install [Nim](https://nim-lang.org/install.html)
- Run `nimble install -y` to generate binaries
If you want to install the latest version from GitHub, you can use the following commands.
The GitHub release is identical to that on PyPI.
**Windows**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
pip install https://github.com/NREL/glm/releases/download/$VERSION/glm-${VERSION#"v"}-py2.py3-none-win_amd64.whl
```
**OSX**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
pip install https://github.com/NREL/glm/releases/download/$VERSION/glm-${VERSION#"v"}-py2.py3-none-macosx_10_7_x86_64.whl
```
**Linux**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
pip install https://github.com/NREL/glm/releases/download/$VERSION/glm-${VERSION#"v"}-py2.py3-none-manylinux1_x86_64.whl
```
A fast [GridLAB-D](https://github.com/gridlab-d/gridlab-d) to JSON (and back) parser.
- Fast GLM to JSON converter.
- Supports nested objects, schedules, definitions, directives, modules, includes and clock objects
- Fast JSON to GLM converter.
- Native support for Python, returns nested dictionaries.
![](./docs/img/python-example.png)
- Descriptive error messages when unable to parse a GridLAB-D model file.
![](./docs/img/error-example.png)
- Tested on all examples in the GridLAB-D source repository.
## Install
Go to the [latest releases page](https://github.com/NREL/glm/releases/latest) for the Python or the CLI for various operating systems.
### Python
You can pip install the package from PyPI or using the wheel (files with extension .whl) after downloading it or directly from the URL from the releases page.
The following installs the latest glm package for Windows, MacOSX or Linux from PyPI.
This will work for Python2 or Python3.
```
pip install glm
```
### CLI
If you want to use the CLI, you can unzip the file from the releases page for your operating system.
There will be two executables in the folder, `glm2json` and `json2glm`.
On Windows, you may have to rename the files to add the `.exe` at the end of the executable in order to run it from a Windows CMD prompt.
You will be able to run it from a Git Bash prompt without renaming it.
You can use the following commands to download and unzip the files on the respective operating systems.
**Windows**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
curl -LO "https://github.com/NREL/glm/releases/download/$VERSION/glm-windows-amd64.zip"
unzip glm-windows-amd64.zip
```
**OSX**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
curl -LO "https://github.com/NREL/glm/releases/download/$VERSION/glm-osx-amd64.tar.xz"
tar -zxvf glm-osx-amd64.tar.xz
```
**Linux**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
curl -LO "https://github.com/NREL/glm/releases/download/$VERSION/glm-linux-amd64.tar.xz"
tar -zxvf glm-linux-amd64.tar.xz
```
The contents of the compressed archive will contain a command line executable, and a module that can be imported into Python.
## Documentation
You can use this from the command line as follows:
```
Usage:
glm2json [required&optional-params]
Convert from glm/json to json/glm
Options(opt-arg sep :|=|spc):
-h, --help write this help to stdout
--version bool false write version to stdout
-p=, --pathToFile= string REQUIRED set pathToFile
--pretty bool false set pretty
```
```
./glm2json --path-to-file ./tests/data/4node.glm --pretty ✔ 10397 18:20:47
{
"clock": {
"timestamp": "2000-01-01 0:00:00",
"timezone": "EST+5EDT"
},
"includes": [],
"objects": [
{
"name": "overhead_line_conductor:100",
"attributes": {
"name": "PhaseCond",
"geometric_mean_radius": "0.0244 ft",
"resistance": "0.306"
},
"children": []
},
{
"name": "overhead_line_conductor:101",
"attributes": {
"name": "NeutralCond",
"geometric_mean_radius": "0.00814 ft",
"resistance": "0.592"
},
"children": []
},
{
"name": "line_spacing:200",
"attributes": {
"name": "LineSpacing",
"distance_AB": "2.5",
"distance_BC": "4.5",
"distance_AC": "7.0",
"distance_AN": "5.656",
"distance_BN": "4.272",
"distance_CN": "5.0"
},
"children": []
},
{
"name": "line_configuration:1",
"attributes": {
"name": "LineConf",
"conductor_A": "PhaseCond",
"conductor_B": "PhaseCond",
"conductor_C": "PhaseCond",
"conductor_N": "NeutralCond",
"spacing": "LineSpacing"
},
"children": []
},
{
"name": "overhead_line",
"attributes": {
"name": "Line1",
"phases": "ABCN",
"from": "Node1",
"to": "Node2",
"length": "2000 ft",
"configuration": "LineConf",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "overhead_line",
"attributes": {
"name": "Line2",
"phases": "ABCN",
"from": "Node3",
"to": "Node4",
"length": "2500 ft",
"configuration": "LineConf",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "node",
"attributes": {
"name": "Node1",
"phases": "ABCN",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "node",
"attributes": {
"name": "Node2",
"phases": "ABCN",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "node",
"attributes": {
"name": "Node3",
"phases": "ABCN",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "node",
"attributes": {
"name": "Node4",
"phases": "ABCN",
"nominal_voltage": "124.0"
},
"children": []
},
{
"name": "tape.recorder",
"attributes": {
"interval": "4.0",
"parent": "network_node2",
"limit": "21600",
"file": "./csv_output/network_node2.csv",
"property": "measured_real_power, measured_real_energy, voltage_A, voltage_B, voltage_C"
},
"children": []
}
],
"modules": [
{
"name": "powerflow",
"attributes": {}
},
{
"name": "tape",
"attributes": {}
}
],
"directives": [],
"definitions": [],
"schedules": []
}
```
## Issues
Feel free to open an issue if something is not working as expected.
## Developer Guide
- Install [Nim](https://nim-lang.org/install.html)
- Run `nimble install -y` to generate binaries
If you want to install the latest version from GitHub, you can use the following commands.
The GitHub release is identical to that on PyPI.
**Windows**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
pip install https://github.com/NREL/glm/releases/download/$VERSION/glm-${VERSION#"v"}-py2.py3-none-win_amd64.whl
```
**OSX**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
pip install https://github.com/NREL/glm/releases/download/$VERSION/glm-${VERSION#"v"}-py2.py3-none-macosx_10_7_x86_64.whl
```
**Linux**
```
export VERSION=$(curl -s "https://github.com/NREL/glm/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
pip install https://github.com/NREL/glm/releases/download/$VERSION/glm-${VERSION#"v"}-py2.py3-none-manylinux1_x86_64.whl
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
glm-0.3.3-py2.py3-none-win_amd64.whl
(310.6 kB
view details)
File details
Details for the file glm-0.3.3-py2.py3-none-win_amd64.whl
.
File metadata
- Download URL: glm-0.3.3-py2.py3-none-win_amd64.whl
- Upload date:
- Size: 310.6 kB
- Tags: Python 2, Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/38.2.4 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80e955796d86641e4bd42b6542527d484cea4e8596368873be5bb969652591e3 |
|
MD5 | cc3da9dd934a1b727083b6123e7096b4 |
|
BLAKE2b-256 | de685b2ddc5190d2c4d5c7e033583c865e2d8955223a9431406300884eba7dc0 |
Provenance
File details
Details for the file glm-0.3.3-py2.py3-none-manylinux1_x86_64.whl
.
File metadata
- Download URL: glm-0.3.3-py2.py3-none-manylinux1_x86_64.whl
- Upload date:
- Size: 298.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/38.2.4 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5879c3325b3a74603c26655c514f936757c67c02d07719de645957108c2b248 |
|
MD5 | 6d983c97c75ebd6f6818f86f57f1279b |
|
BLAKE2b-256 | ee6f210a48fc548b69feb7d12f98e216f5a0cdabd729a256e262fcfec86020e7 |
Provenance
File details
Details for the file glm-0.3.3-py2.py3-none-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: glm-0.3.3-py2.py3-none-macosx_10_7_x86_64.whl
- Upload date:
- Size: 229.1 kB
- Tags: Python 2, Python 3, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74e198b47b2bb12b2263164de12a57e9e90e4570cf35f902786d5426e7c59fc5 |
|
MD5 | 5487155eff3b5f413c19e7fa488eb90d |
|
BLAKE2b-256 | 44edf48846e397a8d6146e95be23d32c9369de36154d97b9a1ee254f3d6a41a3 |