pyoceans / pyCO2

pyCO2 Seawater-Carbon Calculator for Python
MIT License
6 stars 10 forks source link

Progress on pyCO2, and/or considering mocsys for ioos/conda-recipes #5

Closed emiliom closed 8 years ago

emiliom commented 8 years ago

@ocefpaf, I know you don't have time to work on pyCO2 on your own. God knows where you even find the time to do everything you already do!

I wanted to ask if an offer to help out would make a difference in your time allocation. I'll warn you that I've never used CO2SYS myself, so I have no idea how much work this is. However, I do have a pretty strong understanding of the carbonate system. As I've mentioned before, I'm also quite involved in Ocean Acidification data projects, from local (Pacific NW) to "regional" to global. I'm pretty interested in seeing a Python carbonate-system package. Though I no longer speak Matlab, I can still read it; from what I've read [1], CO2SYS-MATLAB is a better starting point for CO2SYS than the R version you may have been looking at (seacarb?).

Another option that's probably a lot easier than reimplementing CO2SYS in Python is to create an ioos conda recipe for mocsy [2], a Fortran library that already includes examples for running it from Python. Since you already handle (I assume seamlessly ...) Fortran dependencies on the ioos conda recipes, I assume that creating a recipe for mocsy would be easy, and I'm willing to help and test.

mocsy was developed mainly to support ocean models [2], but in terms of its accuracy and implementation of the latest, recommended thermodynamic constants and formulations, it compares extremely well with CO2SYS [1]. I think the main disadvantages for wide use is that it only accepts for input the carbonate-variables pair most used in models, AT and CT, rather than the much broader options available with CO2SYS. But if it's fairly straightforward to add it to the ioos binstar (anaconda server?) channel, that would be a nice contribution to the community; and I could consider contributing user-oriented Python enhancements in the future. Also, creating an as-is mocsy conda package doesn't exclude working on a Python CO2SYS-MATLAB implementation in the future.

Ask your wife if she likes these ideas ;)

[1] Orr, J. C., Epitalon, J.-M., and Gattuso, J.-P.: Comparison of ten packages that compute ocean carbonate chemistry, Biogeosciences, 12, 1483-1510, doi:10.5194/bg-12-1483-2015, 2015

[2] Orr, J. C. and Epitalon, J.-M.: Improved routines to model the ocean carbonate system: mocsy 2.0, Geosci. Model Dev., 8, 485-499, doi:10.5194/gmd-8-485-2015, 2015

emiliom commented 8 years ago

I should mention that previously I installed and played with another geochemical computational package in Python, phreeqpy. phreecpy is a Python wrapper around a powerful Fortran package, in this case, PHREEQC, using the IPhreeqc interface (very much a Windows-flavored, COM based/styled interface).

I would love to see a conda phreecpy package, too. My only concern would be that phreecpy doesn't seem to be maintained anymore, but I could find out more with the developer.

FYI, my interest in enabling geochemical workhorse packages in Python is not new ...

ocefpaf commented 8 years ago

@emiliom Your interest in this is reassuring! I do want to make some time for this library in the near future. Maybe the end of the year break... But python-gsw is at the top of the queue.

CO2SYS-MATLAB is a better starting point for CO2SYS than the R version you may have been looking at (seacarb?).

Yes. That does seem like a better starting point. I do have some uncommitted code that goes in that direction that @juoceano (my wife) and I worked on this for SciPy2015.

conda recipe for mocsy [2]

Interesting. I did not know about mocsy. I will take a look.

But if it's fairly straightforward to add it to the ioos binstar

The short answer is "kind of." The code is not "installable". I see some functions that need to be wrapped as a library.

Ask your wife if she likes these ideas ;)

She does! She reminds me everyday to work on this :smile_cat:

I would love to see a conda phreecpy package

I just took a very quick look and it seems to be a ctypes wrapper to a c-lib. That will require some patches to get things in the right place but it is doable.

My interest in enabling geochemical workhorse packages in Python is not new ...

That is a noble goal! I will help with the conda packaging as much as I can.

PS: Are you going to Ocean Sciences in New Orleans?

emiliom commented 8 years ago

Thanks for your replies! I'll start from the end:

I'm 85% sure I'm going to Ocean Sciences. I submitted an abstract (on ocean acidification data management ...). I just need to go through my budgets to confirm that I have the funds. I assume you're going?

I would love to see a conda phreecpy package

I just took a very quick look and it seems to be a ctypes wrapper to a c-lib. That will require some patches to get things in the right place but it is doable.

Thanks for your assessment. Given your limited time, I suggest you don't bother with phreeqpy yet. PHREEQC is probably not used by oceanographers much. Let's focus on carbonate-system packages instead. I just wanted to mention this in this context, for future reference.

But if [mocsy is] fairly straightforward to add it to the ioos binstar

The short answer is "kind of." The code is not "installable". I see some functions that need to be wrapped as a library.

I can get in touch with the mocsy author, James Orr, who is on github. He's a pretty well known oceanographer/modeler. I'm optimistic that he will be interested in making mocsy more readily useable. BTW, he also seems to be linked with the guy who wrote ipython-ferretmagic!

Let me know if I should go ahead and contact James. I would need your help in telling him what's needed to make his code fully installable.

Coincidentally, I just realized that I may have a near-term application for mocsy! I'm working with a regional ROMS modeler who has an adaptation with biogeochemistry and the carbonate system. We will be ingesting some of his carbonate system output over the next couple of months, and I know we'll need to convert from CT and AT to pCO2, etc. mocsy fits right in. Plus, he uses Python, too.

I don't know how much of an audience there will be for a CO2SYS-Python. We can discuss CO2SYS-Python later, after taking care of mocsy if it does turn out to be "fairly" easy.

Ask your wife if she likes these ideas ;)

She does! She reminds me everyday to work on this

Too funny!

ocefpaf commented 8 years ago

I assume you're going?

Yes. It would be nice to meet and maybe get some work done :wink:

I just wanted to mention this in this context, for future reference.

Best way to keep track of this is to open issues at https://github.com/ioos/conda-recipes/issues. I am opening issues for both packages. (See https://github.com/ioos/conda-recipes/issues/550 and https://github.com/ioos/conda-recipes/issues/551.)

I can get in touch with the mocsy author, James Orr, who is on github. He's a pretty well known oceanographer/modeler.

Give me a week to take a better look at the code first. Maybe it will be simple...

I don't know how much of an audience there will be for a CO2SYS-Python. We can discuss CO2SYS-Python later, after taking care of mocsy if it does turn out to be "fairly" easy.

OK let's make packaging mocsy a priority.

emiliom commented 8 years ago

Great, thanks! mocsy it is.

And yes, look forward to getting work done with you at Ocean Sciences.

emiliom commented 8 years ago

I'm using this issue to minimize noise on others, and also to treat this as an ongoing, broader discussion.

At Ocean Sciences a few weeks ago you mentioned you had some ideas about improving the fortran wrapping for mocsy. Any chance we (ie, mainly you!) could spend some time on this in the next 2 weeks??

I'm going to an Ocean Acidification (OA) observing network workshop in Australia in two weeks. I'll be giving a presentation on a new global OA data portal we're developing. Just before my presentation, Jim Orr (mocsy author) will present on "Carbonate chemistry calculation considerations". It'd be great to have more progress on our improvements to the Python mocsy package by then, to be able to discuss with Jim. Jim has made a number of updates to mocsy since we were last in touch with him in November.

I realize two weeks is a short time, but it doesn't hurt to ask ... No worries if you can't.

I'm also looking forward to seeing the progress made on the Python CO2SYS implementation by the person who contacted you a couple of weeks ago.

ocefpaf commented 8 years ago

At Ocean Sciences a few weeks ago you mentioned you had some ideas about improving the fortran wrapping for mocsy. Any chance we (ie, mainly you!) could spend some time on this in the next 2 weeks??

@emiliom to be honest I have the boilerplate specs needed to fix mocsy, but I have no idea how easy it will be be. (If what I have in mind works it can be just a few hours.)

I will be away from the 21-24th April helping @juoceano in a field sampling. I will prioritize this once I get back.

emiliom commented 8 years ago

Thanks. Hopefully what you have in mind will work!

I'm curious: is this your Manaus/Amazon field work?

ocefpaf commented 8 years ago

I'm curious: is this your Manaus/Amazon field work?

Not yet. That will be by the end of the year. This is a small trip to South of Bahia to collect soil around Eucalyptus crops. Don't really know the science behind it as I am just the muscle to dig holes on the ground for this one :wink:

ocefpaf commented 8 years ago

With https://github.com/jamesorr/mocsy/pull/3 and https://github.com/ioos/conda-recipes/blob/master/recipes/mocsy/meta.yaml in place I guess we can cose this issue.