bluemira.equilibria.analysis ============================ .. py:module:: bluemira.equilibria.analysis .. autoapi-nested-parse:: Equilibria and Equilibria optimisation analysis tools Classes ------- .. autoapisummary:: bluemira.equilibria.analysis.EqAnalysis bluemira.equilibria.analysis.MultiEqProfiles bluemira.equilibria.analysis.MultiEqAnalysis Functions --------- .. autoapisummary:: bluemira.equilibria.analysis.select_eq bluemira.equilibria.analysis.select_multi_eqs bluemira.equilibria.analysis.get_eqs bluemira.equilibria.analysis.get_leg_flux_info bluemira.equilibria.analysis.get_target_flux Module Contents --------------- .. py:function:: select_eq(file_path: str, fixed_or_free: bluemira.equilibria.diagnostics.FixedOrFree = FixedOrFree.FREE, dummy_coils: bluemira.equilibria.coils.CoilSet | None = None, from_cocos: int = BLUEMIRA_DEFAULT_COCOS, qpsi_positive: bool = False, control: bluemira.base.constants.CoilType | list[str] | None = None) -> bluemira.equilibria.equilibrium.FixedPlasmaEquilibrium | bluemira.equilibria.equilibrium.Equilibrium Return an Equilibrium or FixedPlasmaEquilibrium object given a particular file name. Cocos indices and qpsi sign are set to Bluemira Defaults unless specified. :param file_path: file path to chosen equilibria :param fixed_or_free: whether or not it is for a fixed plasma boundary :param dummy_coils: coilset if none in equilibria file (a default coilset is used, and a warning message prints if none is provided) :param from_cocos: The COCOS index of the EQDSK file. Used when the determined COCOS is ambiguous. Will raise if given and not one of the determined COCOS indices. :param qpsi_positive: Whether or not qpsi is positive, required for identification when qpsi is not present in the file. :param control: Set which coils are control coils. Can be a coil type, a list of coil names, or None for all coils. N.B. many equilibrium objects already have coilsets with control coils set, and this input may not be necessary. :returns: Equilibrium or FixedPlasmaEquilibrium .. py:function:: select_multi_eqs(equilibrium_input: str | bluemira.equilibria.equilibrium.Equilibrium | collections.abc.Sequence[str | bluemira.equilibria.equilibrium.Equilibrium], fixed_or_free: bluemira.equilibria.diagnostics.FixedOrFree = FixedOrFree.FREE, equilibrium_names: str | collections.abc.Sequence[str] | None = None, dummy_coils: collections.abc.Sequence | None = None, from_cocos: int | collections.abc.Iterable[int] = BLUEMIRA_DEFAULT_COCOS, *, qpsi_positive: bool | collections.abc.Iterable[bool] = False, control_coils: bluemira.base.constants.CoilType | list[str] | None = None) Put information needed to load eq into a dictionary. Cocos indices and qpsi sign are set to Bluemira Defaults unless specified. :param equilibrium_input: List of chosen equilibria or file paths to chosen equilibria :param fixed_or_free: whether or not it is for a fixed plasma boundary :param equilibrium_names: Names of chosen equilibrium :param dummy_coils: coilset if none in equilibria file (a default coilset is used, and a warning message prints if none is provided) :param from_cocos: The COCOS index of the EQDSK file. Used when the determined COCOS is ambiguous. Will raise if given and not one of the determined COCOS indices. :param qpsi_positive: Whether or not qpsi is positive, required for identification when qpsi is not present in the file. :param control_coils: Set which coils are control coils. Can be a coil type, a list of coil names, or None for all coils. N.B. many equilibrium objects already have coilsets with control coils set, and this input may not be necessary. :returns: Dictionary of load info :rtype: equilibria_dict :raises ValueError: If list of input values is not the same length as the input equilibria .. py:function:: get_eqs(equilibria_dict) Use equilibrium load dictionaries to load equilibrium objects and add the objects to the dictionary. :param equilibria_dict: Dictionary of load information for multiple equilibria. :returns: Dictionary updated with equilibrium and profile objects. :rtype: equilibria_dict .. py:function:: get_leg_flux_info(eq_list, n_layers=10, dx_off=0.1, plasma_facing_boundary_list=None, legs_to_plot=DivLegsToPlot.ALL) -> tuple[list[dict[str, float | numpy.ndarray]], list[dict[str, float | numpy.ndarray]]] Get the divertor leg length and grazing angle (used in divertor comparison plotting). :param eq_list: List of Equilibrium objects to compare :param n_layers: Number of flux surfaces to extract for each leg :param dx_off: Total span in radial space of the flux surfaces to extract :param plasma_facing_boundary_list: List of associated plasma facing boundary coordinates :param legs_to_plot: Which legs to plot i.e, upper, lower or all. :returns: * *lengths* -- Dictionary of connection length values for each named leg. * *angles* -- Dictionary of grazing values for each named leg. :raises BluemiraError: If leg pair is chosen that does not exist in chosen eq. .. py:function:: get_target_flux(eq, target, target_coords, n_layers, vertical=False) -> list[bluemira.geometry.coordinates.Coordinates] Get a selection flux surfaces that cross the divertor target. eq: chosen Equilibrium target: Location of divertor target, lower_outer, lower_inner, upper_outer or upper_inner target_coords: Coordinates of divertor target n_layers: Number of flux surfaces to extract for each leg vertical: Set to True if using a vertical target. This boolean determines whether to get flux surfaces across the target x-range (horizontal) or z-range (vertical). :returns: List of flux surface coordinates. :rtype: fs_list :raises BluemiraError: If the target is set to vertical or horizontal incorrectly. .. py:class:: EqAnalysis(input_eq: bluemira.equilibria.equilibrium.Equilibrium | bluemira.equilibria.equilibrium.FixedPlasmaEquilibrium | None = None, reference_eq: bluemira.equilibria.equilibrium.Equilibrium | bluemira.equilibria.equilibrium.FixedPlasmaEquilibrium | None = None, diag_ops: bluemira.equilibria.diagnostics.EqDiagnosticOptions | None = None) Equilibria analysis toolbox for selected Equilibrium. Can compare selected equilibrium to a reference equilibrium. The input and reference equilibria be different types (i.e, fixed or free), and have different grid sizes and grid resolutions. :param diag_ops: Diagnostic plotting options :param input_eq: input equilibrium :param reference_eq: reference equilibrium .. py:attribute:: input :value: None .. py:attribute:: reference :value: None .. py:attribute:: diag_ops .. py:method:: set_input(input_eq: bluemira.equilibria.equilibrium.Equilibrium | bluemira.equilibria.equilibrium.FixedPlasmaEquilibrium) Sets input equilibrium. .. py:method:: set_reference(reference_eq: bluemira.equilibria.equilibrium.Equilibrium | bluemira.equilibria.equilibrium.FixedPlasmaEquilibrium) Sets reference equilibrium. .. py:method:: _get_input() .. py:method:: _get_reference() .. py:method:: plot(ax=None) Plot input equilibria. :returns: Matplotlib Axes object :rtype: ax .. py:method:: plot_field(ax=None) Plot poloidal and toroidal field for input equilibria. :returns: Matplotlib Axes object :rtype: ax :raises BluemiraError: if wrong number of axes is input .. py:method:: plot_profiles(ax=None) Plot profiles for input equilibria. :returns: Matplotlib Axes object :rtype: ax .. py:method:: plot_eq_core_analysis(ax=None) -> tuple[bluemira.equilibria.flux_surfaces.CoreResults, matplotlib.axes.Axes] Plot characteristics of the plasma core for input equilibria and return results. Currently only works for free boundary equilibria. :returns: * *core_results* -- Dataclass for core results. * *ax* -- Matplotlib Axes object :raises BluemiraError: If the equilibrium is fixed boundary. .. py:method:: plot_eq_core_mag_axis(ax=None) Plot a 1-D section through the magnetic axis of the input equilibria. Currently only works for free boundary equilibria. :returns: Matplotlib Axes object :rtype: ax :raises BluemiraError: If the equilibrium is fixed boundary. .. py:method:: physics_info_table() -> bluemira.equilibria.physics.EqSummary Create a table with the physics information from the input equilibria. Not for use with FixedPlasmaEquilibrium. :returns: Dataclass of physics information. :rtype: eq_summary :raises BluemiraError: If the equilibrium is fixed boundary. .. py:method:: control_coil_table(control: list | None = None) Create a table with the control coil information from the input equilibria. Not for use with FixedPlasmaEquilibrium. :param control: Set the control coils with a coil type or list of coil names. :returns: Table with summary of control coil information. :rtype: table :raises BluemiraError: If the equilibrium is fixed boundary. .. py:method:: plot_equilibria_with_profiles(ax=None, show=True) Plot input equilibria alongside profiles. :param ax: List of Matplotlib Axes objects set by user :param show: Whether or not to display the plot :returns: The Matplotlib Axes objects for each subplot. :rtype: ax1, ax2 :raises BluemiraError: if the wrong number of axes is provided .. py:method:: plot_compare_separatrix(title=None, ax=None, show=True) Plot separatricies of input equilibria and reference equilibria. N.B. Plots LCFS if a fixed boundary is used. :param title: Title to be added at top of figure :param ax: Matplotlib Axes objects set by user :param show: Whether or not to display the plot :returns: Matplotlib Axes object :rtype: ax .. py:method:: plot_compare_psi(diag_ops: bluemira.equilibria.diagnostics.EqDiagnosticOptions | None = None, ax=None) Plot Psi comparison. :param diag_ops: Diagnostic plotting options :param ax: List of Matplotlib Axes objects set by user :returns: plotting class :raises BluemiraError: if no reference equilibrium is provided .. py:method:: plot_compare_profiles(reference_profile_sign=None, ax=None, diff=True) Plot equilibria reference and input profiles. The diff option can be used to plot the difference between the reference and input profiles on the same axis. :param reference_profile_sign: To be used with the diff option if the profile convention of the compared equilibria is different. :param ax: Matplotlib axes object. :param diff: If two equilibria are being compared then we have the option of also plotting the difference between them. :returns: Matplotlib Axes object :rtype: ax :raises BluemiraError: if no reference equilibrium or equilibrium file path is provided :raises ValueError: if the profile sign array provided is an incorrect length .. py:method:: plot_target_flux(target: str, target_coords: bluemira.geometry.coordinates.Coordinates, use_reference=True, n_layers=10, vertical=False, ax=None, show=True) Plot the divertor leg flux. Will find flux surfaces at evenly spaced points in x- or z- direction for a set of target coordinates. :param target: Location of divertor target, i.e., lower_outer, lower_inner, upper_outer or upper_inner :param target_coords: Coordinates of divertor target :param use_reference: Plot reference as well as input :param n_layers: Number of flux surfaces to extract for each leg :param vertical: Set to True if using a vertical target. This boolean determines whether to get flux surfaces across the target x-range (horizontal) or z-range (vertical). :param ax: Matplotlib Axes objects set by user :param show: Whether or not to display the plot :returns: * *ax* -- Matplotlib Axes object * *target_flux* -- Coordinates of flux surfaces crossing target for input equilibria * *ref_target_flux* -- Coordinates of flux surfaces crossing target for reference equilibria .. py:class:: MultiEqProfiles Profile dataclass for plotting. .. py:attribute:: pprime :type: list[numpy.typing.NDArray[numpy.float64]] | None :value: None .. py:attribute:: ffprime :type: list[numpy.typing.NDArray[numpy.float64]] | None :value: None .. py:attribute:: fRBpol :type: list[numpy.typing.NDArray[numpy.float64]] | None :value: None .. py:attribute:: pressure :type: list[numpy.typing.NDArray[numpy.float64]] | None :value: None .. py:attribute:: shape :type: list[numpy.typing.NDArray[numpy.float64]] | None :value: None .. py:method:: add_profile(profile, n_points) Add profile to dataclass. .. py:class:: MultiEqAnalysis(equilibria_dict: dict, n_points: int = 50) Equilibria analysis toolbox for multiple Equilibrium. :param equilibria_dict: Dictionary of equilibria load information. Can be created using select_multi_eqs function. .. py:attribute:: equilibria_dict .. py:method:: set_equilibria(equilibria_dict: dict, n_points: int = 50) Use dictionary of equilibria information to get values for plotting. :param equilibria_dict: Dictionary of equilibria load information. Can be created using select_multi_eqs function. :param n_points: Number of profile points to plot. .. py:method:: make_eq_dataclass_list(method, *args) Create a list of dataclasses from a function with equilibrium as the first argument. :param method: Dataclass creation method. :param args: Arguments needed for chosen method. :returns: list of dataclass objects :rtype: results .. py:method:: fill_plotting_profiles(n_points) Calculate profile values for plotting. This is done when a MultiEqAnalysis class initiated but can be reset with different n_points using this function. :param n_points: number of normalised psi points .. py:method:: physics_info_table() Create a table with the the physics information from all listed Equilibria. Not for use with FixedPlasmaEquilibrium. :returns: Table with equilibria physics information. :rtype: table .. py:method:: plot_core_physics(title='Physics Parameters', n_points: int = 50, ax=None, show=True) Plot physics parameters for the core plasma of each equilibria (i.e., plot across the normalised 1-D flux coordinate). title: Title to be added at top of figure n_points: number of normalised psi points ax: Matplotlib Axes objects set by user show: Whether or not to display the plot :returns: * *core_results* -- List[dataclass] of equilibria core physics results. * *ax* -- Matplotlib Axes object .. py:method:: coilset_info_table(value_type=CSData.CURRENT) Create a table with the the control coil information from all listed Equilibria. :param value_type: Choose the type of coilset data to be printed, default is current values. :returns: table with equilibria control coil information. :rtype: table .. py:method:: plot_compare_profiles(ax=None, header=None, n_points=None) Plot the profiles of all the listed equilibria. :param ax: List of Matplotlib Axes objects set by user :param header: Text to be added at the top of the figure :param n_points: number of normalised psi points :returns: The Matplotlib Axes objects for each subplot. :rtype: ax1, ax2, ax3, ax4, ax5, ax6 :raises BluemiraError: if the axes provided are the incorrect shape .. py:method:: plot_compare_flux_surfaces(flux_surface=FluxSurfaceType.LCFS, plot_fixed=True, psi_norm=0.98, title=None, ax=None, show=True) Plot a flux surface of choice for each equilibrium on the same axes. User can select either the LCFS, separatrix or a flux surface with a given psi_norm. Always plots a LCFS for a fixed boundary equilibrium, unless plot_fixed is set to false, in which case no flux surfaces are plotted for any fixed boundary equilibria. :param flux_surface: Type of flux surface to be plotted :param plot_fixed: Weather or not to plot the LCFS for any fixed boundary equilibria. :param psi_norm: The normalised psi value to use, if the user selects the psi norm comparison option. :param title: Title to be added at top of figure :param ax: Matplotlib Axes objects set by user :param show: Whether or not to display the plot :returns: Matplotlib Axes object :rtype: ax .. py:method:: plot_divertor_length_angle(n_layers=10, dx_off=0.1, plasma_facing_boundary_list=None, legs_to_plot=DivLegsToPlot.ALL, ax=None, show=True, radian=True) Plot the divertor leg length and grazing angle for the equilibria divertor legs. :param n_layers: Number of flux surfaces to extract for each leg :param dx_off: Total span in radial space of the flux surfaces to extract :param plasma_facing_boundary_list: List of associated plasma facing boundary coordinates :param legs_to_plot: Which legs to plot i.e, upper, lower or all. :param ax: Matplotlib Axes objects set by user :param show: Whether or not to display the plot :param radian: True for plot angles in units of radians False for plot angles in units of degrees :returns: Matplotlib Axes object :rtype: ax