volue-insight-timeseries 2.0.2__py3-none-any.whl

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.
@@ -0,0 +1,1412 @@
1
+ import warnings
2
+
3
+ from . import util
4
+
5
+
6
+ class BaseCurve:
7
+ def __init__(self, id, metadata, session):
8
+ self._metadata = metadata
9
+ self._session = session
10
+ self.time_zone = 'CET'
11
+ if metadata is None:
12
+ self.hasMetadata = False
13
+ else:
14
+ self.hasMetadata = True
15
+ for key, val in metadata.items():
16
+ setattr(self, key, val)
17
+ self.id = id
18
+ self.tz = util.parse_tz(self.time_zone)
19
+
20
+ def __str__(self):
21
+ if hasattr(self, 'curve_type'):
22
+ curve_type = self.curve_type
23
+ else:
24
+ curve_type = 'UNKNOWN'
25
+ if hasattr(self, 'name'):
26
+ name = self.name
27
+ else:
28
+ name = str(self.id)
29
+ return "{}({})".format(curve_type, name)
30
+
31
+ def _add_from_to(self, args, first, last, prefix=''):
32
+ if first is not None:
33
+ args.append(util.make_arg('{}from'.format(prefix), first))
34
+ if last is not None:
35
+ args.append(util.make_arg('{}to'.format(prefix), last))
36
+
37
+ def _add_functions(self, args, time_zone, filter, function, frequency, output_time_zone):
38
+ if time_zone is not None:
39
+ args.append(util.make_arg('time_zone', time_zone))
40
+ if filter is not None:
41
+ args.append(util.make_arg('filter', filter))
42
+ if function is not None:
43
+ args.append(util.make_arg('function', function))
44
+ if frequency is not None:
45
+ args.append(util.make_arg('frequency', frequency))
46
+ if output_time_zone is not None:
47
+ args.append(util.make_arg('output_time_zone', output_time_zone))
48
+
49
+ def _load_data(self, url, failmsg, urlbase=None):
50
+ if urlbase is None:
51
+ urlbase = self._session.urlbase
52
+ response = self._session.data_request('GET', urlbase, url)
53
+ self._last_response = response
54
+ if response.status_code == 200:
55
+ return response.json()
56
+ elif response.status_code == 204 or response.status_code == 404:
57
+ return None
58
+ raise util.CurveException('{}: {} ({})'.format(failmsg, response.content, response.status_code))
59
+
60
+ def access(self):
61
+ url = '/api/curves/{}/access'.format(self.id)
62
+ return self._load_data(url, 'Failed to load curve access')
63
+
64
+
65
+ class TimeSeriesCurve(BaseCurve):
66
+ def get_data(self, data_from=None, data_to=None, time_zone=None, filter=None,
67
+ function=None, frequency=None, output_time_zone=None):
68
+ """ Getting data from Time Series curves
69
+
70
+ A Time Series curves holds a single time series.
71
+ This is used for actual values, backcasts, normals, etc. This function
72
+ fetches data between two given timestamps. It also possible to process
73
+ the curve directly in the API using filter and aggregation functions.
74
+ This can be used with great effect to reduce the amount of data
75
+ retrieved if the full set of details is not needed.
76
+ All time series are returned
77
+ in a :class:`volue_insight_timeseries.util.TS` object.
78
+
79
+ Parameters
80
+ ----------
81
+
82
+ data_from: time-stamp, optional
83
+ start date (and time) of data to be fetched. If not given, the start
84
+ date of the returned timeseries will be the first date with data
85
+ available. If only the date (without time) is
86
+ given, the time is assumed to be 00:00. The timestamp can be
87
+ provided in any of the following types (also valid without time):
88
+
89
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
90
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
91
+ * pandas.Timestamp object
92
+ * datetime.datetime object
93
+
94
+ data_to: time-stamp, optional
95
+ end date (and time) of data to be fetched. The time-stamp can be
96
+ provided in the same types as ``data_from``.
97
+ End dates are always excluded in the result!
98
+ If not given, the end date of the returned timeseries will be
99
+ the last date with data available.
100
+
101
+ time_zone: str, optional
102
+ Change curve time zone BEFORE performing an aggregation/split
103
+ or applying a filter. If no aggregation/split or filter is applied,
104
+ this will simply change the timezone of the curve. Note that if
105
+ "output_time_zone" is given, this will define the timezone of the
106
+ returned curve, since it is applied AFTER performing an
107
+ aggregation/split or applying a filter and thus AFTER changing
108
+ to given "time_zone" here.
109
+
110
+ You can find valid values for this by calling
111
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
112
+
113
+ filter: str, optional
114
+ only get a specific subset of the data.
115
+ You can find valid values for this by calling
116
+ :meth:`volue_insight_timeseries.session.Session.get_filters`.
117
+
118
+ function: str, optional
119
+ function used to aggregate or split data, must be used together
120
+ with the ``frequency`` parameter.
121
+ You can find valid values for this by calling
122
+ :meth:`volue_insight_timeseries.session.Session.get_functions`.
123
+
124
+ frequency: str, optional
125
+ data will be aggregated or split to the requested frequency using
126
+ the given function. You can find the valid values for this by calling
127
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
128
+
129
+ output_time_zone: str, optional
130
+ Change curve time zone AFTER performing an aggregation/split
131
+ or applying a filter.
132
+
133
+ Returns
134
+ -------
135
+ :class:`volue_insight_timeseries.util.TS` object
136
+ """
137
+
138
+ args = []
139
+ astr = ''
140
+ self._add_from_to(args, data_from, data_to)
141
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
142
+ if len(args) > 0:
143
+ astr = '?{}'.format('&'.join(args))
144
+ url = '/api/series/{}{}'.format(self.id, astr)
145
+ result = self._load_data(url, 'Failed to load curve data')
146
+ if result is None:
147
+ return result
148
+ return util.TS(input_dict=result, curve_type=util.TIME_SERIES)
149
+
150
+
151
+ class TaggedCurve(BaseCurve):
152
+ def get_tags(self):
153
+ """ Get list of available tags for this curve
154
+
155
+ Returns
156
+ -------
157
+ list
158
+ Returns a list of all available tags for a Tagged Instance curve.
159
+ """
160
+ url = '/api/series/tagged/{}/tags'.format(self.id)
161
+ return self._load_data(url, 'Failed to fetch tags')
162
+
163
+ def get_data(self, tag=None, data_from=None, data_to=None, time_zone=None, filter=None,
164
+ function=None, frequency=None, output_time_zone=None):
165
+ """ Getting data from TAGGED curves
166
+
167
+ A tagged curve holds a set of closely related time series, each
168
+ identified by a tag. The most common use of tags is for ensemble
169
+ weather data.
170
+
171
+ This function fetches data for one or multiple given tags and returns
172
+ a list of :class:`volue_insight_timeseries.util.TS` objects.
173
+ It is also possible to process the curve directly in the API using filter
174
+ and aggregation functions. This can be used with great effect to reduce
175
+ the amount of data retrieved if the full set of details is not needed.
176
+ All time series are returned
177
+ in a :class:`volue_insight_timeseries.util.TS` object.
178
+
179
+ Parameters
180
+ ----------
181
+
182
+ tag: str or list, optional
183
+ tag or tags to get the data for. If omitted, the default
184
+ tag is returned. If a list of multiple tags is given, the function
185
+ will return a list with
186
+ a :class:`volue_insight_timeseries.util.TS` object for each tag.
187
+
188
+ data_from: time-stamp, optional
189
+ start date (and time) of data to be fetched. If not given, the start
190
+ date of the returned timeseries will be the first date with data
191
+ available. If only the date (without time) is
192
+ given, the time is assumed to be 00:00. The timestamp can be
193
+ provided in any of the following types (also valid without time):
194
+
195
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
196
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
197
+ * pandas.Timestamp object
198
+ * datetime.datetime object
199
+
200
+ data_to: time-stamp, optional
201
+ end date (and time) of data to be fetched. The time-stamp can be
202
+ provided in the same types as ``data_from``.
203
+ End dates are always excluded in the result!
204
+ If not given, the end date of the returned timeseries will be
205
+ the last date with data available.
206
+
207
+ time_zone: str, optional
208
+ Change curve time zone BEFORE performing an aggregation/split
209
+ or applying a filter. If no aggregation/split or filter is applied,
210
+ this will simply change the timezone of the curve. Note that if
211
+ "output_time_zone" is given, this will define the timezone of the
212
+ returned curve, since it is applied AFTER performing an
213
+ aggregation/split or applying a filter and thus AFTER changing
214
+ to given "time_zone" here.
215
+
216
+ You can find valid values for this by calling
217
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
218
+
219
+ filter: str, optional
220
+ only get a specific subset of the data.
221
+ You can find valid values for this by calling
222
+ :meth:`volue_insight_timeseries.session.Session.get_filters` :
223
+
224
+ function: str, optional
225
+ function used to aggregate or split data, must be used together
226
+ with the ``frequency`` parameter.
227
+ You can find valid values for this by calling
228
+ :meth:`volue_insight_timeseries.session.Session.get_functions` :
229
+
230
+ frequency: str, optional
231
+ data will be aggregated or split to the requested frequency using
232
+ the given function.
233
+ You can find valid values for this by calling
234
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
235
+
236
+ output_time_zone: str, optional
237
+ Change curve time zone AFTER performing an aggregation/split
238
+ or applying a filter.
239
+
240
+ Returns
241
+ -------
242
+ :class:`volue_insight_timeseries.util.TS` object
243
+ """
244
+ unwrap = False
245
+ if tag is None:
246
+ args = []
247
+ unwrap = True
248
+ else:
249
+ if isinstance(tag, str):
250
+ unwrap = True
251
+ args=[util.make_arg('tag', tag)]
252
+ self._add_from_to(args, data_from, data_to)
253
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
254
+ astr = '&'.join(args)
255
+ url = '/api/series/tagged/{}?{}'.format(self.id, astr)
256
+ result = self._load_data(url, 'Failed to load tagged curve data')
257
+ if result is None:
258
+ return result
259
+ res = [util.TS(input_dict=r, curve_type=util.TAGGED) for r in result]
260
+ if unwrap and len(res) == 1:
261
+ res = res[0]
262
+ return res
263
+
264
+
265
+ class InstanceCurve(BaseCurve):
266
+ def search_instances(self, issue_date_from=None, issue_date_to=None,
267
+ issue_dates=None, issue_weekdays=None, issue_days=None, issue_months=None,
268
+ issue_times=None, with_data=False, data_from=None, data_to=None,
269
+ time_zone=None, filter=None, function=None, frequency=None,
270
+ output_time_zone=None, only_accessible=None, modified_since=None):
271
+ """ Getting data from INSTANCE curves for multiple issue_dates
272
+
273
+ An INSTANCE curve typically represents forecast,
274
+ and contains a time series for each issue_date of the forecast.
275
+ This function returns a list of time series for all available
276
+ issue_dates (within a given period, if specified)
277
+ as a a list of :class:`volue_insight_timeseries.util.TS` objects.
278
+ It also possible to process
279
+ the curve directly in the API using filter and aggregation functions.
280
+ This can be used with great effect to reduce the amount of data
281
+ retrieved if the full set of details is not needed.
282
+ By default this function returns
283
+ the :class:`volue_insight_timeseries.util.TS` objects
284
+ without data, which can be change by setting the "with_data" argument
285
+ to True.
286
+
287
+ Parameters
288
+ ----------
289
+
290
+ issue_date_from: time-stamp, optional
291
+ Limits the timerange to return all available issue_dates.
292
+ The time-stamp can be provided in any of the following types :
293
+
294
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
295
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
296
+ * pandas.Timestamp object
297
+ * datetime.datetime object
298
+
299
+ issue_date_to: time-stamp, optional
300
+ Limits the timerange to return for the latest available issue_date.
301
+ The time-stamp can be provided in the same types as
302
+ "issue_date_from".
303
+
304
+ issue_dates: list of time-stamps, optional
305
+ List of timestamps
306
+ to return :class:`volue_insight_timeseries.util.TS` objects for.
307
+ The time-stamps can be provided in the same types as
308
+ "issue_date_from".
309
+
310
+ issue_weekdays: list of str, optional
311
+ Filter issue_date on day of week.
312
+
313
+ issue_days: list of int, optional
314
+ Filter issue_date on day of month
315
+
316
+ issue_months: list of str, optional
317
+ Filter issue_date on month
318
+
319
+ issue_times: list of str, optional
320
+ Filter issue_date on time of day
321
+ Format is 'HH', 'HH:mm' or 'HH:mm:ss'.
322
+
323
+ with_data: bool, optional
324
+ If with_data is False,
325
+ the returned :class:`volue_insight_timeseries.util.TS` object
326
+ only contains the attributes and meta data information but no
327
+ data values.
328
+
329
+ data_from: time-stamp, optional
330
+ start date (and time) of data to be fetched. If not given, the start
331
+ date of the returned timeseries will be the first date with data
332
+ available. If only the date (without time) is
333
+ given, the time is assumed to be 00:00. The timestamp can be
334
+ provided in the same types as "issue_date_from".
335
+
336
+ data_to: time-stamp, optional
337
+ end date (and time) of data to be fetched. The time-stamp can be
338
+ provided in the same types as "issue_date_from".
339
+ End dates are always excluded in the result!
340
+ If not given, the end date of the returned timeseries will be
341
+ the last date with data available.
342
+
343
+ time_zone: str, optional
344
+ Change curve time zone BEFORE performing an aggregation/split
345
+ or applying a filter. If no aggregation/split or filter is applied,
346
+ this will simply change the timezone of the curve. Note that if
347
+ "output_time_zone" is given, this will define the timezone of the
348
+ returned curve, since it is applied AFTER performing an
349
+ aggregation/split or applying a filter and thus AFTER changing
350
+ to given "time_zone" here.
351
+
352
+ You can find valid values for this by calling
353
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
354
+
355
+ filter: str, optional
356
+ only get a specific subset of the data.
357
+ You can find valid values for this by calling
358
+ :meth:`volue_insight_timeseries.session.Session.get_filters` :
359
+
360
+ function: str, optional
361
+ function used to aggregate or split data, must be used together
362
+ with the ``frequency`` parameter.
363
+ You can find valid values for this by calling
364
+ :meth:`volue_insight_timeseries.session.Session.get_functions` :
365
+
366
+ frequency: str, optional
367
+ data will be aggregated or split to the requested frequency using
368
+ the given function.
369
+ You can find valid values for this by calling
370
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
371
+
372
+ output_time_zone: str, optional
373
+ Change curve time zone AFTER performing an aggregation/split
374
+ or applying a filter.
375
+
376
+ modified_since: datestring, pandas.Timestamp or datetime.datetime
377
+ only return instances that where modified after given datetime.
378
+
379
+ Returns
380
+ -------
381
+ :class:`volue_insight_timeseries.util.TS` object
382
+ """
383
+ if only_accessible is not None:
384
+ warnings.warn("only_accessible parameter will be removed soon.", FutureWarning, stacklevel=2)
385
+ args=[util.make_arg('with_data', '{}'.format(with_data).lower())]
386
+ self._add_from_to(args, issue_date_from, issue_date_to, prefix='issue_date_')
387
+ if with_data:
388
+ self._add_from_to(args, data_from, data_to, prefix='data_')
389
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
390
+ if issue_dates is not None:
391
+ args.append(util.make_arg('issue_date', issue_dates))
392
+ if issue_weekdays is not None:
393
+ args.append(util.make_arg('issue_weekday', issue_weekdays))
394
+ if issue_days is not None:
395
+ args.append(util.make_arg('issue_day', issue_days))
396
+ if issue_months is not None:
397
+ args.append(util.make_arg('issue_month', issue_months))
398
+ if issue_times is not None:
399
+ args.append(util.make_arg('issue_time', issue_times))
400
+ if modified_since is not None:
401
+ args.append(util.make_arg('modified_since', modified_since))
402
+ astr = '&'.join(args)
403
+ url = '/api/instances/{}?{}'.format(self.id, astr)
404
+ result = self._load_data(url, 'Failed to find instances')
405
+ if result is None:
406
+ return result
407
+ return [util.TS(input_dict=r, curve_type=util.INSTANCES) for r in result]
408
+
409
+ def get_instance(self, issue_date, with_data=True, data_from=None, data_to=None,
410
+ time_zone=None, filter=None, function=None, frequency=None,
411
+ output_time_zone=None, only_accessible=None):
412
+ """ Getting data from INSTANCE curves for a specific issue_date
413
+
414
+ An INSTANCE curve typically represents forecast,
415
+ and contains a time series for each issue_date of the forecast.
416
+ This function returns the time series for a specified issue_date
417
+ as a :class:`volue_insight_timeseries.util.TS` object.
418
+ It is also possible to process
419
+ the curve directly in the API using filter and aggregation functions.
420
+ This can be used with great effect to reduce the amount of data
421
+ retrieved if the full set of details is not needed.
422
+
423
+ Parameters
424
+ ----------
425
+ issue_date: time-stamp
426
+ Time-stamp representing the issue date to get data for.
427
+ The timestamp can be provided in any of the following types :
428
+
429
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
430
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
431
+ * pandas.Timestamp object
432
+ * datetime.datetime object
433
+
434
+ with_data: bool, optional
435
+ If with_data is False,
436
+ the returned :class:`volue_insight_timeseries.util.TS` object
437
+ only contains the attributes and meta data information but no
438
+ data values.
439
+
440
+ data_from: time-stamp, optional
441
+ start date (and time) of data to be fetched. If not given, the start
442
+ date of the returned timeseries will be the first date with data
443
+ available. If only the date (without time) is
444
+ given, the time is assumed to be 00:00. The timestamp can be
445
+ provided in the same types as "issue_date".
446
+
447
+ data_to: time-stamp, optional
448
+ end date (and time) of data to be fetched. The time-stamp can be
449
+ provided in the same types as "issue_date".
450
+ End dates are always excluded in the result!
451
+ If not given, the end date of the returned timeseries will be
452
+ the last date with data available.
453
+
454
+ time_zone: str, optional
455
+ Change curve time zone BEFORE performing an aggregation/split
456
+ or applying a filter. If no aggregation/split or filter is applied,
457
+ this will simply change the timezone of the curve. Note that if
458
+ "output_time_zone" is given, this will define the timezone of the
459
+ returned curve, since it is applied AFTER performing an
460
+ aggregation/split or applying a filter and thus AFTER changing
461
+ to given "time_zone" here.
462
+
463
+ You can find valid values for this by calling
464
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
465
+
466
+ filter: str, optional
467
+ only get a specific subset of the data.
468
+ You can find valid values for this by calling
469
+ :meth:`volue_insight_timeseries.session.Session.get_filters` :
470
+
471
+ function: str, optional
472
+ function used to aggregate or split data, must be used together
473
+ with the ``frequency`` parameter.
474
+ You can find valid values for this by calling
475
+ :meth:`volue_insight_timeseries.session.Session.get_functions` :
476
+
477
+ frequency: str, optional
478
+ data will be aggregated or split to the requested frequency using
479
+ the given function.
480
+ You can find valid values for this by calling
481
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
482
+
483
+ output_time_zone: str, optional
484
+ Change curve time zone AFTER performing an aggregation/split
485
+ or applying a filter.
486
+
487
+ Returns
488
+ -------
489
+ :class:`volue_insight_timeseries.util.TS` object
490
+ """
491
+ if only_accessible is not None:
492
+ warnings.warn("only_accessible parameter will be removed soon.", FutureWarning, stacklevel=2)
493
+ args=[util.make_arg('with_data', '{}'.format(with_data).lower()),
494
+ util.make_arg('issue_date', issue_date)]
495
+ if with_data:
496
+ self._add_from_to(args, data_from, data_to)
497
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
498
+ astr = '&'.join(args)
499
+ url = '/api/instances/{}/get?{}'.format(self.id, astr)
500
+ result = self._load_data(url, 'Failed to load instance')
501
+ if result is None:
502
+ return result
503
+ return util.TS(input_dict=result, issue_date=issue_date, curve_type=util.INSTANCES)
504
+
505
+ def get_latest(self, issue_date_from=None, issue_date_to=None, issue_dates=None,
506
+ with_data=True, data_from=None, data_to=None, time_zone=None, filter=None,
507
+ function=None, frequency=None, output_time_zone=None, only_accessible=None):
508
+ """ Getting data from INSTANCE curves for the latest available issue_date
509
+
510
+ An INSTANCE curve typically represents forecast,
511
+ and contains a time series for each issue_date of the forecast.
512
+ This function returns the time series for the latest available
513
+ issue_date (within a given period, if specified)
514
+ as a :class:`volue_insight_timeseries.util.TS` object.
515
+ It is also possible to process
516
+ the curve directly in the API using filter and aggregation functions.
517
+ This can be used with great effect to reduce the amount of data
518
+ retrieved if the full set of details is not needed.
519
+
520
+ Parameters
521
+ ----------
522
+
523
+ issue_date_from: time-stamp, optional
524
+ Limits the timerange to search for the latest available issue_date.
525
+ The time-stamp can be provided in any of the following types :
526
+
527
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
528
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
529
+ * pandas.Timestamp object
530
+ * datetime.datetime object
531
+
532
+ issue_date_to: time-stamp, optional
533
+ Limits the timerange to search for the latest available issue_date.
534
+ The time-stamp can be provided in the same types as
535
+ "issue_date_from".
536
+
537
+ issue_dates: list of time-stamps, optional
538
+ List of timestamps in which to search for the latest available
539
+ issue_date.
540
+ The time-stamps can be provided in the same types as
541
+ "issue_date_from".
542
+
543
+ with_data: bool, optional
544
+ If with_data is False,
545
+ the returned :class:`volue_insight_timeseries.util.TS` object
546
+ only contains the attributes and meta data information but no
547
+ data values.
548
+
549
+ data_from: time-stamp, optional
550
+ start date (and time) of data to be fetched. If not given, the start
551
+ date of the returned timeseries will be the first date with data
552
+ available. If only the date (without time) is
553
+ given, the time is assumed to be 00:00. The timestamp can be
554
+ provided in the same types as "issue_date_from".
555
+
556
+ data_to: time-stamp, optional
557
+ end date (and time) of data to be fetched. The time-stamp can be
558
+ provided in the same types as "issue_date_from".
559
+ End dates are always excluded in the result!
560
+ If not given, the end date of the returned timeseries will be
561
+ the last date with data available.
562
+
563
+ time_zone: str, optional
564
+ Change curve time zone BEFORE performing an aggregation/split
565
+ or applying a filter. If no aggregation/split or filter is applied,
566
+ this will simply change the timezone of the curve. Note that if
567
+ "output_time_zone" is given, this will define the timezone of the
568
+ returned curve, since it is applied AFTER performing an
569
+ aggregation/split or applying a filter and thus AFTER changing
570
+ to given "time_zone" here.
571
+
572
+ You can find valid values for this by calling
573
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
574
+
575
+ filter: str, optional
576
+ only get a specific subset of the data.
577
+ You can find valid values for this by calling
578
+ :meth:`volue_insight_timeseries.session.Session.get_filters` :
579
+
580
+ function: str, optional
581
+ function used to aggregate or split data, must be used together
582
+ with the ``frequency`` parameter.
583
+ You can find valid values for this by calling
584
+ :meth:`volue_insight_timeseries.session.Session.get_functions` :
585
+
586
+ frequency: str, optional
587
+ data will be aggregated or split to the requested frequency using
588
+ the given function.
589
+ You can find valid values for this by calling
590
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
591
+
592
+ output_time_zone: str, optional
593
+ Change curve time zone AFTER performing an aggregation/split
594
+ or applying a filter.
595
+
596
+ Returns
597
+ -------
598
+ :class:`volue_insight_timeseries.util.TS` object
599
+ """
600
+ if only_accessible is not None:
601
+ warnings.warn("only_accessible parameter will be removed soon.", FutureWarning, stacklevel=2)
602
+ args=[util.make_arg('with_data', '{}'.format(with_data).lower())]
603
+ self._add_from_to(args, issue_date_from, issue_date_to, prefix='issue_date_')
604
+ if with_data:
605
+ self._add_from_to(args, data_from, data_to, prefix='data_')
606
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
607
+ if issue_dates is not None:
608
+ args.append(util.make_arg('issue_date', issue_dates))
609
+ astr = '&'.join(args)
610
+ url = '/api/instances/{}/latest?{}'.format(self.id, astr)
611
+ result = self._load_data(url, 'Failed to load instance')
612
+ if result is None:
613
+ return result
614
+ return util.TS(input_dict=result, curve_type=util.INSTANCES)
615
+
616
+ def get_relative(self, data_offset, data_max_length=None, issue_date_from=None, issue_date_to=None,
617
+ issue_dates=None, issue_weekdays=None, issue_days=None, issue_months=None, issue_times=None,
618
+ data_from=None, data_to=None, time_zone=None, filter=None, function=None,
619
+ frequency=None, output_time_zone=None):
620
+ """ Get a relative forecast from the INSTANCE curve
621
+
622
+ A relative forecast is a time series created by joining multiple
623
+ instances so that the data date is issue_date + data_offset.
624
+ If the data frequency is higher than the frequency of the selected
625
+ instances, a range of data values from each instance will be used.
626
+ Similarly, if the issue frequency is higher than the data frequency,
627
+ the same data date will be used from several instances.
628
+
629
+ Parameters allow control of the set of instances used and how they
630
+ are joined together, as well as post-processing of the result.
631
+
632
+ Parameters
633
+ ----------
634
+
635
+ data_offset: duration, mandatory
636
+ The duration added to the issue_date to find the start of the data
637
+ fragment. Format is an ISO-8601 duration string up to "days".
638
+
639
+ data_max_length: duration, optional
640
+ The longest duration selected from a single instance, mostly used
641
+ to detect missing instances. ISO-8601 duration string up to "days".
642
+
643
+ issue_date_from: time-stamp, optional
644
+ Limits the timerange used to select instances.
645
+ The time-stamp can be provided in any of the following types :
646
+
647
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
648
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
649
+ * pandas.Timestamp object
650
+ * datetime.datetime object
651
+
652
+ issue_date_to: time-stamp, optional
653
+ Limits the timerange used to select instances.
654
+ The time-stamp can be provided in the same types as
655
+ "issue_date_from".
656
+
657
+ issue_dates: list of time-stamps, optional
658
+ List of timestamps used to select instances.
659
+ The time-stamps can be provided in the same types as
660
+ "issue_date_from".
661
+
662
+ issue_weekdays: list of strings, optional
663
+ Limits the instances to those matching the given weekdays.
664
+
665
+ issue_days: list of integers, optional
666
+ Limits the instances to those matching the given days of month.
667
+
668
+ issue_months: list of strings, optional
669
+ Limits the instances to those matching the given months.
670
+
671
+ issue_times: list of strings, optional
672
+ Limits the instances to those matching the given times of day.
673
+ Format is 'HH', 'HH:mm' or 'HH:mm:ss'.
674
+
675
+ data_from: time-stamp, optional
676
+ start date (and time) of data to be fetched. If not given, the start
677
+ date of the returned timeseries will be determined by the first
678
+ selected instance and the data_offset parameter. If only the date
679
+ (without time) is given, the time is assumed to be 00:00. The
680
+ timestamp can be provided in the same types as "issue_date_from".
681
+
682
+ data_to: time-stamp, optional
683
+ end date (and time) of data to be fetched. The time-stamp can be
684
+ provided in the same types as "issue_date_from".
685
+ End dates are always excluded in the result!
686
+ If not given, the end date of the returned timeseries will be
687
+ the last date with data available in the last instance selected,
688
+ optionally limited by the data_max_length parameter.
689
+
690
+ time_zone: str, optional
691
+ Change curve time zone BEFORE performing an aggregation/split
692
+ or applying a filter. If no aggregation/split or filter is applied,
693
+ this will simply change the timezone of the curve. Note that if
694
+ "output_time_zone" is given, this will define the timezone of the
695
+ returned curve, since it is applied AFTER performing an
696
+ aggregation/split or applying a filter and thus AFTER changing
697
+ to given "time_zone" here.
698
+
699
+ You can find valid values for this by calling
700
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
701
+
702
+ filter: str, optional
703
+ only get a specific subset of the data.
704
+ You can find valid values for this by calling
705
+ :meth:`volue_insight_timeseries.session.Session.get_filters` :
706
+
707
+ function: str, optional
708
+ function used to aggregate or split data, must be used together
709
+ with the ``frequency`` parameter.
710
+ You can find valid values for this by calling
711
+ :meth:`volue_insight_timeseries.session.Session.get_functions` :
712
+
713
+ frequency: str, optional
714
+ data will be aggregated or split to the requested frequency using
715
+ the given function.
716
+ You can find valid values for this by calling
717
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
718
+
719
+ output_time_zone: str, optional
720
+ Change curve time zone AFTER performing an aggregation/split
721
+ or applying a filter.
722
+
723
+ Returns
724
+ -------
725
+ :class:`volue_insight_timeseries.util.TS` object
726
+ """
727
+ args = [util.make_arg('data_offset', '{}'.format(data_offset))]
728
+ self._add_from_to(args, issue_date_from, issue_date_to, prefix='issue_date_')
729
+ self._add_from_to(args, data_from, data_to, prefix='data_')
730
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
731
+ if data_max_length is not None:
732
+ args.append(util.make_arg('data_max_length', data_max_length))
733
+ if issue_dates is not None:
734
+ args.append(util.make_arg('issue_date', issue_dates))
735
+ if issue_weekdays is not None:
736
+ args.append(util.make_arg('issue_weekday', issue_weekdays))
737
+ if issue_days is not None:
738
+ args.append(util.make_arg('issue_day', issue_days))
739
+ if issue_months is not None:
740
+ args.append(util.make_arg('issue_month', issue_months))
741
+ if issue_times is not None:
742
+ args.append(util.make_arg('issue_time', issue_times))
743
+ astr = '&'.join(args)
744
+ url = '/api/instances/{}/relative?{}'.format(self.id, astr)
745
+ result = self._load_data(url, 'Failed to find instances')
746
+ if result is None:
747
+ return result
748
+ return util.TS(input_dict=result, curve_type=util.INSTANCES)
749
+
750
+ def get_absolute(self, data_date, issue_frequency=None, issue_date_from=None, issue_date_to=None):
751
+ """ Get an absolute forecast from the INSTANCE curve
752
+
753
+ An absolute forecast is a time series created by selecting a single
754
+ data date from a range of instances, using the issue_date as
755
+ data date in the result.
756
+
757
+ Parameters
758
+ ----------
759
+
760
+ data_date: time-stamp, mandatory
761
+ The data date of the absolute forecast.
762
+ The time-stamp can be provided in any of the following types :
763
+
764
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
765
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
766
+ * pandas.Timestamp object
767
+ * datetime.datetime object
768
+
769
+ issue_frequency: str, optional
770
+ The frequency of the returned time series. Mandatory if the
771
+ issue frequency of the curve is 'ANY'. Data will only be
772
+ returned for those instances whose issue_date is compatible
773
+ with issue_frequency.
774
+ You can find valid values for this by calling
775
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
776
+
777
+ issue_date_from: time-stamp, optional
778
+ The start of the timerange used to select instances.
779
+ The time-stamp can be provided in the same types as
780
+ "data_date".
781
+
782
+ issue_date_to: time-stamp, optional
783
+ The end of the timerange used to select instances.
784
+ The time-stamp can be provided in the same types as
785
+ "data_date".
786
+
787
+ Returns
788
+ -------
789
+ :class:`volue_insight_timeseries.util.TS` object
790
+ """
791
+ args = [util.make_arg('data_date', data_date)]
792
+ if issue_frequency is not None:
793
+ args.append(util.make_arg('issue_frequency', issue_frequency))
794
+ self._add_from_to(args, issue_date_from, issue_date_to, prefix='issue_date_')
795
+ astr = '&'.join(args)
796
+ url = '/api/instances/{}/absolute?{}'.format(self.id, astr)
797
+ result = self._load_data(url, 'Failed to find instances')
798
+ if result is None:
799
+ return result
800
+ return util.TS(input_dict=result, curve_type=util.INSTANCES)
801
+
802
+
803
+ class TaggedInstanceCurve(BaseCurve):
804
+ def get_tags(self):
805
+ """ Get list of available tags for this curve
806
+
807
+ Returns
808
+ -------
809
+ list
810
+ Returns a list of all available tags for a Tagged Instance curve.
811
+ """
812
+ url = '/api/instances/tagged/{}/tags'.format(self.id)
813
+ return self._load_data(url, 'Failed to fetch tags')
814
+
815
+ def search_instances(self, tags=None, issue_date_from=None, issue_date_to=None,
816
+ issue_dates=None, issue_weekdays=None, issue_days=None, issue_months=None,
817
+ issue_times=None, with_data=False, data_from=None, data_to=None,
818
+ time_zone=None, filter=None, function=None, frequency=None,
819
+ output_time_zone=None, only_accessible=None, modified_since=None):
820
+ """ Getting data from TAGGED_INSTANCE curves for multiple issue_dates
821
+
822
+ A TAGGED INSTANCE curve typically represents forecast that contain
823
+ multiple time series for each issue_date of the forecast, which are
824
+ assigned to so called tags. Each timeseries is therefore defined by a
825
+ unique combination of issue_date and tag. Ensamble forecasts are a
826
+ typical use case for TAGGED INSTANCE curves.
827
+
828
+ This function returns a list of time series for all available
829
+ issue_dates (within a given period, if specified) and tags (from a
830
+ given list of tags, if specified) as
831
+ a list of :class:`volue_insight_timeseries.util.TS` objects.
832
+
833
+ It is also possible to process the curve directly in the API using filter
834
+ and aggregation functions. This can be used with great effect to reduce
835
+ the amount of data retrieved if the full set of details is not needed.
836
+ By default, this function returns
837
+ the :class:`volue_insight_timeseries.util.TS` objects
838
+ without data, which can be change by setting the "with_data" argument
839
+ to True.
840
+
841
+ Parameters
842
+ ----------
843
+
844
+ tags: str or list, optional
845
+ tag or tags to consider. The function will only return objects with
846
+ tags defined here. If None (default) is given, all available tags
847
+ are considered.
848
+
849
+ issue_date_from: time-stamp, optional
850
+ Limits the timerange to return all available issue_dates.
851
+ The time-stamp can be provided in any of the following types :
852
+
853
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
854
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
855
+ * pandas.Timestamp object
856
+ * datetime.datetime object
857
+
858
+ issue_date_to: time-stamp, optional
859
+ Limits the timerange to return for the latest available issue_date.
860
+ The time-stamp can be provided in the same types as
861
+ "issue_date_from".
862
+
863
+ issue_dates: list of time-stamps, optional
864
+ List of timestamps to
865
+ return :class:`volue_insight_timeseries.util.TS` objects for.
866
+ The time-stamps can be provided in the same types as
867
+ "issue_date_from".
868
+
869
+ issue_weekdays: list of str, optional
870
+ Filter issue_date on day of week.
871
+
872
+ issue_days: list of int, optional
873
+ Filter issue_date on day of month
874
+
875
+ issue_months: list of str, optional
876
+ Filter issue_date on month
877
+
878
+ issue_times: list of str, optional
879
+ Filter issue_date on time of day
880
+ Format is 'HH', 'HH:mm' or 'HH:mm:ss'.
881
+
882
+ with_data: bool, optional
883
+ If with_data is False,
884
+ the returned :class:`volue_insight_timeseries.util.TS` object
885
+ only contains the attributes and meta data information but no
886
+ data values.
887
+
888
+ data_from: time-stamp, optional
889
+ start date (and time) of data to be fetched. If not given, the start
890
+ date of the returned timeseries will be the first date with data
891
+ available. If only the date (without time) is
892
+ given, the time is assumed to be 00:00. The timestamp can be
893
+ provided in the same types as "issue_date_from".
894
+
895
+ data_to: time-stamp, optional
896
+ end date (and time) of data to be fetched. The time-stamp can be
897
+ provided in the same types as "issue_date_from".
898
+ End dates are always excluded in the result!
899
+ If not given, the end date of the returned timeseries will be
900
+ the last date with data available.
901
+
902
+ time_zone: str, optional
903
+ Change curve time zone BEFORE performing an aggregation/split
904
+ or applying a filter. If no aggregation/split or filter is applied,
905
+ this will simply change the timezone of the curve. Note that if
906
+ "output_time_zone" is given, this will define the timezone of the
907
+ returned curve, since it is applied AFTER performing an
908
+ aggregation/split or applying a filter and thus AFTER changing
909
+ to given "time_zone" here.
910
+
911
+ You can find valid values for this by calling
912
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
913
+
914
+ filter: str, optional
915
+ only get a specific subset of the data.
916
+ You can find valid values for this by calling
917
+ :meth:`volue_insight_timeseries.session.Session.get_filters` :
918
+
919
+ function: str, optional
920
+ function used to aggregate or split data, must be used together
921
+ with the ``frequency`` parameter.
922
+ You can find valid values for this by calling
923
+ :meth:`volue_insight_timeseries.session.Session.get_functions` :
924
+
925
+ frequency: str, optional
926
+ data will be aggregated or split to the requested frequency using
927
+ the given function.
928
+ You can find valid values for this by calling
929
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
930
+
931
+ output_time_zone: str, optional
932
+ Change curve time zone AFTER performing an aggregation/split
933
+ or applying a filter.
934
+
935
+ modified_since: datestring, pandas.Timestamp or datetime.datetime
936
+ only return instances that where modified after given datetime.
937
+
938
+ Returns
939
+ -------
940
+ :class:`volue_insight_timeseries.util.TS` object
941
+ """
942
+ if only_accessible is not None:
943
+ warnings.warn("only_accessible parameter will be removed soon.", FutureWarning, stacklevel=2)
944
+ args=[util.make_arg('with_data', '{}'.format(with_data).lower())]
945
+ if tags is not None:
946
+ args.append(util.make_arg('tag', tags))
947
+ self._add_from_to(args, issue_date_from, issue_date_to, prefix='issue_date_')
948
+ if with_data:
949
+ self._add_from_to(args, data_from, data_to, prefix='data_')
950
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
951
+ if issue_dates is not None:
952
+ args.append(util.make_arg('issue_date', issue_dates))
953
+ if issue_weekdays is not None:
954
+ args.append(util.make_arg('issue_weekday', issue_weekdays))
955
+ if issue_days is not None:
956
+ args.append(util.make_arg('issue_day', issue_days))
957
+ if issue_months is not None:
958
+ args.append(util.make_arg('issue_month', issue_months))
959
+ if issue_times is not None:
960
+ args.append(util.make_arg('issue_time', issue_times))
961
+ if modified_since is not None:
962
+ args.append(util.make_arg('modified_since', modified_since))
963
+ astr = '&'.join(args)
964
+ url = '/api/instances/tagged/{}?{}'.format(self.id, astr)
965
+ result = self._load_data(url, 'Failed to find tagged instances')
966
+ if result is None:
967
+ return result
968
+ return [util.TS(input_dict=r, curve_type=util.TAGGED_INSTANCES) for r in result]
969
+
970
+ def get_instance(self, issue_date, tag=None, with_data=True, data_from=None, data_to=None,
971
+ time_zone=None, filter=None, function=None, frequency=None,
972
+ output_time_zone=None, only_accessible=None):
973
+ """ Getting data from TAGGED_INSTANCE curves for a specific issue_date
974
+
975
+ A TAGGED INSTANCE curve typically represents forecast that contain
976
+ multiple time series for each issue_date of the forecast, which are
977
+ assigned to so called tags. Each timeseries is therefore defined by a
978
+ unique combination of issue_date and tag. Ensamble forecasts are a
979
+ typical use case for TAGGED INSTANCE curves.
980
+
981
+ This function returns a time series for the combinations of a specified
982
+ issue_date and all given tags as
983
+ a list of :class:`volue_insight_timeseries.util.TS` objects.
984
+ It is also possible to process the curve directly in the API using filter
985
+ and aggregation functions. This can be used with great effect to reduce
986
+ the amount of data retrieved if the full set of details is not needed.
987
+
988
+ Parameters
989
+ ----------
990
+
991
+ issue_date: time-stamp
992
+ Time-stamp representing the issue date to get data for.
993
+ The timestamp can be provided in any of the following types :
994
+
995
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
996
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
997
+ * pandas.Timestamp object
998
+ * datetime.datetime object
999
+
1000
+ tag: str or list, optional
1001
+ tag or tags to get the data for. If omitted, the default
1002
+ tag is returned. If a list of multiple tags is given, the function
1003
+ will return a list with a :class:`volue_insight_timeseries.util.TS`
1004
+ object for each tag.
1005
+
1006
+ with_data: bool, optional
1007
+ If with_data is False,
1008
+ the returned :class:`volue_insight_timeseries.util.TS` object
1009
+ only contains the attributes and meta data information but no
1010
+ data values.
1011
+
1012
+ data_from: time-stamp, optional
1013
+ start date (and time) of data to be fetched. If not given, the start
1014
+ date of the returned timeseries will be the first date with data
1015
+ available. If only the date (without time) is
1016
+ given, the time is assumed to be 00:00. The timestamp can be
1017
+ provided in the same types as "issue_date".
1018
+
1019
+ data_to: time-stamp, optional
1020
+ end date (and time) of data to be fetched. The time-stamp can be
1021
+ provided in the same types as "issue_date".
1022
+ End dates are always excluded in the result!
1023
+ If not given, the end date of the returned timeseries will be
1024
+ the last date with data available.
1025
+
1026
+ time_zone: str, optional
1027
+ Change curve time zone BEFORE performing an aggregation/split
1028
+ or applying a filter. If no aggregation/split or filter is applied,
1029
+ this will simply change the timezone of the curve. Note that if
1030
+ "output_time_zone" is given, this will define the timezone of the
1031
+ returned curve, since it is applied AFTER performing an
1032
+ aggregation/split or applying a filter and thus AFTER changing
1033
+ to given "time_zone" here.
1034
+
1035
+ You can find valid values for this by calling
1036
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
1037
+
1038
+ filter: str, optional
1039
+ only get a specific subset of the data.
1040
+ You can find valid values for this by calling
1041
+ :meth:`volue_insight_timeseries.session.Session.get_filters` :
1042
+
1043
+ function: str, optional
1044
+ function used to aggregate or split data, must be used together
1045
+ with the ``frequency`` parameter.
1046
+ You can find valid values for this by calling
1047
+ :meth:`volue_insight_timeseries.session.Session.get_functions` :
1048
+
1049
+ frequency: str, optional
1050
+ data will be aggregated or split to the requested frequency using
1051
+ the given function.
1052
+ You can find valid values for this by calling
1053
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
1054
+
1055
+ output_time_zone: str, optional
1056
+ Change curve time zone AFTER performing an aggregation/split
1057
+ or applying a filter.
1058
+
1059
+ Returns
1060
+ -------
1061
+ :class:`volue_insight_timeseries.util.TS` object
1062
+ """
1063
+
1064
+ if only_accessible is not None:
1065
+ warnings.warn("only_accessible parameter will be removed soon.", FutureWarning, stacklevel=2)
1066
+ args=[util.make_arg('with_data', '{}'.format(with_data).lower()),
1067
+ util.make_arg('issue_date', issue_date)]
1068
+ unwrap = False
1069
+ if tag is None:
1070
+ unwrap = True
1071
+ else:
1072
+ if isinstance(tag, str):
1073
+ unwrap = True
1074
+ args.append(util.make_arg('tag', tag))
1075
+ if with_data:
1076
+ self._add_from_to(args, data_from, data_to)
1077
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
1078
+ astr = '&'.join(args)
1079
+ url = '/api/instances/tagged/{}/get?{}'.format(self.id, astr)
1080
+ result = self._load_data(url, 'Failed to load tagged instance')
1081
+ if result is None:
1082
+ return result
1083
+ res = [util.TS(input_dict=r, issue_date=issue_date, curve_type=util.TAGGED_INSTANCES) for r in result]
1084
+ if unwrap and len(res) == 1:
1085
+ res = res[0]
1086
+ return res
1087
+
1088
+ def get_latest(self, tags=None, issue_date_from=None, issue_date_to=None, issue_dates=None,
1089
+ with_data=True, data_from=None, data_to=None, time_zone=None, filter=None,
1090
+ function=None, frequency=None, output_time_zone=None, only_accessible=None):
1091
+ """ Getting data from TAGGED INSTANCE curves for the latest issue_date
1092
+
1093
+ A TAGGED INSTANCE curve typically represents forecasts that contain
1094
+ multiple time series for each issue_date of the forecast, which are
1095
+ assigned to so called tags. Each timeseries is therefore defined by a
1096
+ unique combination of issue_date and tag. Ensamble forecasts are a
1097
+ typical use case for TAGGED INSTANCE curves.
1098
+
1099
+ This function returns the time series for ONE tag and the latest
1100
+ available issue_date (within a given period, if specified)
1101
+ as :class:`volue_insight_timeseries.util.TS` objects. The tag to get the
1102
+ data for can be specified in the "tags" argument. If None (=all tags)
1103
+ or a list of tags is provided, only the timeseries for one of the tags
1104
+ (the first one found to have valid data) is returned. So it is
1105
+ recommended to specify ONE desired tag in "tags".
1106
+
1107
+ It also possible to process
1108
+ the curve directly in the API using filter and aggregation functions.
1109
+ This can be used with great effect to reduce the amount of data
1110
+ retrieved if the full set of details is not needed.
1111
+
1112
+ Parameters
1113
+ ----------
1114
+ tags: string or list, optional
1115
+ tag or list of tags to consider when returning the
1116
+ :class:`volue_insight_timeseries.util.TS` object.
1117
+ The function returns a timeseries
1118
+ for ONE of the given tags. If you want get data for a specific tag,
1119
+ only specify one tag here (recommended!).
1120
+
1121
+ issue_date_from: time-stamp, optional
1122
+ Limits the timerange to search for the latest available issue_date.
1123
+ The time-stamp can be provided in any of the following types :
1124
+
1125
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
1126
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
1127
+ * pandas.Timestamp object
1128
+ * datetime.datetime object
1129
+
1130
+ issue_date_to: time-stamp, optional
1131
+ Limits the timerange to search for the latest available issue_date.
1132
+ The time-stamp can be provided in the same types as
1133
+ "issue_date_from".
1134
+
1135
+ issue_dates: list of time-stamps, optional
1136
+ List of timestamps in which to search for the latest available
1137
+ issue_date.
1138
+ The time-stamps can be provided in the same types as
1139
+ "issue_date_from".
1140
+
1141
+ with_data: bool, optional
1142
+ If with_data is False,
1143
+ the returned :class:`volue_insight_timeseries.util.TS` object
1144
+ only contains the attributes and meta data information but no
1145
+ data values.
1146
+
1147
+ data_from: time-stamp, optional
1148
+ start date (and time) of data to be fetched. If not given, the start
1149
+ date of the returned timeseries will be the first date with data
1150
+ available. If only the date (without time) is
1151
+ given, the time is assumed to be 00:00. The timestamp can be
1152
+ provided in the same types as "issue_date_from".
1153
+
1154
+ data_to: time-stamp, optional
1155
+ end date (and time) of data to be fetched. The time-stamp can be
1156
+ provided in the same types as "issue_date_from".
1157
+ End dates are always excluded in the result!
1158
+ If not given, the end date of the returned timeseries will be
1159
+ the last date with data available.
1160
+
1161
+ time_zone: str, optional
1162
+ Change curve time zone BEFORE performing an aggregation/split
1163
+ or applying a filter. If no aggregation/split or filter is applied,
1164
+ this will simply change the timezone of the curve. Note that if
1165
+ "output_time_zone" is given, this will define the timezone of the
1166
+ returned curve, since it is applied AFTER performing an
1167
+ aggregation/split or applying a filter and thus AFTER changing
1168
+ to given "time_zone" here.
1169
+
1170
+ You can find valid values for this by calling
1171
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
1172
+
1173
+ filter: str, optional
1174
+ only get a specific subset of the data.
1175
+ You can find valid values for this by calling
1176
+ :meth:`volue_insight_timeseries.session.Session.get_filters` :
1177
+
1178
+ function: str, optional
1179
+ function used to aggregate or split data, must be used together
1180
+ with the ``frequency`` parameter.
1181
+ You can find valid values for this by calling
1182
+ :meth:`volue_insight_timeseries.session.Session.get_functions` :
1183
+
1184
+ frequency: str, optional
1185
+ data will be aggregated or split to the requested frequency using
1186
+ the given function.
1187
+ You can find valid values for this by calling
1188
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
1189
+
1190
+ output_time_zone: str, optional
1191
+ Change curve time zone AFTER performing an aggregation/split
1192
+ or applying a filter.
1193
+
1194
+ Returns
1195
+ -------
1196
+ :class:`volue_insight_timeseries.util.TS` object
1197
+ """
1198
+
1199
+ if only_accessible is not None:
1200
+ warnings.warn("only_accessible parameter will be removed soon.", FutureWarning, stacklevel=2)
1201
+ args=[util.make_arg('with_data', '{}'.format(with_data).lower())]
1202
+ if tags is not None:
1203
+ args.append(util.make_arg('tag', tags))
1204
+ self._add_from_to(args, issue_date_from, issue_date_to, prefix='issue_date_')
1205
+ if with_data:
1206
+ self._add_from_to(args, data_from, data_to, prefix='data_')
1207
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
1208
+ if issue_dates is not None:
1209
+ args.append(util.make_arg('issue_date', issue_dates))
1210
+ astr = '&'.join(args)
1211
+ url = '/api/instances/tagged/{}/latest?{}'.format(self.id, astr)
1212
+ result = self._load_data(url, 'Failed to load tagged instance')
1213
+ if result is None:
1214
+ return result
1215
+ return util.TS(input_dict=result, curve_type=util.TAGGED_INSTANCES)
1216
+
1217
+
1218
+ def get_relative(self, data_offset, data_max_length=None, tag=None, issue_date_from=None, issue_date_to=None,
1219
+ issue_dates=None, issue_weekdays=None, issue_days=None, issue_months=None, issue_times=None,
1220
+ data_from=None, data_to=None, time_zone=None, filter=None, function=None,
1221
+ frequency=None, output_time_zone=None):
1222
+ """ Get a relative forecast from the TAGGED INSTANCE curve
1223
+
1224
+ A relative forecast is a time series created by joining multiple
1225
+ instances so that the data date is issue_date + data_offset.
1226
+ If the data frequency is higher than the frequency of the selected
1227
+ instances, a range of data values from each instance will be used.
1228
+ Similarly if the issue frequency is higher than the data frequency,
1229
+ the same data date will be used from several instances.
1230
+
1231
+ Parameters allow control of the set of instances used and how they
1232
+ are joined together, as well as post-processing of the result.
1233
+
1234
+ Parameters
1235
+ ----------
1236
+
1237
+ data_offset: duration, mandatory
1238
+ The duration added to the issue_date to find the start of the data
1239
+ fragment. Format is an ISO-8601 duration string up to "days".
1240
+
1241
+ data_max_length: duration, optional
1242
+ The longest duration selected from a single instance, mostly used
1243
+ to detect missing instances. ISO-8601 duration string up to "days".
1244
+
1245
+ tag: str, optional
1246
+ tag to get the data for. If omitted, the default tag is used.
1247
+
1248
+ issue_date_from: time-stamp, optional
1249
+ Limits the timerange used to select instances.
1250
+ The time-stamp can be provided in any of the following types :
1251
+
1252
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
1253
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
1254
+ * pandas.Timestamp object
1255
+ * datetime.datetime object
1256
+
1257
+ issue_date_to: time-stamp, optional
1258
+ Limits the timerange used to select instances.
1259
+ The time-stamp can be provided in the same types as
1260
+ "issue_date_from".
1261
+
1262
+ issue_dates: list of time-stamps, optional
1263
+ List of timestamps used to select instances.
1264
+ The time-stamps can be provided in the same types as
1265
+ "issue_date_from".
1266
+
1267
+ issue_weekdays: list of strings, optional
1268
+ Limits the instances to those matching the given weekdays.
1269
+
1270
+ issue_days: list of integers, optional
1271
+ Limits the instances to those matching the given days of month.
1272
+
1273
+ issue_months: list of strings, optional
1274
+ Limits the instances to those matching the given months.
1275
+
1276
+ issue_times: list of strings, optional
1277
+ Limits the instances to those matching the given times of day.
1278
+ Format is 'HH', 'HH:mm' or 'HH:mm:ss'.
1279
+
1280
+ data_from: time-stamp, optional
1281
+ start date (and time) of data to be fetched. If not given, the start
1282
+ date of the returned timeseries will be determined by the first
1283
+ selected instance and the data_offset parameter. If only the date
1284
+ (without time) is given, the time is assumed to be 00:00. The
1285
+ timestamp can be provided in the same types as "issue_date_from".
1286
+
1287
+ data_to: time-stamp, optional
1288
+ end date (and time) of data to be fetched. The time-stamp can be
1289
+ provided in the same types as "issue_date_from".
1290
+ End dates are always excluded in the result!
1291
+ If not given, the end date of the returned timeseries will be
1292
+ the last date with data available in the last instance selected,
1293
+ optionally limited by the data_max_length parameter.
1294
+
1295
+ time_zone: str, optional
1296
+ Change curve time zone BEFORE performing an aggregation/split
1297
+ or applying a filter. If no aggregation/split or filter is applied,
1298
+ this will simply change the timezone of the curve. Note that if
1299
+ "output_time_zone" is given, this will define the timezone of the
1300
+ returned curve, since it is applied AFTER performing an
1301
+ aggregation/split or applying a filter and thus AFTER changing
1302
+ to given "time_zone" here.
1303
+
1304
+ You can find valid values for this by calling
1305
+ :meth:`volue_insight_timeseries.session.Session.get_time_zones`.
1306
+
1307
+ filter: str, optional
1308
+ only get a specific subset of the data.
1309
+ You can find valid values for this by calling
1310
+ :meth:`volue_insight_timeseries.session.Session.get_filters` :
1311
+
1312
+ function: str, optional
1313
+ function used to aggregate or split data, must be used together
1314
+ with the ``frequency`` parameter.
1315
+ You can find valid values for this by calling
1316
+ :meth:`volue_insight_timeseries.session.Session.get_functions` :
1317
+
1318
+ frequency: str, optional
1319
+ data will be aggregated or split to the requested frequency using
1320
+ the given function.
1321
+ You can find valid values for this by calling
1322
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
1323
+
1324
+ output_time_zone: str, optional
1325
+ Change curve time zone AFTER performing an aggregation/split
1326
+ or applying a filter.
1327
+
1328
+ Returns
1329
+ -------
1330
+ :class:`volue_insight_timeseries.util.TS` object
1331
+ """
1332
+ args = [util.make_arg('data_offset', '{}'.format(data_offset))]
1333
+ self._add_from_to(args, issue_date_from, issue_date_to, prefix='issue_date_')
1334
+ self._add_from_to(args, data_from, data_to, prefix='data_')
1335
+ self._add_functions(args, time_zone, filter, function, frequency, output_time_zone)
1336
+ if data_max_length is not None:
1337
+ args.append(util.make_arg('data_max_length', data_max_length))
1338
+ if tag is not None:
1339
+ args.append(util.make_arg('tag', tag))
1340
+ if issue_dates is not None:
1341
+ args.append(util.make_arg('issue_date', issue_dates))
1342
+ if issue_weekdays is not None:
1343
+ args.append(util.make_arg('issue_weekday', issue_weekdays))
1344
+ if issue_days is not None:
1345
+ args.append(util.make_arg('issue_day', issue_days))
1346
+ if issue_months is not None:
1347
+ args.append(util.make_arg('issue_month', issue_months))
1348
+ if issue_times is not None:
1349
+ args.append(util.make_arg('issue_time', issue_times))
1350
+ astr = '&'.join(args)
1351
+ url = '/api/instances/tagged/{}/relative?{}'.format(self.id, astr)
1352
+ result = self._load_data(url, 'Failed to find instances')
1353
+ if result is None:
1354
+ return result
1355
+ return util.TS(input_dict=result, curve_type=util.TAGGED_INSTANCES)
1356
+
1357
+ def get_absolute(self, data_date, issue_frequency=None, tag=None, issue_date_from=None, issue_date_to=None):
1358
+ """ Get an absolute forecast from the INSTANCE curve
1359
+
1360
+ An absolute forecast is a time series created by selecting a single
1361
+ data date from a range of instances, using the issue_date as
1362
+ data date in the result.
1363
+
1364
+ Parameters
1365
+ ----------
1366
+
1367
+ data_date: time-stamp, mandatory
1368
+ The data date of the absolute forecast.
1369
+ The time-stamp can be provided in any of the following types :
1370
+
1371
+ * datestring in format '%Y-%M-%DT%h:%m:%sZ',
1372
+ eg '2017-01-01' or '2018-12-16T13:45:00Z'
1373
+ * pandas.Timestamp object
1374
+ * datetime.datetime object
1375
+
1376
+ issue_frequency: str, optional
1377
+ The frequency of the returned time series. Mandatory if the
1378
+ issue frequency of the curve is 'ANY'. Data will only be
1379
+ returned for those instances whose issue_date is compatible
1380
+ with issue_frequency.
1381
+ You can find valid values for this by calling
1382
+ :meth:`volue_insight_timeseries.session.Session.get_frequencies`.
1383
+
1384
+ tag: str, optional
1385
+ tag to get the data for. If omitted, the default tag is used.
1386
+
1387
+ issue_date_from: time-stamp, optional
1388
+ The start of the timerange used to select instances.
1389
+ The time-stamp can be provided in the same types as
1390
+ "data_date".
1391
+
1392
+ issue_date_to: time-stamp, optional
1393
+ The end of the timerange used to select instances.
1394
+ The time-stamp can be provided in the same types as
1395
+ "data_date".
1396
+
1397
+ Returns
1398
+ -------
1399
+ :class:`volue_insight_timeseries.util.TS` object
1400
+ """
1401
+ args = [util.make_arg('data_date', data_date)]
1402
+ if issue_frequency is not None:
1403
+ args.append(util.make_arg('issue_frequency', issue_frequency))
1404
+ if tag is not None:
1405
+ args.append(util.make_arg('tag', tag))
1406
+ self._add_from_to(args, issue_date_from, issue_date_to, prefix='issue_date_')
1407
+ astr = '&'.join(args)
1408
+ url = '/api/instances/tagged/{}/absolute?{}'.format(self.id, astr)
1409
+ result = self._load_data(url, 'Failed to find instances')
1410
+ if result is None:
1411
+ return result
1412
+ return util.TS(input_dict=result, curve_type=util.TAGGED_INSTANCES)