glm python库
glm的Python项目详细描述
glm
一个快速的GridLAB-D到json(和后面的)解析器。
- 快速glm到json的转换。
- 支持嵌套对象、计划、定义、指令、模块、包含和时钟对象
- 快速json到glm的转换。
- 对python的本机支持,返回嵌套字典。
- 无法分析gridlab-d模型文件时的描述性错误消息。
- 在gridlab-d源代码库中的所有示例上进行了测试。
安装
转到python的latest releases page或各种操作系统的cli。
Python
您可以从pypi安装软件包,也可以在下载后使用wheel(扩展名为.whl的文件)或直接从releases页面的url安装软件包。
下面从pypi安装最新的用于windows、macosx或linux的glm包。 这对Python2或Python3有效。
pip install glm
这还会安装glm2json
和json2glm
cli实用程序。
cli
如果要使用cli,可以从操作系统的releases页面解压缩文件。
文件夹中将有两个可执行文件,glm2json
和json2glm
。
在windows上,您可能需要重命名文件,以便在可执行文件的末尾添加.exe
,以便在windows cmd提示符下运行它。
您将能够在git bash提示符下运行它,而无需重命名它。
您可以使用以下命令下载和解压缩相应操作系统上的文件。
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
压缩存档的内容将包含一个命令行可执行文件和一个可以导入python的模块。
文档
您可以在命令行中使用此命令,如下所示:
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": []
}
问题
如果某个问题没有按预期工作,请随时打开问题。
开发人员指南
- 安装Nim
- 运行
nimble install -y
生成二进制文件
如果要从github安装最新版本,可以使用以下命令。 github版本与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