Skip to content

Commit

Permalink
Merge pull request #21 from lopezvoliver/tests
Browse files Browse the repository at this point in the history
Re-add xarray tests
  • Loading branch information
lopezvoliver authored Mar 4, 2024
2 parents 5e3ac15 + efb739d commit b0fd0af
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 37 deletions.
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
with io.open(op.join(here, "requirements.txt"), encoding="utf-8") as f:
all_reqs = f.read().split("\n")

with io.open(op.join(here, "requirements_dev.txt"), encoding="utf-8") as f:
dev_reqs = [x.strip() for x in f.read().split("\n")]

install_requires = [x.strip() for x in all_reqs if "git+" not in x]
dependency_links = [x.strip().replace("git+", "") for x in all_reqs if "git+" not in x]

extras_requires = {
"all": dev_reqs
}

requirements = [ ]

setup_requirements = [ ]
Expand All @@ -39,6 +46,7 @@
],
description="Evapotranspiration (ET) models for use in python and with integration into Google Earth Engine.",
install_requires=install_requires,
extras_require=extras_requires,
dependency_links=dependency_links,
license="MIT license",
long_description=readme,
Expand Down
74 changes: 37 additions & 37 deletions tests/test_geeet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


import unittest
#import xarray as xr
import xarray as xr

from geeet import geeet

Expand Down Expand Up @@ -42,19 +42,19 @@ def setUp(self):
**{key:np.array(value) for key,value in self.tseb_series_inputs.items()},
**self.tseb_series_inputs_scalar
)
#self.tseb_series_inputs_xr=xr.merge([
# xr.DataArray(self.tseb_series_inputs["Alb"]).rename("albedo"),
# xr.DataArray(self.tseb_series_inputs["NDVI"]).rename("NDVI"),
# xr.DataArray(self.tseb_series_inputs["Tr"]).rename("radiometric_temperature"),
# xr.DataArray(self.tseb_series_inputs["Ta"]).rename("air_temperature"),
# xr.DataArray(self.tseb_series_inputs["P"]).rename("surface_pressure"),
# xr.DataArray(self.tseb_series_inputs["U"]).rename("wind_speed"),
# xr.DataArray(self.tseb_series_inputs["Sdn"]).rename("solar_radiation"),
# xr.DataArray(self.tseb_series_inputs["Ldn"]).rename("thermal_radiation"),
# ])
#self.tseb_series_xr = geeet.tseb.tseb_series(
# self.tseb_series_inputs_xr, **self.tseb_series_inputs_scalar
#)
self.tseb_series_inputs_xr=xr.merge([
xr.DataArray(self.tseb_series_inputs["Alb"]).rename("albedo"),
xr.DataArray(self.tseb_series_inputs["NDVI"]).rename("NDVI"),
xr.DataArray(self.tseb_series_inputs["Tr"]).rename("radiometric_temperature"),
xr.DataArray(self.tseb_series_inputs["Ta"]).rename("air_temperature"),
xr.DataArray(self.tseb_series_inputs["P"]).rename("surface_pressure"),
xr.DataArray(self.tseb_series_inputs["U"]).rename("wind_speed"),
xr.DataArray(self.tseb_series_inputs["Sdn"]).rename("solar_radiation"),
xr.DataArray(self.tseb_series_inputs["Ldn"]).rename("thermal_radiation"),
])
self.tseb_series_xr = geeet.tseb.tseb_series(
self.tseb_series_inputs_xr, **self.tseb_series_inputs_scalar
)

def tearDown(self):
"""Tear down test fixtures, if any."""
Expand Down Expand Up @@ -110,29 +110,29 @@ def test_tseb_series_np_energy_balance(self):
10
)

#def test_tseb_series_xr_consistency(self):
# """Test tseb_series outputs consistency (xr.DataArray)."""
# residuals = self.tseb_series_xr.assign(
# LEr = lambda x: x.LE-x.LEc-x.LEs,
# Rnr = lambda x: x.Rn-x.Rnc-x.Rns
# )
# self.assertListAlmostEqual(
# residuals.LEr.values,
# [0,0], 10
# )
# self.assertListAlmostEqual(
# residuals.Rnr.values,
# [0,0], 10
# )

#def test_tseb_series_xr_energy_balance(self):
# """Test tseb_series energy balance (xr.DataArray)."""
# self.assertListAlmostEqual(
# self.tseb_series_xr.assign(
# EB = lambda x: x.Rn-x.LEc-x.LEs-x.G-x.Hc-x.Hs,
# ).EB.values,
# [0,0], 10
# )
def test_tseb_series_xr_consistency(self):
"""Test tseb_series outputs consistency (xr.DataArray)."""
residuals = self.tseb_series_xr.assign(
LEr = lambda x: x.LE-x.LEc-x.LEs,
Rnr = lambda x: x.Rn-x.Rnc-x.Rns
)
self.assertListAlmostEqual(
residuals.LEr.values,
[0,0], 10
)
self.assertListAlmostEqual(
residuals.Rnr.values,
[0,0], 10
)

def test_tseb_series_xr_energy_balance(self):
"""Test tseb_series energy balance (xr.DataArray)."""
self.assertListAlmostEqual(
self.tseb_series_xr.assign(
EB = lambda x: x.Rn-x.LEc-x.LEs-x.G-x.Hc-x.Hs,
).EB.values,
[0,0], 10
)

if __name__ == "__main__":
unittest.main()

0 comments on commit b0fd0af

Please sign in to comment.