Fields
FieldMesh
FieldMesh(h5=None, data=None)
Class for openPMD External Field Mesh data.
Initialized on on openPMD beamphysics particle group:
- h5: open h5 handle, or str that is a file
- data: raw data
The required data is stored in ._data, and consists of dicts:
'attrs''components'
Component data is always 3D.
Initialization from openPMD-beamphysics HDF5 file:
FieldMesh('file.h5')
Initialization from a data dict:
FieldMesh(data=data)
Derived properties:
.r,.theta,.z.Br,.Btheta,.Bz.Er,.Etheta,.Ez-
.E,.B -
.phase .scale-
.factor -
.harmonic -
.frequency -
.shape .geometry.mins,.maxs,.deltas.meshgrid.dr,.dtheta,.dz
Booleans:
.is_pure_electric.is_pure_magnetic.is_static
Units and labels
.units.axis_labels
Plotting:
.plot.plot_onaxis
Writers
.write.write_astra_1d.write_astra_3d.write_gpt.write_impact_emfield_cartesian.to_cylindrical.to_astra_1d.to_impact_solrf.to_impact_impact_emfield_cartesian.write_gpt.write_superfish
Constructors (class methods):
.from_ansys_ascii_3d.from_astra_3d.from_superfish.from_onaxis.expand_onaxis
Methods:
-
__eq__–Checks that all attributes and component internal data are the same
-
__getitem__–Returns component data from a key
-
axis_index–Returns axis index for a named axis label key.
-
axis_points–Returns 3D points for the specified axis to be used by the interpolator.
-
axis_values–Returns the values of the specified field along the given axis, allowing for partial replacement of points.
-
component_is_zero–Returns True if all elements in a component are zero.
-
coord_vec–Gets the coordinate vector from a named axis key.
-
copy–Returns a deep copy
-
from_ansys_ascii_3d–Class method to return a FieldMesh from ANSYS ASCII files.
-
from_astra_3d–Class method to parse multiple 3D astra fieldmap files,
-
from_impact_emfield_cartesian–Class method to read an Impact-T style 1Tv3.T7 file corresponding to
-
from_onaxis–Parameters
-
from_superfish–Class method to parse a superfish T7 style file.
-
interpolate–Interpolates the field data for the given key at specified points.
-
interpolator–Returns an interpolator for a given field key.
-
plot–Plots the specified component of the data, with various customization options for appearance and behavior.
-
scaled_component–Retruns a component scaled by the complex factor
-
to_cylindrical–Returns a new FieldMesh in cylindrical geometry.
-
units–Returns the units of any key
-
write–Writes openPMD-beamphysics format to an open h5 handle, or new file if h5 is a str.
-
write_gpt–Writes a GPT field file.
-
write_impact_emfield_cartesian–Writes Impact-T style 1Tv3.T7 file corresponding to
-
write_superfish–Write a Superfish T7 file.
Attributes:
-
axis_labels– -
coord_vecs–Uses gridSpacing, gridSize, and gridOriginOffset to return coordinate vectors.
-
factor–factor to multiply fields by, possibly complex.
-
is_pure_electric–Returns True if there are no non-zero mageneticField components
-
is_pure_magnetic–Returns True if there are no non-zero electricField components
-
meshgrid–Usses coordinate vectors to produce a standard numpy meshgrids.
-
phase–Returns the complex argument
phi = -2*pi*RFphase
Source code in beamphysics/fields/fieldmesh.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
axis_labels
property
axis_labels
coord_vecs
property
coord_vecs
Uses gridSpacing, gridSize, and gridOriginOffset to return coordinate vectors.
factor
property
factor
factor to multiply fields by, possibly complex.
factor = scale * exp(i*phase)
is_pure_electric
property
is_pure_electric
Returns True if there are no non-zero mageneticField components
is_pure_magnetic
property
is_pure_magnetic
Returns True if there are no non-zero electricField components
meshgrid
property
meshgrid
Usses coordinate vectors to produce a standard numpy meshgrids.
phase
property
writable
phase
Returns the complex argument phi = -2*pi*RFphase
to multiply the oscillating field by.
Can be set.
__eq__
__eq__(other)
Checks that all attributes and component internal data are the same
Source code in beamphysics/fields/fieldmesh.py
893 894 895 896 897 898 899 900 | |
__getitem__
__getitem__(key)
Returns component data from a key
If the key starts with:
re_im_abs_
the appropriate numpy operator is applied.
Source code in beamphysics/fields/fieldmesh.py
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
axis_index
axis_index(key)
Returns axis index for a named axis label key.
Examples:
.axis_labels == ('x', 'y', 'z').axis_index('z')returns2
Source code in beamphysics/fields/fieldmesh.py
284 285 286 287 288 289 290 291 292 293 294 295 296 | |
axis_points
axis_points(axis_label)
Returns 3D points for the specified axis to be used by the interpolator.
Parameters:
-
axis_label(str) –The label of the coordinate axis. Example: 'r' for cylindrical geometries.
Returns:
-
numpy.ndarray of shape (n, 3)–An array of 3D points, where the specified axis is populated, and other axes are zero.
Source code in beamphysics/fields/fieldmesh.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
axis_values
axis_values(axis_label, field_key, **kwargs)
Returns the values of the specified field along the given axis, allowing for partial replacement of points.
Parameters:
-
axis_label(str) –The label of the coordinate axis.
-
field_key(str) –The key representing the field data to interpolate.
-
**kwargs(dict, default:{}) –Key-value pairs to replace parts of the internal points array. The keys should be axis labels, and the values should be the corresponding values to set. Example:
x=0, y=1will set points along 'x' and 'y' axes.
Returns:
-
tuple(ndarray, ndarray)–A tuple containing: - An array of coordinate values along the specified axis. - An array of interpolated field values at the corresponding points.
Source code in beamphysics/fields/fieldmesh.py
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 | |
component_is_zero
component_is_zero(key)
Returns True if all elements in a component are zero.
Source code in beamphysics/fields/fieldmesh.py
415 416 417 418 419 420 | |
coord_vec
coord_vec(key)
Gets the coordinate vector from a named axis key.
Source code in beamphysics/fields/fieldmesh.py
359 360 361 362 363 364 | |
copy
copy()
Returns a deep copy
Source code in beamphysics/fields/fieldmesh.py
1054 1055 1056 | |
from_ansys_ascii_3d
classmethod
from_ansys_ascii_3d(*, efile=None, hfile=None, frequency=None)
Class method to return a FieldMesh from ANSYS ASCII files.
The format of each file is: header1 (ignored) header2 (ignored) x y z re_fx im_fx re_fy im_fy re_fz im_fz ... in C order, with oscillations as exp(iomegat)
Parameters:
-
efile–Filename with complex electric field data in V/m
-
hfile–Filename with complex magnetic H field data in A/m
-
frequency–Frequency in Hz
Returns:
Source code in beamphysics/fields/fieldmesh.py
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 | |
from_astra_3d
classmethod
from_astra_3d(common_filename, frequency=0)
Class method to parse multiple 3D astra fieldmap files, based on the common filename.
Source code in beamphysics/fields/fieldmesh.py
739 740 741 742 743 744 745 746 747 | |
from_impact_emfield_cartesian
classmethod
from_impact_emfield_cartesian(filename, frequency=0, eleAnchorPt='beginning')
Class method to read an Impact-T style 1Tv3.T7 file corresponding to
the 111: EMfldCart element.
Parameters:
-
filename(str) –Path to the file where the field data will be written.
-
frequency(float, default:0) –Fundamental frequency in Hz This simply adds 'fundamentalFrequency' to attrs default=0
Returns:
-
FieldMesh–
Source code in beamphysics/fields/fieldmesh.py
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 | |
from_onaxis
classmethod
from_onaxis(*, z=None, Bz=None, Ez=None, frequency=0, harmonic=None, eleAnchorPt='beginning')
Parameters:
-
z–z-coordinates. Must be regularly spaced.
-
Bz–magnetic field at r=0 in T Default: None
-
Ez–Electric field at r=0 in V/m Default: None
-
frequency–fundamental frequency in Hz. Default: 0
-
harmonic–Harmonic of the fundamental the field actually oscillates at. Default: 1 if frequency !=0, otherwise 0.
-
eleAnchorPt–Element anchor point. Should be one of 'beginning', 'center', 'end' Default: 'beginning'
Returns:
-
field(FieldMesh) –Instantiated fieldmesh
Source code in beamphysics/fields/fieldmesh.py
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 | |
from_superfish
classmethod
from_superfish(filename, type=None, geometry='cylindrical')
Class method to parse a superfish T7 style file.
Source code in beamphysics/fields/fieldmesh.py
783 784 785 786 787 788 789 790 | |
interpolate
interpolate(key, points)
Interpolates the field data for the given key at specified points.
Parameters:
-
key(str) –The key representing the field data to interpolate.
-
points(numpy.ndarray of shape (3,) or (n, 3)) –An array of n 3d points at which to interpolate the field data. The points should be ordered according to
.axis_labels.
Returns:
-
ndarray–The interpolated field values at the specified points.
Source code in beamphysics/fields/fieldmesh.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
interpolator
interpolator(key)
Returns an interpolator for a given field key.
Parameters:
-
key(str) –The key representing the field data to interpolate. Examples include: - 'Ez' for scaled/phased data - 'magneticField/y' for raw component data
Returns:
-
RegularGridInterpolator–An interpolator object that can be used to interpolate points. The points to interpolate should be ordered according to
.axis_labels.
Source code in beamphysics/fields/fieldmesh.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
plot
plot(component=None, *, cmap=None, nice=True, stream=False, mirror=None, density=2, linewidth=1, arrowsize=1, axes=None, return_figure=False, **kwargs)
Plots the specified component of the data, with various customization options for appearance and behavior.
Parameters:
-
component(str, default:None) –The component of the data to be plotted (e.g., 'Ex', 'B'). If None, defaults to 'B' for pure magetic fields, otherwise 'E'
-
cmap(str or Colormap, default:None) –The colormap to use for the plot. Defaults to a default colormap if not provided.
-
stream(bool, default:False) –If True, adds streamlines to the plot (useful for vector field visualization). Defaults to False.
-
mirror(str, default:None) –'r' symmetrizes the data in the r plane. Only for cylindrical plots with r = 0 on the edge of the data Defaults to None.
-
density(float, default:2) –The density of streamlines when
stream=True. Higher values result in more streamlines. Defaults to 1. -
linewidth(float, default:1) –The line width for streamlines. Defaults to 1.
-
arrowsize(float, default:1) –The size of arrows for streamlines when
stream=True. Defaults to 1. -
axes(Axes, default:None) –A matplotlib Axes object on which to draw the plot. If None, a new figure and axes will be created.
-
return_figure(bool, default:False) –If True, returns the matplotlib Figure object. Defaults to False.
-
**kwargs(dict, default:{}) –Additional keyword arguments passed to the underlying plotting functions.
Returns:
-
Figure or None–Returns the matplotlib Figure object if
return_figure=True. Otherwise, the function does not return a value.
Notes
- If
axesis provided, the plot will be drawn on the given axes. - Symmetrizing the data is useful for visualizing symmetric datasets, but it modifies the data displayed.
- The
streamparameter is intended for vector field visualization and works best with continuous data.
Examples:
Plot a single component with a specific colormap:
>>> obj.plot(component='x', cmap='viridis')
Plot with streamlines and return the figure:
>>> fig = obj.plot(stream=True, return_figure=True)
Symmetrize the data before plotting:
>>> obj.plot(symmetrize=True)
Customize the appearance of streamlines:
>>> obj.plot(stream=True, density=2, linewidth=0.5, arrowsize=2)
Source code in beamphysics/fields/fieldmesh.py
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 | |
scaled_component
scaled_component(key)
Retruns a component scaled by the complex factor factor = scaleexp(iphase)
Source code in beamphysics/fields/fieldmesh.py
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
to_cylindrical
to_cylindrical()
Returns a new FieldMesh in cylindrical geometry.
If the current geometry is rectangular, this will use the y=0 slice.
Source code in beamphysics/fields/fieldmesh.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | |
units
units(key)
Returns the units of any key
Source code in beamphysics/fields/fieldmesh.py
582 583 584 585 586 587 588 589 590 591 592 | |
write
write(h5, name=None)
Writes openPMD-beamphysics format to an open h5 handle, or new file if h5 is a str.
Source code in beamphysics/fields/fieldmesh.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
write_gpt
write_gpt(filePath, asci2gdf_bin=None, verbose=True)
Writes a GPT field file.
Source code in beamphysics/fields/fieldmesh.py
650 651 652 653 654 655 656 657 | |
write_impact_emfield_cartesian
write_impact_emfield_cartesian(filename)
Writes Impact-T style 1Tv3.T7 file corresponding to
the 111: EMfldCart element.
The file will contain grid information for X, Y, and Z dimensions followed by field values. The field values are stored as complex numbers in the format (real, imaginary).
Parameters:
-
filename(str) –Path to the file where the field data will be written.
Source code in beamphysics/fields/fieldmesh.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
write_superfish
write_superfish(filePath, verbose=False)
Write a Superfish T7 file.
For static fields, a Poisson T7 file is written.
For dynamic (harmonic /= 0) fields, a Fish T7 file is written
If .is_static, a Poisson file is written. Otherwise a Fish file is written.
Parameters:
-
filePath(str or Path) –Output file path.
Source code in beamphysics/fields/fieldmesh.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |