Skip to content

Commit a450db3

Browse files
committed
Align .iea.web path handling with .ssp.data
1 parent 3378e43 commit a450db3

File tree

1 file changed

+12
-20
lines changed
  • message_ix_models/tools/iea

1 file changed

+12
-20
lines changed

message_ix_models/tools/iea/web.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
from message_ix_models.tools.exo_data import ExoDataSource, register_source
1616
from message_ix_models.util import (
17+
HAS_MESSAGE_DATA,
1718
cached,
18-
local_data_path,
1919
package_data_path,
2020
private_data_path,
2121
)
@@ -30,15 +30,6 @@
3030

3131
DIMS = ["COUNTRY", "PRODUCT", "TIME", "FLOW", "MEASURE"]
3232

33-
FWF_COLUMNS = {
34-
"COUNTRY": (0, 26),
35-
"PRODUCT": (26, 32),
36-
"TIME": (32, 48),
37-
"FLOW": (48, 64),
38-
"MEASURE": (64, 68),
39-
"Value": (68, 100),
40-
}
41-
4233
#: Subset of columns to load, mapped to returned values.
4334
CSV_COLUMNS = {
4435
"COUNTRY": "node",
@@ -225,7 +216,7 @@ def load_data(
225216
provider: str,
226217
edition: str,
227218
query_expr="MEASURE == 'TJ' and TIME >= 1980",
228-
base_path=None,
219+
path: Optional[Path] = None,
229220
) -> pd.DataFrame:
230221
"""Load data from the IEA World Energy Balances.
231222
@@ -252,15 +243,16 @@ def load_data(
252243
files = FILES[(provider, edition)]
253244

254245
# Identify a location that contains the `files`
255-
if base_path is None:
256-
try:
257-
base_path = private_data_path("iea")
258-
assert base_path.joinpath(files[0]).exists()
259-
except AssertionError:
260-
base_path = local_data_path("iea")
261-
assert base_path.joinpath(files[0]).exists()
262-
263-
return iea_web_data_for_query(base_path, *files, query_expr=query_expr)
246+
if path is None:
247+
if HAS_MESSAGE_DATA:
248+
path = private_data_path("iea")
249+
else:
250+
path = package_data_path("test", "iea")
251+
log.warning(f"Reading random data from {path}")
252+
253+
assert path.joinpath(files[0]).exists()
254+
255+
return iea_web_data_for_query(path, *files, query_expr=query_expr)
264256

265257

266258
def generate_code_lists(

0 commit comments

Comments
 (0)