Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Azad77 authored Jan 17, 2024
1 parent b76d18c commit 2c9f557
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_brightness_temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np
import unittest

from pylst.temperature import BrightnessTemperatureLandsat

# Test class for BrightnessTemperatureLandsat
class TestBrightnessTemperature(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Setting up a sample band with all zeros
cls.sample_band_10 = np.zeros((5, 5))
# Creating an instance of the BrightnessTemperatureLandsat class
cls.brightness_temp = BrightnessTemperatureLandsat()

# Test whether the method returns a tuple
def test_method_returns_tuple(self):
output = self.brightness_temp(self.sample_band_10)
self.assertIsInstance(output, tuple)

# Test whether the output size matches the input size
def test_output_and_input_size_equal(self):
output = self.brightness_temp(self.sample_band_10)
self.assertEqual(self.sample_band_10.shape, output[0].shape)


if __name__ == "__main__":
unittest.main() # Run the tests if this script is executed directly
48 changes: 48 additions & 0 deletions tests/test_emissivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import unittest
import numpy as np

from pylst.emissivity.emissivity import ComputeMonoWindowEmissivity, ComputeEmissivityGopinadh

# Test class for testing emissivity computation methods
class TestEmissivityComputation(unittest.TestCase):
@classmethod
def setUpClass(self):
# Setting up a sample NDVI and red band with all zeros
#cls.sample_ndvi = 'band_4_red_Landsat.tif'
#cls.sample_red_band = 'band_4_red_Landsat.tif'
# Sample NDVI and red band data (replace with your actual data)
self.sample_ndvi = np.array([[0.1, 0.2], [0.3, 0.4]])
self.sample_red_band = np.array([[0.5, 0.6], [0.7, 0.8]])

# Test whether the methods return a tuple
def test_method_returns_tuple(self):
# Instantiate the classes for different emissivity computation methods
mono_window_emissivity = ComputeMonoWindowEmissivity()
#nbem_emissivity = ComputeEmissivityNBEM()
gopinadh_emissivity = ComputeEmissivityGopinadh()

# Compute emissivity for the sample data using different methods
output_mono_window = mono_window_emissivity(ndvi=self.sample_ndvi, red_band=self.sample_red_band)
#output_nbem = nbem_emissivity(ndvi=self.sample_ndvi, red_band=self.sample_red_band)
output_gopinadh = gopinadh_emissivity(ndvi=self.sample_ndvi)

# Assert that the outputs are tuples
self.assertIsInstance(output_mono_window, tuple)
#self.assertIsInstance(output_nbem, tuple)
self.assertIsInstance(output_gopinadh, tuple)

# Test whether the output sizes match the input sizes
def test_output_and_input_size_equal(self):
# Instantiate the class for mono-window emissivity computation method
mono_window_emissivity = ComputeMonoWindowEmissivity()

# Compute emissivity for the sample data using the mono-window method
output = mono_window_emissivity(ndvi=self.sample_ndvi, red_band=self.sample_red_band)

# Assert that the output shapes match the input shapes
self.assertEqual(self.sample_ndvi.shape, output[0].shape)
self.assertEqual(self.sample_ndvi.shape, output[1].shape)

# Run the tests if this script is executed directly
if __name__ == "__main__":
unittest.main()
27 changes: 27 additions & 0 deletions tests/test_nrs_normalization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
"""
@author: Azad Rasul
"""
import unittest
import numpy as np
from pylst.normalization.normalizer import nrs

class TestNRSNormalization(unittest.TestCase):

def test_nrs_normalization(self):
# Create a sample input array
lst = np.array([1, 2, 3, 4, 5])

# Compute NRS using my function
result = nrs(lst)

# Expected calculation of NRS
NR = lst / np.sqrt(np.sum(np.square(lst)))
expected_result = NR * (np.mean(lst)) / np.mean(NR)

# Assert that the computed NRS matches the expected result
np.testing.assert_array_almost_equal(result, expected_result, decimal=6)

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

28 changes: 28 additions & 0 deletions tests/test_plotter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
"""
@author: Azad Rasul
"""
import pylst
# Importing the functions from plotter.py
from pylst.visualization import rastshow, plot_data

# Example data to plot
data = [1, 2, 3, 4, 5]

# Calling the plot_data function
plot_data(data)

# Path to the raster file
path_to_raster = ('C:\\Users\\gardi\\Chirps_Erbil.tif')

# Calling the rastshow function to display the raster
# Call rastshow with a valid figsize argument
rastshow(
path_to_raster,
title='Rain of Erbil from CHIRPS',
colorbar_label='Ran (mm)',
xlabel='Longitude',
ylabel='Latitude',
cmap='viridis',
figsize=(8, 6) # Change to valid width and height values in inches
)
31 changes: 31 additions & 0 deletions tests/test_single_window_temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import numpy as np
import unittest

from pylst.temperature import MonoWindowLST

class TestMonoWindowLST(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Setting up sample data and class instance for testing
cls.sample_band_10 = np.zeros((5, 5)) # Creating a sample band 10 array
cls.mask = np.random.randint(0, high=1, size=(5, 5), dtype=int) # Creating a random mask
cls.mask = cls.mask == 1 # Converting random mask to boolean type
cls.lst_algorithm = MonoWindowLST() # Initializing MonoWindowLST instance

def test_output_and_input_size_equal(self):
# Testing if the output size matches input size
output = self.lst_algorithm(
emissivity_10=self.sample_band_10,
brightness_temperature_10=self.sample_band_10,
mask=self.mask,
)
self.assertEqual(self.sample_band_10.shape, output.shape)

def test_max_temp_less_than_or_equal_max_earth_temp(self):
# Testing if the maximum temperature in the algorithm is within known Earth temperature limits
self.assertEqual(self.lst_algorithm.max_earth_temp, 273.15 + 56.7)

if __name__ == "__main__":
# Running the unit tests
unittest.main()

142 changes: 142 additions & 0 deletions tests/test_split_window_temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import numpy as np
import unittest

from pylst.temperature import (
BrightnessTemperatureLandsat,
SplitWindowJiminezMunozLST,
SplitWindowKerrLST,
SplitWindowMcMillinLST,
SplitWindowPriceLST,
SplitWindowSobrino1993LST,
)

# Test class for SplitWindowSobrino1993LST
class TestSplitWindowSobrino1993LST(unittest.TestCase):
# Sample data initialization
sample_band_10 = np.zeros((5, 5)) # Sample Band 10 data
mask = np.random.randint(0, high=2, size=(5, 5), dtype=int) == 1 # Random mask data

# Test for output and input size equality
def test_output_and_input_size_equal(self):
# Running the SplitWindowSobrino1993LST algorithm
output = SplitWindowSobrino1993LST()(
emissivity_10=self.sample_band_10,
emissivity_11=self.sample_band_10,
brightness_temperature_10=self.sample_band_10,
brightness_temperature_11=self.sample_band_10,
mask=self.mask,
)
self.assertEqual(self.sample_band_10.shape, output.shape) # Checking if output size matches input size

# Test for ensuring maximum temperature is within the acceptable range
def test_max_temp_less_than_or_equal_max_earth_temp(self):
lst_algorithm = SplitWindowSobrino1993LST()
# Checking if the maximum earth temperature matches the expected value
self.assertEqual(lst_algorithm.max_earth_temp, 273.15 + 56.7)



# Test class for SplitWindowJiminezMunozLST functionality
class TestSplitWindowJiminezMunozLST(unittest.TestCase):
# Creating sample data for testing purposes
sample_band_10 = np.zeros((5, 5)) # Sample data for band 10
mask = np.random.randint(0, high=2, size=(5, 5), dtype=int) == 1 # Generating a random mask

# Test to ensure the output size matches the input size
def test_output_and_input_size_equal(self):
# Calling the SplitWindowJiminezMunozLST function with sample data
output = SplitWindowJiminezMunozLST()(
emissivity_10=self.sample_band_10,
emissivity_11=self.sample_band_10,
brightness_temperature_10=self.sample_band_10,
brightness_temperature_11=self.sample_band_10,
mask=self.mask,
)
# Asserting that the input and output shapes match
self.assertEqual(self.sample_band_10.shape, output.shape)

# Test to ensure the maximum temperature is within a certain range
def test_max_temp_less_than_or_equal_max_earth_temp(self):
# Creating an instance of the SplitWindowJiminezMunozLST class
lst_algorithm = SplitWindowJiminezMunozLST()
# Asserting that the maximum earth temperature is within a specific range
self.assertEqual(lst_algorithm.max_earth_temp, 273.15 + 56.7)

class TestSplitWindowKerrLST(unittest.TestCase):
# Sample data setup for testing purposes
sample_band_10 = np.zeros((5, 5))
mask = np.random.randint(0, high=2, size=(5, 5), dtype=int) == 1

# Test to verify output size matches input size
def test_output_and_input_size_equal(self):
# Call the method being tested with sample input data
output = SplitWindowKerrLST()(
brightness_temperature_10=self.sample_band_10,
brightness_temperature_11=self.sample_band_10,
ndvi=self.sample_band_10,
mask=self.mask,
)
# Assert that the output size matches the input size
self.assertEqual(self.sample_band_10.shape, output.shape)

# Test to ensure maximum temperature doesn't exceed maximum Earth temperature
def test_max_temp_less_than_or_equal_max_earth_temp(self):
# Create an instance of the tested class
lst_algorithm = SplitWindowKerrLST()
# Assert that the maximum calculated Earth temperature is within limits
self.assertEqual(lst_algorithm.max_earth_temp, 273.15 + 56.7)

# Test class for SplitWindowMcMillinLST
class TestSplitWindowMcMillinLST(unittest.TestCase):
# Sample data for testing
sample_band_10 = np.zeros((5, 5)) # Creating a sample Band 10 data
mask = np.random.randint(0, high=2, size=(5, 5), dtype=int) == 1 # Generating a random mask

# Testing whether the output size matches the input size
def test_output_and_input_size_equal(self):
# Running the SplitWindowMcMillinLST algorithm
output = SplitWindowMcMillinLST()(
brightness_temperature_10=self.sample_band_10,
brightness_temperature_11=self.sample_band_10,
mask=self.mask,
)
# Checking if the output size matches the input size
self.assertEqual(self.sample_band_10.shape, output.shape)

# Testing if the maximum calculated temperature is less than or equal to the maximum Earth temperature
def test_max_temp_less_than_or_equal_max_earth_temp(self):
# Creating an instance of the SplitWindowMcMillinLST algorithm
lst_algorithm = SplitWindowMcMillinLST()
# Checking if the maximum calculated temperature matches the expected maximum Earth temperature
self.assertEqual(lst_algorithm.max_earth_temp, 273.15 + 56.7)

# Create a test class inheriting from unittest.TestCase
class TestSplitWindowPriceLST(unittest.TestCase):
# Sample data for testing
sample_band_10 = np.zeros((5, 5))
mask = np.random.randint(0, high=2, size=(5, 5), dtype=int) == 1

# Test case to ensure output and input sizes are equal
def test_output_and_input_size_equal(self):
# Create an instance of the class or method being tested
output = SplitWindowPriceLST()(
# Provide sample data to the method
emissivity_10=self.sample_band_10,
emissivity_11=self.sample_band_10,
brightness_temperature_10=self.sample_band_10,
brightness_temperature_11=self.sample_band_10,
mask=self.mask,
)
# Assert that the output shape matches the input shape
self.assertEqual(self.sample_band_10.shape, output.shape)

# Test case to verify maximum temperature constraints
def test_max_temp_less_than_or_equal_max_earth_temp(self):
# Create an instance of the class being tested
lst_algorithm = SplitWindowPriceLST()
# Assert that the maximum earth temperature is as expected
self.assertEqual(lst_algorithm.max_earth_temp, 273.15 + 56.7)

# Run the tests if this file is executed directly
if __name__ == "__main__":
unittest.main()

0 comments on commit 2c9f557

Please sign in to comment.