Regarding parsing the BSDF

I was writing the python code to parse the BSDF. I read the btdf valuse from the xml file (Klems), then use the btdf values to multiply the solid angles, Finally I sum the values for all outgoing patches at each incident angles to get 145 hemisphere transimissions.

However, the derived hemiphere transimissions have some small deviations with the values displayed on BSDFViewer. I don’t know what caused these deviations, any insights?

I don’t confirm that the solid angles formula I used is corrected, below is my python code for calculating the solid angles.

def solidAngleCalc(patchnum):
    phiRange = [np.array([0,5]),np.array([5,15]),np.array([15,25]),
                np.array([25,35]),np.array([35,45]),np.array([45,55]),
                np.array([55,65]),np.array([65,75]),np.array([75,90])]  
    subdivs = [1,8,16,20,24,24,24,16,12]
    sum = 0
    i = 0
    for i in range(len(subdivs)):
        sum += subdivs[i]
        if(sum >= patchnum):
            break
    owega = 0
    Radtheta = math.radians(phiRange[i][0])
    Radtheta1 = math.radians(phiRange[i][1])
    owega = math.pi*(math.cos(Radtheta)**2-math.cos(Radtheta1)**2)/subdivs[i]
    return owega

Below is my code for reading the btdf and brdf values from xml file:

def PraseBSDF(file):
    DOMTree = xml.dom.minidom.parse(file)
    collection = DOMTree.documentElement
    waves = collection.getElementsByTagName("WavelengthData")
    btdf = None
    brdf = None
    for record in waves:
        wavelength = record.getElementsByTagName('Wavelength')[0].firstChild.data
        block = record.getElementsByTagName('WavelengthDataBlock')[0]
        scatterData = block.getElementsByTagName("ScatteringData")
        data = str.strip(scatterData[0].childNodes[0].data)        
        values = data.split(',')      
        elements = []
        
        for value in values:
            if value is not None and value !='':
                elements.append(float(str.strip(value)))    
        Type = record.getElementsByTagName("WavelengthDataDirection")
        if "Transmission Front" in Type[0].childNodes[0].data and wavelength=='Solar':
            btdf = np.array(elements)
            btdf = btdf.reshape(145,145)
        if "Reflection Front" in Type[0].childNodes[0].data and wavelength=='Solar':
            brdf = np.array(elements)
            brdf = brdf.reshape(145,145)
    return btdf, brdf

Below is for transmissions calculation:

def solidAngleVector():
    solidAngles = []
    for i in range(1,146):
        solidAngles.append(solidAngleCalc(i))
    return np.array(solidAngles).reshape(1,-1)
solidAngles = solidAngleVector()  
Trans = np.multiply(solidAngles,btdf)
Refs = np.multiply(solidAngles,brdf)
hemisphereTrans= np.sum(Trans,axis = 0)
hemisphereRefls = np.sum(Refs, axis = 0)

Below is the result comparison: