Skip to content

Commit 62201ba

Browse files
initial release
1 parent abe487a commit 62201ba

File tree

10 files changed

+234
-2
lines changed

10 files changed

+234
-2
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ["3.10"]
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v3 # This is already the latest version
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v4 # This is also the latest version
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install .[dev] # Use dev to install pytest
31+
32+
- name: Run tests
33+
run: |
34+
pytest

.github/workflows/python-publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
deploy:
20+
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up Python
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: '3.x'
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install build
33+
- name: Build package
34+
run: python -m build
35+
- name: Publish package
36+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37+
with:
38+
user: __token__
39+
password: ${{ secrets.PYPI_API_TOKEN }}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# SEBAL-soil-heat-flux
2-
Soil Heat Flux Remote Sensing Method from the Surface Energy Balance for Land (SEBAL) Evapotranspiration Model in Python
1+
# Soil Heat Flux Remote Sensing Method from the Surface Energy Balance for Land (SEBAL) Evapotranspiration Model in Python
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from typing import Union
2+
3+
import numpy as np
4+
import rasters as rt
5+
from rasters import Raster
6+
7+
def calculate_SEBAL_soil_heat_flux(
8+
Rn: Union[Raster, np.ndarray],
9+
ST_C: Union[Raster, np.ndarray],
10+
NDVI: Union[Raster, np.ndarray],
11+
albedo: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
12+
"""
13+
This function calculates the soil heat flux (G) in the Surface Energy Balance Algorithm for Land (SEBAL) model.
14+
The formula used in the function is a simplification of the more complex relationship between these variables in the energy balance at the surface.
15+
16+
Parameters:
17+
Rn (np.ndarray): Net radiation at the surface.
18+
ST_C (np.ndarray): Surface temperature in Celsius.
19+
NDVI (np.ndarray): Normalized Difference Vegetation Index, indicating the presence and condition of vegetation.
20+
albedo (np.ndarray): Measure of the diffuse reflection of solar radiation.
21+
22+
Returns:
23+
np.ndarray: The soil heat flux (G), a key component in the energy balance.
24+
25+
Reference:
26+
"Evapotranspiration Estimation Based on Remote Sensing and the SEBAL Model in the Bosten Lake Basin of China" [^1^][1]
27+
"""
28+
# Empirical coefficients used in the calculation
29+
coeff1 = 0.0038
30+
coeff2 = 0.0074
31+
32+
# Vegetation cover correction factor
33+
NDVI_correction = 1 - 0.98 * NDVI ** 4
34+
35+
# Calculation of the soil heat flux (G)
36+
G = Rn * ST_C * (coeff1 + coeff2 * albedo) * NDVI_correction
37+
38+
G = rt.clip(G, 0, None)
39+
40+
return G

SEBAL_soil_heat_flux/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .SEBAL_soil_heat_flux import *
2+
3+
from os.path import join, abspath, dirname
4+
5+
with open(join(abspath(dirname(__file__)), "version.txt")) as f:
6+
version = f.read()
7+
8+
__version__ = version
9+
__author__ = "Gregory H. Halverson"

SEBAL_soil_heat_flux/version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.1

makefile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
PACKAGE_NAME = SEBAL-soil-heat-flux
2+
ENVIRONMENT_NAME = $(PACKAGE_NAME)
3+
DOCKER_IMAGE_NAME = $(PACKAGE_NAME)
4+
5+
clean:
6+
rm -rf *.o *.out *.log
7+
rm -rf build/
8+
rm -rf dist/
9+
rm -rf *.egg-info
10+
rm -rf .pytest_cache
11+
find . -type d -name "__pycache__" -exec rm -rf {} +
12+
13+
test:
14+
pytest
15+
16+
build:
17+
python -m build
18+
19+
twine-upload:
20+
twine upload dist/*
21+
22+
dist:
23+
make clean
24+
make build
25+
make twine-upload
26+
27+
remove-environment:
28+
mamba env remove -y -n $(ENVIRONMENT_NAME)
29+
30+
install:
31+
pip install -e .[dev]
32+
33+
uninstall:
34+
pip uninstall $(PACKAGE_NAME)
35+
36+
reinstall:
37+
make uninstall
38+
make install
39+
40+
environment:
41+
mamba create -y -n $(ENVIRONMENT_NAME) -c conda-forge python=3.10
42+
43+
colima-start:
44+
colima start -m 16 -a x86_64 -d 100
45+
46+
docker-build:
47+
docker build -t $(DOCKER_IMAGE_NAME):latest .
48+
49+
docker-build-environment:
50+
docker build --target environment -t $(DOCKER_IMAGE_NAME):latest .
51+
52+
docker-build-installation:
53+
docker build --target installation -t $(DOCKER_IMAGE_NAME):latest .
54+
55+
docker-interactive:
56+
docker run -it $(DOCKER_IMAGE_NAME) fish
57+
58+
docker-remove:
59+
docker rmi -f $(DOCKER_IMAGE_NAME)

pyproject.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[build-system]
2+
requires = ["setuptools>=60", "setuptools-scm>=8.0", "wheel"]
3+
4+
[project]
5+
name = "SEBAL-soil-heat-flux"
6+
version = "1.0.1"
7+
description = "Soil Heat Flux Remote Sensing Method from the Surface Energy Balance for Land (SEBAL) Evapotranspiration Model in Python"
8+
readme = "README.md"
9+
authors = [
10+
{ name = "Gregory Halverson", email = "[email protected]" },
11+
]
12+
classifiers = [
13+
"Programming Language :: Python :: 3",
14+
"Operating System :: OS Independent",
15+
]
16+
dependencies = [
17+
"numpy",
18+
"rasters"
19+
]
20+
21+
requires-python = ">=3.10"
22+
23+
[project.optional-dependencies]
24+
dev = [
25+
"build",
26+
"pytest>=6.0",
27+
"pytest-cov",
28+
"jupyter",
29+
"pytest",
30+
"twine"
31+
]
32+
33+
[tool.setuptools.package-data]
34+
SEBAL_soil_heat_flux = ["*.txt"]
35+
36+
[project.urls]
37+
"Homepage" = "https://github.com/JPL-Evapotranspiration-Algorithms/SEBAL-soil-heat-flux"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_import_SEBAL_soil_heat_flux():
2+
from SEBAL_soil_heat_flux import calculate_SEBAL_soil_heat_flux

tests/test_import_dependencies.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
3+
# List of dependencies
4+
dependencies = [
5+
"numpy",
6+
"rasters"
7+
]
8+
9+
# Generate individual test functions for each dependency
10+
@pytest.mark.parametrize("dependency", dependencies)
11+
def test_dependency_import(dependency):
12+
__import__(dependency)

0 commit comments

Comments
 (0)