mvdh7 / PyCO2SYS

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

Pythonic API #28

Closed lukegre closed 4 years ago

lukegre commented 4 years ago

Feature I spoke about at OSM. Finally got around to doing it :)

Also set up a test configuration. I've written two tests to ensure that the api works. Will need to do the DOCs, but thought I'd see if you want to accept the merge first.

The way I've structured this is to add a script called api.py. This is not called in by default and has to be imported manually with from PyCO2SYS.api import CO2SYS_wrap as co2sys. The main reason for not making this automatic is that it requires pandas and the rest of your script does not.

The function returns a pandas.DataFrame with rows as the input examples, and columns as the variable names. Alternatively, if one of the inputs is an xarray.DataArray, then the outputs will be output as this type (for gridded data).

mvdh7 commented 4 years ago

Hey, thank you very much @luke-gregor, this is a fantastic addition!

Please can I ask that you switch this to merge into the develop branch instead of master? The master always contains the most recently released version. I need to write some contributing guidelines to clarify this. I realise I could just copy your code in directly but then we lose GitHub's tracking of your contribution, which would be a shame.

There are a lot of updates in develop and a v1.3 release will come very soon - it would be great to include this there. In theory the changes should not affect anything that just uses the main CO2SYS function as a black box (with the exception that there may be additional entries in the output dict).

If you can add some docs that would also be very useful. This could be on the docs site and/or in notebooks here (only just started on this): https://github.com/mvdh7/PyCO2SYS-examples - if you want to add notebooks I can give you direct access there.

lukegre commented 4 years ago

What markdown flavour are you using for docs?

mvdh7 commented 4 years ago

What markdown flavour are you using for docs?

I've never given it enough thought to know if I'm sticking to a particular flavour, but the docs are generated using https://squidfunk.github.io/mkdocs-material/ so any of the extensions included there are fine to use.

mvdh7 commented 4 years ago

Replaced by https://github.com/mvdh7/PyCO2SYS/pull/29