Skip to content

Conversation

gitlinffff
Copy link

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

dopplershift and others added 28 commits May 23, 2025 13:43
* vectorize the function using pybind11/numpy.h, achieving handling numpy array, float and dtype

* add dewpoint, add constants.hpp, adding other functions WIP
…midity_from_mixing_ratio, specific_humidity_from_dewpoint
@CLAassistant
Copy link

CLAassistant commented Jun 23, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ dopplershift
✅ gitlinffff
❌ Linfeng Li


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.

Comment on lines +2 to +3
requires = ["setuptools>=61", "setuptools-scm[toml]>=3.4", "scikit-build-core", "pybind11"]
build-backend = "scikit_build_core.build"
Copy link
Contributor

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)
Copy link
Contributor

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
Comment on lines 7 to 8
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
Copy link
Contributor

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.

Comment on lines +3 to +5
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
Copy link
Contributor

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
Comment on lines 5 to 6
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <iostream> // for std::cerr
#include "math.hpp"

double lambert_wm1(double x, double tol, int max_iter) {
Copy link
Contributor

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;
Copy link
Contributor

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,
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants