Skip to content

Commit

Permalink
feat(ALR): add closure_target parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
msorvoja committed Dec 17, 2024
1 parent 5f47ff2 commit 33f4d78
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion eis_toolkit/transformations/coda/alr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from eis_toolkit.exceptions import InvalidColumnException, NumericValueSignException
from eis_toolkit.utilities.aitchison_geometry import _closure
from eis_toolkit.utilities.checks.compositional import check_in_simplex_sample_space
from eis_toolkit.utilities.miscellaneous import rename_columns_by_pattern
from eis_toolkit.utilities.miscellaneous import perform_closure, rename_columns_by_pattern


@beartype
Expand All @@ -24,6 +24,7 @@ def alr_transform(
columns: Optional[Sequence[str]] = None,
denominator_column: Optional[str] = None,
keep_denominator_column: bool = False,
closure_target: Optional[int] = None,
) -> pd.DataFrame:
"""
Perform an additive logratio transformation on the data.
Expand All @@ -34,6 +35,7 @@ def alr_transform(
denominator_column: The name of the column to be used as the denominator column.
keep_denominator_column: Whether to include the denominator column in the result. If True, the returned
dataframe retains its original shape.
closure_target: Target row sum for closure. If None, no closure is performed.
Returns:
A new dataframe containing the ALR transformed data.
Expand Down Expand Up @@ -63,6 +65,9 @@ def alr_transform(
else:
columns_to_transform = df.columns.to_list()

if closure_target is not None:
df = perform_closure(df, columns_to_transform, closure_target)

check_in_simplex_sample_space(df)

if not keep_denominator_column and denominator_column in columns_to_transform:
Expand Down

0 comments on commit 33f4d78

Please sign in to comment.