Field Registry¶
Field metadata registry mapping canonical field names to quantity types, SI unit labels, human-readable names, and LaTeX symbols. Single source of truth for field display metadata.
fields
¶
Field metadata registry: names, units, and display labels.
Maps every canonical field name to its physical quantity type, SI unit
label, human-readable long name, and LaTeX symbol. The literal lives in
pypic._field_table; this module resolves lookups through the alias
and species-pattern fallbacks, and owns register_field.
compute.field_si_factor reads the table directly at lookup time.
FieldInfo
dataclass
¶
Metadata for a single field or derived quantity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantity_type
|
str
|
Physical quantity type matching |
required |
long_name
|
str
|
Human-readable name (e.g. |
required |
si_unit
|
str
|
SI unit label (e.g. |
required |
latex
|
str
|
LaTeX symbol for plot labels (e.g. |
''
|
unit_dimension
|
tuple[int, ...] | None
|
openPMD-style 7-tuple of integer SI base-unit powers
(length, mass, time, current, temperature, amount, luminosity).
|
None
|
Source code in src/pypic/_field_table.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
QuantityType
¶
Bases: StrEnum
Physical quantity types for field metadata and SI conversion.
Each member corresponds to a key in Normalization.si_factor()
and maps to a default SI unit label. Since QuantityType is a
StrEnum, members compare equal to plain strings:
QuantityType.B_FIELD == "b_field" is True.
Examples:
>>> QuantityType.B_FIELD
<QuantityType.B_FIELD: 'b_field'>
>>> QuantityType.B_FIELD == "b_field"
True
Source code in src/pypic/fields.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 | |
quantity_dimension(quantity)
¶
Return the openPMD unitDimension 7-tuple for a quantity type.
The tuple gives integer powers of the SI base units in the order (length, mass, time, current, temperature, amount, luminosity).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantity
|
str or QuantityType
|
Physical quantity type — one of the keys in |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
Seven-element tuple of integer dimensional powers. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If quantity is not a recognized quantity type. |
Examples:
>>> quantity_dimension("b_field")
(0, 1, -2, -1, 0, 0, 0)
>>> quantity_dimension(QuantityType.VELOCITY)
(1, 0, -1, 0, 0, 0, 0)
>>> quantity_dimension("dimensionless")
(0, 0, 0, 0, 0, 0, 0)
Source code in src/pypic/fields.py
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 | |
register_field(name, quantity_type, *, long_name='', si_unit=None, latex='', unit_dimension=None)
¶
Register metadata for a custom field.
Enables field_info(), field_si_factor(), in_si(),
in_units(), and unit_label() for user-defined fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name (e.g. |
required |
quantity_type
|
QuantityType | str
|
Physical quantity type — must be a key in |
required |
long_name
|
str
|
Human-readable label for plot titles. |
''
|
si_unit
|
str | None
|
SI unit label. If |
None
|
latex
|
str
|
LaTeX symbol for plot labels. |
''
|
unit_dimension
|
tuple[int, ...] | None
|
openPMD |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If quantity_type is not recognized, unit_dimension is not a length-7 sequence of ints, or name is already registered. |
Source code in src/pypic/fields.py
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 | |
unregister_field(name)
¶
Remove custom field metadata.
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not registered. |
Source code in src/pypic/fields.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
field_info(name, *, axis_names=None)
¶
Look up metadata for a field or derived quantity.
Resolution order:
- Direct lookup in the registry
- Compute alias resolution (
"B_mag"->"|B|") - Field alias fallback (
"Bx"->"B_1") - Per-species regex patterns (
"n_s5","omega_p_s3")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field or derived quantity name. |
required |
axis_names
|
tuple[str, str, str] | None
|
Coordinate axis labels. When provided, component labels are localized (e.g. "component 1" -> "x-component" for Cartesian). |
None
|
Returns:
| Type | Description |
|---|---|
FieldInfo
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If name cannot be resolved. |
Examples:
>>> field_info("|B|").si_unit
'T'
>>> field_info("beta").latex
'$\\beta$'
>>> field_info("B_1", axis_names=("x", "y", "z")).long_name
'Magnetic field x-component'
Source code in src/pypic/fields.py
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 | |
vector_component(name)
¶
Split a registered vector component name into (base, component).
The Tier-3 form <base>_<component> with a registered metadata
entry marks a vector component: B_1, KEF_s0_2, E_prime_3.
Scalars, tensor components (P_s0_11) and unregistered names
return None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field or derived quantity name. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, int] | None
|
Vector base name and 1-based component, or |
Examples:
>>> vector_component("B_1")
('B', 1)
>>> vector_component("KEF_s0_2")
('KEF_s0', 2)
>>> vector_component("P_s0_11") is None
True
>>> vector_component("rho_c") is None
True
Source code in src/pypic/fields.py
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 633 | |
unit_label(name, *, to_si=False)
¶
Return a unit label string for a field, suitable for plot axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field or derived quantity name. |
required |
to_si
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
str
|
|
Examples:
>>> unit_label("B_1", to_si=True)
'T'
>>> unit_label("B_1")
'normalized'
>>> unit_label("beta", to_si=True)
''
>>> unit_label("beta")
''
Source code in src/pypic/fields.py
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 | |
quantity_units(quantity_type)
¶
Return the SI unit label for a physical quantity type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantity_type
|
str
|
Quantity type string (e.g. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SI unit label. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If quantity_type is unknown. |
Examples:
>>> quantity_units("b_field")
'T'
>>> quantity_units("dimensionless")
''
Source code in src/pypic/fields.py
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 | |