Skip to content

Feature: Saturation Index Retrieval and Plotting#395

Open
SuixiongTay wants to merge 29 commits into
KingsburyLab:mainfrom
SuixiongTay:scaling_sat_index
Open

Feature: Saturation Index Retrieval and Plotting#395
SuixiongTay wants to merge 29 commits into
KingsburyLab:mainfrom
SuixiongTay:scaling_sat_index

Conversation

@SuixiongTay
Copy link
Copy Markdown
Collaborator

@SuixiongTay SuixiongTay commented May 13, 2026

Summary

This PR adds support for querying saturation indices (SI) through a new get_saturation_index method on the Solution class. The method retrieves SI from the active backend engine. This PR addresses #58.

  • Added a def phases(self) function in solution.py to access the PHREEQC wrapper to retrieve the equilibrium phase data collected in pyEQL/phreeqc/core.py
  • Implemented the get_saturation_index so it can retrieve saturation index (SI) keys and values from the backend engine
  • Added get_plot feature within the get_saturation_index(get_plot=True) method to visualize the SI of solid and gas phases using plotly based on the phases returned from the defined engine.

Below is an example for seawater:

s1 = Solution.from_preset("seawater")
s1.equilibrate()
si = s1.get_saturation_index(get_plot=True)
newplot (2)

Below is another example for a custom engine and solution:

custom_eos = PhreeqcEOS(phreeqc_db="vitens.dat")
s1 = Solution({'Na+': '10 mol/L', 'K+': '10 mol/L', 'Cl-': '10 mol/L'}, pH=9, temperature= '25 degC', engine=custom_eos)
si = s1.get_saturation_index(get_plot=True)
newplot (3)

Todos

  • Compile Ksp values across the commonly-encountered scalants, defined under pyEQL_db.dat. (Suggestions?)
  • Additional pytest

@SuixiongTay SuixiongTay changed the title Feature: Saturation Index Retrieval and Plotting [WIP] Feature: Saturation Index Retrieval and Plotting May 13, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.42%. Comparing base (7c49fa5) to head (992bb32).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #395      +/-   ##
==========================================
+ Coverage   86.23%   86.42%   +0.19%     
==========================================
  Files          14       14              
  Lines        1853     1879      +26     
  Branches      323      326       +3     
==========================================
+ Hits         1598     1624      +26     
  Misses        209      209              
  Partials       46       46              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@YitongPan1
Copy link
Copy Markdown
Collaborator

Hi Shaun, I updated some tests for the saturation index, please let me know if there is anything not covered yet, thank you!

@SuixiongTay
Copy link
Copy Markdown
Collaborator Author

Thanks Yitong, the coverage looks quite comprehensive.

I noticed the test is failing for test_multi_mineral_si because carbonate species are missing. Adding that in should solve the problem. Thanks!

@rkingsbury rkingsbury marked this pull request as ready for review May 15, 2026 13:25
Copy link
Copy Markdown
Member

@rkingsbury rkingsbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks both! This looks pretty good. See small comments.

Comment thread tests/test_solution.py
Comment thread tests/test_solution.py Outdated
Comment thread tests/test_solution.py Outdated
Comment thread src/pyEQL/solution.py Outdated
Comment thread src/pyEQL/solution.py Outdated
Comment thread src/pyEQL/solution.py Outdated
Comment thread tests/test_solution.py Outdated
Comment thread tests/test_solution.py Outdated
@rkingsbury rkingsbury changed the title [WIP] Feature: Saturation Index Retrieval and Plotting Feature: Saturation Index Retrieval and Plotting May 15, 2026
@SuixiongTay SuixiongTay changed the title Feature: Saturation Index Retrieval and Plotting [WIP] Feature: Saturation Index Retrieval and Plotting May 15, 2026
@SuixiongTay SuixiongTay marked this pull request as draft May 15, 2026 16:42
@SuixiongTay SuixiongTay marked this pull request as ready for review May 16, 2026 14:25
@SuixiongTay SuixiongTay changed the title [WIP] Feature: Saturation Index Retrieval and Plotting Feature: Saturation Index Retrieval and Plotting May 16, 2026
Copy link
Copy Markdown
Member

@rkingsbury rkingsbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good; apologies I missed some of the comments from a few weeks ago. I think it just needs:

  1. Some clarification about how the SI is calculated in the docstring, and
  2. some edits to the unit tests

And will be good to go.

Comment thread src/pyEQL/solution.py Outdated
Comment thread tests/test_solution.py Outdated
Comment thread tests/test_solution.py Outdated
Comment thread tests/test_solution.py Outdated
Comment thread tests/test_solution.py
Comment thread tests/test_solution.py Outdated
Comment thread docs/examples/.ipynb_checkpoints/pyeql_tutorial_charge_balancing-checkpoint.ipynb Outdated
@rkingsbury rkingsbury added this to the v1.5.0 milestone May 28, 2026
@SuixiongTay SuixiongTay marked this pull request as draft May 29, 2026 11:44
@SuixiongTay SuixiongTay changed the title Feature: Saturation Index Retrieval and Plotting WIP - Feature: Saturation Index Retrieval and Plotting May 29, 2026
@SuixiongTay SuixiongTay marked this pull request as ready for review May 29, 2026 16:44
@SuixiongTay SuixiongTay changed the title WIP - Feature: Saturation Index Retrieval and Plotting Feature: Saturation Index Retrieval and Plotting May 29, 2026
@SuixiongTay SuixiongTay requested a review from rkingsbury May 29, 2026 16:54
Copy link
Copy Markdown
Member

@rkingsbury rkingsbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SuixiongTay ! Nice job with the additional documentation in the docstring. I've always felt that adding extra explanation makes a huge difference for making a package usable and understandable.

@SuixiongTay SuixiongTay mentioned this pull request May 29, 2026
@rkingsbury
Copy link
Copy Markdown
Member

@SuixiongTay looks like we're still failing due to the ** error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants