GSVSoil
1# coding: utf-8 2# GSV soil model: it simulates soil spectra from a few parameters 3# It is adpated from: Jiang, C., Fang, H., 2019. GSV: a general model for hyperspectral soil reflectance simulation. 4# Int. J. Appl. Earth Obs. Geoinformation 83, 101932. https://doi.org/10.1016/j.jag.2019.101932 5import numpy as np 6import os 7from typing import List, Union 8 9 10class GSVSoil(object): 11 """ 12 GSV soil model: it simulates soil spectra from a few parameters 13 It is adpated from: Jiang, C., Fang, H., 2019. GSV: a general model for hyperspectral soil reflectance simulation. 14 Int. J. Appl. Earth Obs. Geoinformation 83, 101932. https://doi.org/10.1016/j.jag.2019.101932. 15 Code example: 16 ``` 17 import matplotlib.pyplot as plt 18 gsv_model = GSVSoil() 19 for c1 in [0.3, 0.7]: 20 for c2 in [-0.1, 0]: 21 for c3 in [0, 0.05]: 22 for cSM in [-0.2, 0]: 23 spectra = gsv_model.get_soil_spectra_gsv3(np.arange(400, 2501, 10), 24 c1, c2, c3, cSM) 25 plt.plot(np.arange(400, 2501, 10), spectra) 26 plt.show() 27 ``` 28 """ 29 def __init__(self,): 30 curr_dir = os.path.split(os.path.realpath(__file__))[0] 31 self.__GSV = np.vstack([np.loadtxt(os.path.join(curr_dir, r'data/DryVec.txt')), 32 np.loadtxt(os.path.join(curr_dir, r'data/SMVec.txt'))]) 33 # self.__WVL = np.arange(400, 2501, 10) 34 35 def get_soil_spectra_gsv3(self, wavelength: Union[List[float], np.ndarray], 36 c1: float, 37 c2: float, 38 c3: float, 39 csm: float) -> List: 40 """ 41 Compute the soil reflectance with GSV soil model 42 :param wavelength: Wavelength for generating soil reflectance 43 :param c1: c1, c2, c3 are three coefficients to determine a dry soil spectrum,Usually, 44 c1 controls the brightness (not physically) of the soil, c2 and c3 control the shapes. 45 :param c2: 46 :param c3: 47 :param csm: csm determines a wet soil spectrum. They are combined to form a soil spectrum. Recommendation value 48 of csm is [-0.6, 0], 0 means no wet is considered, smaller value means more wet. 49 :return: a list with soil reflectance 50 """ 51 lower_bound = np.array(list(map(lambda x: int((x-400)/10), wavelength))) 52 upper_bound = lower_bound + 1 53 upper_bound[upper_bound >= 211] = 210 54 gsv = self.__GSV[:, lower_bound] 55 spec_lower = c1*gsv[0]+c2*gsv[1]+c3*gsv[2]+csm*gsv[3] 56 gsv = self.__GSV[:, upper_bound] 57 spec_upper = c1 * gsv[0] + c2 * gsv[1] + c3 * gsv[2] + csm * gsv[3] 58 spec = list(map(lambda lr, ur, wl, lb: lr+(ur-lr)/10*(wl-lb*10-400), spec_lower, spec_upper, 59 wavelength, lower_bound)) 60 return spec 61 62 def get_soil_spectra_gsv1(self, wavelength, c1, csm): 63 """ 64 Compute the soil reflectance with GSV soil model 65 :param wavelength: Wavelength for generating soil reflectance 66 :param c1: c1 the coefficient to determine a dry soil spectrum 67 :param csm: csm determines a wet soil spectrum. 68 :return: a list with soil reflectance 69 """ 70 lower_bound = np.array(list(map(lambda x: int((x - 400) / 10), wavelength))) 71 upper_bound = lower_bound + 1 72 upper_bound[upper_bound >= 211] = 210 73 gsv = self.__GSV[:, lower_bound] 74 spec_lower = c1 * gsv[0] + csm * gsv[3] 75 gsv = self.__GSV[:, upper_bound] 76 spec_upper = c1 * gsv[0] + csm * gsv[3] 77 spec = list( 78 map(lambda lr, ur, wl, lb: lr + (ur - lr) / 10 * (wl - lb * 10 - 400), spec_lower, spec_upper, wavelength, 79 lower_bound)) 80 return spec 81 82 83if __name__ == "__main__": 84 # spec = gsv.get_soil_spectra_gsv3(np.arange(400, 2501, 10), 0.4, -0.01, 0.04, -0.13) 85 # plt.plot(np.arange(400, 2501, 10), spec) 86 # plt.ylim([0,1]) 87 # plt.xlim([400, 2500]) 88 # plt.show() 89 import matplotlib.pyplot as plt 90 gsv_model = GSVSoil() 91 for c1 in [0.3, 0.7]: 92 for c2 in [-0.1, 0]: 93 for c3 in [0, 0.05]: 94 for cSM in [-0.2, 0]: 95 spectra = gsv_model.get_soil_spectra_gsv3(np.arange(400, 2501, 10), c1, c2, c3, cSM) 96 plt.plot(np.arange(400, 2501, 10), spectra) 97 plt.show()
class
GSVSoil:
11class GSVSoil(object): 12 """ 13 GSV soil model: it simulates soil spectra from a few parameters 14 It is adpated from: Jiang, C., Fang, H., 2019. GSV: a general model for hyperspectral soil reflectance simulation. 15 Int. J. Appl. Earth Obs. Geoinformation 83, 101932. https://doi.org/10.1016/j.jag.2019.101932. 16 Code example: 17 ``` 18 import matplotlib.pyplot as plt 19 gsv_model = GSVSoil() 20 for c1 in [0.3, 0.7]: 21 for c2 in [-0.1, 0]: 22 for c3 in [0, 0.05]: 23 for cSM in [-0.2, 0]: 24 spectra = gsv_model.get_soil_spectra_gsv3(np.arange(400, 2501, 10), 25 c1, c2, c3, cSM) 26 plt.plot(np.arange(400, 2501, 10), spectra) 27 plt.show() 28 ``` 29 """ 30 def __init__(self,): 31 curr_dir = os.path.split(os.path.realpath(__file__))[0] 32 self.__GSV = np.vstack([np.loadtxt(os.path.join(curr_dir, r'data/DryVec.txt')), 33 np.loadtxt(os.path.join(curr_dir, r'data/SMVec.txt'))]) 34 # self.__WVL = np.arange(400, 2501, 10) 35 36 def get_soil_spectra_gsv3(self, wavelength: Union[List[float], np.ndarray], 37 c1: float, 38 c2: float, 39 c3: float, 40 csm: float) -> List: 41 """ 42 Compute the soil reflectance with GSV soil model 43 :param wavelength: Wavelength for generating soil reflectance 44 :param c1: c1, c2, c3 are three coefficients to determine a dry soil spectrum,Usually, 45 c1 controls the brightness (not physically) of the soil, c2 and c3 control the shapes. 46 :param c2: 47 :param c3: 48 :param csm: csm determines a wet soil spectrum. They are combined to form a soil spectrum. Recommendation value 49 of csm is [-0.6, 0], 0 means no wet is considered, smaller value means more wet. 50 :return: a list with soil reflectance 51 """ 52 lower_bound = np.array(list(map(lambda x: int((x-400)/10), wavelength))) 53 upper_bound = lower_bound + 1 54 upper_bound[upper_bound >= 211] = 210 55 gsv = self.__GSV[:, lower_bound] 56 spec_lower = c1*gsv[0]+c2*gsv[1]+c3*gsv[2]+csm*gsv[3] 57 gsv = self.__GSV[:, upper_bound] 58 spec_upper = c1 * gsv[0] + c2 * gsv[1] + c3 * gsv[2] + csm * gsv[3] 59 spec = list(map(lambda lr, ur, wl, lb: lr+(ur-lr)/10*(wl-lb*10-400), spec_lower, spec_upper, 60 wavelength, lower_bound)) 61 return spec 62 63 def get_soil_spectra_gsv1(self, wavelength, c1, csm): 64 """ 65 Compute the soil reflectance with GSV soil model 66 :param wavelength: Wavelength for generating soil reflectance 67 :param c1: c1 the coefficient to determine a dry soil spectrum 68 :param csm: csm determines a wet soil spectrum. 69 :return: a list with soil reflectance 70 """ 71 lower_bound = np.array(list(map(lambda x: int((x - 400) / 10), wavelength))) 72 upper_bound = lower_bound + 1 73 upper_bound[upper_bound >= 211] = 210 74 gsv = self.__GSV[:, lower_bound] 75 spec_lower = c1 * gsv[0] + csm * gsv[3] 76 gsv = self.__GSV[:, upper_bound] 77 spec_upper = c1 * gsv[0] + csm * gsv[3] 78 spec = list( 79 map(lambda lr, ur, wl, lb: lr + (ur - lr) / 10 * (wl - lb * 10 - 400), spec_lower, spec_upper, wavelength, 80 lower_bound)) 81 return spec
GSV soil model: it simulates soil spectra from a few parameters It is adpated from: Jiang, C., Fang, H., 2019. GSV: a general model for hyperspectral soil reflectance simulation. Int. J. Appl. Earth Obs. Geoinformation 83, 101932. https://doi.org/10.1016/j.jag.2019.101932. Code example:
import matplotlib.pyplot as plt
gsv_model = GSVSoil()
for c1 in [0.3, 0.7]:
for c2 in [-0.1, 0]:
for c3 in [0, 0.05]:
for cSM in [-0.2, 0]:
spectra = gsv_model.get_soil_spectra_gsv3(np.arange(400, 2501, 10),
c1, c2, c3, cSM)
plt.plot(np.arange(400, 2501, 10), spectra)
plt.show()
def
get_soil_spectra_gsv3( self, wavelength: Union[List[float], numpy.ndarray], c1: float, c2: float, c3: float, csm: float) -> List:
36 def get_soil_spectra_gsv3(self, wavelength: Union[List[float], np.ndarray], 37 c1: float, 38 c2: float, 39 c3: float, 40 csm: float) -> List: 41 """ 42 Compute the soil reflectance with GSV soil model 43 :param wavelength: Wavelength for generating soil reflectance 44 :param c1: c1, c2, c3 are three coefficients to determine a dry soil spectrum,Usually, 45 c1 controls the brightness (not physically) of the soil, c2 and c3 control the shapes. 46 :param c2: 47 :param c3: 48 :param csm: csm determines a wet soil spectrum. They are combined to form a soil spectrum. Recommendation value 49 of csm is [-0.6, 0], 0 means no wet is considered, smaller value means more wet. 50 :return: a list with soil reflectance 51 """ 52 lower_bound = np.array(list(map(lambda x: int((x-400)/10), wavelength))) 53 upper_bound = lower_bound + 1 54 upper_bound[upper_bound >= 211] = 210 55 gsv = self.__GSV[:, lower_bound] 56 spec_lower = c1*gsv[0]+c2*gsv[1]+c3*gsv[2]+csm*gsv[3] 57 gsv = self.__GSV[:, upper_bound] 58 spec_upper = c1 * gsv[0] + c2 * gsv[1] + c3 * gsv[2] + csm * gsv[3] 59 spec = list(map(lambda lr, ur, wl, lb: lr+(ur-lr)/10*(wl-lb*10-400), spec_lower, spec_upper, 60 wavelength, lower_bound)) 61 return spec
Compute the soil reflectance with GSV soil model
Parameters
- wavelength: Wavelength for generating soil reflectance
- c1: c1, c2, c3 are three coefficients to determine a dry soil spectrum,Usually, c1 controls the brightness (not physically) of the soil, c2 and c3 control the shapes.
- c2:
- c3:
- csm: csm determines a wet soil spectrum. They are combined to form a soil spectrum. Recommendation value of csm is [-0.6, 0], 0 means no wet is considered, smaller value means more wet.
Returns
a list with soil reflectance
def
get_soil_spectra_gsv1(self, wavelength, c1, csm):
63 def get_soil_spectra_gsv1(self, wavelength, c1, csm): 64 """ 65 Compute the soil reflectance with GSV soil model 66 :param wavelength: Wavelength for generating soil reflectance 67 :param c1: c1 the coefficient to determine a dry soil spectrum 68 :param csm: csm determines a wet soil spectrum. 69 :return: a list with soil reflectance 70 """ 71 lower_bound = np.array(list(map(lambda x: int((x - 400) / 10), wavelength))) 72 upper_bound = lower_bound + 1 73 upper_bound[upper_bound >= 211] = 210 74 gsv = self.__GSV[:, lower_bound] 75 spec_lower = c1 * gsv[0] + csm * gsv[3] 76 gsv = self.__GSV[:, upper_bound] 77 spec_upper = c1 * gsv[0] + csm * gsv[3] 78 spec = list( 79 map(lambda lr, ur, wl, lb: lr + (ur - lr) / 10 * (wl - lb * 10 - 400), spec_lower, spec_upper, wavelength, 80 lower_bound)) 81 return spec
Compute the soil reflectance with GSV soil model
Parameters
- wavelength: Wavelength for generating soil reflectance
- c1: c1 the coefficient to determine a dry soil spectrum
- csm: csm determines a wet soil spectrum.
Returns
a list with soil reflectance