Giter Club home page Giter Club logo

co2syspy's Introduction

co2syspy

Travis-CI Build Status Coverage Status

A Python interpretation of CO2SYS (http://cdiac.ess-dive.lbl.gov/ftp/co2sys/).

This package is not stable, nor fully tested. It is also not very pythonic.

Example

First, import the package:

import co2sys

Use the old-school interface with co2sys.CO2SYS(). First, lets setup some variables to input:

par1type = 1  # The first parameter supplied is of type "1", which is "alkalinity"
par2type = 2  # The first parameter supplied is of type "2", which is "DIC"
par3type = 3  # The first parameter supplied is of type "3", which is "pH"
presin   = 4.036785269144779e3  # Pressure at input conditions
tempout  = 0  # Temperature at output conditions.
presout  = 0  # Pressure    at output conditions.
pHscale  = 1  # pH scale at which the input pH is reported ("1" means "Total Scale")
k1k2c    = 4  # Choice of H2CO3 and HCO3- dissociation constants K1 and K2 ("4" means "Mehrbach refit")
kso4c    = 1  # Choice of HSO4- dissociation constants KSO4 ("1" means "Dickson")
alk_s  = 2.337701660156250e3
dic_s  = 2.186364257812500e3
sal_s  = 34.875812530517578
temp_s = 2.197510004043579
si_s   = 49.758834838867188
p_s    = 1.458118438720703

Now, take all of this and run with it:

out, niceheaders = co2sys.CO2SYS(alk_s, dic_s, par1type, par2type, sal_s, 
                                 temp_s, tempout, presin, presout, si_s, 
                                 p_s, pHscale, k1k2c, kso4c)

Our output system variables are now held in out and the traditional CO2SYS "nice headers" are in niceheaders.

Installation

Install co2syspy from conda with:

conda install co2syspy -c sbmalev

Install with pip using:

pip install co2syspy

Support and development

License

co2syspy is available under the Open Source GPLv3 (https://www.gnu.org/licenses).

co2syspy's People

Contributors

brews avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

co2syspy's Issues

Need more comprehensive testing harness

Need more comprehensive testing harness.

Right now I just have one basic smoke test for my specific use-case. Should look at coverage and be sure to write tests that at least cover all the major use-cases based on input into co2sys.CO2SYS().

Need to update travis-ci OSX script

Right now our OSX travis-ci script is failing with error:


�[31mError:�[0m python 2.7.14 is already installed

To upgrade to 3.6.5, run `brew upgrade python`



travis_time:end:0487433c:start=1523325290285842000,finish=1523325379170473000,duration=88884631000
�[0K

�[31;1mThe command "if [[ "$JOB_OS" == "MacOSX" ]]; then brew update; brew install python3; fi" failed and exited with 1 during .�[0m



Your build has been stopped.

/Users/travis/.travis/job_stages: line 166: shell_session_update: command not found

I think this has something to do with homebrew now using python3 by default...

Broadcasting and array input

Originally posted by @aholdsworth in #4 :

The code only seems to work for scalar inputs. I would have liked to use it for 3d fields, but it's not yet working for even the following simple test case. This is example 6 found here (https://github.com/jamesorr/CO2SYS-MATLAB/blob/master/notebooks/CO2SYS-Matlab_tutorial.ipynb) for the matlab version:


par1type = 1; # The first parameter supplied is of type "1", which is "alkalinity"
par1 = 2300; # value of the first parameter
par2type = 2; # The first parameter supplied is of type "1", which is "DIC"
par2 =np.arange(2000,2200,5) # value of the second parameter, which is a long vector of different DIC's!
sal = 35; # Salinity of the sample
tempin = 10; # Temperature at input conditions
presin = 0; # Pressure at input conditions
tempout = 0; # Temperature at output conditions - doesn't matter in this example
presout = 0; # Pressure at output conditions - doesn't matter in this example
sil = 50; # Concentration of silicate in the sample (in umol/kg)
po4 = 2; # Concentration of phosphate in the sample (in umol/kg)
pHscale = 1; # pH scale at which the input pH is reported ("1" means "Total Scale") - doesn't matter in this example
k1k2c = 4; # Choice of dissociation constants K1 and K2 ("4" means "Mehrbach refit")
kso4c = 1; # Choice of KSO4 ("1" means "Dickson")
print('par2', par2)

A =co2sys.CO2SYS(par1,par2,par1type,par2type,sal,tempin,tempout,presin,presout,sil,po4,pHscale,k1k2c,kso4c)

We've only written co2syspy for scalar input and broadcasting support would be nice.

In the meantime, as a quick fix, the simplest option would be to use something like a for-loop for the different input.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.