Skip to content

Commit

Permalink
Add unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Jul 7, 2024
1 parent 73d92ba commit 7e80328
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ private/
*$py.class
*.nc
changelog_update.md
test_data/

# C extensions
*.so
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ HyperCoast supports the reading and visualization of hyperspectral data from var

## Acknowledgement

This projects draws inspiration and adapts source code from the [nasa/EMIT-Data-Resources](https://github.com/nasa/EMIT-Data-Resources) repository. Credit goes to the original authors.
This project draws inspiration and adapts source code from the [nasa/EMIT-Data-Resources](https://github.com/nasa/EMIT-Data-Resources) repository. Credit goes to the original authors.
55 changes: 55 additions & 0 deletions tests/test_aviris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import unittest
import hypercoast
import os
import matplotlib

matplotlib.use("Agg") # Use the Agg backend to suppress plots


class TestHypercoastDesis(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.url = "https://github.com/opengeos/datasets/releases/download/hypercoast/desis.tif"
cls.filepath = "test_data/desis.tif"
os.makedirs("test_data", exist_ok=True)
hypercoast.download_file(cls.url, cls.filepath)
cls.dataset = hypercoast.read_desis(cls.filepath)

def test_download_file(self):
self.assertTrue(os.path.exists(self.filepath))

def test_read_desis(self):
dataset = hypercoast.read_desis(self.filepath)
self.assertIsNotNone(dataset)

def test_map_add_desis_single_band(self):
m = hypercoast.Map()
self.assertIsNotNone(m)
m.add_basemap("Hybrid")
m.add_desis(
self.filepath,
wavelengths=[1000],
vmin=0,
vmax=5000,
nodata=0,
colormap="jet",
)
m.add_colormap(cmap="jet", vmin=0, vmax=0.5, label="Reflectance")
html = m.to_html()
assert "DESIS" in html

def test_map_add_desis_rgb(self):
m = hypercoast.Map()
self.assertIsNotNone(m)
m.add_basemap("Hybrid")
m.add_desis(
self.filepath, wavelengths=[900, 600, 525], vmin=0, vmax=1000, nodata=0
)
m.add("spectral")
html = m.to_html()
assert "DESIS" in html


if __name__ == "__main__":
unittest.main()
35 changes: 35 additions & 0 deletions tests/test_emit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
import hypercoast
import os


class TestHypercoastEmit(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.url = "https://github.com/opengeos/datasets/releases/download/netcdf/EMIT_L2A_RFL_001_20240404T161230_2409511_009.nc"
cls.filepath = "test_data/EMIT_L2A_RFL_001_20240404T161230_2409511_009.nc"
os.makedirs("test_data", exist_ok=True)
hypercoast.download_file(cls.url, cls.filepath)
cls.dataset = hypercoast.read_emit(cls.filepath)

def test_download_file(self):
self.assertTrue(os.path.exists(self.filepath))

def test_read_emit(self):
dataset = hypercoast.read_emit(self.filepath)
self.assertIsNotNone(dataset)

def test_map(self):
m = hypercoast.Map()
m.add_basemap("SATELLITE")
wavelengths = [1000, 600, 500]
m.add_emit(self.dataset, wavelengths, vmin=0, vmax=0.3, layer_name="EMIT")
m.add("spectral")
html = m.to_html()
self.assertIsNotNone(m)
assert "EMIT" in html


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_hypercoast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import unittest

from hypercoast import hypercoast
import hypercoast


class TestHypercoast(unittest.TestCase):
Expand Down
31 changes: 31 additions & 0 deletions tests/test_neon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest
import hypercoast
import os


class TestHypercoastNeon(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.url = "https://github.com/opengeos/datasets/releases/download/hypercoast/NEON_D02_SERC_DP3_368000_4306000_reflectance.h5"
cls.filepath = "test_data/neon.h5"
os.makedirs("test_data", exist_ok=True)
hypercoast.download_file(cls.url, cls.filepath)
cls.dataset = hypercoast.read_neon(cls.filepath)

def test_download_file(self):
self.assertTrue(os.path.exists(self.filepath))

def test_read_neon(self):
dataset = hypercoast.read_neon(self.filepath)
self.assertIsNotNone(dataset)

def test_map_set_center(self):
m = hypercoast.Map()
m.set_center(-76.5134, 38.8973, 16)
self.assertEqual(m.center, [38.8973, -76.5134])
self.assertEqual(m.zoom, 16)


if __name__ == "__main__":
unittest.main()
66 changes: 66 additions & 0 deletions tests/test_pace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import unittest
import hypercoast
import os
import matplotlib

matplotlib.use("Agg") # Use the Agg backend to suppress plots


class TestHypercoast(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.url = "https://github.com/opengeos/datasets/releases/download/netcdf/PACE_OCI.20240423T184658.L2.OC_AOP.V1_0_0.NRT.nc"
cls.filepath = "test_data/PACE_OCI.20240423T184658.L2.OC_AOP.V1_0_0.NRT.nc"
os.makedirs("test_data", exist_ok=True)
hypercoast.download_file(cls.url, cls.filepath)
cls.dataset = hypercoast.read_pace(cls.filepath)

def test_download_file(self):
self.assertTrue(os.path.exists(self.filepath))

def test_view_pace_pixel_locations(self):
plot = hypercoast.view_pace_pixel_locations(self.filepath, step=20)
self.assertIsNotNone(plot)

def test_read_pace(self):
dataset = hypercoast.read_pace(self.filepath)
self.assertIsNotNone(dataset)

def test_map(self):
m = hypercoast.Map()
m.add_basemap("Hybrid")
wavelengths = [450]
m.add_pace(
self.dataset,
wavelengths,
colormap="jet",
vmin=0,
vmax=0.02,
layer_name="PACE",
)
m.add_colormap(cmap="jet", vmin=0, vmax=0.02, label="Reflectance")
m.add("spectral")
html = m.to_html()
self.assertIsNotNone(m)
assert "PACE" in html

m = hypercoast.Map()
m.add_basemap("Hybrid")
wavelengths = [450, 550, 650]
m.add_pace(
self.dataset,
wavelengths,
indexes=[3, 2, 1],
vmin=0,
vmax=0.02,
layer_name="PACE",
)
m.add("spectral")
html = m.to_html()
self.assertIsNotNone(m)
assert "PACE" in html


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

0 comments on commit 7e80328

Please sign in to comment.