Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
43a8b44
Envphys - C headers - Remove incorrect file description
jomey Jul 13, 2026
0781d03
Envphys - C headers - Remove unused macros and constants.
jomey Jul 13, 2026
74438c3
Envphys - Saturation Vapor Pressure - Consolidate the math into the C…
jomey Jul 13, 2026
9c645f4
Tests - Distribute - Change the topo mock to a function
jomey Jul 17, 2026
0696925
Tests - Distribute - Add case for wet bulb temperature
jomey Jul 17, 2026
72f64bb
Enphys - Wet Bulb temperature - Fix call to vapor pressure
jomey Jul 17, 2026
862afb1
C code - Add clang-format und apply to changed files.
jomey Jul 17, 2026
fafc10f
Distribute - VaporPressure - Lint code and update doc strings.
jomey Jul 17, 2026
2dd3e4e
Envphys - Vapor Pressure - Rename method for better clarity
jomey Jul 17, 2026
68c6aaf
PR review - Implement some @copilot suggestions
jomey Jul 17, 2026
bbc6220
Envphys - Constants - No need to define LOG_10 as it is already avail…
jomey Jul 17, 2026
93efbc0
Envphys - C Constants - Replace custom macros with standard C library…
jomey Jul 17, 2026
20c8885
Envphys - C - Expand on clang formatter and apply to changed files
jomey Jul 17, 2026
9747be1
Envphys C - Replace legacy use of numpy array declaration
jomey Sep 11, 2026
e39e262
Enphys - Remove exposure of sati and satw
jomey Sep 14, 2026
d92f5cb
Envphys - Topotherm - Use log10 for efficiency
jomey Sep 15, 2026
414cb9c
Envphus - topotherm - Improve error logging for incorrect temperatures.
jomey Sep 15, 2026
299f341
Envphys - Improve vapor pressure docstring
jomey Sep 15, 2026
09f07fd
Makefile - Add new target for dev centric install
jomey Sep 15, 2026
932e5e9
Makefile - Ensure binaries are up to date before test and install
jomey Sep 17, 2026
6844636
Setup.py - Suppress deprecated NumPy API warning
jomey Sep 17, 2026
c2aa541
Setup.py - Lint file
jomey Sep 17, 2026
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
50 changes: 50 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
BasedOnStyle: LLVM
Language: C

# Core Formatting
ColumnLimit: 100
TabWidth: 4
IndentWidth: 4
UseTab: Never
MaxEmptyLinesToKeep: 1

# Line Wrapping & Breaking
ReflowComments: true # Wraps long comment lines to fit ColumnLimit
BreakBeforeBraces: Attach # Keeps opening braces on the same line as statements
BreakBeforeBinaryOperators: All # Wraps lines BEFORE operators (e.g., +, &&)
AlignAfterOpenBracket: BlockIndent # Aligns wrapped arguments to a new indented block

# Parameter & Argument Layout
BinPackArguments: false # Forces one argument per line if they wrap
BinPackParameters: false # Forces one parameter per line if they wrap
AllowAllParametersOfDeclarationOnNextLine: true
AllowAllArgumentsOnNextLine: true

# Alignment Rules
IndentCaseLabels: true # Indents 'case' statements inside a 'switch'
AlignEscapedNewlines: Left # Aligns backslashes in multi-line macros to the left

AlignConsecutiveMacros: # Aligns macro definitions horizontally
Enabled: true
AcrossEmptyLines: true
AcrossComments: false

AlignConsecutiveAssignments: # Aligns '=' operators on consecutive lines
Enabled: true
AcrossEmptyLines: false
AcrossComments: true

# Code Style & Readability
PointerAlignment: Right # Places asterisk next to name: 'int *ptr'
SortIncludes: CaseSensitive # Automatically sorts #include headers alphabetically

# Whitespace Padding
SpaceBeforeParens: Custom # Required to unlock fine-grained spacing rules
SpaceBeforeParensOptions: # Replaces the deprecated SpaceBeforeFunctionDeclarationParens flag
AfterFunctionDeclarationName: false # Enforces 'void func()' instead of 'void func ()'
AfterFunctionDefinitionName: false # Enforces 'void func() {}' instead of 'void func () {}'
AfterControlStatements: true # Enforces 'if (x)' instead of 'if(x)'
SpacesInParens: Custom # Replaces deprecated 'SpaceInEmptyParentheses'
SpacesInParensOptions:
InEmptyParentheses: false # Disallows spaces like 'void func( )
SpacesInContainerLiterals: true # Adds spacing inside initializers: '{ 1, 2 }'
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ isort: ## using isort to sort imports
lint:
flake8 smrf

tests:
tests: build_extensions
python3 -m unittest discover -s smrf/tests/

tests_fast_fail:
tests_fast_fail: build_extensions
python3 -m unittest discover -s smrf/tests/ -f

coverage: ## run coverage and submit
Expand Down Expand Up @@ -97,5 +97,8 @@ dist: clean
python setup.py bdist_wheel
ls -l dist

install: clean
python3 -m pip install -e .[dev]
install: clean build_extensions
python3 -m pip install .[dev]

install-dev: clean
python3 -m pip install --no-deps -e .[dev]
75 changes: 34 additions & 41 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,82 @@
import os

import numpy
from setuptools import Extension, setup
from Cython.Distutils import build_ext
from Cython.Build import cythonize
from Cython.Distutils import build_ext
from setuptools import Extension, setup

# Give user option to specify local compiler name
if "CC" not in os.environ:
os.environ["CC"] = "gcc"

print("Compiler set to: " + os.environ["CC"])

extension_params = dict(
extra_compile_args=[
'-fopenmp',
'-O3',
extension_params = {
"extra_compile_args": [
"-fopenmp",
"-O3",
],
extra_link_args=['-fopenmp'],
include_dirs=[numpy.get_include()]
)
"extra_link_args": ["-fopenmp"],
"include_dirs": [numpy.get_include()],
"define_macros": [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This removes the numpy compile warning

}

directives = {
'language_level': "3str",
'embedsignature': True,
'boundscheck': False,
'wraparound': False,
'initializedcheck': False,
'cdivision': True,
'binding': True,
"language_level": "3str",
"embedsignature": True,
"boundscheck": False,
"wraparound": False,
"initializedcheck": False,
"cdivision": True,
"binding": True,
}

extensions = []

# detrended kriging
extensions += [
Extension(
'smrf.spatial.dk.detrended_kriging',
"smrf.spatial.dk.detrended_kriging",
sources=[
os.path.join('smrf/spatial/dk', source_file) for source_file in [
os.path.join("smrf/spatial/dk", source_file)
for source_file in [
"detrended_kriging.pyx",
"krige.c",
"lusolv.c",
"array.c"
"array.c",
]
],
**extension_params
**extension_params,
),
]

# envphys core c functions
extensions += [
Extension(
'smrf.envphys.core.envphys_c',
"smrf.envphys.core.envphys_c",
sources=[
os.path.join('smrf/envphys/core', val) for val in [
"envphys_c.pyx",
"topotherm.c",
"dewpt.c",
"iwbt.c"
]
os.path.join("smrf/envphys/core", val)
for val in ["envphys_c.pyx", "topotherm.c", "dewpt.c", "iwbt.c"]
],
**extension_params
**extension_params,
),
Extension(
'smrf.envphys.solar.toposplit',
sources=['smrf/envphys/solar/toposplit.pyx'],
**extension_params
"smrf.envphys.solar.toposplit",
sources=["smrf/envphys/solar/toposplit.pyx"],
**extension_params,
),
Extension(
'smrf.utils.wind.wind_c',
"smrf.utils.wind.wind_c",
sources=[
os.path.join('smrf/utils/wind', val) for val in [
"wind_c.pyx",
"breshen.c",
"calc_wind.c"
]
os.path.join("smrf/utils/wind", val)
for val in ["wind_c.pyx", "breshen.c", "calc_wind.c"]
],
**extension_params
**extension_params,
),
]

setup(
cmdclass={
'build_ext': build_ext
},
cmdclass={"build_ext": build_ext},
ext_modules=cythonize(
extensions,
compiler_directives=directives,
Expand Down
7 changes: 3 additions & 4 deletions smrf/data/input/wrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from smrf.data.input.gridded_input import GriddedInput
from smrf.data.input.netcdf import metadata_name_from_index
from smrf.envphys.vapor_pressure import satvp
from smrf.envphys.vapor_pressure import svp_for_celsius
from smrf.utils.utils import apply_utm


Expand Down Expand Up @@ -143,9 +143,8 @@ def load(self):
self.air_temp = self.air_temp - 273.15

self._logger.debug('Calculating vapor_pressure')
vp = satvp(self.dew_point.values)
self.vapor_pressure = pd.DataFrame(
vp, index=time, columns=self.primary_id)
vp = svp_for_celsius(self.dew_point.values)
self.vapor_pressure = pd.DataFrame(vp, index=time, columns=self.primary_id)

self._logger.debug('Loading cloud_factor')
self.cloud_factor = pd.DataFrame(index=time, columns=self.primary_id)
Expand Down
22 changes: 10 additions & 12 deletions smrf/distribute/vapor_pressure.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import numpy as np

from .variable_base import VariableBase
from smrf.envphys.core import envphys_c
from smrf.utils import utils

from .variable_base import VariableBase


class VaporPressure(VariableBase):
"""
Expand All @@ -13,8 +13,8 @@ class VaporPressure(VariableBase):
:mod:`smrf.envphys.vapor_pressure.rh2vp`. The vapor pressure is distributed
instead of the relative humidity as it is an absolute measurement of the
vapor within the atmosphere and will follow elevational trends (typically
negative). Were as relative humidity is a relative measurement which
varies in complex ways over the topography. From the distributed vapor
negative). Wereas relative humidity is a relative measurement which
varies in complex ways over the topography. From the distributed vapor
pressure, the dew point is calculated for use by other distribution
methods. The dew point temperature is further corrected to ensure that it
does not exceed the distributed air temperature.
Expand Down Expand Up @@ -49,7 +49,7 @@ def __init__(self, config, topo):
def distribute(self, data, ta):
"""
Distribute air temperature given a Panda's dataframe for a single time
step. Calls :mod:`smrf.distribute.ImageData._distribute`.
step. Calls :mod:`smrf.distribute.VariableBase._distribute`.

The following steps are performed when distributing vapor pressure:

Expand All @@ -65,18 +65,16 @@ def distribute(self, data, ta):

"""

self._logger.debug('%s -- Distributing vapor_pressure' % data.name)
self._logger.debug("%s -- Distributing vapor_pressure" % data.name)

# calculate the vapor pressure
self._distribute(data)

# set the limits
self.vapor_pressure = utils.set_min_max(self.vapor_pressure,
self.min,
self.max)
self.vapor_pressure = utils.set_min_max(self.vapor_pressure, self.min, self.max)

# calculate the dew point
self._logger.debug('%s -- Calculating dew point' % data.name)
self._logger.debug("%s -- Calculating dew point" % data.name)

# use the core_c to calculate the dew point
dew_point_temperature = np.zeros_like(self.vapor_pressure, dtype=np.float64)
Expand All @@ -89,13 +87,13 @@ def distribute(self, data, ta):

ind = dew_point_temperature >= ta

if (np.sum(ind) > 0):
if np.sum(ind) > 0:
dew_point_temperature[ind] = ta[ind] - 0.2

self.dew_point = dew_point_temperature

# calculate wet bulb temperature
if self.precip_temp_method == 'wet_bulb':
if self.precip_temp_method == "wet_bulb":
# initialize timestep wet_bulb
wet_bulb = np.zeros_like(self.vapor_pressure, dtype=np.float64)
# calculate wet_bulb
Expand Down
Loading