Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vectorize instead of jit in EOS #66

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions pop_tools/eos.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import dask
import numpy as np
import xarray as xr
from numba import jit
from numba import vectorize


@jit(nopython=True)
@vectorize(['float64(float64)', 'float32(float32)'], nopython=True)
def compute_pressure(depth):
"""
Convert depth in meters to pressure in bars.
Expand Down Expand Up @@ -113,18 +113,14 @@ def eos(salt, temp, return_coefs=False, **kwargs):
dRHOdT.attrs['long_name'] = 'Thermal expansion coefficient'

else:
if isinstance(salt.data, dask.array.Array):
RHO = xr.apply_ufunc(
_compute_eos,
salt,
temp,
pressure,
dask='parallelized',
output_dtypes=[salt.dtype],
)
else:
RHO = xr.full_like(salt, fill_value=np.nan)
RHO[:] = _compute_eos(salt.data, temp.data, pressure.data)
RHO = xr.apply_ufunc(
_compute_eos,
salt,
temp,
pressure,
dask='parallelized',
output_dtypes=[salt.dtype],
)

RHO.name = 'density'
RHO.attrs['units'] = 'kg/m^3'
Expand All @@ -145,7 +141,10 @@ def eos(salt, temp, return_coefs=False, **kwargs):
return RHO


@jit(nopython=True)
@vectorize(
['float64(float64, float64, float64)', 'float32(float32, float32, float32)'],
nopython=True,
)
def _compute_eos(salt, temp, pressure):
# MWJF EOS coefficients
# *** these constants will be used to construct the numerator
Expand Down