Skip to content

Commit

Permalink
Couple more fixes for some failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cgmorton committed Feb 17, 2024
1 parent 9d5ea23 commit b006ec2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
12 changes: 4 additions & 8 deletions openet/sims/tests/test_b_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,17 @@ def test_Model_crop_type_source_cdl_image():
def test_Model_crop_type_source_cdl_image_exception():
"""Requesting a CDL image that doesn't exist should raise an EE exception"""
with pytest.raises(Exception):
utils.getinfo(default_model_obj(crop_type_source='USDA/NASS/CDL/2099'))
# CGM - The exception is raised in the _crop_type() method which is
# in the init. If crop_type is a lazy property then it is necessary
# to request the property in order to raise the exception.
# utils.getinfo(default_model_obj(
# crop_type_source='USDA/NASS/CDL/2099').crop_type)
# Intentionally using .getInfo() since utils.getinfo() might catch the exception
default_model_obj(crop_type_source='USDA/NASS/CDL/2099').crop_type.getInfo()


@pytest.mark.parametrize(
'crop_type_source',
[
'projects/openet/assets/crop_type/v2023a',
'projects/openet/assets/crop_type/v2021a',
'projects/openet/crop_type/v2021a',
'projects/earthengine-legacy/assets/projects/openet/crop_type/v2021a',
# 'projects/openet/crop_type/v2021a',
# 'projects/earthengine-legacy/assets/projects/openet/crop_type/v2021a',
]
)
def test_Model_crop_type_source_openet_crop_type(crop_type_source):
Expand Down
6 changes: 3 additions & 3 deletions openet/sims/tests/test_c_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ def test_Image_from_landsat_c2_sr_kc():

def test_Image_from_landsat_c2_sr_et():
"""Test if ET can be built from a Landsat images"""
image_id = 'LANDSAT/LC08/C02/T1_L2/LC08_044033_20170716'
output = utils.getinfo(sims.Image.from_landsat_c2_sr(
'LANDSAT/LC08/C02/T1_L2/LC08_044033_20170716',
et_reference_source='IDAHO_EPSCOR/GRIDMET', et_reference_band='etr').et)
image_id, et_reference_source='IDAHO_EPSCOR/GRIDMET', et_reference_band='etr').et)
assert output['properties']['system:index'] == image_id.split('/')[-1]


Expand All @@ -410,7 +410,7 @@ def test_Image_from_landsat_c2_sr_scaling():
'system:index': ee.String(sr_img.get('system:index')),
'system:time_start': ee.Number(sr_img.get('system:time_start'))})
)
# cloud score masking do not work with a constant image
# cloud score masking and filter_flag option do not work with a constant image
# and must be explicitly set to False
output = utils.constant_image_value(sims.Image.from_landsat_c2_sr(
input_img, cloudmask_args={'cloud_score_flag': False, 'filter_flag': False}).ndvi)
Expand Down
14 changes: 8 additions & 6 deletions openet/sims/tests/test_d_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def scene_coll(variables, et_fraction=[0.4, 0.4, 0.4], et=[5, 5, 5], ndvi=[0.6,
ee.ImageCollection
"""
img = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044033_20170716') \
img = (
ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044033_20170716')
.select(['B2']).double().multiply(0)
)
mask = img.add(1).updateMask(1).uint8()

# The time band needs to be the 0 UTC time (date)
Expand Down Expand Up @@ -68,7 +70,7 @@ def test_from_scene_et_fraction_daily_values(tol=0.0001):
)

TEST_POINT = (-121.5265, 38.7399)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=10)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=30)
assert abs(output['ndvi']['2017-07-01'] - 0.2) <= tol
assert abs(output['ndvi']['2017-07-08'] - 0.2) <= tol
assert abs(output['ndvi']['2017-07-10'] - 0.25) <= tol
Expand Down Expand Up @@ -99,7 +101,7 @@ def test_from_scene_et_fraction_monthly_values(tol=0.0001):
)

TEST_POINT = (-121.5265, 38.7399)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=10)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=30)
assert abs(output['ndvi']['2017-07-01'] - 0.6) <= tol
assert abs(output['et_fraction']['2017-07-01'] - 0.4) <= tol
assert abs(output['et_reference']['2017-07-01'] - 236.5) <= tol
Expand All @@ -121,7 +123,7 @@ def test_from_scene_et_fraction_custom_values(tol=0.0001):
)

TEST_POINT = (-121.5265, 38.7399)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=10)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=30)
assert abs(output['ndvi']['2017-07-01'] - 0.6) <= tol
assert abs(output['et_fraction']['2017-07-01'] - 0.4) <= tol
assert abs(output['et_reference']['2017-07-01'] - 236.5) <= tol
Expand All @@ -143,7 +145,7 @@ def test_from_scene_et_fraction_monthly_et_reference_factor(tol=0.0001):
)

TEST_POINT = (-121.5265, 38.7399)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=10)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=30)
assert abs(output['ndvi']['2017-07-01'] - 0.6) <= tol
assert abs(output['et_fraction']['2017-07-01'] - 0.4) <= tol
assert abs(output['et_reference']['2017-07-01'] - 236.5 * 0.5) <= tol
Expand All @@ -166,7 +168,7 @@ def test_from_scene_et_fraction_monthly_et_reference_resample(tol=0.0001):
)

TEST_POINT = (-121.5265, 38.7399)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=10)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=30)
assert abs(output['ndvi']['2017-07-01'] - 0.6) <= tol
assert abs(output['et_fraction']['2017-07-01'] - 0.4) <= tol
assert abs(output['et_reference']['2017-07-01'] - 236.5) <= tol
Expand Down
3 changes: 3 additions & 0 deletions openet/sims/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def getinfo(ee_obj, n=4):
# sleep(i ** 2)
# else:
# raise e
except Exception as e:
logging.info(e)
break

if output:
break
Expand Down

0 comments on commit b006ec2

Please sign in to comment.