tsadar.core.modules.ts_params#
Functions
|
Returns activation and inverse activation functions for a parameter based on its configuration. |
|
Generates a filter specification dictionary based on the provided configuration and Thomson scattering parameters. This function traverses the configuration parameters and updates a filter specification tree to indicate which parameters are active and should be included in further processing. :param cfg_params: A dictionary containing configuration parameters for each species. Each species maps to a dictionary of parameter keys and their associated settings, including an "active" flag. :type cfg_params: Dict :param ts_params: An object representing the Thomson scattering parameters, structured as a tree. :type ts_params: ThomsonParams. |
Classes
|
ElectronParams encapsulates the parameters and distribution functions for electron populations in inverse Thomson scattering fits. |
|
GeneralParams is a module for managing and transforming normalized and unnormalized parameters used in Thomson scattering analysis, that dont neatly fit with the ion or electron params. |
|
IonParams is a module for handling ion parameter normalization, activation, and denormalization. |
|
ThomsonParams is an Equinox module that encapsulates the configuration and parameter management for a Thomson scattering fits. |
- class tsadar.core.modules.ts_params.ElectronParams(cfg, batch_size, batch=True, activate=False)Source#
ElectronParams encapsulates the parameters and distribution functions for electron populations in inverse Thomson scattering fits. .. attribute:: normed_Te
Normalized electron temperature(s).
- type:
Array
- normed_ne#
Normalized electron density(ies).
- Type:
Array
- Te_scale#
Scaling factor for electron temperature normalization.
- Type:
float
- Te_shift#
Shift for electron temperature normalization.
- Type:
float
- ne_scale#
Scaling factor for electron density normalization.
- Type:
float
- ne_shift#
Shift for electron density normalization.
- Type:
float
- distribution_functions#
Electron distribution function(s), either 1D or 2D, possibly batched.
- Type:
Union[List[DistributionFunction1V], List[DistributionFunction2V], DistributionFunction1V, DistributionFunction2V]
- batch#
Whether parameters are batched.
- Type:
bool
- act_funs#
Activation functions for parameters.
- Type:
Dict[str, Callable]
- inv_act_funs#
Inverse activation functions for parameters.
- Type:
Dict[str, Callable]
- Parameters:
cfg (dict) – Configuration dictionary specifying bounds, values, and distribution settings for parameters.
batch_size (int) – Number of batches (if batch=True).
batch (bool, optional) – Whether to use batched parameters. Defaults to True.
activate (bool, optional) – Whether to apply activation functions. Defaults to False.
- init_dists(dist_cfg, batch_size, batch, activate)Source#
Initializes the electron distribution function(s) based on configuration.
- get_unnormed_params()Source#
Returns a dictionary of physical (unnormalized) parameters and distribution function parameters.
- __call__()Source#
Returns a dictionary of physical parameters and distribution function values (and velocities).
- Te_scale: float#
- Te_shift: float#
- ne_scale: float#
- ne_shift: float#
- batch: bool#
- dist_rot: float#
- act_funs: Dict[str, Callable]#
- inv_act_funs: Dict[str, Callable]#
- normed_Te: Array#
- normed_ne: Array#
- distribution_functions: List[DistributionFunction1V] | List[DistributionFunction2V] | DistributionFunction1V | DistributionFunction2V#
- init_dists(dist_cfg, batch_size, batch, activate)Source#
Initializes distribution functions based on the provided configuration. :param dist_cfg: Configuration dictionary specifying the distribution type and dimension.
“dim” (int): The dimension of the distribution (1 or 2).
“type” (str): The type of distribution (e.g., “dlm”, “mx”, “arbitrary”, “sph”).
- Parameters:
batch_size (int) – Number of distributions to initialize if batch mode is enabled.
batch (bool) – Whether to initialize a batch of distributions.
activate (callable) – Activation function or parameter passed to certain distribution constructors.
- Returns:
distribution_functions –
- For 1D distributions:
If batch is True: list of distribution function instances or callables.
If batch is False: a single distribution function instance or callable.
- For 2D distributions:
Only single distribution function instance (batch mode not supported).
- Raises:
NotImplementedError – If the specified distribution type or dimension is not supported, or if batch mode is requested for 2D distributions.
- get_unnormed_params()Source#
Retrieve the unnormalized parameters for the current object. This method collects and returns the unnormalized (physical) parameters for the object, including electron temperature (“Te”), electron density (“ne”), and any additional parameters from the associated distribution functions. :returns: dict –
- A dictionary containing:
“Te”: Unnormalized electron temperature, computed by applying the activation function to the normalized value, then scaling and shifting.
“ne”: Unnormalized electron density, computed similarly to “Te”.
Additional keys and values from the unnormalized parameters of the distribution functions, either as arrays (if multiple distribution functions are present) or as single values.
Notes
If self.distribution_functions is a list, the method aggregates parameters from each distribution function and stacks them into arrays.
If self.distribution_functions is a single object, its unnormalized parameters are included directly.
- class tsadar.core.modules.ts_params.IonParams(cfg, batch_size, batch=True, activate=False)Source#
IonParams is a module for handling ion parameter normalization, activation, and denormalization. .. attribute:: normed_Ti
Normalized ion temperature(s).
- type:
Array
- normed_Z#
Normalized ion charge state(s).
- Type:
Array
- fract#
Normalized ion fraction(s).
- Type:
Array
- Ti_scale#
Scaling factor for ion temperature normalization.
- Type:
float
- Ti_shift#
Shift for ion temperature normalization.
- Type:
float
- Z_scale#
Scaling factor for ion charge normalization.
- Type:
float
- Z_shift#
Shift for ion charge normalization.
- Type:
float
- A#
Ion mass number (or array if batch).
- Type:
int
- act_funs#
Dictionary of activation functions for each parameter.
- Type:
Dict[str, Callable]
- inv_act_funs#
Dictionary of inverse activation functions for each parameter.
- Type:
Dict[str, Callable]
- Parameters:
cfg (dict) – Configuration dictionary containing parameter bounds, values, and activation settings.
batch_size (int) – Number of samples in the batch.
batch (bool, optional) – Whether to use batch mode (default: True).
activate (bool, optional) – Whether to apply activation functions (default: False).
- __call__()Source#
- Returns a dictionary with the denormalized and activated parameters:
“A”: Ion mass number(s).
“fract”: Activated and denormalized ion fraction(s).
“Ti”: Activated and denormalized ion temperature(s).
“Z”: Activated and denormalized ion charge state(s).
- Ti_scale: float#
- Ti_shift: float#
- Z_scale: float#
- Z_shift: float#
- Va_scale: float#
- Va_shift: float#
- act_funs: Dict[str, Callable]#
- inv_act_funs: Dict[str, Callable]#
- normed_Ti: Array#
- normed_Z: Array#
- normed_Va: Array#
- A: int#
- fract: Array#
- __call__()Source#
Returns a dictionary of unnormalized (physical) parameter values. The parameters are denormalized by applying the activation functions and scaling factors defined in the class. The returned dictionary contains:
“A”: The ion mass number.
“fract”: The ion species fraction.
“Ti”: Ion temperature.
“Z”: Ionization state.
- Returns:
dict – Dictionary with keys “A”, “fract”, “Ti”, and “Z” containing the processed values.
- tsadar.core.modules.ts_params.get_act_and_inv_act(param_cfg: Dict, activate: bool)Source#
Returns activation and inverse activation functions for a parameter based on its configuration. If the parameter is active (being fit) and activation is requested, returns a sigmoid activation and its inverse (logit). Otherwise, returns the identity function for both activation and its inverse. :param param_cfg: Configuration dictionary for the parameter, must contain an “active” key deteriming if the parameter is being fit. :type param_cfg: Dict :param activate: Whether to use the activation function. :type activate: bool
- Returns:
Tuple[Callable, Callable] – A tuple containing the activation function and its inverse.
Note
The inverse activation function uses a stabilized logit transformation, which may be problematic near 0 and 1.
- class tsadar.core.modules.ts_params.GeneralParams(cfg, batch_size: int, batch=True, activate=False)Source#
GeneralParams is a module for managing and transforming normalized and unnormalized parameters used in Thomson scattering analysis, that dont neatly fit with the ion or electron params. It handles parameter normalization, activation functions, and provides utilities for converting between normalized and physical parameter values. .. attribute:: normed_lam
Normalized probe wavelength parameter.
- type:
Array
- normed_amp1#
Normalized amplitude 1 parameter, used for the blue-shifted EPW.
- Type:
Array
- normed_amp2#
Normalized amplitude 2 parameter, used for the red-shifted EPW.
- Type:
Array
- normed_amp3#
Normalized amplitude 3 parameter, used for the IAW.
- Type:
Array
- normed_ne_gradient#
Normalized electron density gradient parameter.
- Type:
Array
- normed_Te_gradient#
Normalized electron temperature gradient parameter.
- Type:
Array
- normed_ud#
Normalized drift velocity parameter.
- Type:
Array
- normed_Va#
Normalized fluid velocity parameter.
- Type:
Array
- lam_scale#
Scaling factor for wavelength.
- Type:
float
- lam_shift#
Shift for wavelength.
- Type:
float
- amp1_scale#
Scaling factor for amplitude 1.
- Type:
float
- amp1_shift#
Shift for amplitude 1.
- Type:
float
- amp2_scale#
Scaling factor for amplitude 2.
- Type:
float
- amp2_shift#
Shift for amplitude 2.
- Type:
float
- amp3_scale#
Scaling factor for amplitude 3.
- Type:
float
- amp3_shift#
Shift for amplitude 3.
- Type:
float
- ne_gradient_scale#
Scaling factor for electron density gradient.
- Type:
float
- ne_gradient_shift#
Shift for electron density gradient.
- Type:
float
- Te_gradient_scale#
Scaling factor for electron temperature gradient.
- Type:
float
- Te_gradient_shift#
Shift for electron temperature gradient.
- Type:
float
- ud_scale#
Scaling factor for drift velocity.
- Type:
float
- ud_shift#
Shift for drift velocity.
- Type:
float
- Va_scale#
Scaling factor for fluid velocity.
- Type:
float
- Va_shift#
Shift for fluid velocity.
- Type:
float
- act_funs#
Dictionary of activation functions for each parameter.
- Type:
Dict[str, Callable]
- Parameters:
cfg (dict) – Configuration dictionary containing parameter bounds, values, and activation function info.
batch_size (int) – Number of samples in the batch.
batch (bool, optional) – Whether to initialize parameters as batched arrays. Defaults to True.
activate (bool, optional) – Whether to apply activation functions. Defaults to False.
- __call__()Source#
Returns a dictionary of unnormalized (physical) parameter values, applying activation functions and scaling/shifting as necessary.
- normed_lam: Array#
- normed_amp1: Array#
- normed_amp2: Array#
- normed_amp3: Array#
- normed_ne_gradient: Array#
- normed_Te_gradient: Array#
- normed_ud: Array#
- lam_scale: float#
- lam_shift: float#
- amp1_scale: float#
- amp1_shift: float#
- amp2_scale: float#
- amp2_shift: float#
- amp3_scale: float#
- amp3_shift: float#
- ne_gradient_scale: float#
- ne_gradient_shift: float#
- Te_gradient_scale: float#
- Te_gradient_shift: float#
- ud_scale: float#
- ud_shift: float#
- act_funs: Dict[str, Callable]#
- __call__()Source#
Applies the corresponding activation functions and denormalizes each parameter using its scale and shift values. :returns: dict –
- A dictionary containing the denormalized values for the following parameters:
“lam”: Probe wavelength parameter.
“amp1”: Amplitude 1 parameter.
“amp2”: Amplitude 2 parameter.
“amp3”: Amplitude 3 parameter.
“ne_gradient”: Electron density gradient parameter.
“Te_gradient”: Electron temperature gradient parameter.
“ud”: Drift velocity parameter.
“Va”: Fluid velocity parameter.
- class tsadar.core.modules.ts_params.ThomsonParams(param_cfg, num_params: int, batch=True, activate=False)Source#
ThomsonParams is an Equinox module that encapsulates the configuration and parameter management for a Thomson scattering fits. It manages electron, ion, and general parameters, providing methods for normalization, extraction, and fitting of parameters. .. attribute:: electron
The electron parameter module.
- type:
ElectronParams
- general#
The general parameter module.
- Type:
- param_cfg#
The configuration dictionary for all parameters, specifying parameter values and activation states.
- Type:
Dict
- num_params#
Number of parameters to generate for each field, same as batch size.
- Type:
int
- batch#
Whether to operate in batch mode. Defaults to True.
- Type:
bool, optional
- activate#
Whether to activate parameters. Defaults to False.
- Type:
bool, optional
- renormalize_ions(tmp_dict)Source#
Renormalizes the ion fractions in the provided dictionary so that their sum is 1. Also ensures that temperature parameters marked as “same” are synchronized across ions.
- get_unnormed_params()Source#
Returns a dictionary of all unnormalized parameters (electron, ions, general), with ion fractions renormalized.
- __call__()Source#
Returns a dictionary of all current parameters (electron, ions, general), with ion fractions renormalized.
- get_fitted_params(param_cfg)Source#
Only parameters marked as “active” for fitting in the configuration are included. Special handling is applied for certain keys referencing the distribtuion function (e.g., “m”, “f”, “fe”, “flm”). Returns a tuple of (fitted_params, num_params), where fitted_params is a dictionary of selected parameters, and num_params is the count of active fitted parameters.
- Raises:
AssertionError – If no ion species are found in the input configuration.
- electron: ElectronParams#
- general: GeneralParams#
- param_cfg: Dict#
- renormalize_ions(tmp_dict)Source#
Renormalizes the fractional abundances of ions in the provided dictionary so that their sum equals 1. For each ion, if the temperature (“Ti”) is set to be the same as the first ion (as specified in the parameter configuration), it copies the temperature value from the first ion. Then, it sums the fractional abundances (“fract”) of all ions. Finally, it normalizes each ion’s fractional abundance by dividing by the total sum. :param tmp_dict: A dictionary containing ion parameters, where each ion is keyed as “ion-1”, “ion-2”, etc.,
and contains at least the keys “Ti” (temperature) and “fract” (fractional abundance).
- Returns:
dict – The updated dictionary with normalized fractional abundances and synchronized temperatures where specified.
- set_fe_to_matte(tmp_dict)Source#
I looked into putting this in the distribution function definition but since it need information from the electron and all ions it had to be done last
- get_unnormed_params()Source#
Retrieve a dictionary of unnormalized parameters for the electron, general, and ion components. This method collects the unnormalized parameters from the electron, general, and each ion object, combines them into a single dictionary, and then applies ion renormalization to the result. :returns: dict –
- A dictionary containing unnormalized parameters for ‘electron’, ‘general’, and each ion
(with keys formatted as ‘ion-<index>’), after applying ion renormalization.
- __call__()Source#
Aggregates and returns a dictionary of plasma parameters.
This method constructs a dictionary containing electron and general parameters, as well as parameters for each ion species. The keys are: - “electron”: the result of self.electron() - “general”: the result of self.general() - “ion-<n>”: the result of each ion() in self.ions, where <n> is the 1-based index
The resulting dictionary is then passed through self.renormalize_ions() for further processing before being returned.
- Returns:
dict – A dictionary containing electron, general, and ion parameters, possibly renormalized.
- get_fitted_params(param_cfg)Source#
Extracts and returns the fitted parameters based on the provided parameter configuration. This method iterates through the unnormalized parameters and selects those that are marked as “active” for fitting in the param_cfg dictionary. It constructs a dictionary of fitted parameters and counts the number of active parameters. Special handling is applied for keys:
“m”: Included only if param_cfg[k][“fe”][“active”] is True.
“f”, “fe”, “flm”: Always included. For “flm”, additional keys ‘fvxvy’ and ‘v’ are set using the result of calling self().
- Parameters:
param_cfg (dict) – Configuration dictionary specifying which parameters are active for fitting.
- Returns:
tuple – fitted_params (dict): Dictionary containing the selected fitted parameters. num_params (int): The number of active fitted parameters.
- tsadar.core.modules.ts_params.get_filter_spec(cfg_params: Dict, ts_params: ThomsonParams) DictSource#
Generates a filter specification dictionary based on the provided configuration and Thomson scattering parameters. This function traverses the configuration parameters and updates a filter specification tree to indicate which parameters are active and should be included in further processing. :param cfg_params: A dictionary containing configuration parameters for each species. Each species maps to a
dictionary of parameter keys and their associated settings, including an “active” flag.
- Parameters:
ts_params (ThomsonParams) – An object representing the Thomson scattering parameters, structured as a tree.
- Returns:
Dict –
- A filter specification dictionary/tree with boolean values indicating which parameters are active (True)
and should be included in further computations.