API Reference¶
StillSuit Class¶
stillsuit.StillSuit
dataclass
¶
This class provides an interface to an sqlite database that facilitates the storage of gravitational wave results. It defines methods that are largely agnostic about e.g., column names, but some tables must exist and some relationships must exist.
These tables will be related in the following way
-------- ------------
| filter | | simulation | -------- ------------ | | static tables (defined up front)
| | dynamic tables (appended to as analysis progresses)
v v
--------- -------
| trigger | | event | --------- ------- \ | \ V =============== || trigger map || This table is automatically generated ===============
Users define their own column names in a yaml file called "config" that will be provided to this class to initialize it. It is required always since it also defines schema validation.
When starting an analysis from scratch, it is expected that the user will first insert some static data in the filter table (e.g., a table defining CBC template parameters or burst template parameters) and a simulation table (optional) if injections were performed which holds parameters about a simulated signal put into the data.
As an analysis progresses, it is expected that events are inserted one by one. Events are actually a relationship between three tables 1) a trigger table holding measured parameters of one GW detector search; 2) an event table which holds data corresponding to the gravitational wave event defined a the collection of one or more triggers. A third table called "trigger_map" will be automatically made by this class to define the relationships.
NOTE: according to documentation: https://www.sqlite.org/lang_createtable.html#rowid, the primary keys defined in the schema all follow the convention that they will be an alias for the built in rowid.
Parameters:¶
dict
A dictionary (just the output of yaml.load) defining the custom user schema
dbname: str The database name. If it exists it will be loaded, if not it will be created. Default ":memory:" inplace: Transform the database in place. Incompatable with in memory databases or gzip database. Default: False
Source code in stillsuit/__init__.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 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 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 361 362 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 448 449 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 | |
static_tables_and_columns
property
¶
__post_init__()
¶
Setup the database, row factory and schema
Source code in stillsuit/__init__.py
connect(config, dbname, inplace=False)
classmethod
¶
This class method allows a user to connect to an sqlite database. In some ways, it is similar to the sqlite3.connect() function, but it adds schema validation and initializes an empty database. It also returns the schema dictionary that was applied to the DB.
If config is None and dbname points to an existing database, the schema will be loaded from the database's metadata table.
Source code in stillsuit/__init__.py
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 448 449 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 | |
load_schema_from_config(config)
classmethod
¶
Load the user schema from a config file, then
1) Validate that the required tables are present 2) Add a new "trigger_map" table. 3) Merge the BASE SCHEMA (class defined special column names and relationships) into the user schema
return the merged schema.
Source code in stillsuit/__init__.py
db_schema(db)
classmethod
¶
Return the current schema in the database
insert_static(d, cursor=None)
¶
This is a method to insert list of dictionarys of static data, e.g.,
d = {"filter": [{"col1":
Source code in stillsuit/__init__.py
insert_event(d, ignore_sim=False, ignore_cols=None)
¶
Required format { "trigger": [{...}, ...], "event": {...} }
Furthermore, data and trigger must have the same length and be 1:1.
NOTE: this method modifies the trigger and event dictionaries to add references to internal keys. If you don't want that behavior save a copy before you insert or otherwise deal with it.
Source code in stillsuit/__init__.py
get_events(ignore_automatic=False, simulation=False)
¶
A generator to return a dictionary of all the information about an event
Source code in stillsuit/__init__.py
get_missed_found(selection_func=lambda x: True, ignore_automatic=False)
¶
Source code in stillsuit/__init__.py
cluster(win_in_sec=1.0, column='network_snr')
¶
Cluster the current database by events that maximize "column" within a fixed time window of "win_in_sec"
Source code in stillsuit/__init__.py
cluster_final(win_in_sec=1.0, column='network_snr')
¶
Final round of clustering.
Source code in stillsuit/__init__.py
index()
¶
flush()
¶
Commit the DB results. This will generally only be done if asked. An exception is when the initial structure is set up for a new db
to_file(filename)
¶
Save in-memory database to file
Source code in stillsuit/__init__.py
Helper Functions¶
stillsuit.serialize(conn)
¶
stillsuit.deserialize(conn, byte_stream)
¶
stillsuit.select_data_from_db(cursor, table_name)
¶
stillsuit.insert_ignore(cursor, table_name, rows, column_names)
¶
Source code in stillsuit/__init__.py
Command-Line Tools¶
stillsuit-merge-reduce¶
Merge multiple databases and cluster events.
Options:
| Option | Type | Description |
|---|---|---|
-s, --config-schema |
PATH | YAML schema file for database structure (required) |
-c, --clustering-column |
TEXT | Column to maximize during clustering (required) |
-w, --clustering-window |
FLOAT | Time window in seconds for clustering (required) |
-d, --db-to-insert-into |
PATH | Output database path (must not exist) (required) |
--dbs |
PATH... | Input database files to merge |
--final-round |
FLAG | Apply final clustering round for boundary handling |
-v, --verbose |
FLAG | Enable verbose output |
Example:
stillsuit-merge-reduce \
--config-schema config/tutorial_schema.yaml \
--clustering-column network_snr \
--clustering-window 1.0 \
--db-to-insert-into output.sqlite \
--verbose \
--final-round \
--dbs input1.sqlite input2.sqlite
Schema Configuration¶
YAML Schema Format¶
Each table in the schema is defined with the following structure:
table_name:
columns:
- {name: "column_name", type: TYPE, constraints: "CONSTRAINTS"}
relationships:
- {"foreign_table": "foreign_key_column"}
static: True/False
indices: # optional
index_name: ["column1", "column2"]
Supported Data Types¶
| Type | Description |
|---|---|
NULL |
NULL value |
INTEGER |
Signed integer (0-8 bytes) |
REAL |
8-byte IEEE floating point |
TEXT |
UTF-8 text string |
BLOB |
Binary data |
Reserved Column Names¶
Column names starting with __ or _ are reserved:
| Column | Description |
|---|---|
__filter_id |
Filter/template identifier |
__trigger_id |
Trigger unique identifier |
__event_id |
Event unique identifier |
__data_id |
Data source identifier |
__trigger_map_id |
Trigger-event relationship identifier |
_simulation_id |
Simulation identifier |
Required Tables¶
The following tables must always be defined:
trigger- Individual detector measurementsevent- Gravitational wave event candidates
Automatic Tables¶
trigger_map- Automatically manages trigger-to-event relationships
NumPy Type Support¶
Stillsuit automatically handles NumPy data types:
np.int32/np.int64→INTEGERnp.float16/np.float32/np.float64→REAL