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)
[...]
