MMMIDataWrapper.to_scaled#
- MMMIDataWrapper.to_scaled(var)[source]#
Transform variable from original to scaled space.
Handles three scenarios based on input type:
String ending with ‘_original_scale’: Returns the corresponding base variable from posterior (e.g., “mu_original_scale” → posterior[“mu”]). The base variable is already in scaled space.
String without ‘_original_scale’ suffix: Returns the variable directly from posterior (e.g., “channel_contribution” → posterior[“channel_contribution”]). These variables are already in scaled space, so no transformation is applied.
xr.DataArray: Assumes the data is in original scale and divides by target_scale to convert to scaled space.
- Parameters:
- var
strorxr.DataArray One of: - Variable name ending with ‘_original_scale’ (returns base scaled variable) - Variable name in posterior (returns as-is, already scaled) - DataArray in original space (divides by target_scale)
- var
- Returns:
xr.DataArrayVariable in scaled space
- Raises:
ValueErrorIf string variable is not found in posterior, or if target_scale is not found in constant_data when scaling a DataArray
Examples
>>> # Get scaled version of original scale variable >>> scaled = wrapper.to_scaled("mu_original_scale") >>> >>> # Get already-scaled variable directly >>> scaled = wrapper.to_scaled("channel_contribution") >>> >>> # Convert DataArray from original to scaled space >>> original_data = posterior["mu"] * constant_data.target_scale >>> scaled = wrapper.to_scaled(original_data)