@iiasa/ixmp4-ts 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/core/iamc/data.js +12 -6
- package/dist/cjs/core/meta.js +1 -3
- package/dist/cjs/core/utils.js +75 -1
- package/dist/cjs/data/base.js +1 -1
- package/dist/cjs/index.js +47 -1
- package/dist/esm/core/iamc/data.js +12 -6
- package/dist/esm/core/meta.js +1 -3
- package/dist/esm/core/utils.js +51 -1
- package/dist/esm/data/base.js +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/types/core/iamc/data.d.ts +8 -3
- package/dist/types/core/run.d.ts +8 -0
- package/dist/types/core/utils.d.ts +2 -1
- package/dist/types/index.d.ts +2 -0
- package/package.json +5 -8
@@ -100,10 +100,14 @@ class RunIamcData extends base_1.BaseFacade {
|
|
100
100
|
/**
|
101
101
|
* Tabulates IAMC format timeseries data with optional filtering.
|
102
102
|
* @param filter Optional. Filter for tabulating IAMC format timeseries data.
|
103
|
+
* @param wide Optional. Whether to return the data in IAMC wide format or not, defaults to false.
|
103
104
|
* @returns A dfd.DataFrame representing the tabulated data.
|
104
105
|
* @throws An error if illegal filters are applied.
|
105
106
|
*/
|
106
|
-
tabulate(
|
107
|
+
tabulate(_a = {
|
108
|
+
wide: false,
|
109
|
+
}) {
|
110
|
+
var { wide = false } = _a, filter = __rest(_a, ["wide"]);
|
107
111
|
return __awaiter(this, void 0, void 0, function* () {
|
108
112
|
if (filter !== undefined && filter !== null) {
|
109
113
|
// these filters do not make sense when applied from a Run
|
@@ -114,12 +118,13 @@ class RunIamcData extends base_1.BaseFacade {
|
|
114
118
|
throw new Error(`Illegal filter for 'iamc.tabulate()': ${illegalFilter}`);
|
115
119
|
}
|
116
120
|
}
|
117
|
-
return yield this.repository.tabulate(Object.assign({ run: { id: this.run.id, defaultOnly: false }, joinRuns: false }, filter));
|
121
|
+
return yield this.repository.tabulate(Object.assign({ run: { id: this.run.id, defaultOnly: false }, joinRuns: false, wide }, filter));
|
118
122
|
});
|
119
123
|
}
|
120
124
|
contractParameters(df) {
|
121
125
|
return __awaiter(this, void 0, void 0, function* () {
|
122
126
|
let timeseriesDf = df
|
127
|
+
.loc({ columns: ['region', 'variable', 'unit', 'run__id'] })
|
123
128
|
.groupby(['region', 'variable', 'unit', 'run__id'])
|
124
129
|
.agg({ run__id: 'min' })
|
125
130
|
.loc({ columns: ['region', 'variable', 'unit', 'run__id'] });
|
@@ -160,13 +165,15 @@ class PlatformIamcData extends base_1.BaseFacade {
|
|
160
165
|
/**
|
161
166
|
* Tabulates IAMC data with optional filtering.
|
162
167
|
* @param filter Optional. Filter for retrieving IAMC data.
|
163
|
-
* @param
|
168
|
+
* @param joinRuns Optional. Whether to join runs or not, defaults to true.
|
169
|
+
* @param wide Optional. Whether to return the data in IAMC wide format or not, defaults to false.
|
164
170
|
* @returns A Promise that resolves to a dfd.DataFrame containing the tabulated data.
|
165
171
|
*/
|
166
172
|
tabulate(_a = {
|
167
173
|
joinRuns: true,
|
174
|
+
wide: false,
|
168
175
|
}) {
|
169
|
-
var { joinRuns = true } = _a, filter = __rest(_a, ["joinRuns"]);
|
176
|
+
var { joinRuns = true, wide = false } = _a, filter = __rest(_a, ["joinRuns", "wide"]);
|
170
177
|
return __awaiter(this, void 0, void 0, function* () {
|
171
178
|
if (filter === undefined) {
|
172
179
|
filter = {};
|
@@ -188,9 +195,8 @@ class PlatformIamcData extends base_1.BaseFacade {
|
|
188
195
|
if (df.columns.includes('unit')) {
|
189
196
|
// TODO report bug to danfojs: df.replace('oldValue', '', { columns: ['column_name'] }) throws: Params Error: Must specify param 'newValue' to replace with (probably newValue is cast to boolean and emty string is falsy)
|
190
197
|
df = df.replace('dimensionless', ' ', { columns: ['unit'] });
|
191
|
-
console.warn(`Unit name "dimensionless" has been replaced with ' ', this will be rejected by ixmp4.`);
|
192
198
|
}
|
193
|
-
return df;
|
199
|
+
return wide ? (0, utils_1.toIamcWide)(df) : df;
|
194
200
|
});
|
195
201
|
}
|
196
202
|
}
|
package/dist/cjs/core/meta.js
CHANGED
@@ -64,9 +64,7 @@ class MetaIndicatorRepository extends base_1.BaseFacade {
|
|
64
64
|
if (filter === undefined) {
|
65
65
|
filter = {};
|
66
66
|
}
|
67
|
-
return
|
68
|
-
columns: ['id', 'type'],
|
69
|
-
});
|
67
|
+
return yield this.backend.meta.tabulate(filter, joinRunIndex);
|
70
68
|
});
|
71
69
|
}
|
72
70
|
}
|
package/dist/cjs/core/utils.js
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.dfToDimensionless = exports.unitToDimensionless = exports.substitudeType = void 0;
|
26
|
+
exports.toIamcWide = exports.dfToDimensionless = exports.unitToDimensionless = exports.substitudeType = void 0;
|
27
|
+
const dfd = __importStar(require("danfojs"));
|
4
28
|
const datapoint_1 = require("../data/iamc/datapoint");
|
5
29
|
function substitudeType(df, type) {
|
6
30
|
if (!df.columns.includes(type)) {
|
@@ -36,6 +60,56 @@ function dfToDimensionless(df) {
|
|
36
60
|
}
|
37
61
|
// TODO report bug to danfojs: df.replace('oldValue', '', { columns: ['column_name'] }) throws: Params Error: Must specify param 'newValue' to replace with (probably newValue is cast to boolean and emty string is falsy)
|
38
62
|
df.replace(' ', 'dimensionless', { columns: ['unit'] });
|
63
|
+
console.warn(`Unit name "dimensionless" has been replaced with ' ', this will be rejected by ixmp4.`);
|
39
64
|
return df;
|
40
65
|
}
|
41
66
|
exports.dfToDimensionless = dfToDimensionless;
|
67
|
+
function toIamcWide(df) {
|
68
|
+
// cannot convert empty dataframe to wide format
|
69
|
+
if (df.shape[0] === 0) {
|
70
|
+
// drop columns of iamc long format if present
|
71
|
+
if (df.columns.includes('step_year')) {
|
72
|
+
df = df.drop({ columns: ['step_year'] });
|
73
|
+
}
|
74
|
+
if (df.columns.includes('value')) {
|
75
|
+
df = df.drop({ columns: ['value'] });
|
76
|
+
}
|
77
|
+
return df;
|
78
|
+
}
|
79
|
+
// TODO make this work for other types than ANNUAL as well
|
80
|
+
if (df.query(df['type'].ne('ANNUAL')).shape[0] > 0) {
|
81
|
+
throw new Error('Only ANNUAL data is supported for conversion to wide format');
|
82
|
+
}
|
83
|
+
const allYears = [...new Set(df['step_year'].values)];
|
84
|
+
const data = dfd.toJSON(df);
|
85
|
+
const dataMap = new Map();
|
86
|
+
for (const row of data) {
|
87
|
+
const index = getIamcRowIndex(row);
|
88
|
+
if (dataMap.has(index)) {
|
89
|
+
dataMap.get(index).push(row);
|
90
|
+
}
|
91
|
+
else {
|
92
|
+
dataMap.set(index, [row]);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
const wideIamcData = [];
|
96
|
+
for (const iamcRows of dataMap.values()) {
|
97
|
+
wideIamcData.push(buildIamcWideRow(iamcRows, allYears));
|
98
|
+
}
|
99
|
+
return new dfd.DataFrame(wideIamcData);
|
100
|
+
}
|
101
|
+
exports.toIamcWide = toIamcWide;
|
102
|
+
function getIamcRowIndex(row) {
|
103
|
+
return `${row.model}__${row.scenario}__${row.version}__${row.region}__${row.variable}__${row.unit}`;
|
104
|
+
}
|
105
|
+
function buildIamcWideRow(iamcRows, allYears) {
|
106
|
+
const wideRow = Object.assign({}, iamcRows[0]);
|
107
|
+
delete wideRow['step_year'];
|
108
|
+
delete wideRow['value'];
|
109
|
+
const yearsValues = {};
|
110
|
+
iamcRows.forEach((row) => (yearsValues[row.step_year] = row.value));
|
111
|
+
for (const year of allYears) {
|
112
|
+
wideRow[year] = yearsValues[year] || null;
|
113
|
+
}
|
114
|
+
return wideRow;
|
115
|
+
}
|
package/dist/cjs/data/base.js
CHANGED
@@ -166,7 +166,7 @@ class BaseRepository {
|
|
166
166
|
else {
|
167
167
|
const dfList = pages
|
168
168
|
.map((page) => (0, utils_1.jsonToDf)(page))
|
169
|
-
.filter((df) => df.
|
169
|
+
.filter((df) => df.size !== undefined);
|
170
170
|
return dfd.concat({ dfList: dfList, axis: 0 });
|
171
171
|
}
|
172
172
|
}
|
package/dist/cjs/index.js
CHANGED
@@ -1,5 +1,51 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Platform = void 0;
|
26
|
+
exports.danfo = exports.InvalidCredentials = exports.BadFilterArguments = exports.InvalidRunMeta = exports.NoDefaultRunVersion = exports.SchemaError = exports.OperationNotSupported = exports.DeletionPrevented = exports.NotUnique = exports.NotFound = exports.Forbidden = exports.InvalidToken = exports.MissingToken = exports.PlatformNotUnique = exports.PlatformNotFound = exports.UnknownApiError = exports.ManagerApiError = exports.ImproperlyConfigured = exports.BadRequest = exports.InconsistentIamcType = exports.ProgrammingError = exports.IxmpError = exports.Platform = void 0;
|
4
27
|
var platform_1 = require("./core/platform");
|
5
28
|
Object.defineProperty(exports, "Platform", { enumerable: true, get: function () { return platform_1.Platform; } });
|
29
|
+
var exceptions_1 = require("./core/exceptions");
|
30
|
+
Object.defineProperty(exports, "IxmpError", { enumerable: true, get: function () { return exceptions_1.IxmpError; } });
|
31
|
+
Object.defineProperty(exports, "ProgrammingError", { enumerable: true, get: function () { return exceptions_1.ProgrammingError; } });
|
32
|
+
Object.defineProperty(exports, "InconsistentIamcType", { enumerable: true, get: function () { return exceptions_1.InconsistentIamcType; } });
|
33
|
+
Object.defineProperty(exports, "BadRequest", { enumerable: true, get: function () { return exceptions_1.BadRequest; } });
|
34
|
+
Object.defineProperty(exports, "ImproperlyConfigured", { enumerable: true, get: function () { return exceptions_1.ImproperlyConfigured; } });
|
35
|
+
Object.defineProperty(exports, "ManagerApiError", { enumerable: true, get: function () { return exceptions_1.ManagerApiError; } });
|
36
|
+
Object.defineProperty(exports, "UnknownApiError", { enumerable: true, get: function () { return exceptions_1.UnknownApiError; } });
|
37
|
+
Object.defineProperty(exports, "PlatformNotFound", { enumerable: true, get: function () { return exceptions_1.PlatformNotFound; } });
|
38
|
+
Object.defineProperty(exports, "PlatformNotUnique", { enumerable: true, get: function () { return exceptions_1.PlatformNotUnique; } });
|
39
|
+
Object.defineProperty(exports, "MissingToken", { enumerable: true, get: function () { return exceptions_1.MissingToken; } });
|
40
|
+
Object.defineProperty(exports, "InvalidToken", { enumerable: true, get: function () { return exceptions_1.InvalidToken; } });
|
41
|
+
Object.defineProperty(exports, "Forbidden", { enumerable: true, get: function () { return exceptions_1.Forbidden; } });
|
42
|
+
Object.defineProperty(exports, "NotFound", { enumerable: true, get: function () { return exceptions_1.NotFound; } });
|
43
|
+
Object.defineProperty(exports, "NotUnique", { enumerable: true, get: function () { return exceptions_1.NotUnique; } });
|
44
|
+
Object.defineProperty(exports, "DeletionPrevented", { enumerable: true, get: function () { return exceptions_1.DeletionPrevented; } });
|
45
|
+
Object.defineProperty(exports, "OperationNotSupported", { enumerable: true, get: function () { return exceptions_1.OperationNotSupported; } });
|
46
|
+
Object.defineProperty(exports, "SchemaError", { enumerable: true, get: function () { return exceptions_1.SchemaError; } });
|
47
|
+
Object.defineProperty(exports, "NoDefaultRunVersion", { enumerable: true, get: function () { return exceptions_1.NoDefaultRunVersion; } });
|
48
|
+
Object.defineProperty(exports, "InvalidRunMeta", { enumerable: true, get: function () { return exceptions_1.InvalidRunMeta; } });
|
49
|
+
Object.defineProperty(exports, "BadFilterArguments", { enumerable: true, get: function () { return exceptions_1.BadFilterArguments; } });
|
50
|
+
Object.defineProperty(exports, "InvalidCredentials", { enumerable: true, get: function () { return exceptions_1.InvalidCredentials; } });
|
51
|
+
exports.danfo = __importStar(require("danfojs"));
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as dfd from 'danfojs';
|
2
2
|
import { BaseFacade } from '../base';
|
3
|
-
import { dfToDimensionless, substitudeType } from '../utils';
|
3
|
+
import { dfToDimensionless, substitudeType, toIamcWide } from '../utils';
|
4
4
|
import { VariableRepository } from './variable';
|
5
5
|
/**
|
6
6
|
* Represents IAMC format data for a specific Run.
|
@@ -55,10 +55,13 @@ class RunIamcData extends BaseFacade {
|
|
55
55
|
/**
|
56
56
|
* Tabulates IAMC format timeseries data with optional filtering.
|
57
57
|
* @param filter Optional. Filter for tabulating IAMC format timeseries data.
|
58
|
+
* @param wide Optional. Whether to return the data in IAMC wide format or not, defaults to false.
|
58
59
|
* @returns A dfd.DataFrame representing the tabulated data.
|
59
60
|
* @throws An error if illegal filters are applied.
|
60
61
|
*/
|
61
|
-
async tabulate(filter
|
62
|
+
async tabulate({ wide = false, ...filter } = {
|
63
|
+
wide: false,
|
64
|
+
}) {
|
62
65
|
if (filter !== undefined && filter !== null) {
|
63
66
|
// these filters do not make sense when applied from a Run
|
64
67
|
const illegalFilter = Object.keys(filter).filter((key) => {
|
@@ -71,11 +74,13 @@ class RunIamcData extends BaseFacade {
|
|
71
74
|
return await this.repository.tabulate({
|
72
75
|
run: { id: this.run.id, defaultOnly: false },
|
73
76
|
joinRuns: false,
|
77
|
+
wide,
|
74
78
|
...filter,
|
75
79
|
});
|
76
80
|
}
|
77
81
|
async contractParameters(df) {
|
78
82
|
let timeseriesDf = df
|
83
|
+
.loc({ columns: ['region', 'variable', 'unit', 'run__id'] })
|
79
84
|
.groupby(['region', 'variable', 'unit', 'run__id'])
|
80
85
|
.agg({ run__id: 'min' })
|
81
86
|
.loc({ columns: ['region', 'variable', 'unit', 'run__id'] });
|
@@ -118,11 +123,13 @@ class PlatformIamcData extends BaseFacade {
|
|
118
123
|
/**
|
119
124
|
* Tabulates IAMC data with optional filtering.
|
120
125
|
* @param filter Optional. Filter for retrieving IAMC data.
|
121
|
-
* @param
|
126
|
+
* @param joinRuns Optional. Whether to join runs or not, defaults to true.
|
127
|
+
* @param wide Optional. Whether to return the data in IAMC wide format or not, defaults to false.
|
122
128
|
* @returns A Promise that resolves to a dfd.DataFrame containing the tabulated data.
|
123
129
|
*/
|
124
|
-
async tabulate({ joinRuns = true, ...filter } = {
|
130
|
+
async tabulate({ joinRuns = true, wide = false, ...filter } = {
|
125
131
|
joinRuns: true,
|
132
|
+
wide: false,
|
126
133
|
}) {
|
127
134
|
if (filter === undefined) {
|
128
135
|
filter = {};
|
@@ -144,9 +151,8 @@ class PlatformIamcData extends BaseFacade {
|
|
144
151
|
if (df.columns.includes('unit')) {
|
145
152
|
// TODO report bug to danfojs: df.replace('oldValue', '', { columns: ['column_name'] }) throws: Params Error: Must specify param 'newValue' to replace with (probably newValue is cast to boolean and emty string is falsy)
|
146
153
|
df = df.replace('dimensionless', ' ', { columns: ['unit'] });
|
147
|
-
console.warn(`Unit name "dimensionless" has been replaced with ' ', this will be rejected by ixmp4.`);
|
148
154
|
}
|
149
|
-
return df;
|
155
|
+
return wide ? toIamcWide(df) : df;
|
150
156
|
}
|
151
157
|
}
|
152
158
|
export { RunIamcData, PlatformIamcData };
|
package/dist/esm/core/meta.js
CHANGED
@@ -16,9 +16,7 @@ class MetaIndicatorRepository extends BaseFacade {
|
|
16
16
|
if (filter === undefined) {
|
17
17
|
filter = {};
|
18
18
|
}
|
19
|
-
return
|
20
|
-
columns: ['id', 'type'],
|
21
|
-
});
|
19
|
+
return await this.backend.meta.tabulate(filter, joinRunIndex);
|
22
20
|
}
|
23
21
|
}
|
24
22
|
/**
|
package/dist/esm/core/utils.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import * as dfd from 'danfojs';
|
1
2
|
import { DataPointType } from '../data/iamc/datapoint';
|
2
3
|
function substitudeType(df, type) {
|
3
4
|
if (!df.columns.includes(type)) {
|
@@ -31,6 +32,55 @@ function dfToDimensionless(df) {
|
|
31
32
|
}
|
32
33
|
// TODO report bug to danfojs: df.replace('oldValue', '', { columns: ['column_name'] }) throws: Params Error: Must specify param 'newValue' to replace with (probably newValue is cast to boolean and emty string is falsy)
|
33
34
|
df.replace(' ', 'dimensionless', { columns: ['unit'] });
|
35
|
+
console.warn(`Unit name "dimensionless" has been replaced with ' ', this will be rejected by ixmp4.`);
|
34
36
|
return df;
|
35
37
|
}
|
36
|
-
|
38
|
+
function toIamcWide(df) {
|
39
|
+
// cannot convert empty dataframe to wide format
|
40
|
+
if (df.shape[0] === 0) {
|
41
|
+
// drop columns of iamc long format if present
|
42
|
+
if (df.columns.includes('step_year')) {
|
43
|
+
df = df.drop({ columns: ['step_year'] });
|
44
|
+
}
|
45
|
+
if (df.columns.includes('value')) {
|
46
|
+
df = df.drop({ columns: ['value'] });
|
47
|
+
}
|
48
|
+
return df;
|
49
|
+
}
|
50
|
+
// TODO make this work for other types than ANNUAL as well
|
51
|
+
if (df.query(df['type'].ne('ANNUAL')).shape[0] > 0) {
|
52
|
+
throw new Error('Only ANNUAL data is supported for conversion to wide format');
|
53
|
+
}
|
54
|
+
const allYears = [...new Set(df['step_year'].values)];
|
55
|
+
const data = dfd.toJSON(df);
|
56
|
+
const dataMap = new Map();
|
57
|
+
for (const row of data) {
|
58
|
+
const index = getIamcRowIndex(row);
|
59
|
+
if (dataMap.has(index)) {
|
60
|
+
dataMap.get(index).push(row);
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
dataMap.set(index, [row]);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
const wideIamcData = [];
|
67
|
+
for (const iamcRows of dataMap.values()) {
|
68
|
+
wideIamcData.push(buildIamcWideRow(iamcRows, allYears));
|
69
|
+
}
|
70
|
+
return new dfd.DataFrame(wideIamcData);
|
71
|
+
}
|
72
|
+
function getIamcRowIndex(row) {
|
73
|
+
return `${row.model}__${row.scenario}__${row.version}__${row.region}__${row.variable}__${row.unit}`;
|
74
|
+
}
|
75
|
+
function buildIamcWideRow(iamcRows, allYears) {
|
76
|
+
const wideRow = { ...iamcRows[0] };
|
77
|
+
delete wideRow['step_year'];
|
78
|
+
delete wideRow['value'];
|
79
|
+
const yearsValues = {};
|
80
|
+
iamcRows.forEach((row) => (yearsValues[row.step_year] = row.value));
|
81
|
+
for (const year of allYears) {
|
82
|
+
wideRow[year] = yearsValues[year] || null;
|
83
|
+
}
|
84
|
+
return wideRow;
|
85
|
+
}
|
86
|
+
export { substitudeType, unitToDimensionless, dfToDimensionless, toIamcWide };
|
package/dist/esm/data/base.js
CHANGED
package/dist/esm/index.js
CHANGED
@@ -1 +1,3 @@
|
|
1
1
|
export { Platform } from './core/platform';
|
2
|
+
export { IxmpError, ProgrammingError, InconsistentIamcType, BadRequest, ImproperlyConfigured, ManagerApiError, UnknownApiError, PlatformNotFound, PlatformNotUnique, MissingToken, InvalidToken, Forbidden, NotFound, NotUnique, DeletionPrevented, OperationNotSupported, SchemaError, NoDefaultRunVersion, InvalidRunMeta, BadFilterArguments, InvalidCredentials, } from './core/exceptions';
|
3
|
+
export * as danfo from 'danfojs';
|
@@ -55,10 +55,13 @@ declare class RunIamcData extends BaseFacade {
|
|
55
55
|
/**
|
56
56
|
* Tabulates IAMC format timeseries data with optional filtering.
|
57
57
|
* @param filter Optional. Filter for tabulating IAMC format timeseries data.
|
58
|
+
* @param wide Optional. Whether to return the data in IAMC wide format or not, defaults to false.
|
58
59
|
* @returns A dfd.DataFrame representing the tabulated data.
|
59
60
|
* @throws An error if illegal filters are applied.
|
60
61
|
*/
|
61
|
-
tabulate(filter?:
|
62
|
+
tabulate({ wide, ...filter }?: {
|
63
|
+
wide?: boolean;
|
64
|
+
} & IamcDataFilter): Promise<dfd.DataFrame>;
|
62
65
|
private contractParameters;
|
63
66
|
}
|
64
67
|
/**
|
@@ -77,11 +80,13 @@ declare class PlatformIamcData extends BaseFacade {
|
|
77
80
|
/**
|
78
81
|
* Tabulates IAMC data with optional filtering.
|
79
82
|
* @param filter Optional. Filter for retrieving IAMC data.
|
80
|
-
* @param
|
83
|
+
* @param joinRuns Optional. Whether to join runs or not, defaults to true.
|
84
|
+
* @param wide Optional. Whether to return the data in IAMC wide format or not, defaults to false.
|
81
85
|
* @returns A Promise that resolves to a dfd.DataFrame containing the tabulated data.
|
82
86
|
*/
|
83
|
-
tabulate({ joinRuns, ...filter }?: {
|
87
|
+
tabulate({ joinRuns, wide, ...filter }?: {
|
84
88
|
joinRuns?: boolean;
|
89
|
+
wide?: boolean;
|
85
90
|
} & IamcDataFilter): Promise<dfd.DataFrame>;
|
86
91
|
}
|
87
92
|
export { RunIamcData, PlatformIamcData };
|
package/dist/types/core/run.d.ts
CHANGED
@@ -9,12 +9,20 @@ import { RunMetaIndicatorRepository } from './meta';
|
|
9
9
|
import { ModelFilter as BaseModelFilter } from '../data/model';
|
10
10
|
import { RunFilter as BaseRunFilter } from '../data/run';
|
11
11
|
import { ScenarioFilter as BaseScenarioFilter } from '../data/scenario';
|
12
|
+
import { VariableFilter as BaseVariableFilter } from '../data/iamc/variable';
|
13
|
+
import { UnitFilter as BaseUnitFilter } from '../data/unit';
|
14
|
+
import { RegionFilter as BaseRegionFilter } from '../data/region';
|
12
15
|
/**
|
13
16
|
* Represents a filter for listing and tabulating runs.
|
14
17
|
*/
|
15
18
|
type RunFilter = BaseRunFilter & {
|
16
19
|
model?: BaseModelFilter;
|
17
20
|
scenario?: BaseScenarioFilter;
|
21
|
+
iamc?: {
|
22
|
+
variable?: BaseVariableFilter;
|
23
|
+
region?: BaseRegionFilter;
|
24
|
+
unit?: BaseUnitFilter;
|
25
|
+
};
|
18
26
|
};
|
19
27
|
/**
|
20
28
|
* Represents a Modeling Run.
|
@@ -3,4 +3,5 @@ import { DataPointType } from '../data/iamc/datapoint';
|
|
3
3
|
declare function substitudeType(df: dfd.DataFrame, type?: DataPointType): dfd.DataFrame;
|
4
4
|
declare function unitToDimensionless(name: string): string;
|
5
5
|
declare function dfToDimensionless(df: dfd.DataFrame): dfd.DataFrame;
|
6
|
-
|
6
|
+
declare function toIamcWide(df: dfd.DataFrame): dfd.DataFrame;
|
7
|
+
export { substitudeType, unitToDimensionless, dfToDimensionless, toIamcWide };
|
package/dist/types/index.d.ts
CHANGED
@@ -18,3 +18,5 @@ export type { DataPoint as DataPointModel } from './data/iamc/datapoint';
|
|
18
18
|
export type { Variable as VariableModel } from './data/iamc/variable';
|
19
19
|
export type { TimeSeries as TimeSeriesModel } from './data/iamc/timeseries';
|
20
20
|
export type { Lookup } from './data/filters';
|
21
|
+
export { IxmpError, ProgrammingError, InconsistentIamcType, BadRequest, ImproperlyConfigured, ManagerApiError, UnknownApiError, PlatformNotFound, PlatformNotUnique, MissingToken, InvalidToken, Forbidden, NotFound, NotUnique, DeletionPrevented, OperationNotSupported, SchemaError, NoDefaultRunVersion, InvalidRunMeta, BadFilterArguments, InvalidCredentials, } from './core/exceptions';
|
22
|
+
export * as danfo from 'danfojs';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@iiasa/ixmp4-ts",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "typescript client for ixmp4, a data warehouse for scenario analysis",
|
6
6
|
"repository": {
|
@@ -58,8 +58,8 @@
|
|
58
58
|
"lint:prettier:root": "prettier 'src/**/*.{js,mjs,cjs,ts,json}'",
|
59
59
|
"lint": "npm run lint:js && npm run lint:prettier",
|
60
60
|
"lint:fix": "npm run lint:prettier:root -- --write --list-different && npm run lint:js -- --fix",
|
61
|
-
"test": "
|
62
|
-
"test:debug": "DEBUG=testcontainers:containers
|
61
|
+
"test": "vitest run",
|
62
|
+
"test:debug": "DEBUG=testcontainers:containers vitest run",
|
63
63
|
"prepublishOnly": "npm run build",
|
64
64
|
"doc": "typedoc --out ./doc/build ./src"
|
65
65
|
},
|
@@ -81,19 +81,16 @@
|
|
81
81
|
},
|
82
82
|
"devDependencies": {
|
83
83
|
"@nuxt/eslint-config": "^0.2.0",
|
84
|
-
"@types/jest": "^29.5.10",
|
85
84
|
"@types/web": "^0.0.134",
|
86
85
|
"@types/webgl-ext": "^0.0.36",
|
87
86
|
"@types/webgl2": "^0.0.10",
|
88
87
|
"eslint-config-prettier": "^9.0.0",
|
89
88
|
"eslint-plugin-prettier": "^5.0.1",
|
90
|
-
"jest": "^29.7.0",
|
91
|
-
"jest-extended": "^4.0.2",
|
92
89
|
"prettier": "^3.1.0",
|
93
90
|
"testcontainers": "^10.3.2",
|
94
|
-
"ts-jest": "^29.1.1",
|
95
91
|
"typedoc": "^0.25.7",
|
96
|
-
"typescript": "^5.3.2"
|
92
|
+
"typescript": "^5.3.2",
|
93
|
+
"vitest": "^1.3.1"
|
97
94
|
},
|
98
95
|
"dependencies": {
|
99
96
|
"axios": "^1.6.2",
|