-
Notifications
You must be signed in to change notification settings - Fork 436
Linfeng - First PR of c++ thermo using pybind11 #3856
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
base: main
Are you sure you want to change the base?
Linfeng - First PR of c++ thermo using pybind11 #3856
Conversation
* vectorize the function using pybind11/numpy.h, achieving handling numpy array, float and dtype * add dewpoint, add constants.hpp, adding other functions WIP
…verting saturation vapor pressure WIP
…midity_from_mixing_ratio, specific_humidity_from_dewpoint
…multiple dimensions
…elProfileHelper wip
Linfeng Li seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
requires = ["setuptools>=61", "setuptools-scm[toml]>=3.4", "scikit-build-core", "pybind11"] | ||
build-backend = "scikit_build_core.build" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're using that build backend, you can drop setuptools from the build-requires list too.
#set(CMAKE_CXX_STANDARD 14) | ||
#set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason you need the interpreter? It looks like the module development component would be enough so far.
src/thermo.hpp
Outdated
#include <pybind11/pybind11.h> | ||
#include <pybind11/numpy.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be the first includes in the file.
#include <pybind11/pybind11.h> | ||
#include <pybind11/numpy.h> | ||
#include <pybind11/stl.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be the first includes in the file.
src/thermo.cpp
Outdated
#include <pybind11/pybind11.h> | ||
#include <pybind11/numpy.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be the first includes in the file
#include <iostream> // for std::cerr | ||
#include "math.hpp" | ||
|
||
double lambert_wm1(double x, double tol, int max_iter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to use the SciPy LambertW (or the xsf function it wraps (C++ in a separate repo for people who don't want all of SciPy), or the Cython wrapper it might generate (it looks like it would be scipy.special._ufuncs.lambertw
)? If we are very lucky, PyCapsule_Import()
would get the correct function with little effort.
src/math.cpp
Outdated
|
||
for (int i = 0; i < max_iter; ++i) { | ||
double ew = std::exp(w); | ||
double wew = w * ew; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like spellcheck would prefer a name like w_ew
"Calculate relative humidity from temperature and dewpoint.", | ||
py::arg("temperature"), py::arg("dewpoint"), py::arg("phase")); | ||
|
||
m.def("dry_lapse", &DryLapseVectorized, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason this doesn't follow the pattern of py::vectorize(DryLapse)
? That seems to be what the current implementation does.
…'structured binding'
…ler and an array with one element
c++ functions I created at this stage:
MoistAirGasConstant
MoistAirSpecificHeatPressure
WaterLatentHeatVaporization
WaterLatentHeatSublimation
RelativeHumidityFromDewPoint
DryLapse
DryLapseProfile
CaldlnTdlnP
MoistLapse
MoistLapseProfile
LCL
_CheckPressure
_SaturationVaporPressureLiquid
_SaturationVaporPressureSolid
SaturationVaporPressure
DewPoint
MixingRatio
SaturationMixingRatio
SpecificHumidityFromMixingRatio
SpecificHumidityFromDewPoint
VirtualTemperature
lambert_wm1