mvdh7 / PyCO2SYS

Marine carbonate system calculations in Python
https://PyCO2SYS.readthedocs.io
GNU General Public License v3.0
50 stars 9 forks source link

Convert fCO2 to pCO2 and vice versa as standalone functions #59

Closed lukegre closed 2 years ago

lukegre commented 2 years ago

At the moment, this calculation requires the k_constants["FugFac"] input. This makes it a bit bulky if you'd quickly like to convert pCO2 --> fCO2. All the components are there (i.e., gas.fugacityfactor), it would just be a matter of reorganising a little bit.

One possible way of doing this would be to call the current function convert._fCO2_to_pCO2 that gets called by the existing scripts in PyCO2SYS. The old name could then be used for a standalone function that uses gas.fugacityfactor the calculate the factor. This approach would require some refactoring. I had a quick look at the code and it could also be xarray friendly out of the box 👍

Alternatively, we can add it to the api.

mvdh7 commented 2 years ago

Hey, if I understand what you're asking correctly, then you can already do this with the pyco2.sys API, by only providing par1 with no par2:

import PyCO2SYS as pyco2

results = pyco2.sys(
    par1=pCO2_data,
    par1_type=4,
    **temperature_salinity_settings_etc
)
fCO2_data = results["fCO2"]

The one-parameter (or no-parameter) calculation modes are described in the docs here and in the paper's Section 3.4.

mvdh7 commented 2 years ago

Closing this for now, feel free to continue if the solution above isn't what you were looking for @lukegre