Signal
A Signal provides a time-varying value to actors and grid
signals. See the Signals and Datasets concept page for
usage examples.
Signal
Bases: ABC
Abstract base class for signals.
Source code in vessim/signal.py
13 14 15 16 17 18 19 20 21 22 23 24 25 | |
at
abstractmethod
Return the signal's value at the given elapsed time since sim_start.
elapsed accepts a timedelta or float interpreted as
seconds since sim_start.
Source code in vessim/signal.py
16 17 18 19 20 21 22 | |
finalize
Perform necessary finalization tasks of a signal.
Source code in vessim/signal.py
24 25 | |
StaticSignal
Bases: Signal
Source code in vessim/signal.py
28 29 30 31 32 33 34 35 36 37 38 39 40 | |
Trace
Bases: Signal
Replays a time series indexed by an offset since simulation start.
Internally a Trace is always offset-indexed: row 0 sits at offset=0
seconds, every other row is a positive offset from there. For a Trace,
the queried elapsed time and a row's offset are the same coordinate:
at(elapsed) returns the value whose offset best matches the elapsed
time the simulation has accumulated since sim_start.
The accepted index types are:
TimedeltaIndexor numeric (interpreted as offset seconds): used as-is. Must start at offset=0.anchormust not be provided. This is the canonical form.DatetimeIndex: a convenience for calendar-stamped data.anchoris required and must match an existing row exactly; that row is rebased to offset=0 and earlier rows are dropped.
For loading offset-indexed or datetime-indexed CSVs, use Trace.from_csv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Series | DataFrame
|
A pandas |
required |
anchor
|
Optional[Timestamp | str]
|
Required when |
None
|
on_overflow
|
Literal['raise']
|
What to do if queried beyond the trace's range.
Currently only |
'raise'
|
column
|
Optional[str]
|
Default column to use when |
None
|
fill_method
|
Literal['ffill', 'bfill']
|
How values between timestamps are computed. Either
|
'ffill'
|
Source code in vessim/signal.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
from_csv
classmethod
Load a Trace from a CSV file.
Vessim expects offset-indexed CSVs: the first column is the offset
in seconds since the trace start (row 0 at 0). Remaining columns are
value columns (zones, regions, etc.).
As a utility, datetime-indexed CSVs are also accepted and converted on
load: pass anchor=<timestamp> to mark which row corresponds to
offset=0. See Signals and Datasets for the
full schema and recipes for fetching data from public APIs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the CSV file. |
required |
anchor
|
Optional[Timestamp | str]
|
Required if the first column is a datetime; must match a
row in the data exactly. That row becomes |
None
|
column
|
Optional[str]
|
Default column to use when |
None
|
scale
|
float
|
Multiplier applied to all values. Useful for normalized data. |
1.0
|
on_overflow
|
Literal['raise']
|
See |
'raise'
|
fill_method
|
Literal['ffill', 'bfill']
|
See |
'ffill'
|
Source code in vessim/signal.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
columns
Returns a list of all available columns.
Source code in vessim/signal.py
216 217 218 | |
at
Return the trace's value at the given elapsed time since sim_start.
If elapsed falls between sample points, fill_method decides how to
interpolate. If elapsed falls outside the trace, a ValueError is
raised (subject to on_overflow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elapsed
|
Optional[timedelta | float]
|
Elapsed time since |
None
|
column
|
Optional[str]
|
Column to query. Required if the trace has more than one. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in vessim/signal.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
Software-in-the-Loop signals
These signals require the sil extra (pip install vessim[sil]). See the
Software-in-the-Loop concept page for the full picture.
SilSignal
Bases: Signal
Base class for Software-in-the-Loop signals with background polling.
This class provides common functionality for signals that need to periodically fetch data from external sources (APIs, databases, etc.) and cache the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_interval
|
float
|
Interval in seconds between data updates |
5.0
|
timeout
|
float
|
Request timeout in seconds for external calls |
10.0
|
Source code in vessim/signal.py
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 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
at
Return the current cached value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elapsed
|
Optional[timedelta | float]
|
Elapsed time since |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Current cached value |
Source code in vessim/signal.py
347 348 349 350 351 352 353 354 355 356 | |
finalize
Stop background polling and clean up resources.
Source code in vessim/signal.py
358 359 360 | |
PrometheusSignal
Bases: SilSignal
Signal that pulls energy usage data from a Prometheus instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prometheus_url
|
str
|
Base URL of the Prometheus server (e.g., 'http://localhost:9090') |
required |
query
|
str
|
PromQL query to fetch energy usage data |
required |
update_interval
|
float
|
Interval in seconds between metric updates |
10
|
timeout
|
float
|
Request timeout in seconds |
10
|
username
|
Optional[str]
|
Username for HTTP Basic Authentication (optional) |
None
|
password
|
Optional[str]
|
Password for HTTP Basic Authentication (optional) |
None
|
Source code in vessim/signal.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
WatttimeSignal
Bases: SilSignal
Real-time carbon intensity signal from WattTime API.
This signal fetches real-time marginal carbon intensity data from the WattTime API. It requires username and password. If the login fails (e.g., user doesn't exist), it will prompt the user to confirm auto-registration and request an email address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
WattTime API username |
required |
password
|
str
|
WattTime API password |
required |
region
|
Optional[str]
|
Grid region (balancing authority) code, e.g., 'CAISO_NORTH'. Must be provided if location is not specified. |
None
|
location
|
Optional[tuple[float, float]]
|
Tuple of (latitude, longitude) coordinates to automatically determine region. Alternative to specifying region directly. |
None
|
base_url
|
str
|
Base URL for WattTime API, defaults to 'https://api.watttime.org' |
'https://api.watttime.org'
|
update_interval
|
float
|
Interval in seconds between API calls (default: 300 seconds as WattTime updates every 5 minutes) |
300
|
timeout
|
float
|
Request timeout in seconds |
10
|
Source code in vessim/signal.py
450 451 452 453 454 455 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 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |