def test_utci_raises(): with pytest.raises(ValueError): universal_thermal_climate_index( { "tas": np.array([295, 296]), "sfcWind": np.array([6.0, 6.0]), "hurs": np.array([100, 100]), "huss": np.array([0.006, 0.006]), }, np.array([303, 304]), ) with pytest.raises(ValueError): universal_thermal_climate_index({}, np.array([303, 304]))
def test_utci_array(): EXPECTED_RESULT = 273.15 + np.array([19.60850656, 21.2151128]) TEST_RESULT = universal_thermal_climate_index( { "tas": np.array([295, 296]), "sfcWind": np.array([6.0, 6.0]), "hurs": np.array([100, 100]), }, np.array([303, 304]), ) assert np.allclose(TEST_RESULT, EXPECTED_RESULT)
def test_utci_huss(): EXPECTED_RESULT = 273.15 + np.array([19.81876334, 20.98888025]) TEST_RESULT = universal_thermal_climate_index( { "tas": np.array([295, 296]), "sfcWind": np.array([6.0, 6.0]), "huss": np.array([0.0167, 0.0167]), # approx 100% RH at 295K, 1000hPa }, np.array([303, 304]), ) assert np.allclose(TEST_RESULT, EXPECTED_RESULT)
def test_utci_huss_ps(): EXPECTED_RESULT = 273.15 + np.array([17.86596553, 17.84009998]) TEST_RESULT = universal_thermal_climate_index( { "tas": np.array([295, 296]), "sfcWind": np.array([6.0, 6.0]), "huss": np.array([0.012, 0.010]), "ps": np.array([96000, 75000]), }, np.array([303, 304]), ) assert np.allclose(TEST_RESULT, EXPECTED_RESULT)
def test_integration_array(): EXPECTED_RESULT = 273.15 + np.array([22.32159032, 18.02267449]) mrt = mean_radiant_temperature( { "rlds": np.array([150, 50]), "rlus": np.array([350, 150]), "rsdsdiff": np.array([400, 200]), "rsus": np.array([100, 50]), "rsds": np.array([700, 400]), }, cos_zenith=np.array([0.5, 0.2]), lit=np.array([1, 1]), ) TEST_RESULT = universal_thermal_climate_index( { "tas": np.array([295, 296]), "sfcWind": np.array([6.0, 6.0]), "hurs": np.array([100, 100]), }, mrt, ) assert np.allclose(TEST_RESULT, EXPECTED_RESULT)
emissivity=0.97, cos_zenith=mean_cosz, lit=lit ) # regrid wind to temperature grid # don't think area-weighting makes sense, use bi-linear uas_cube_regrid = uas_cube.regrid(tas_cube, iris.analysis.Linear()) vas_cube_regrid = vas_cube.regrid(tas_cube, iris.analysis.Linear()) wind = np.sqrt(uas_cube_regrid.data**2 + vas_cube_regrid.data**2) # calculate UTCI utci = universal_thermal_climate_index( { "tas": tas_cube.data, "sfcWind": wind, "huss": huss_cube.data }, mrt ) # make cubes out of output (only UTCI to save space and time) utci_cube = iris.cube.Cube( utci, units='K', var_name='utci', long_name='Universal Thermal Climate Index', dim_coords_and_dims=[ (tas_cube.coord('time'), 0), (tas_cube.coord('latitude'), 1), (tas_cube.coord('longitude'), 2) ]