transformations
cognite.powerops.prerun_transformations.transformations.RelativeDatapoint
Bases: BaseModel
A relative datapoint that states from what minute to apply an offset value. To be used when for instance adding different offset values at different points in time from start time of an array of time series data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset_minute
|
The number of minutes from start time of an input array of time series data to apply a value |
required | |
offset_value
|
The value to apply to the existing value at the offset_minute point in time |
required |
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.AddConstant
Bases: Transformation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
constant
|
The value to add to the time series data |
required |
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Add value to input time series
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data. Only the first one, time_series_data[0], is used - the constant value will be added to every value of this time series |
required |
Returns:
Type | Description |
---|---|
Series
|
The first pd.Series from the input tuple with the constant added to all values |
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.MultiplyConstant
Bases: Transformation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
constant
|
The value to multiply the time series data with |
required |
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Multiply value to input time series
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data. Only the first one, time_series_data[0], is used - the constant value will be multiplied to every value of this time series |
required |
Returns:
Type | Description |
---|---|
Series
|
The resulting series when taking the first series in time_series_data and multiplying |
Series
|
all values by a constant |
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.StaticValues
Bases: DynamicTransformation
Provides a list of static values from SHOP start time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relative_datapoints
|
The relative datapoints to apply to |
required |
Source code in cognite/powerops/prerun_transformations/transformations.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
pre_apply(client, shop_model, start, end)
Preprocessing step that needs to run before apply()
to set the shop start time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
CogniteClient
|
_ not used in this transformation, but needs to be provided |
required |
shop_model
|
dict
|
_ not used in this transformation, but needs to be provided |
required |
start
|
int
|
datetime of SHOP start time |
required |
Example:
from cognite.client import CogniteClient
start_time = datetime.timestamp(datetime(2000, 1, 1, 12))
end_time = datetime.timestamp(datetime(2000, 1, 5, 12))
client = CogniteClient()
model = {}
relative_datapoints = [
... RelativeDatapoint(offset_minute=0, offset_value=42),
... RelativeDatapoint(offset_minute=1440, offset_value=4200),
... ]
s = StaticValues(relative_datapoints=relative_datapoints)
s.pre_apply(client=client, shop_model=model, start=start_time, end=end_time)
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(_)
Returns:
Type | Description |
---|---|
Series
|
Pandas Series based from SHOP start time |
Example:
from cognite.client import CogniteClient
start_time = datetime.timestamp(datetime(2000, 1, 1, 12))
end_time = datetime.timestamp(datetime(2000, 1, 5, 12))
client = CogniteClient()
model = {}
relative_datapoints = [
... RelativeDatapoint(offset_minute=0, offset_value=42),
... RelativeDatapoint(offset_minute=1440, offset_value=4200),
... ]
s = StaticValues(relative_datapoints=relative_datapoints)
s.pre_apply(client=client, shop_model=model, start=start_time, end=end_time)
s.apply(_)
2000-01-01 12:00:00 42.0
2000-01-01 13:00:00 42.0
2000-01-02 12:00:00 4200.0
dtype: float64
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.ToBool
Bases: Transformation
"Greater than 0" transformation of time series data to a series of 0s and 1s. 1s if the value is > 0.
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data. Only the first one, time_series_data[0], is used - every value of this time series will be converted to 0 or 1 |
required |
Returns:
Type | Description |
---|---|
Series
|
The transformed time series |
Example:
>>> values = [0, 1, 2, -1]
>>> time_series_data = (pd.Series(
... values,
... index=pd.date_range(start='25/05/2021', periods = len(values)),
... ),)
>>> b = ToBool()
>>> b.apply(time_series_data=time_series_data)
2021-05-25 0
2021-05-26 1
2021-05-27 1
2021-05-28 0
Freq: D, dtype: int64
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.ZeroIfNotOne
Bases: Transformation
Transforms time series data to a series of 0s and 1s. 1s if the value is exactly 1.
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data. Only the first one, time_series_data[0], is used - every value of this time series will be converted to 0 or 1 |
required |
Returns:
Type | Description |
---|---|
Series
|
The transformed time series |
Example:
>>> values = [0, 1, 2, -1]
>>> time_series_data = (pd.Series(
... values,
... index=pd.date_range(start='25/05/2021', periods = len(values)),
... ),)
>>> b = ZeroIfNotOne()
>>> b.apply(time_series_data=time_series_data)
2021-05-25 0
2021-05-26 1
2021-05-27 0
2021-05-28 0
Freq: D, dtype: int64
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.OneIfTwo
Bases: Transformation
Transforms time series data to a series of 0s and 1s. 1s if the value is exactly 2.
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data. Only the first one, time_series_data[0], is used - every value of this time series will be converted to 0 or 1 |
required |
Returns:
Type | Description |
---|---|
Series
|
The transformed time series |
Example:
>>> values = [0, 1, 2, -1]
>>> time_series_data = (pd.Series(
... values,
... index=pd.date_range(start='25/05/2021', periods = len(values)),
... ),)
>>> b = OneIfTwo()
>>> b.apply(time_series_data=time_series_data)
2021-05-25 0
2021-05-26 0
2021-05-27 1
2021-05-28 0
Freq: D, dtype: int64
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.SumTimeseries
Bases: Transformation
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Sum two or more time series together in place without any interpolation between points
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data. Where all the time series in the tuple are summed together |
required |
Returns:
Type | Description |
---|---|
Series
|
Concatenated timeseries with values added together |
Example:
>>> timestamps = [
... datetime(2022, 1, 1, 0),
... datetime(2022, 1, 1, 1),
... datetime(2022, 1, 1, 2),
... datetime(2022, 1, 1, 3),
... datetime(2022, 1, 1, 4),
... datetime(2022, 1, 1, 5),
... ]
>>> values = [42.0] * len(timestamps)
>>> time_series_data1 = pd.Series(values, index=timestamps)
>>> time_series_data1
2022-01-01 00:00:00 42.0
2022-01-01 01:00:00 42.0
2022-01-01 02:00:00 42.0
2022-01-01 03:00:00 42.0
2022-01-01 04:00:00 42.0
2022-01-01 05:00:00 42.0
dtype: float64
>>> timestamps2 = [t + timedelta(hours=timestamps.index(t)) for t in timestamps]
>>> values2 = [20.0] * len(timestamps)
>>> time_series_data2 = pd.Series(values2, index=timestamps2)
>>> time_series_data2
2022-01-01 00:00:00 20.0
2022-01-01 02:00:00 20.0
2022-01-01 04:00:00 20.0
2022-01-01 06:00:00 20.0
2022-01-01 08:00:00 20.0
2022-01-01 10:00:00 20.0
dtype: float64
>>> time_series_data = (pd.Series(values, index=timestamps), pd.Series(values2, index=timestamps2))
>>> c = SumTimeseries()
>>> c.apply(time_series_data)
2022-01-01 00:00:00 62.0
2022-01-01 01:00:00 42.0
2022-01-01 02:00:00 62.0
2022-01-01 03:00:00 42.0
2022-01-01 04:00:00 62.0
2022-01-01 05:00:00 42.0
2022-01-01 06:00:00 20.0
2022-01-01 08:00:00 20.0
2022-01-01 10:00:00 20.0
dtype: float64
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.HeightToVolume
Bases: DynamicTransformation
TODO
Source code in cognite/powerops/prerun_transformations/transformations.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
|
pre_apply(client, shop_model, start, end)
Preprocessing step that needs to run before apply()
to set the volumes and heights from shop case file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
CogniteClient
|
_ not used in this transformation |
required |
shop_model
|
dict
|
SHOP model file |
required |
start
|
int
|
_ not used in this transformation |
required |
end
|
int
|
_ not used in this transformation |
required |
Example:
from cognite.client import CogniteClient
start_time = datetime.timestamp(datetime(2000, 1, 1, 12))
end_time = datetime.timestamp(datetime(2000, 1, 10, 12))
model = {"reservoir": {"Lundevatn": {"vol_head": {"x": [10, 20, 40, 80, 160], "y": [2, 4, 6, 8, 10]}}}}
client = CogniteClient()
h = HeightToVolume(object_type="reservoir", object_name="Lundevatn")
h.pre_apply(client=client, shop_model=model, start=start_time, end=end_time)
h.volumes
Out[4]: [10, 20, 40, 80, 160]
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data. Only the first one, time_series_data[0], is used - the height to volume will be applied to each value of this time series |
required |
Returns:
Type | Description |
---|---|
Series
|
The transformed time series |
Example:
from cognite.client import CogniteClient
start_time = datetime.timestamp(datetime(2000, 1, 1, 12))
end_time = datetime.timestamp(datetime(2000, 1, 10, 12))
model = {"reservoir": {"Lundevatn": {"vol_head": {"x": [10, 20, 40, 80, 160], "y": [2, 4, 6, 8, 10]}}}}
client = CogniteClient()
time_series_data = (pd.Series(
{
1: 1, # below interpolation bounds
2: 4,
3: 6,
4: 7, # interpolated
5: 11, # above interpolation bounds
}
),)
h = HeightToVolume(object_type="reservoir", object_name="Lundevatn")
h.pre_apply(client=client, shop_model=model, start=start_time, end=end_time)
h.apply(time_series_data=time_series_data)
1 10.0
2 20.0
3 40.0
4 60.0
5 160.0
dtype: float64
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.DoNothing
Bases: Transformation
Don't apply any transformations, just return the unchanged Series
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.Round
Bases: Transformation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
digits
|
The number of decimal places to round to |
required |
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Round the time series values to the specified number of decimals, using the "round half to even" method
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data. Only the first one, time_series_data[0], is used - the round will be applied to every value of this time series |
required |
Returns:
Type | Description |
---|---|
Series
|
The first pd.Series from the input tuple with the rounding applied to all values |
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.AddFromOffset
Bases: Transformation
Adds values to input timeseries based on a list of relative datapoints with values to be added to corresponding offset minute from start time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relative_datapoints
|
The values to add to existing time series based at offset minute times from time series |
required |
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data. Only the first one, time_series_data[0], is used - the add from offset will be applied to each value in this time series |
required |
Example:
>>> timestamps = [
... datetime(2022, 1, 1, 0),
... datetime(2022, 1, 1, 1),
... datetime(2022, 1, 1, 2),
... datetime(2022, 1, 1, 3),
... datetime(2022, 1, 1, 4),
... datetime(2022, 1, 1, 5),
... ]
>>> values = [42.0] * len(timestamps)
>>> time_series_data = (pd.Series(values, index=timestamps),)
>>> time_series_data
(2022-01-01 00:00:00 42.0
2022-01-01 01:00:00 42.0
2022-01-01 02:00:00 42.0
2022-01-01 03:00:00 42.0
2022-01-01 04:00:00 42.0
2022-01-01 05:00:00 42.0
dtype: float64,)
>>> relative_datapoints = [
... RelativeDatapoint(offset_minute=0, offset_value=1),
... RelativeDatapoint(offset_minute=20, offset_value=-2),
... RelativeDatapoint(offset_minute=230, offset_value=3),
... ]
>>> a = AddFromOffset(relative_datapoints=relative_datapoints)
>>> a.apply(time_series_data)
2022-01-01 00:00:00 43.0
2022-01-01 00:20:00 40.0
2022-01-01 01:00:00 40.0
2022-01-01 02:00:00 40.0
2022-01-01 03:00:00 40.0
2022-01-01 03:50:00 45.0
2022-01-01 04:00:00 45.0
2022-01-01 05:00:00 45.0
dtype: float64
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.MultiplyFromOffset
Bases: Transformation
Multiplies values to input timeseries based on a list of relative datapoints
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relative_datapoints
|
A tuple of time series data. Only the first one, time_series_data[0], is used - the multiply from offset will be applied to each value in this time series |
required |
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Example:
>>> timestamps = [datetime(2022, 1, 1) + timedelta(minutes=i) for i in range(6)]
>>> values = [10.0] * 6
>>> time_series_data = (pd.Series(values, index=timestamps),)
>>> time_series_data
(2022-01-01 00:00:00 10.0
2022-01-01 00:01:00 10.0
2022-01-01 00:02:00 10.0
2022-01-01 00:03:00 10.0
2022-01-01 00:04:00 10.0
2022-01-01 00:05:00 10.0
dtype: float64,)
>>> relative_datapoints = [
... RelativeDatapoint(offset_minute=1, offset_value=2),
... RelativeDatapoint(offset_minute=2, offset_value=0),
... RelativeDatapoint(offset_minute=4, offset_value=1.5),
... ]
>>> m = MultiplyFromOffset(relative_datapoints=relative_datapoints)
>>> m.apply(time_series_data)
2022-01-01 00:00:00 10.0
2022-01-01 00:01:00 20.0
2022-01-01 00:02:00 0.0
2022-01-01 00:03:00 0.0
2022-01-01 00:04:00 15.0
2022-01-01 00:05:00 15.0
Freq: min, dtype: float64
Source code in cognite/powerops/prerun_transformations/transformations.py
cognite.powerops.prerun_transformations.transformations.AddWaterInTransit
Bases: DynamicTransformation
Adds water in transit (previously discharged water) to the inflow time series.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
discharge_ts_external_id
|
external id of discharge timeseries to retrieve from CDF |
required | |
transit_object_type
|
gate or plant |
required | |
transit_object_name
|
name of gate or plant |
required |
Source code in cognite/powerops/prerun_transformations/transformations.py
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 |
|
pre_apply(client, shop_model, start, end)
Preprocessing step that needs to run before apply()
to set the shape,
retrieve and set discharge time series data, and set SHOP start and end times
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
CogniteClient
|
CogniteClient authenticated to project to retrieve discharge timeseries from |
required |
shop_model
|
dict
|
SHOP model dict |
required |
start
|
int
|
SHOP start time in milliseconds since epoch |
required |
end
|
int
|
SHOP end time in milliseconds since epoch |
required |
Example:
from cognite.client import CogniteClient
start_time = datetime.timestamp(datetime(2000, 1, 1, 12))
end_time = datetime.timestamp(datetime(2000, 1, 5, 12))
client = CogniteClient()
model = {"gate": {"gate1": {"shape_discharge": {"ref": 0, "x": [0, 60, 120], "y": [0.1, 0.5, 0.4]}}}}
t = AddWaterInTransit(discharge_ts_external_id="discharge_ts",
... transit_object_type="gate",
... transit_object_name="gate1")
t.pre_apply(client=client, shop_model=model, start=start_time, end=end_time)
t.shape
{0: 0.1, 60: 0.5, 120: 0.4}
Source code in cognite/powerops/prerun_transformations/transformations.py
apply(time_series_data)
Run apply()
after preprocessing step to add water in transit to add water in transit (discharge water) to
inflow time series
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_series_data
|
tuple[Series]
|
A tuple of time series data representing inflow. Only the first one, time_series_data[0], is used |
required |
Example:
from cognite.client import CogniteClient
start = datetime(year=2022, month=5, day=20, hour=22)
end = start + timedelta(days=5)
start_time = datetime.timestamp(start) * 1000
end_time = datetime.timestamp(end) * 1000
client = CogniteClient()
model = {"gate": {"gate1": {"shape_discharge": {"ref": 0, "x": [0, 60, 120], "y": [0.1, 0.5, 0.4]}}}}
t = AddWaterInTransit(discharge_ts_external_id="discharge_ts",
... transit_object_type="gate",
... transit_object_name="gate1")
t.pre_apply(client=client, shop_model=model, start=start_time, end=end_time)
inflow = [1, 2, 3, 2, 4, 5, 3, 1, 2, 0, 7, 5, 9, 0, 0, 9, 8, 7, 6, 5, 4, 7, 8, 9]
timestamps = [start + timedelta(hours=2 * i) for i in range(len(inflow))]
time_series_data = (pd.Series(inflow, index=timestamps),)
t.apply(time_series_data)
Out[1]:
2022-05-20 22:00:00 3.5
2022-05-20 23:00:00 3.5
2022-05-21 00:00:00 3.0
2022-05-21 01:00:00 3.0
2022-05-21 02:00:00 4.5
...
2022-05-25 17:00:00 9.0
2022-05-25 18:00:00 9.0
2022-05-25 19:00:00 9.0
2022-05-25 20:00:00 9.0
2022-05-25 21:00:00 9.0
Freq: H, Length: 120, dtype: float64