Skip to content

Commit

Permalink
Ruff-style
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdh7 committed Dec 13, 2024
1 parent f2a23e4 commit 1cc2458
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 18 deletions.
10 changes: 6 additions & 4 deletions PyCO2SYS/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright (C) 2020--2024 Matthew P. Humphreys et al. (GNU GPLv3)
"""Alternative APIs for executing the main CO2SYS function."""

from ..engine import _CO2SYS, CO2SYS
from . import ezio
from ..engine import CO2SYS, _CO2SYS


def CO2SYS_wrap(
Expand Down Expand Up @@ -114,9 +114,10 @@ def CO2SYS_wrap(
system parameters. Note that output variables are labelled as the original
CO2SYS output names, and not the wrapper inputs.
"""
from autograd import numpy as np
import inspect

import pandas as pd
from autograd import numpy as np

try:
import xarray as xr
Expand Down Expand Up @@ -177,8 +178,9 @@ def printv(*args, **kwargs):
df = pd.DataFrame(params, index=np.arange(max(sizes)))
except ValueError:
raise UserWarning(
"Your inputs must be length of 1 or n (sizes shown below)"
":\n {}".format(str(sizes))
"Your inputs must be length of 1 or n (sizes shown below)" ":\n {}".format(
str(sizes)
)
)

# DEFINE PARAMETER TYPES
Expand Down
2 changes: 1 addition & 1 deletion PyCO2SYS/buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright (C) 2020--2024 Matthew P. Humphreys et al. (GNU GPLv3)
"""Calculate various buffer factors of the marine carbonate system."""

import jax
from jax import numpy as np

from . import solubility, solve
from .meta import egrad

Expand Down
1 change: 0 additions & 1 deletion PyCO2SYS/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from autograd import numpy as np


RGasConstant_DOEv2 = 83.1451 # ml bar-1 K-1 mol-1, DOEv2 (always used by default)
RGasConstant_DOEv3 = 83.14472 # ml bar-1 K-1 mol-1, DOEv3 (never used in PyCO2SYS)
RGasConstant_CODATA2018 = 83.14462618 # 10^-1 J mol^-1 K^-1 (available from v1.4.1)
Expand Down
3 changes: 3 additions & 0 deletions PyCO2SYS/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
fCO2_to_CO2aq
Convert CO2 fugacity to aqueous content.
"""

import copy

from jax import numpy as np

from . import constants


Expand Down
1 change: 1 addition & 0 deletions PyCO2SYS/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Helpers for the main CO2SYS program."""

from autograd import numpy as np

from .. import convert, equilibria, salts, solve
from . import nd, system

Expand Down
2 changes: 2 additions & 0 deletions PyCO2SYS/engine/nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""Carbonate system solving in N dimensions."""

import itertools

from autograd import numpy as np

from .. import convert, equilibria, salts, solve, uncertainty, upsilon

# Define function input keys that should be converted to floats
Expand Down
19 changes: 13 additions & 6 deletions PyCO2SYS/engine/system.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# PyCO2SYS: marine carbonate system calculations in Python.
# Copyright (C) 2020--2024 Matthew P. Humphreys et al. (GNU GPLv3)
import itertools

import networkx as nx
from jax import numpy as np
import numpy as onp
from jax import numpy as np
from matplotlib import pyplot as plt

from .. import (
bio,
buffers,
Expand All @@ -29,11 +31,17 @@
"k_CO2_1atm": equilibria.p1atm.k_CO2_W74,
"k_H2S_total_1atm": equilibria.p1atm.k_H2S_total_YM95,
# pH scale conversion factors at 1 atm
"free_to_sws_1atm": lambda total_fluoride, total_sulfate, k_HF_free_1atm, k_HSO4_free_1atm: convert.pH_free_to_sws(
"free_to_sws_1atm": lambda total_fluoride,
total_sulfate,
k_HF_free_1atm,
k_HSO4_free_1atm: convert.pH_free_to_sws(
total_fluoride, total_sulfate, k_HF_free_1atm, k_HSO4_free_1atm
),
"nbs_to_sws": convert.pH_nbs_to_sws, # because fH doesn't get pressure-corrected
"tot_to_sws_1atm": lambda total_fluoride, total_sulfate, k_HF_free_1atm, k_HSO4_free_1atm: convert.pH_tot_to_sws(
"tot_to_sws_1atm": lambda total_fluoride,
total_sulfate,
k_HF_free_1atm,
k_HSO4_free_1atm: convert.pH_tot_to_sws(
total_fluoride, total_sulfate, k_HF_free_1atm, k_HSO4_free_1atm
),
# Equilibrium constants at 1 atm and on the seawater pH scale
Expand Down Expand Up @@ -491,7 +499,7 @@
),
2: dict(
k_BOH3_nbs_1atm=equilibria.p1atm.k_BOH3_nbs_LTB69,
k_BOH3_sws_1atm=lambda k_BOH3_total_1atm, nbs_to_sws: (
k_BOH3_sws_1atm=lambda k_BOH3_nbs_1atm, nbs_to_sws: (
k_BOH3_nbs_1atm * nbs_to_sws
),
),
Expand Down Expand Up @@ -902,7 +910,6 @@ def _assemble(self, icase, values):
return graph, funcs, values

def _get(self, parameters, graph, funcs, values, save_steps, verbose):

def printv(*args, **kwargs):
if verbose:
print(*args, **kwargs)
Expand Down Expand Up @@ -1252,7 +1259,7 @@ def get_grad(self, var_of, var_wrt):
def get_grads(self, vars_of, vars_wrt):
for var_of in vars_of:
for var_wrt in vars_wrt:
get_grad(var_of, var_wrt)
self.get_grad(var_of, var_wrt)

def get_values_original(self):
return {k: self.values[k] for k in self.nodes_original}
3 changes: 2 additions & 1 deletion PyCO2SYS/equilibria/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"""Calculate equilibrium constants from temperature, salinity and pressure."""

from autograd import numpy as np
from . import p1atm, pcx

from .. import constants, convert, gas, solubility
from . import p1atm, pcx, pressured


def prepare(temperature, pressure, equilibria):
Expand Down
6 changes: 4 additions & 2 deletions PyCO2SYS/equilibria/p1atm.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@
Carbonic acid dissociation constants following PLR18.
Used when opt_k_carbonic = 18.
"""

from jax import numpy as np

from .. import convert


Expand Down Expand Up @@ -1388,7 +1390,7 @@ def k_H2CO3_sws_MGH06(temperature, salinity):
B_1 = -530.123 * salinity**0.5 - 6.103 * salinity
C_1 = -2.06950 * salinity**0.5
pK1 = A_1 + B_1 / TempK + C_1 * np.log(TempK) + pK1_0 # pK1 sigma = 0.0054
return 10.0 ** -(pK1)
return 10.0**-(pK1)


def k_HCO3_sws_MGH06(temperature, salinity):
Expand All @@ -1413,7 +1415,7 @@ def k_HCO3_sws_MGH06(temperature, salinity):
B_2 = -772.483 * salinity**0.5 - 20.051 * salinity
C_2 = -3.3336 * salinity**0.5
pK2 = A_2 + B_2 / TempK + C_2 * np.log(TempK) + pK2_0 # pK2 sigma = 0.011
return 10.0 ** -(pK2)
return 10.0**-(pK2)


def k_H2CO3_sws_M10(temperature, salinity):
Expand Down
2 changes: 2 additions & 0 deletions PyCO2SYS/equilibria/pcx.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
factor_k_CO2
Calculate the pressure-correction factor for k_CO2 following W74 eq. 5.
"""

# Original notes from CO2SYS-MATLAB regarding pressure corrections:
# ****************************************************************************
# Correct dissociation constants for pressure
Expand Down Expand Up @@ -127,6 +128,7 @@
# Kappas are in cm3/mole/bar
# ****************************************************************************
from jax import numpy as np

from .. import convert


Expand Down
1 change: 1 addition & 0 deletions PyCO2SYS/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""

from jax import numpy as np

from . import convert


Expand Down
5 changes: 2 additions & 3 deletions PyCO2SYS/meta.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# PyCO2SYS: marine carbonate system calculations in Python.
# Copyright (C) 2020--2024 Matthew P. Humphreys et al. (GNU GPLv3)
"""Define metadata about PyCO2SYS."""

import jax
from jax import numpy as np

Expand Down Expand Up @@ -44,9 +45,7 @@ def hello():
Lasciate ogni speranza, voi ch' entrate!
Dante, Inferno iii, 9
sign on the entrance gates of hell
""".format(
version_xyz
)
""".format(version_xyz)
) # (All hope abandon, ye who enter here!)


Expand Down
1 change: 1 addition & 0 deletions PyCO2SYS/solubility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Calculate saturation states of soluble solids."""

from autograd import numpy as np

from . import convert


Expand Down
2 changes: 2 additions & 0 deletions PyCO2SYS/uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""Propagate uncertainties through marine carbonate system calculations."""

import copy

from autograd import numpy as np

from . import engine

# Default uncertainties in pK values following OEDG18
Expand Down
1 change: 1 addition & 0 deletions PyCO2SYS/upsilon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# PyCO2SYS: marine carbonate system calculations in Python.
# Copyright (C) 2020--2024 Matthew P. Humphreys et al. (GNU GPLv3)
from jax import numpy as np

from . import constants

bh_TOG93_H24 = 28995 # J / mol
Expand Down

0 comments on commit 1cc2458

Please sign in to comment.