Hawk¶
Hawk-specific data loading, DMD wrappers, and visualisation.
hawk ¶
Hawk-specific data loading, DMD wrappers, and visualisation.
Everything specific to the hawk flight dataset lives here: NPZ file
loading, mean-shape retrieval via morphing_birds.Hawk3D, batch RMSE
analysis, and marker-position plots. General-purpose DMD logic is in
the other modules; this layer fills in hawk defaults.
Functions:
| Name | Description |
|---|---|
load_bird_data |
Load a hawk NPZ file into a DataFrame. |
get_average_shape |
Return the mean hawk shape via |
normalise_hawk_data |
Centre hawk markers by subtracting the mean shape. |
bin_hawk_dataframe |
Bin with hawk-specific column casting. |
run_hawk_dmd |
|
run_sequence_dmd |
Load one hawk sequence and run DMD. |
batch_rmse_analysis |
DMD + RMSE on many sequences. |
plot_hawk_markers |
4x3 scatter grid of marker positions. |
plot_hawk_markers_shaded |
4x3 binned mean +/- 1 SD bands. |
plot_hawk_2d |
2x4 y-z projections. |
plot_single_sequence |
Single-sequence scatter. |
load_bird_data ¶
load_bird_data(bird_name: str, behaviour: str, perch_distance: str | None = None, bilateral: str = 'Bilateral', turn: str = 'Straight', verbose: bool = False) -> tuple[pd.DataFrame, np.ndarray]
Load hawk marker and info data from NPZ files.
Constructs a file path from the identifiers, loads the marker and
info arrays from the NPZ archive, and merges them into a single
DataFrame. Column names are read from ColumnNames.npz in the
same directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bird_name
|
str
|
Individual hawk identifier, e.g. |
required |
behaviour
|
str
|
Flight phase label used in the filename, e.g. |
required |
perch_distance
|
str
|
Distance to perch, e.g. |
None
|
bilateral
|
str
|
|
'Bilateral'
|
turn
|
str
|
Turn direction: |
'Straight'
|
verbose
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
wingbeat_df |
DataFrame
|
Combined info + marker DataFrame with one row per frame.
Info columns include |
marker_column_names |
ndarray
|
1-D string array of marker column names, length
|
Source code in src/birddmd/hawk.py
get_average_shape ¶
Return the mean hawk shape via Hawk3D.
Instantiates a morphing_birds.Hawk3D object from the mean-shape
CSV and returns either the full bilateral marker set or the
right-side-only subset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_markers
|
int
|
Number of anatomical markers: 8 for bilateral (both wings) or 4 for unilateral (right side only). |
required |
mean_shape_path
|
str
|
Path to the mean-shape CSV file. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If n_markers is not 4 or 8. |
Source code in src/birddmd/hawk.py
normalise_hawk_data ¶
Centre hawk markers by subtracting the mean hawk shape.
Infers the marker count from the array shape, loads the
corresponding mean shape via get_average_shape, and
subtracts it from every frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markers
|
ndarray
|
Raw marker positions, either shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
normalised |
ndarray
|
Mean-subtracted markers, same shape as markers. |
average_shape |
ndarray
|
The mean shape that was subtracted, shape
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If markers is not 2-D or 3-D. |
Source code in src/birddmd/hawk.py
bin_hawk_dataframe ¶
bin_hawk_dataframe(dataframe: DataFrame, x_axis: str = 'HorzDistance', bin_size: float = 0.01) -> pd.DataFrame
Bin a hawk DataFrame, casting hawk-specific columns to float.
Wraps bin_dataframe_means, automatically
casting HorzDistance and VertDistance to float before
binning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Hawk flight DataFrame (e.g. from |
required |
x_axis
|
str
|
Column to bin along, typically |
'HorzDistance'
|
bin_size
|
float
|
Width of each bin in the units of x_axis (metres for distance, seconds for time). |
0.01
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Binned DataFrame with one row per bin, containing group means of all numeric columns. |
Source code in src/birddmd/hawk.py
run_hawk_dmd ¶
run_hawk_dmd(data: ndarray, times: ndarray | None = None, n_modes: int = 6, d: int = 2, eig_constraints: set[str] | None = None, n_markers: int = 8, mean_shape_path: str | None = None, verbose: bool = True, **kwargs) -> DMDResult
Run DMD with hawk defaults.
Loads the mean hawk shape automatically and delegates to
run_dmd. This is the recommended entry
point for single-array hawk analyses where you already have the
marker data in memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Marker positions, shape |
required |
times
|
ndarray
|
Time vector, shape |
None
|
n_modes
|
int
|
Number of DMD modes (SVD rank). |
6
|
d
|
int
|
Hankel delay-embedding depth. |
2
|
eig_constraints
|
set of str
|
Constraints passed to BOPDMD, e.g. |
None
|
n_markers
|
int
|
Number of anatomical markers (8 bilateral, 4 unilateral). |
8
|
mean_shape_path
|
str
|
Path to the mean-shape CSV. Defaults to the bundled file. |
None
|
verbose
|
bool
|
If |
True
|
**kwargs
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
DMDResult
|
Complete DMD results including eigenvalues, modes, reconstruction, etc. |
Source code in src/birddmd/hawk.py
run_sequence_dmd ¶
run_sequence_dmd(bird_name: str, perch_dist: str, turn: str, behaviour: str, seqID: str, n_modes: int = 10, d: int = 2, eig_constraints: set[str] | None = None, min_seq_length: int | None = None, interpolate: bool = False, verbose: bool = True) -> DMDResult | None
Load one hawk sequence from disk and run DMD on it.
Convenience wrapper that chains load_bird_data,
load_sequence_data, optional spline
interpolation, and run_dmd into a single
call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bird_name
|
str
|
Individual hawk identifier, e.g. |
required |
perch_dist
|
str
|
Distance to perch, e.g. |
required |
turn
|
str
|
Turn direction: |
required |
behaviour
|
str
|
Flight phase label, e.g. |
required |
seqID
|
str
|
Unique sequence identifier within the loaded dataset. |
required |
n_modes
|
int
|
Number of DMD modes (SVD rank). |
10
|
d
|
int
|
Hankel delay-embedding depth. |
2
|
eig_constraints
|
set of str
|
Constraints passed to BOPDMD, e.g. |
None
|
min_seq_length
|
int
|
Minimum number of frames required. Sequences shorter than
this are skipped. Defaults to |
None
|
interpolate
|
bool
|
If |
False
|
verbose
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
DMDResult or None
|
Complete DMD results, or |
Source code in src/birddmd/hawk.py
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 | |
batch_rmse_analysis ¶
batch_rmse_analysis(df: DataFrame, seqIDs: list[str], marker_column_names: ndarray, average_shape: ndarray, n_modes: int = 6, d: int = 2, marker_names: list[str] | None = None, verbose: bool = False, per_frame: bool = False) -> pd.DataFrame
Run DMD on many hawk sequences and collect RMSE statistics.
Iterates over seqIDs, fits a DMD model to each sequence, and
computes the root-mean-square reconstruction error. Sequences
that fail (e.g. due to convergence issues) are silently skipped
unless verbose is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Full hawk dataset containing all sequences (e.g. from
|
required |
seqIDs
|
list of str
|
Sequence identifiers to analyse. |
required |
marker_column_names
|
ndarray
|
1-D string array of marker column names, length
|
required |
average_shape
|
ndarray
|
Mean hawk shape, shape |
required |
n_modes
|
int
|
Number of DMD modes (SVD rank). |
6
|
d
|
int
|
Hankel delay-embedding depth. |
2
|
marker_names
|
list of str
|
Human-readable marker names used as suffixes for per-marker
RMSE columns (e.g. |
None
|
verbose
|
bool
|
If |
False
|
per_frame
|
bool
|
If
|
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per successfully analysed sequence, with columns
|
Source code in src/birddmd/hawk.py
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 | |
plot_hawk_markers ¶
plot_hawk_markers(dataframe: DataFrame, _marker_column_names: ndarray, x_axis: str = 'HorzDistance') -> Figure
Plot a 4x3 scatter grid of marker positions.
Each row corresponds to one of the four marker positions (see
MARKER_POSITIONS); each column shows the x, y, or z
coordinate. Left and right markers are overlaid in the same
colour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Hawk flight DataFrame with marker columns following the
|
required |
_marker_column_names
|
ndarray
|
1-D string array of marker column names (used for layout
consistency; individual columns are constructed from
|
required |
x_axis
|
str
|
Column to plot on the horizontal axis. |
'HorzDistance'
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure with 12 scatter subplots. |
Source code in src/birddmd/hawk.py
plot_hawk_markers_shaded ¶
plot_hawk_markers_shaded(dataframe: DataFrame, _marker_column_names: ndarray, x_axis: str = 'HorzDistance', bin_size: float = 0.01) -> Figure
Plot a 4x3 grid of binned mean +/- 1 SD bands for hawk markers.
Same layout as plot_hawk_markers but instead of raw
scatter points, data are binned along x_axis and the mean is
shown as a solid (left) or dotted (right) line with a shaded
+/- 1 standard deviation band. The x-coordinate uses absolute
values before averaging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Hawk flight DataFrame with marker columns following the
|
required |
_marker_column_names
|
ndarray
|
1-D string array of marker column names. |
required |
x_axis
|
str
|
Column to bin along. |
'HorzDistance'
|
bin_size
|
float
|
Width of each bin in the units of x_axis (metres for distance, seconds for time). |
0.01
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure with 12 shaded-band subplots. |
Source code in src/birddmd/hawk.py
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 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 | |
plot_hawk_2d ¶
Plot 2x4 y-z projections of hawk marker positions.
Each subplot shows one marker's lateral (y) vs. vertical (z) position across all frames, coloured by time. Useful for visualising the spatial envelope of wing kinematics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Hawk flight DataFrame with marker columns and a |
required |
marker_column_names
|
ndarray
|
1-D string array of marker column names, length
|
required |
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure with 8 equal-aspect subplots. |
Source code in src/birddmd/hawk.py
plot_single_sequence ¶
plot_single_sequence(dataframe: DataFrame, seq_num: int, marker_name: str = 'right_wingtip_z', x_axis: str = 'HorzDistance') -> Figure
Plot a single hawk sequence for one marker coordinate.
Selects the sequence at position seq_num (zero-indexed) from the
unique seqID values and scatter-plots the chosen marker
coordinate against the horizontal axis, coloured by time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Hawk flight DataFrame with |
required |
seq_num
|
int
|
Zero-based index into the sorted unique sequence IDs. |
required |
marker_name
|
str
|
Column name of the marker coordinate to plot on the vertical
axis, e.g. |
'right_wingtip_z'
|
x_axis
|
str
|
Column for the horizontal axis. |
'HorzDistance'
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure with a single scatter subplot. |