def test_albedo_separation(albedo, Rs_1, F, fc, aleafv, aleafn, aleafl, adeadv, adeadn, adeadl, zs, iterations, expected, tol=1E-10): output_images = tseb_utils.albedo_separation(ee.Image.constant(albedo), ee.Image.constant(Rs_1), ee.Image.constant(F), ee.Image.constant(fc), ee.Image.constant(aleafv), ee.Image.constant(aleafn), ee.Image.constant(aleafl), ee.Image.constant(adeadv), ee.Image.constant(adeadn), ee.Image.constant(adeadl), ee.Image.constant(zs), iterations) output = utils.constant_image_value( ee.Image(output_images).rename( ['Rs_c', 'Rs_s', 'albedo_c', 'albedo_s'])) for k in expected.keys(): logging.debug('\n {}'.format(k)) logging.debug(' Target values: {}'.format(expected[k])) logging.debug(' Output values: {}'.format(output[k])) assert abs(output[k] - expected[k]) <= tol
def test_compute_r_s(u_attr, T_s, T_c, hc, F, d0, z0m, leaf, leaf_s, fm_h, expected, tol=1E-10): output_image = tseb_utils.compute_r_s(ee.Image.constant(u_attr), ee.Image.constant(T_s), ee.Image.constant(T_c), ee.Image.constant(hc), ee.Image.constant(F), ee.Image.constant(d0), ee.Image.constant(z0m), ee.Image.constant(leaf), ee.Image.constant(leaf_s), ee.Image.constant(fm_h)) output = list(utils.constant_image_value(output_image).values())[0] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_emissivity(T_air, expected, tol=1E-8): output_image = tseb_utils.emissivity(ee.Image.constant(T_air)) output = list(utils.constant_image_value(output_image).values())[0] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_temp_separation_ts(T_c, fc_q, T_air, t0, expected, tol=1E-10): output_image = tseb_utils.temp_separation_ts(ee.Image.constant(T_c), ee.Image.constant(fc_q), ee.Image.constant(T_air), ee.Image.constant(t0)) output = list(utils.constant_image_value(output_image).values())[0] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_compute_r_ah(u_attr, d0, z0h, z_t, fh, expected, tol=1E-10): output_image = tseb_utils.compute_r_ah(ee.Image.constant(u_attr), ee.Image.constant(d0), ee.Image.constant(z0h), ee.Image.constant(z_t), ee.Image.constant(fh)) output = list(utils.constant_image_value(output_image).values())[0] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_compute_u_attr(u, d0, z0m, z_u, fm, expected, tol=1E-10): output_image = tseb_utils.compute_u_attr(ee.Image.constant(u), ee.Image.constant(d0), ee.Image.constant(z0m), ee.Image.constant(z_u), ee.Image.constant(fm)) output = list(utils.constant_image_value(output_image).values())[0] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_solar_zenith_constant(timestamp, xy, expected, tol=1E-10): """Check that the solar_zenith function also works for constant images""" output_images = tseb_utils.solar_zenith( date=ee.Date(timestamp), lon=ee.Image.constant(xy[0]).multiply(math.pi / 180), lat=ee.Image.constant(xy[1]).multiply(math.pi / 180)) output = utils.constant_image_value( ee.Image(output_images).rename(['vs']))['vs'] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_sunrise_sunset_constant(timestamp, xy, expected, tol=1E-10): """Check that the sunset_sunrise function works for constant images""" output_images = tseb_utils.sunrise_sunset( date=ee.Date(timestamp), lon=ee.Image.constant(xy[0]).multiply(math.pi / 180), lat=ee.Image.constant(xy[1]).multiply(math.pi / 180)) output = utils.constant_image_value(ee.Image(output_images) \ .rename(['t_rise', 't_end'])) for k in expected.keys(): logging.debug('\n {}'.format(k)) logging.debug(' Target values: {:.12f}'.format(expected[k])) logging.debug(' Output values: {:.12f}'.format(output[k])) assert abs(output[k] - expected[k]) <= tol
def test_compute_stability_fh(H, t0, u_attr, r_air, z_t, d0, expected, tol=1E-10): output_image = tseb_utils.compute_stability_fh(ee.Image.constant(H), ee.Image.constant(t0), ee.Image.constant(u_attr), ee.Image.constant(r_air), ee.Image.constant(z_t), ee.Image.constant(d0)) output = list(utils.constant_image_value(output_image).values())[0] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_compute_Rn_s(albedo_s, T_air, T_c, T_s, e_atm, Rs_s, F, expected, tol=1E-10): output_image = tseb_utils.compute_Rn_s(ee.Image.constant(albedo_s), ee.Image.constant(T_air), ee.Image.constant(T_c), ee.Image.constant(T_s), ee.Image.constant(e_atm), ee.Image.constant(Rs_s), ee.Image.constant(F)) output = list(utils.constant_image_value(output_image).values())[0] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_compute_G0(Rn, Rn_s, albedo, ndvi, t_rise, t_end, time, EF_s, expected, tol=1E-10): output_image = tseb_utils.compute_G0(ee.Image.constant(Rn), ee.Image.constant(Rn_s), ee.Image.constant(albedo), ee.Image.constant(ndvi), ee.Image.constant(t_rise), ee.Image.constant(t_end), ee.Image.constant(time), ee.Image.constant(EF_s)) output = list(utils.constant_image_value(output_image).values())[0] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_tseb_pt(T_air, T_rad, u, p, z, Rs_1, Rs24, vza, zs, aleafv, aleafn, aleafl, adeadv, adeadn, adeadl, albedo, ndvi, lai, clump, hc, time, t_rise, t_end, leaf_width, a_PT_in, iterations, expected, tol=1E-8): output_image = tseb.tseb_pt( ee.Image.constant(T_air), ee.Image.constant(T_rad), ee.Image.constant(u), ee.Image.constant(p), ee.Image.constant(z), ee.Image.constant(Rs_1), ee.Image.constant(Rs24), ee.Image.constant(vza), ee.Image.constant(zs), ee.Image.constant(aleafv), ee.Image.constant(aleafn), ee.Image.constant(aleafl), ee.Image.constant(adeadv), ee.Image.constant(adeadn), ee.Image.constant(adeadl), ee.Image.constant(albedo), ee.Image.constant(ndvi), ee.Image.constant(lai), ee.Image.constant(clump), ee.Image.constant(hc), ee.Image.constant(time), ee.Image.constant(t_rise), ee.Image.constant(t_end), ee.Image.constant(leaf_width), ee.Image.constant(a_PT_in), iterations) output = list(utils.constant_image_value(output_image).values())[0] logging.debug('\n Target values: {}'.format(expected)) logging.debug(' Output values: {}'.format(output)) assert abs(output - expected) <= tol
def test_constant_image_value(tol=0.000001): expected = 10.123456789 input = ee.Image.constant(expected) output = utils.constant_image_value(input)['constant'] assert abs(output - expected) <= tol
def test_Landsat_get_ndvi(red=0.2, nir=0.7, expected=0.5556, tol=0.001): input_img = ee.Image.constant([0.2, 0.2, red, nir, 0.2, 0.2, 300, 0]) \ .rename(['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B10', 'BQA']) \ .setMulti(l8_properties) ndvi = ee.Image(landsat.Landsat(input_img)._get_ndvi()) assert abs(utils.constant_image_value(ndvi)['ndvi'] - expected) <= tol