Skip to content
Snippets Groups Projects
tests.py 4.61 KiB
Newer Older
    radshape = rad.shape
    rad = rad.reshape(np.prod(radshape))

    thr = np.array(threshold['bt11'])
    confidence = np.zeros(rad.shape)

    if thr[4] == 1:
        # the C code has the line below that I don't quite understand the purpose of.
        # It seems to be setting the bit to 0 if the BT value is greater than the midpoint
        #
        # if (m31 >= dobt11[1]) (void) set_bit(13, pxout.testbits);

        #confidence = utils.conf_test(rad, thr)
        confidence = conf.conf_test(rad, thr)

    return confidence.reshape(radshape)
def test_11_4diff(rad1, rad2, threshold, viirs_data, sg_thresh):
    radshape = rad1.shape
    raddiff = (rad1 - rad2).reshape(np.prod(radshape))
    day = np.zeros(radshape)
    day[viirs_data.solar_zenith <= 85] = 1
    day = day.reshape(raddiff.shape)
    sunglint = np.zeros(rad1.shape)
    sunglint[viirs_data.sunglint_angle <= sg_thresh] = 1
    sunglint = sunglint.reshape(raddiff.shape)
    thr = threshold['test11_4lo']
    confidence[(day == 1) & (sunglint == 0)] = utils.conf_test(raddiff[(day == 1) & (sunglint == 0)], thr)
def nir_refl_test(rad, threshold, sunglint_thresholds, viirs_data):
    sza = viirs_data.solar_zenith.values
    refang = viirs_data.sunglint_angle.values
    vza = viirs_data.sensor_zenith.values
    dtr = np.pi/180
    # Keep in mind that band_n uses MODIS band numbers (i.e. 2=0.86um and 7=2.1um)
    # For VIIRS would be 2=M07 (0.865um) and 7=M11 (2.25um)
    vzcpow = 0.75  # THIS NEEDS TO BE READ FROM THE THRESHOLDS FILE

    radshape = rad.shape
    rad = rad.reshape(np.prod(radshape))
    confidence = np.zeros(rad.shape)
    sza = sza.reshape(rad.shape)
    vza = vza.reshape(rad.shape)
    refang = refang.reshape(rad.shape)
    sunglint_flag = utils.sunglint_scene(refang, sunglint_thresholds).reshape(rad.shape)

    # ref2 [5]
    # b2coeffs [4]
    # b2mid [1]
    # b2bias_adj [1]
    # b2lo [1]
    # vzcpow [3] (in different place)

    coeffs = threshold['b2coeffs']
    hicut0 = np.array(coeffs[0] + coeffs[1]*sza + coeffs[2]*np.power(sza, 2) + coeffs[3]*np.power(sza, 3))
    hicut0 = (hicut0 * 0.01) + threshold['b2adj']
    hicut0 = hicut0 * threshold['b2bias_adj']
    midpt0 = hicut0 + (threshold['b2mid'] * threshold['b2bias_adj'])
    locut0 = midpt0 + (threshold['b2lo'] * threshold['b2bias_adj'])
    thr = np.array([locut0, midpt0, hicut0, threshold['ref2'][3]*np.ones(rad.shape)])
    print(thr.shape)
    # corr_thr = np.zeros((4, 4))
    corr_thr = np.zeros((4, rad.shape[0]))

    corr_thr[:3, sunglint_flag == 0] = thr[:3, sunglint_flag == 0] * (1./np.power(cosvza[sunglint_flag == 0], vzcpow))
    corr_thr[3, sunglint_flag == 0] = thr[3, sunglint_flag == 0]

#    for flag in range(1, 4):
#        sunglint_thr = utils.get_sunglint_thresholds(refang, sunglint_thresholds, band_n, flag, thr)
#        corr_thr[:3, sunglint_flag == flag] = sunglint_thr[:3, :] * (1./np.power(cosvza, vzcpow[0]))
#        corr_thr[3, sunglint_flag == flag] = sunglint_thr[3, :]
        # corr_thr[flag, :3] = sunglint_thr[:3] * (1./np.power(cosvza, vzcpow[0]))

    confidence = conf.conf_test(rad, corr_thr)
    #confidence[sunglint_flag == 1] = utils.conf_test(rad[sunglint_flag == 1], corr_thr[1, :])
    #confidence[sunglint_flag == 2] = utils.conf_test(rad[sunglint_flag == 2], corr_thr[2, :])
    #confidence[sunglint_flag == 3] = utils.conf_test(rad[sunglint_flag == 3], corr_thr[3, :])
    #confidence[sunglint_flag == 0] = utils.conf_test(rad[sunglint_flag == 0], corr_thr[0, :])

    #for flag in range(1, 4):
    #    sunglint_thr = utils.get_sunglint_thresholds(refang, sunglint_thresholds, band_n, flag, thr)
    #    pass

    return confidence.reshape(radshape)
def vis_nir_ratio_test(rad1, rad2, threshold):
    pass


class CloudMaskTests(object):

    def __init__(self, scene, radiance, coefficients):
        self.scene = scene
        self.coefficients = coefficients

    def select_coefficients(self):
        pass

    def test_G1(self):
        pass

    def test_G2(self):
        pass

    def test_G3(self):
        pass

    def test_G4(self):
        pass

    def overall_confidence(self):
        pass


def test():
    rad = np.random.randint(50, size=[4, 8])
    # coeffs = [5, 42, 20, 28, 15, 35, 1]
    # coeffs = [20, 28, 5, 42, 15, 35, 1]
    coeffs = [35, 15, 20, 1, 1]
    # confidence = conf_test_dble(rad, coeffs)
    confidence = test_11um(rad, coeffs)
    print(rad)
    print('\n')
    print(confidence)


if __name__ == "__main__":
    test()