Skip to content

Commit b8ae3de

Browse files
jtlaitnmaarnio
authored andcommitted
added closure checks also when geochemical data that is in ppm or ppb
1 parent 3db18bd commit b8ae3de

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

eis_toolkit/utilities/checks/compositional.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ def check_in_simplex_sample_space(df: pd.DataFrame, tolerance: Number = 0.0001)
3636
row_sums = df.sum(axis=1)
3737
closed_to_one = (row_sums - 1).abs() < tolerance
3838
closed_to_hundred = (row_sums - 100).abs() < tolerance
39+
closed_to_million = (row_sums - 1e6).abs() < tolerance
40+
closed_to_billion = (row_sums - 1e9).abs() < tolerance
3941

40-
if not closed_to_one.all() and not closed_to_hundred.all():
41-
raise InvalidCompositionException(f"Input data is not closed to 1 or 100 within tolerance of {tolerance}.")
42+
is_valid = closed_to_one.all() or closed_to_hundred.all() or closed_to_million.all() or closed_to_billion.all()
43+
44+
if not is_valid:
45+
raise InvalidCompositionException(
46+
f"Input data is not closed to 1, 100 (%), 10^6 (ppm) or 10^9 (ppb) within tolerance of {tolerance}."
47+
)
4248

4349
return None

tests/utilities/compositional_test.py

+18
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def test_compositional_data_invalid():
7777
def test_check_for_simplex_sample_space():
7878
"""Test whether or not a dataframe belongs to a simplex sample space is correctly identified."""
7979
unit_simplex_df = pd.DataFrame([[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.2, 0.3]])
80+
closed_to_hundred_df = unit_simplex_df * 100
81+
closed_to_million_df = unit_simplex_df * 1e6
82+
closed_to_billion_df = unit_simplex_df * 1e9
8083
non_simplex_positive_df = pd.DataFrame([1, 2, 3, 4], [5, 6, 7, 8])
8184
non_positive_df = pd.DataFrame([-1, 2, 3, 4], [1, 2, 3, 4])
8285

@@ -91,3 +94,18 @@ def test_check_for_simplex_sample_space():
9194
check_in_simplex_sample_space(unit_simplex_df)
9295
except Exception as ex:
9396
assert False, f"{type(ex)}: {ex}"
97+
98+
try:
99+
check_in_simplex_sample_space(closed_to_hundred_df)
100+
except Exception as ex:
101+
assert False, f"{type(ex)}: {ex}"
102+
103+
try:
104+
check_in_simplex_sample_space(closed_to_million_df)
105+
except Exception as ex:
106+
assert False, f"{type(ex)}: {ex}"
107+
108+
try:
109+
check_in_simplex_sample_space(closed_to_billion_df)
110+
except Exception as ex:
111+
assert False, f"{type(ex)}: {ex}"

0 commit comments

Comments
 (0)