def test_refet_hourly_func_output(hourly_params): """Test hourly RefET calculation at a single point and time""" # If I don't copy, the pop changes the test values in hourly_data() inputs = hourly_params.copy() surface = inputs.pop('surface') expected = inputs.pop('expected') print('ETr: {}'.format(expected)) # Cast all numeric inputs to ee.Number type except tmean (for now) adj_inputs = {} for k, v in inputs.items(): if k == 'rso_type': adj_inputs[k] = v elif k == 'tmean': adj_inputs[k] = ee.Image.constant(v) else: adj_inputs[k] = ee.Number(v) if surface.lower() == 'etr': refet = Hourly(**adj_inputs).etr() elif surface.lower() == 'eto': refet = Hourly(**adj_inputs).eto() output = refet\ .reduceRegion(ee.Reducer.first(), geometry=constant_geom, scale=1)\ .getInfo() assert float(output[surface.lower()]) == pytest.approx(expected, abs=0.01)
def test_refet_hourly_default_method_etr(): refet = Hourly(tmean=ee.Image.constant(h_args['tmean']), ea=ee.Image.constant(h_args['ea']), rs=ee.Image.constant(h_args['rs']), uz=ee.Image.constant(h_args['uz']), zw=ee.Image.constant(s_args['zw']), elev=ee.Number(s_args['elev']), lat=ee.Number(s_args['lat']), lon=ee.Number(s_args['lon']), doy=ee.Number(h_args['doy']), time=ee.Number(h_args['time'])) output = refet.etr()\ .reduceRegion(ee.Reducer.first(), geometry=constant_geom, scale=1)\ .getInfo() assert float(output['etr']) == pytest.approx(h_args['etr_asce'])
def test_refet_hourly_input_positions(): refet = Hourly(ee.Image.constant(h_args['tmean']), ee.Image.constant(h_args['ea']), ee.Image.constant(h_args['rs']), ee.Image.constant(h_args['uz']), ee.Image.constant(s_args['zw']), ee.Number(s_args['elev']), ee.Number(s_args['lat']), ee.Number(s_args['lon']), ee.Number(h_args['doy']), ee.Number(h_args['time']), method='refet') output = refet.etr()\ .reduceRegion(ee.Reducer.first(), geometry=constant_geom, scale=1)\ .getInfo() assert float(output['etr']) == pytest.approx(h_args['etr_refet'])
def test_refet_daily_etsz(surface, expected): refet = Hourly(tmean=ee.Image.constant(h_args['tmean']), ea=ee.Image.constant(h_args['ea']), rs=ee.Image.constant(h_args['rs']), uz=ee.Image.constant(h_args['uz']), zw=ee.Image.constant(s_args['zw']), elev=ee.Number(s_args['elev']), lat=ee.Number(s_args['lat']), lon=ee.Number(s_args['lon']), doy=ee.Number(h_args['doy']), time=ee.Number(h_args['time']), method='refet') output = refet.etsz(surface).rename(['etsz']).reduceRegion( reducer=ee.Reducer.first(), geometry=ee.Geometry.Rectangle([0, 0, 10, 10], 'EPSG:32613', False), scale=1).getInfo() assert float(output['etsz']) == pytest.approx(expected)
def test_refet_hourly_nldas_etr(): """Generate a fake NLDAS image from the test values""" nldas_time = ee.Date('2015-07-01T{}:00:00'.format(int(h_args['time'])), 'UTC').millis() wind_u = h_args['uz'] / (2**0.5) nldas_img = ee.Image.constant([ h_args['tmean'], h_args['q_asce'], h_args['rs'] / 0.0036, wind_u, wind_u])\ .rename(['temperature', 'specific_humidity', 'shortwave_radiation', 'wind_u', 'wind_v'])\ .set('system:time_start', nldas_time) refet = Hourly.nldas(ee.Image(nldas_img), elev=ee.Number(s_args['elev']), lat=ee.Number(s_args['lat']), lon=ee.Number(s_args['lon']), zw=ee.Number(s_args['zw']), method='asce') output = refet.etr()\ .reduceRegion(ee.Reducer.first(), geometry=constant_geom, scale=1)\ .getInfo() assert float(output['etr']) == pytest.approx(h_args['etr_asce'])