entsoe client
version
免责声明:该库是为了实验各种概念而编写的。 subsodules ientsoe_client.parametertypes和ientsoe_client.queries直接。为了重构ientsoe_client.parsers,下一步是建立固定装置,标准化XML树的扁平化并将记录从DataFrame库中解散。
制定可读的查询并处理熊猫的数据,包括一组详尽的预定义查询。
> >> import requests
> >> from lxml import objectify
> >> from lxml . etree import dump
> >> url = 'https://transparency.entsoe.eu/api?'
... 'documentType=A81&businessType=A95&psrType=A04&type_MarketAgreement.Type=A01&controlArea_Domain=10YNL----------L'
... f '&periodStart=202101010000&periodEnd=202104010000&securityToken={api_key}'
> >> response = requests . Session (). get ( url = url )
> >> element = objectify . fromstring ( response . content )
> >> dump ( element )
< Balancing_MarketDocument xmlns = "urn:iec62325.351:tc57wg16:451-6:balancingdocument:3:0" >
< mRID > 051 b91beed574b48b4548214e9001afc < / mRID >
< revisionNumber > 1 < / revisionNumber >
< type > A81 < / type >
< process . processType > A34 < / process . processType >
< sender_MarketParticipant . mRID codingScheme = "A01" > 10 X1001A1001A450 < / sender_MarketParticipant . mRID >
< sender_MarketParticipant . marketRole . type > A32 < / sender_MarketParticipant . marketRole . type >
< receiver_MarketParticipant . mRID codingScheme = "A01" > 10 X1001A1001A450 < / receiver_MarketParticipant . mRID >
< receiver_MarketParticipant . marketRole . type > A33 < / receiver_MarketParticipant . marketRole . type >
< createdDateTime > 2021 - 10 - 04 T18 : 12 : 43 Z < / createdDateTime >
< controlArea_Domain . mRID codingScheme = "A01" > 10 YNL - - - - - - - - - - L < / controlArea_Domain . mRID >
< period . timeInterval >
< start > 2020 - 12 - 31 T23 : 00 Z < / start >
< end > 2021 - 03 - 31 T22 : 00 Z < / end >
< / period . timeInterval >
< TimeSeries >
< mRID > 1 < / mRID >
< businessType > A95 < / businessType >
< type_MarketAgreement . type > A01 < / type_MarketAgreement . type >
< mktPSRType . psrType > A04 < / mktPSRType . psrType >
< flowDirection . direction > A03 < / flowDirection . direction >
< quantity_Measure_Unit . name > MAW < / quantity_Measure_Unit . name >
< curveType > A01 < / curveType >
< Period >
< timeInterval >
< start > 2020 - 12 - 31 T23 : 00 Z < / start >
< end > 2021 - 01 - 01 T23 : 00 Z < / end >
< / timeInterval >
< resolution > PT60M < / resolution >
< Point >
< position > 1 < / position >
< quantity > 44 < / quantity >
< / Point >
< Point >
< position > 2 < / position >
< quantity > 44 < / quantity >
[...]变成
> >> import entsoe_client as ec
> >> from entsoe_client . ParameterTypes import *
> >> client = ec . Client ( api_key )
> >> parser = ec . Parser
> >> query = ec . Query (
... documentType = DocumentType ( "Contracted reserves" ),
... psrType = PsrType ( "Generation" ),
... businessType = BusinessType ( "Frequency containment reserve" ),
... controlArea_Domain = Area ( "NL" ),
... type_MarketAgreementType = MarketAgreementType ( "Daily" ),
... periodStart = "2021-01-01T00:00" ,
... periodEnd = "2021-04-01T00:00"
... )
> >> response = client ( query )
> >> df = parser . parse ( response )
> >> df . iloc [:,: 3 ]. head ()
position quantity Period . timeInterval . start ...
2020 - 12 - 31 23 : 00 : 00 + 00 : 00 1 44 2020 - 12 - 31 T23 : 00 Z
2021 - 01 - 01 00 : 00 : 00 + 00 : 00 2 44 2020 - 12 - 31 T23 : 00 Z
2021 - 01 - 01 01 : 00 : 00 + 00 : 00 3 44 2020 - 12 - 31 T23 : 00 Z
2021 - 01 - 01 02 : 00 : 00 + 00 : 00 4 44 2020 - 12 - 31 T23 : 00 Z
2021 - 01 - 01 03 : 00 : 00 + 00 : 00 5 44 2020 - 12 - 31 T23 : 00 Z
...预定义的查询是通用查询类的子集,涵盖了ENTSO-E API指南的所有示例。
> >> predefined_query = ec . Queries . Balancing . AmountOfBalancingReservesUnderContract (
... controlArea_Domain = Area ( "NL" ),
... type_MarketAgreementType = MarketAgreementType ( "Daily" ),
... psrType = PsrType ( "Generation" ),
... periodStart = "2021-01-01T00:00" ,
... periodEnd = "2021-04-01T00:00"
... )
...
> >> predefined_query () == query ()
True主要贡献
这些允许在自然语言和获取请求所需的代码之间进行映射,例如DocumentType.A85 == DocumentType("Imbalance price") 。此功能允许跟踪查询,而无需在文档之间跳跃或添加注释。
ENTSO-E API指南是用于实现任何API连接器的微小集合,并反映了Entso-E透明平台上的所有仪表板。
响应文档以XML架构为单位,可以解析为PANDAS数据范围。
实施:gl_marketDocuments,tramasemnnetwork_marketDocuments,publication_marketDocuments和balincing_marketDocuments。
缺少:中断,拥塞管理和系统操作。
然而,ientso-e客户端寻求从查询到数据帧的最低限度,并且需要有关如何制定查询和解释解析响应的各种列的域知识。
ientso-e依靠许多代码(类型)映射到所需的查询。类型是用.help()函数在枚举类中编码的,以列出所有内容。它们可以通过类型[代码]或类型(字符串)来解决,使交互变得容易。 HTTP请求和响应通常需要代码,而我们希望将查询作为人类可读字符串提出。
来自ientsoe_client导入查询
来自ientsoe_client.parametertypes Import *
queries.transmission.capacityallocatedOutsideeu(
out_domain =区域('SK'),
in_domain =区域('ua_bei'),
MarketAgreementType = MarketAgreementType('Daily'),#原始代码:A01
auctionType = auctionType('equallicit'),#原始代码:A02
Aapaigatory = AuctionCategory('hourly'),#原始代码:A04
分类sequence_attributeinstancecomponent_position = 1,
周期= 201601012300,
期限= 201601022300)
>>> parametertypes.documentType ['a25'] == parametertypes.documentType('分配结果文档') 真的 >>> ec.parametertypes.documentType.help() --- documentType --- API_PARAMETER:描述 [...] A25:分配结果文档 A71:一代预测 A72:储层填充信息 A73:实际一代 A85:不平衡价格 A86:不平衡量 [...] API_PARAMETER:描述 --- documentType --- >>> ec.parametertypes.businesstype.help() ---商业类型--- API_PARAMETER:描述 [...] A25:一般能力信息 A29:已经分配的能力(AAC) A97:手动频率修复储备 B08:总提名能力 C22:共享平衡储备能力 C24:实际储备能力 [...] API_PARAMETER:描述 ---商业类型---
#从sample_plot.py共享
导入ientsoe_client作为ec
从设置导入api_key
#实例化客户端,解析器和查询。
客户端= ec.client(api_key)
解析器= ec.parser()
查询= ec.queries.generation.ggregatedGenerationPertype(
in_domain = ec.parametertypes.area('de_lu'),
周期= 202109050200,
期限= 202109070200)
#提取数据。
响应=客户端(查询)
df =解析器(响应)
[...]
#变换数据。
生产= df [〜消费_mask] [['数量','limeseries.mktpsrtype.psrtype']]]
## psrtype,例如b01`:=`biomass`。
生产['generationType'] =生产['limeseries.mktpsrtype.psrtype']。
应用(lambda x:parametertypes.psrtype [x] .value)#映射ientso-e psrtypes中的人类可读字符串。
producty_by_type = pd.pivot_table(生产,
index = production.index,
列='GenerationType',
值='数量')
[...]
# 阴谋。
production_by_type.plot.bar(title =“ de-lu中的生产类型”,
Xlabel =“ UTC”,
ylabel ='MWH',
ax = ax,
** plot_params)
[...]
