Skip to content

Commit 6a98bcd

Browse files
lorrieqcorradio
authored andcommitted
Add JP prices (#1577)
* Add JP prices * Fetch based on fiscal year, update README
1 parent c31b852 commit 6a98bcd

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ A ⇉ B: unidirectional operation, only with power flow "from A to B"
314314

315315
### Electricity prices (day-ahead) data sources
316316
- France: [RTE](http://www.rte-france.com/en/eco2mix/eco2mix-mix-energetique-en)
317+
- Japan: [JEPX](http://www.jepx.org)
317318
- Nicaragua: [CNDC](http://www.cndc.org.ni/)
318319
- Singapore: [EMC](https://www.emcsg.com)
319320
- Turkey: [EPIAS](https://seffaflik.epias.com.tr/transparency/piyasalar/gop/ptf.xhtml)

parsers/JP.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
# The arrow library is used to handle datetimes
55
import arrow
6+
import datetime as dt
67
import pandas as pd
78
from . import occtonet
89

@@ -16,6 +17,8 @@
1617
# JP-SK : Shikoku
1718
# JP-KY : Kyushu
1819
# JP-ON : Okinawa
20+
# JP-CG : Chūgoku
21+
1922

2023
def fetch_production(zone_key='JP-TK', session=None, target_datetime=None,
2124
logger=logging.getLogger(__name__)):
@@ -118,15 +121,59 @@ def fetch_consumption_df(zone_key='JP-TK', target_datetime=None,
118121
df = df[['datetime', 'cons']]
119122
return df
120123

124+
125+
def fetch_price(zone_key='JP-TK', session=None, target_datetime=None,
126+
logger=logging.getLogger(__name__)):
127+
if target_datetime is None:
128+
target_datetime = dt.datetime.now() + dt.timedelta(days=1)
129+
130+
# price files contain data for fiscal year and not calendar year.
131+
if target_datetime.month <= 3:
132+
fiscal_year = target_datetime.year - 1
133+
else:
134+
fiscal_year = target_datetime.year
135+
url = 'http://www.jepx.org/market/excel/spot_{}.csv'.format(fiscal_year)
136+
df = pd.read_csv(url)
137+
138+
df = df.iloc[:, [0, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14]]
139+
df.columns = ['Date', 'Period', 'JP-HKD', 'JP-TH', 'JP-TK', 'JP-CB',
140+
'JP-HR', 'JP-KN', 'JP-CG', 'JP-SK', 'JP-KY']
141+
142+
if zone_key not in df.columns[2:]:
143+
return []
144+
145+
start = target_datetime - dt.timedelta(days=1)
146+
df['Date'] = df['Date'].apply(lambda x: dt.datetime.strptime(x, '%Y/%m/%d'))
147+
df = df[(df['Date'] >= start.date()) & (df['Date'] <= target_datetime.date())]
148+
149+
df['datetime'] = df.apply(lambda row: arrow.get(row['Date']).shift(
150+
minutes=30 * (row['Period'] - 1)).replace(tzinfo='Asia/Tokyo'), axis=1)
151+
152+
data = list()
153+
for row in df.iterrows():
154+
data.append({
155+
'zoneKey': zone_key,
156+
'currency': 'JPY',
157+
'datetime': row[1]['datetime'].datetime,
158+
'price': row[1][zone_key],
159+
'source': 'jepx.org'
160+
})
161+
162+
return data
163+
164+
121165
def parse_dt(row):
122166
"""
123167
Parses timestamps from date and time
124168
"""
125169
return arrow.get(' '.join([row['Date'], row['Time']]).replace('/', '-'),
126170
'YYYY-M-D H:mm').replace(tzinfo='Asia/Tokyo').datetime
127171

172+
128173
if __name__ == '__main__':
129174
"""Main method, never used by the Electricity Map backend, but handy for testing."""
130175

131176
print('fetch_production() ->')
132177
print(fetch_production())
178+
print('fetch_price() ->')
179+
print(fetch_price())

0 commit comments

Comments
 (0)