@iiasa/ixmp4-ts 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/cjs/core/exceptions.js +2 -2
  2. package/dist/cjs/core/iamc/data.js +57 -34
  3. package/dist/cjs/core/iamc/variable.js +10 -0
  4. package/dist/cjs/core/meta.js +15 -5
  5. package/dist/cjs/core/model.js +10 -0
  6. package/dist/cjs/core/region.js +10 -0
  7. package/dist/cjs/core/run.js +14 -4
  8. package/dist/cjs/core/scenario.js +10 -0
  9. package/dist/cjs/core/unit.js +10 -0
  10. package/dist/cjs/core/utils.js +187 -55
  11. package/dist/cjs/data/base.js +25 -7
  12. package/dist/cjs/data/iamc/datapoint.js +20 -11
  13. package/dist/cjs/data/iamc/timeseries.js +12 -12
  14. package/dist/cjs/data/iamc/variable.js +9 -4
  15. package/dist/cjs/data/meta.js +9 -4
  16. package/dist/cjs/data/model.js +9 -4
  17. package/dist/cjs/data/region.js +9 -4
  18. package/dist/cjs/data/run.js +9 -4
  19. package/dist/cjs/data/scenario.js +9 -4
  20. package/dist/cjs/data/unit.js +9 -4
  21. package/dist/cjs/data/utils.js +4 -5
  22. package/dist/cjs/dataframe/dataframe.js +1 -5
  23. package/dist/cjs/dataframe/utils.js +4 -5
  24. package/dist/cjs/index.js +3 -1
  25. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  26. package/dist/esm/core/iamc/data.js +51 -30
  27. package/dist/esm/core/iamc/variable.js +8 -0
  28. package/dist/esm/core/meta.js +8 -0
  29. package/dist/esm/core/model.js +8 -0
  30. package/dist/esm/core/region.js +8 -0
  31. package/dist/esm/core/run.js +8 -0
  32. package/dist/esm/core/scenario.js +8 -0
  33. package/dist/esm/core/unit.js +8 -0
  34. package/dist/esm/core/utils.js +176 -50
  35. package/dist/esm/data/base.js +16 -0
  36. package/dist/esm/data/iamc/datapoint.js +8 -1
  37. package/dist/esm/data/iamc/variable.js +3 -0
  38. package/dist/esm/data/meta.js +3 -0
  39. package/dist/esm/data/model.js +3 -0
  40. package/dist/esm/data/region.js +3 -0
  41. package/dist/esm/data/run.js +3 -0
  42. package/dist/esm/data/scenario.js +3 -0
  43. package/dist/esm/data/unit.js +3 -0
  44. package/dist/esm/dataframe/dataframe.js +1 -5
  45. package/dist/esm/index.js +1 -0
  46. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  47. package/dist/types/core/iamc/data.d.ts +35 -5
  48. package/dist/types/core/iamc/variable.d.ts +6 -0
  49. package/dist/types/core/meta.d.ts +6 -0
  50. package/dist/types/core/model.d.ts +6 -0
  51. package/dist/types/core/region.d.ts +6 -0
  52. package/dist/types/core/run.d.ts +6 -0
  53. package/dist/types/core/scenario.d.ts +6 -0
  54. package/dist/types/core/unit.d.ts +6 -0
  55. package/dist/types/core/utils.d.ts +30 -1
  56. package/dist/types/data/base.d.ts +4 -0
  57. package/dist/types/data/iamc/datapoint.d.ts +3 -1
  58. package/dist/types/data/iamc/variable.d.ts +1 -0
  59. package/dist/types/data/meta.d.ts +1 -0
  60. package/dist/types/data/model.d.ts +1 -0
  61. package/dist/types/data/region.d.ts +1 -0
  62. package/dist/types/data/run.d.ts +1 -0
  63. package/dist/types/data/scenario.d.ts +1 -0
  64. package/dist/types/data/unit.d.ts +1 -0
  65. package/dist/types/index.d.ts +2 -1
  66. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  67. package/package.json +4 -5
@@ -29,78 +29,132 @@ function unitToDimensionless(name) {
29
29
  function dfToDimensionless(df) {
30
30
  if (df
31
31
  .loc({ columns: ['unit'] })
32
- .values.map(toString)
32
+ .values.map(String)
33
33
  .includes('dimensionless')) {
34
34
  throw new Error("Unit name 'dimensionless' is reserved, use an empty string '' instead.");
35
35
  }
36
36
  df.replaceValue('', 'dimensionless', 'unit');
37
37
  return df;
38
38
  }
39
+ /**
40
+ * Standardizes the columns of a DataFrame in IAMC format.
41
+ * @param df DataFrame in IAMC format
42
+ * @returns DataFrame in IAMC format with standardized columns
43
+ */
44
+ function standardizeIamcDf(df) {
45
+ if (df.columns.includes('time_series__id')) {
46
+ df = df.dropColumns(['time_series__id']);
47
+ }
48
+ if (df.columns.includes('unit')) {
49
+ df = df.replaceValue('dimensionless', ' ', 'unit');
50
+ }
51
+ // Rename step_category to subannual
52
+ if (df.columns.includes('step_category')) {
53
+ df = df.renameColumns({ step_category: 'subannual' });
54
+ }
55
+ return df;
56
+ }
57
+ /**
58
+ * Converts a DataFrame in IAMC long format to wide format.
59
+ * @param df The DataFrame to convert
60
+ * @returns A DataFrame in IAMC wide format
61
+ */
39
62
  function toIamcWide(df) {
40
- // cannot convert empty dataframe to wide format
63
+ // empty df: drop long-format columns if present
41
64
  if (df.shape[0] === 0) {
42
- // drop columns of iamc long format if present
43
- if (df.columns.includes('step_year')) {
44
- df = df.dropColumns(['step_year']);
45
- }
46
- if (df.columns.includes('value')) {
47
- df = df.dropColumns(['value']);
48
- }
49
- return df;
50
- }
51
- // TODO make this work for other types than ANNUAL as well
52
- const types = df.columnValues('type');
53
- if (types.some((type) => type !== 'ANNUAL')) {
54
- throw new Error('Only ANNUAL data is supported for conversion to wide format');
55
- }
56
- const allYears = [...new Set(df.columnValues('step_year'))];
57
- allYears.sort();
58
- const stepYearIndex = df.columns.indexOf('step_year');
59
- const valueIndex = df.columns.indexOf('value');
60
- const newColumnsIndices = df.columns
65
+ const longCols = [
66
+ 'step_year',
67
+ 'step_datetime',
68
+ 'step_category',
69
+ 'subannual',
70
+ 'value',
71
+ ];
72
+ const toDrop = longCols.filter((c) => df.columns.includes(c));
73
+ return toDrop.length ? df.dropColumns(toDrop) : df;
74
+ }
75
+ // column index map
76
+ const colIdx = Object.fromEntries(df.columns.map((c, i) => [c, i]));
77
+ // collect unique, non-null times
78
+ const uniqueNonNull = (arr) => [...new Set(arr.filter((v) => v !== null && v !== undefined))];
79
+ const years = df.columns.includes('step_year')
80
+ ? uniqueNonNull(df.columnValues('step_year')).sort((a, b) => a - b)
81
+ : [];
82
+ const datetimes = df.columns.includes('step_datetime')
83
+ ? uniqueNonNull(df.columnValues('step_datetime')).sort()
84
+ : [];
85
+ const allTimes = sortTimesWithYearFirst(years, datetimes);
86
+ // indices to carry over (everything but time and value)
87
+ const takeOverIdx = df.columns
61
88
  .map((_, i) => i)
62
- .filter((i) => i !== stepYearIndex && i !== valueIndex);
63
- const columns = [];
64
- const dtypes = [];
65
- for (const index of newColumnsIndices) {
66
- columns.push(df.columns[index]);
67
- dtypes.push(df.dtypes[index]);
68
- }
69
- const yearColumnsIndex = new Map();
70
- for (const year of allYears) {
71
- columns.push(year.toString());
89
+ .filter((i) => i !== (colIdx['step_year'] ?? -1) &&
90
+ i !== (colIdx['step_datetime'] ?? -1) &&
91
+ i !== (colIdx['value'] ?? -1));
92
+ // base schema (carry-over columns + dtypes)
93
+ const columns = takeOverIdx.map((i) => df.columns[i]);
94
+ const dtypes = takeOverIdx.map((i) => df.dtypes[i]);
95
+ // add time columns
96
+ const yearColIdx = new Map();
97
+ const dtColIdx = new Map();
98
+ for (const time of allTimes) {
99
+ columns.push(String(time));
72
100
  dtypes.push(DType.FLOAT32);
73
- yearColumnsIndex.set(year, columns.length - 1);
101
+ const newIdx = columns.length - 1;
102
+ if (typeof time === 'number')
103
+ yearColIdx.set(time, newIdx);
104
+ else
105
+ dtColIdx.set(time, newIdx);
74
106
  }
75
- const rowIdentifiers = [
107
+ // row identifiers: prefer step_category, fall back to subannual if present
108
+ const stepCategoryCol = df.columns.includes('step_category')
109
+ ? 'step_category'
110
+ : df.columns.includes('subannual')
111
+ ? 'subannual'
112
+ : undefined;
113
+ const idCols = [
76
114
  'model',
77
115
  'scenario',
78
116
  'version',
79
117
  'region',
80
118
  'variable',
81
119
  'unit',
82
- ].map((col) => df.columns.indexOf(col));
120
+ 'type',
121
+ stepCategoryCol,
122
+ ].filter(Boolean);
123
+ const idIdxs = idCols.map((c) => colIdx[c]);
124
+ // data mapping
83
125
  const dataMap = new Map();
84
- for (const row of df.values) {
85
- const index = getIamcRowIndex(row, rowIdentifiers);
86
- if (dataMap.has(index)) {
87
- dataMap.get(index)[yearColumnsIndex.get(row[stepYearIndex])] =
88
- row[valueIndex];
126
+ const yearIdx = colIdx['step_year'];
127
+ const dtIdx = colIdx['step_datetime'];
128
+ const valueIdx = colIdx['value'];
129
+ for (const dfRow of df.values) {
130
+ const key = getIamcRowIndex(dfRow, idIdxs);
131
+ let wideRow = dataMap.get(key);
132
+ if (!wideRow) {
133
+ wideRow = takeOverIdx
134
+ .map((i) => dfRow[i])
135
+ .concat(Array(allTimes.length).fill(null));
136
+ dataMap.set(key, wideRow);
89
137
  }
90
- else {
91
- const wideRow = row
92
- .filter((_, i) => newColumnsIndices.includes(i))
93
- .concat(new Array(allYears.length).fill(null));
94
- wideRow[yearColumnsIndex.get(row[stepYearIndex])] = row[valueIndex];
95
- dataMap.set(index, wideRow);
138
+ const year = yearIdx !== undefined ? dfRow[yearIdx] : undefined;
139
+ const dt = dtIdx !== undefined ? dfRow[dtIdx] : undefined;
140
+ let targetIdx;
141
+ if (year !== undefined && year !== null)
142
+ targetIdx = yearColIdx.get(year);
143
+ else if (dt !== undefined && dt !== null)
144
+ targetIdx = dtColIdx.get(dt);
145
+ if (targetIdx !== undefined) {
146
+ wideRow[targetIdx] = dfRow[valueIdx];
96
147
  }
97
148
  }
98
- const wideIamcData = [];
99
- for (const wideRow of dataMap.values()) {
100
- wideIamcData.push(wideRow);
101
- }
149
+ const wideIamcData = Array.from(dataMap.values());
102
150
  return new DataFrame(wideIamcData, { columns, dtypes });
103
151
  }
152
+ /**
153
+ * Generates a unique row index for IAMC data based on the row's identifiers.
154
+ * @param row The row data as an array
155
+ * @param rowIdentifiers The indices of the identifiers in the row
156
+ * @returns A string that uniquely identifies the row
157
+ */
104
158
  function getIamcRowIndex(row, rowIdentifiers) {
105
159
  return rowIdentifiers.map((i) => row[i]).join('_');
106
160
  }
@@ -124,4 +178,76 @@ function withIamcDefault(filter) {
124
178
  }
125
179
  return filter;
126
180
  }
127
- export { substitudeType, unitToDimensionless, dfToDimensionless, toIamcWide, withIamcDefault, };
181
+ function sortTimesWithYearFirst(years, dateTimes) {
182
+ // Create a combined array with type information
183
+ const combined = [];
184
+ // Add years with their metadata
185
+ for (const year of years) {
186
+ combined.push({ value: year, isYear: true, year });
187
+ }
188
+ // Add datetimes with their extracted year
189
+ for (const dateTime of dateTimes) {
190
+ // Extract year from datetime string (format: 2005-03-01T01:00:00)
191
+ const year = parseInt(dateTime.substring(0, 4), 10);
192
+ combined.push({ value: dateTime, isYear: false, year });
193
+ }
194
+ // Sort by year first, then by type (years before datetimes), then by value
195
+ combined.sort((a, b) => {
196
+ // First sort by year
197
+ if (a.year !== b.year) {
198
+ return a.year - b.year;
199
+ }
200
+ // Within the same year, years come before datetimes
201
+ if (a.isYear && !b.isYear) {
202
+ return -1;
203
+ }
204
+ if (!a.isYear && b.isYear) {
205
+ return 1;
206
+ }
207
+ // If both are the same type, sort by value
208
+ if (a.value < b.value) {
209
+ return -1;
210
+ }
211
+ if (a.value > b.value) {
212
+ return 1;
213
+ }
214
+ return 0;
215
+ });
216
+ // Return just the values
217
+ return combined.map((item) => item.value);
218
+ }
219
+ /**
220
+ * Splits a DataFrame into separate DataFrames based on DataPointType.
221
+ * @param df The DataFrame to split
222
+ * @returns An object containing DataFrames for each type present in the data
223
+ */
224
+ function splitDataFrameByType(df) {
225
+ const result = {};
226
+ // If no type column exists, return the original dataframe as annual
227
+ if (!df.columns.includes('type')) {
228
+ result.annual = df;
229
+ return result;
230
+ }
231
+ // Get unique types in the dataframe
232
+ const typeValues = df.columnValues('type');
233
+ const uniqueTypes = [...new Set(typeValues)];
234
+ // Filter dataframe for each type present
235
+ for (const type of uniqueTypes) {
236
+ const filteredDf = df.query({
237
+ conditions: { column: 'type', predicate: (value) => value === type },
238
+ });
239
+ switch (type) {
240
+ case DataPointType.ANNUAL:
241
+ result.annual = filteredDf;
242
+ break;
243
+ case DataPointType.CATEGORICAL:
244
+ result.categorical = filteredDf;
245
+ break;
246
+ case DataPointType.DATETIME:
247
+ result.datetime = filteredDf;
248
+ break;
249
+ }
250
+ }
251
+ return result;
252
+ }
253
+ export { substitudeType, unitToDimensionless, dfToDimensionless, standardizeIamcDf, toIamcWide, withIamcDefault, getIamcRowIndex, sortTimesWithYearFirst, splitDataFrameByType, };
@@ -126,6 +126,22 @@ class BaseRepository {
126
126
  return jsonToDf(data);
127
127
  }
128
128
  }
129
+ async _count({ filter, params, }) {
130
+ if (this.enumerationMethod === 'GET') {
131
+ params = { ...params, ...filter, limit: 0 };
132
+ filter = undefined;
133
+ }
134
+ else {
135
+ params = { ...params, limit: 0 };
136
+ }
137
+ const data = await this._requestEnumeration(params, filter, true);
138
+ if (data === undefined || data.total === undefined) {
139
+ throw new UnknownApiError({
140
+ message: 'Count result does not contain total count.',
141
+ });
142
+ }
143
+ return data.total;
144
+ }
129
145
  async _bulkUpsert(df, params) {
130
146
  return await this._request(`${this.prefix}bulk/`, 'POST', params, dfToJson(df));
131
147
  }
@@ -16,9 +16,10 @@ class DataPointRepository extends BaseRepository {
16
16
  params: { joinParameters },
17
17
  }));
18
18
  }
19
- async tabulate({ joinParameters = false, joinRuns = false, filter = {}, } = {
19
+ async tabulate({ joinParameters = false, joinRuns = false, joinRunId = false, filter = {}, } = {
20
20
  joinParameters: false,
21
21
  joinRuns: false,
22
+ joinRunId: false,
22
23
  filter: {},
23
24
  }) {
24
25
  return await this._tabulate({
@@ -26,9 +27,15 @@ class DataPointRepository extends BaseRepository {
26
27
  params: {
27
28
  joinParameters,
28
29
  joinRuns,
30
+ joinRunId,
29
31
  },
30
32
  });
31
33
  }
34
+ async count(filter = {}) {
35
+ return await this._count({
36
+ filter,
37
+ });
38
+ }
32
39
  async bulkUpsert(df) {
33
40
  await this._bulkUpsert(df);
34
41
  }
@@ -13,6 +13,9 @@ class VariableRepository extends BaseRepository {
13
13
  async tabulate(filter = {}) {
14
14
  return await this._tabulate({ filter });
15
15
  }
16
+ async count(filter = {}) {
17
+ return await this._count({ filter });
18
+ }
16
19
  async create(name) {
17
20
  return await this._post({ name });
18
21
  }
@@ -14,6 +14,9 @@ class MetaIndicatorRepository extends BaseRepository {
14
14
  async tabulate(filter = {}, joinRunIndex) {
15
15
  return await this._tabulate({ filter, params: { joinRunIndex } });
16
16
  }
17
+ async count(filter = {}) {
18
+ return await this._count({ filter });
19
+ }
17
20
  async create(run__id, key, value) {
18
21
  const res = await this._post({
19
22
  run__id,
@@ -13,6 +13,9 @@ class ModelRepository extends BaseRepository {
13
13
  async tabulate(filter = {}) {
14
14
  return await this._tabulate({ filter });
15
15
  }
16
+ async count(filter = {}) {
17
+ return await this._count({ filter });
18
+ }
16
19
  async create(name) {
17
20
  const res = await this._post({ name });
18
21
  return res;
@@ -14,6 +14,9 @@ class RegionRepository extends BaseRepository {
14
14
  async tabulate(filter = {}) {
15
15
  return await this._tabulate({ filter });
16
16
  }
17
+ async count(filter = {}) {
18
+ return await this._count({ filter });
19
+ }
17
20
  async create(name, hierarchy) {
18
21
  const res = await this._post({
19
22
  name: name,
@@ -8,6 +8,9 @@ class RunRepository extends BaseRepository {
8
8
  async tabulate(filter = {}) {
9
9
  return await this._tabulate({ filter });
10
10
  }
11
+ async count(filter = {}) {
12
+ return await this._count({ filter });
13
+ }
11
14
  async create(modelName, scenarioName) {
12
15
  const res = await this._post({
13
16
  model_name: modelName,
@@ -13,6 +13,9 @@ class ScenarioRepository extends BaseRepository {
13
13
  async tabulate(filter = {}) {
14
14
  return await this._tabulate({ filter });
15
15
  }
16
+ async count(filter = {}) {
17
+ return await this._count({ filter });
18
+ }
16
19
  async create(name) {
17
20
  return (await this._post({ name }));
18
21
  }
@@ -22,5 +22,8 @@ class UnitRepository extends BaseRepository {
22
22
  async tabulate(filter = {}) {
23
23
  return await this._tabulate({ filter });
24
24
  }
25
+ async count(filter = {}) {
26
+ return await this._count({ filter });
27
+ }
25
28
  }
26
29
  export { UnitRepository };
@@ -191,11 +191,7 @@ class DataFrame {
191
191
  values = options.rows.map((i) => values[i]);
192
192
  index = options.rows.map((i) => index[i]);
193
193
  }
194
- return new DataFrame(values, {
195
- index,
196
- columns,
197
- dtypes,
198
- });
194
+ return new DataFrame(values, { index, columns, dtypes });
199
195
  }
200
196
  /**
201
197
  * Returns the value at the specified index and column.
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { Platform } from './core/platform';
2
+ export { DataPointType } from './data/iamc/datapoint';
2
3
  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
4
  export { DataFrame, DType, concat, toJson, toCsv, merge, DataFrameError, InvalidColumn, InvalidIndex, } from './dataframe';
@@ -0,0 +1 @@
1
+ {"root":["../../src/backend.ts","../../src/index.ts","../../src/core/base.ts","../../src/core/exceptions.ts","../../src/core/meta.ts","../../src/core/model.ts","../../src/core/platform.ts","../../src/core/region.ts","../../src/core/run.ts","../../src/core/scenario.ts","../../src/core/unit.ts","../../src/core/utils.ts","../../src/core/iamc/data.ts","../../src/core/iamc/variable.ts","../../src/data/base.ts","../../src/data/docs.ts","../../src/data/filters.ts","../../src/data/info.ts","../../src/data/meta.ts","../../src/data/model.ts","../../src/data/region.ts","../../src/data/run.ts","../../src/data/scenario.ts","../../src/data/unit.ts","../../src/data/utils.ts","../../src/data/iamc/datapoint.ts","../../src/data/iamc/index.ts","../../src/data/iamc/timeseries.ts","../../src/data/iamc/variable.ts","../../src/dataframe/dataframe.ts","../../src/dataframe/exceptions.ts","../../src/dataframe/index.ts","../../src/dataframe/utils.ts"],"version":"5.9.2"}
@@ -11,6 +11,15 @@ import { RunFilter as BaseRunFilter } from '../../data/run';
11
11
  import { ScenarioFilter as BaseScenarioFilter } from '../../data/scenario';
12
12
  import { IamcDataFilter as BaseIamcDataFilter } from '../../data/iamc/datapoint';
13
13
  import { VariableRepository } from './variable';
14
+ /**
15
+ * Represents the result of tabulating IAMC data with metadata about present types.
16
+ */
17
+ type IamcDataResult = {
18
+ presentTypes: DataPointType[];
19
+ annual?: DataFrame;
20
+ categorical?: DataFrame;
21
+ datetime?: DataFrame;
22
+ };
14
23
  /**
15
24
  * Represents a filter for tabulating IAMC format data.
16
25
  */
@@ -56,11 +65,17 @@ declare class RunIamcData extends BaseFacade {
56
65
  * Tabulates IAMC format timeseries data with optional filtering.
57
66
  * @param filter Optional. Filter for tabulating IAMC format timeseries data.
58
67
  * @param wide Optional. Whether to return the data in IAMC wide format or not, defaults to false.
59
- * @returns A DataFrame representing the tabulated data.
68
+ * @param splitByType Optional. Whether to return separate DataFrames for different DataPointTypes, defaults to false.
69
+ * @returns A DataFrame representing the tabulated data, or a IamcDataResult with metadata and separate DataFrames by type if splitByType is true.
60
70
  * @throws An error if illegal filters are applied.
61
71
  */
62
- tabulate({ wide, ...filter }?: {
72
+ tabulate(params: {
73
+ wide?: boolean;
74
+ splitByType: true;
75
+ } & IamcDataFilter): Promise<IamcDataResult>;
76
+ tabulate(params?: {
63
77
  wide?: boolean;
78
+ splitByType?: boolean;
64
79
  } & IamcDataFilter): Promise<DataFrame>;
65
80
  private contractParameters;
66
81
  }
@@ -82,12 +97,27 @@ declare class PlatformIamcData extends BaseFacade {
82
97
  * @param filter Optional. Filter for retrieving IAMC data.
83
98
  * @param joinRuns Optional. Whether to join runs or not, defaults to true.
84
99
  * @param wide Optional. Whether to return the data in IAMC wide format or not, defaults to false.
85
- * @returns A Promise that resolves to a DataFrame containing the tabulated data.
100
+ * @param splitByType Optional. Whether to return separate DataFrames for different DataPointTypes, defaults to false.
101
+ * @returns A Promise that resolves to a DataFrame containing the tabulated data, or a IamcDataResult with metadata and separate DataFrames by type if splitByType is true.
86
102
  */
87
- tabulate({ joinRuns, wide, ...filter }?: {
103
+ tabulate(params: {
88
104
  joinRuns?: boolean;
105
+ joinRunId?: boolean;
89
106
  wide?: boolean;
107
+ splitByType: true;
108
+ } & IamcDataFilter): Promise<IamcDataResult>;
109
+ tabulate(params?: {
110
+ joinRuns?: boolean;
111
+ joinRunId?: boolean;
112
+ wide?: boolean;
113
+ splitByType?: boolean;
90
114
  } & IamcDataFilter): Promise<DataFrame>;
115
+ /**
116
+ * Counts IAMC datapoints with optional filtering.
117
+ * @param filter Optional. Filter for counting IAMC datapoints.
118
+ * @returns A promise that resolves to the count of datapoints.
119
+ */
120
+ count(filter?: IamcDataFilter): Promise<number>;
91
121
  }
92
122
  export { RunIamcData, PlatformIamcData };
93
- export type { IamcDataFilter };
123
+ export type { IamcDataFilter, IamcDataResult };
@@ -93,6 +93,12 @@ declare class VariableRepository extends BaseFacade {
93
93
  * @returns A Promise that resolves to the tabulated result.
94
94
  */
95
95
  tabulate(filter?: VariableFilter): Promise<any>;
96
+ /**
97
+ * Counts Variables with optional filtering.
98
+ * @param filter Optional. Filter for counting Variables.
99
+ * @returns A Promise that resolves to the count of Variables.
100
+ */
101
+ count(filter?: VariableFilter): Promise<number>;
96
102
  }
97
103
  export { Variable, VariableRepository };
98
104
  export type { VariableFilter };
@@ -28,6 +28,12 @@ declare class MetaIndicatorRepository extends BaseFacade {
28
28
  tabulate({ joinRunIndex, ...filter }?: {
29
29
  joinRunIndex?: boolean;
30
30
  } & MetaIndicatorFilter): Promise<DataFrame>;
31
+ /**
32
+ * Counts meta indicators with optional filtering.
33
+ * @param filter Optional. Filter for counting meta indicators.
34
+ * @returns A promise that resolves to the count of meta indicators.
35
+ */
36
+ count(filter?: MetaIndicatorFilter): Promise<number>;
31
37
  }
32
38
  /**
33
39
  * Repository for accessing meta indicators of a specific run.
@@ -96,6 +96,12 @@ declare class ModelRepository extends BaseFacade {
96
96
  * @returns A promise that resolves to the tabulated result.
97
97
  */
98
98
  tabulate(filter?: ModelFilter): Promise<DataFrame>;
99
+ /**
100
+ * Counts models with optional filtering.
101
+ * @param filter Optional. Filter for counting models.
102
+ * @returns A promise that resolves to the count of models.
103
+ */
104
+ count(filter?: ModelFilter): Promise<number>;
99
105
  }
100
106
  export { Model, ModelRepository };
101
107
  export type { ModelFilter };
@@ -108,6 +108,12 @@ declare class RegionRepository extends BaseFacade {
108
108
  * @returns A promise that resolves to a DataFrame containing the tabulated regions.
109
109
  */
110
110
  tabulate(filter?: RegionFilter): Promise<DataFrame>;
111
+ /**
112
+ * Counts regions with optional filtering.
113
+ * @param filter Optional. Filter for counting regions.
114
+ * @returns A promise that resolves to the count of regions.
115
+ */
116
+ count(filter?: RegionFilter): Promise<number>;
111
117
  }
112
118
  export { Region as Region, RegionRepository };
113
119
  export type { RegionFilter };
@@ -123,6 +123,12 @@ declare class RunRepository extends BaseFacade {
123
123
  * @returns A promise that resolves to a DataFrame containing the tabulated runs.
124
124
  */
125
125
  tabulate(filter?: RunFilter): Promise<DataFrame>;
126
+ /**
127
+ * Counts runs with optional filtering.
128
+ * @param filter Optional. Filter for counting runs.
129
+ * @returns A promise that resolves to the count of runs.
130
+ */
131
+ count(filter?: RunFilter): Promise<number>;
126
132
  }
127
133
  export { Run, RunRepository };
128
134
  export type { RunFilter };
@@ -101,6 +101,12 @@ declare class ScenarioRepository extends BaseFacade {
101
101
  * @returns A Promise that resolves to a DataFrame containing the tabulated data.
102
102
  */
103
103
  tabulate(filter?: ScenarioFilter): Promise<DataFrame>;
104
+ /**
105
+ * Counts scenarios with optional filtering.
106
+ * @param filter Optional. Filter for counting scenarios.
107
+ * @returns A promise that resolves to the count of scenarios.
108
+ */
109
+ count(filter?: ScenarioFilter): Promise<number>;
104
110
  }
105
111
  export { Scenario, ScenarioRepository };
106
112
  export type { ScenarioFilter };
@@ -114,6 +114,12 @@ declare class UnitRepository extends BaseFacade {
114
114
  * @returns A promise that resolves with a DataFrame object.
115
115
  */
116
116
  tabulate(filter?: UnitFilter): Promise<DataFrame>;
117
+ /**
118
+ * Counts units with optional filtering.
119
+ * @param filter Optional. Filter for counting units.
120
+ * @returns A promise that resolves to the count of units.
121
+ */
122
+ count(filter?: UnitFilter): Promise<number>;
117
123
  }
118
124
  export { Unit, UnitRepository };
119
125
  export type { UnitFilter };
@@ -9,7 +9,25 @@ import { ModelFilter } from './model';
9
9
  declare function substitudeType(df: DataFrame, type?: DataPointType): DataFrame;
10
10
  declare function unitToDimensionless(name: string): string;
11
11
  declare function dfToDimensionless(df: DataFrame): DataFrame;
12
+ /**
13
+ * Standardizes the columns of a DataFrame in IAMC format.
14
+ * @param df DataFrame in IAMC format
15
+ * @returns DataFrame in IAMC format with standardized columns
16
+ */
17
+ declare function standardizeIamcDf(df: DataFrame): DataFrame;
18
+ /**
19
+ * Converts a DataFrame in IAMC long format to wide format.
20
+ * @param df The DataFrame to convert
21
+ * @returns A DataFrame in IAMC wide format
22
+ */
12
23
  declare function toIamcWide(df: DataFrame): DataFrame;
24
+ /**
25
+ * Generates a unique row index for IAMC data based on the row's identifiers.
26
+ * @param row The row data as an array
27
+ * @param rowIdentifiers The indices of the identifiers in the row
28
+ * @returns A string that uniquely identifies the row
29
+ */
30
+ declare function getIamcRowIndex(row: any[], rowIdentifiers: number[]): string;
13
31
  /**
14
32
  * Processes the filter to ensure that IAMC filter is enabled by default unless explicitly disabled.
15
33
  * When enabled, only entities with associated datapoints are returned.
@@ -17,4 +35,15 @@ declare function toIamcWide(df: DataFrame): DataFrame;
17
35
  * @returns The processed filter with IAMC default settings
18
36
  */
19
37
  declare function withIamcDefault(filter?: RunFilter | ScenarioFilter | ModelFilter | RegionFilter | UnitFilter): PlainObject;
20
- export { substitudeType, unitToDimensionless, dfToDimensionless, toIamcWide, withIamcDefault, };
38
+ declare function sortTimesWithYearFirst(years: number[], dateTimes: string[]): (number | string)[];
39
+ /**
40
+ * Splits a DataFrame into separate DataFrames based on DataPointType.
41
+ * @param df The DataFrame to split
42
+ * @returns An object containing DataFrames for each type present in the data
43
+ */
44
+ declare function splitDataFrameByType(df: DataFrame): {
45
+ annual?: DataFrame;
46
+ categorical?: DataFrame;
47
+ datetime?: DataFrame;
48
+ };
49
+ export { substitudeType, unitToDimensionless, dfToDimensionless, standardizeIamcDf, toIamcWide, withIamcDefault, getIamcRowIndex, sortTimesWithYearFirst, splitDataFrameByType, };
@@ -43,6 +43,10 @@ declare class BaseRepository {
43
43
  filter?: object;
44
44
  params?: object;
45
45
  }): Promise<DataFrame>;
46
+ _count({ filter, params, }: {
47
+ filter?: object;
48
+ params?: object;
49
+ }): Promise<number>;
46
50
  _bulkUpsert(df: DataFrame, params?: object): Promise<void>;
47
51
  _bulkDelete(df: DataFrame, params?: object): Promise<void>;
48
52
  private static throwRemoteException;
@@ -24,11 +24,13 @@ declare class DataPointRepository extends BaseRepository {
24
24
  joinParameters?: boolean;
25
25
  filter: PlainObject;
26
26
  }): Promise<DataPoint[]>;
27
- tabulate({ joinParameters, joinRuns, filter, }?: {
27
+ tabulate({ joinParameters, joinRuns, joinRunId, filter, }?: {
28
28
  joinParameters?: boolean;
29
29
  joinRuns?: boolean;
30
+ joinRunId?: boolean;
30
31
  filter: PlainObject;
31
32
  }): Promise<DataFrame>;
33
+ count(filter?: PlainObject): Promise<number>;
32
34
  bulkUpsert(df: DataFrame): Promise<void>;
33
35
  bulkDelete(df: DataFrame): Promise<void>;
34
36
  }