diff --git a/openet/ptjpl/image.py b/openet/ptjpl/image.py index 300cebf..e297eb5 100644 --- a/openet/ptjpl/image.py +++ b/openet/ptjpl/image.py @@ -934,18 +934,24 @@ def from_landsat_c2_sr(cls, sr_image, cloudmask_args={}, **kwargs): # Rename bands to generic names input_bands = ee.Dictionary({ - 'LANDSAT_4': ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B7', 'ST_B6', 'QA_PIXEL'], - 'LANDSAT_5': ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B7', 'ST_B6', 'QA_PIXEL'], - 'LANDSAT_7': ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B7', 'ST_B6', 'QA_PIXEL'], - 'LANDSAT_8': ['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', 'ST_B10', 'QA_PIXEL'], - 'LANDSAT_9': ['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', 'ST_B10', 'QA_PIXEL'], + 'LANDSAT_4': ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B7', + 'ST_B6', 'QA_PIXEL', 'QA_RADSAT'], + 'LANDSAT_5': ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B7', + 'ST_B6', 'QA_PIXEL', 'QA_RADSAT'], + 'LANDSAT_7': ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B7', + 'ST_B6', 'QA_PIXEL', 'QA_RADSAT'], + 'LANDSAT_8': ['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', + 'ST_B10', 'QA_PIXEL', 'QA_RADSAT'], + 'LANDSAT_9': ['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', + 'ST_B10', 'QA_PIXEL', 'QA_RADSAT'], }) - output_bands = ['blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'tir', 'QA_PIXEL'] + output_bands = ['blue', 'green', 'red', 'nir', 'swir1', 'swir2', + 'lst', 'QA_PIXEL', 'QA_RADSAT'] prep_image = ( sr_image.select(input_bands.get(spacecraft_id), output_bands) - .multiply([0.0000275, 0.0000275, 0.0000275, 0.0000275, 0.0000275, 0.0000275, 0.00341802, 1]) - .add([-0.2, -0.2, -0.2, -0.2, -0.2, -0.2, 149.0, 0]) + .multiply([0.0000275, 0.0000275, 0.0000275, 0.0000275, 0.0000275, 0.0000275, 0.00341802, 1, 1]) + .add([-0.2, -0.2, -0.2, -0.2, -0.2, -0.2, 149.0, 0, 0]) ) # Default the cloudmask flags to True if they were not @@ -964,9 +970,8 @@ def from_landsat_c2_sr(cls, sr_image, cloudmask_args={}, **kwargs): cloudmask_args['cloud_score_pct'] = 100 if 'filter_flag' not in cloudmask_args.keys(): cloudmask_args['filter_flag'] = False - # QA_RADSAT band will need to be added above if applying saturated masking - # if 'saturated_flag' not in cloudmask_args.keys(): - # cloudmask_args['saturated_flag'] = False + if 'saturated_flag' not in cloudmask_args.keys(): + cloudmask_args['saturated_flag'] = False cloud_mask = openet.core.common.landsat_c2_sr_cloud_mask(sr_image, **cloudmask_args) @@ -981,7 +986,7 @@ def from_landsat_c2_sr(cls, sr_image, cloudmask_args={}, **kwargs): if c2_lst_correct: lst = openet.core.common.landsat_c2_sr_lst_correct(sr_image, landsat.ndvi(prep_image)) else: - lst = prep_image.select(['tir']) + lst = prep_image.select(['lst']) # Build the input image input_image = ee.Image([ diff --git a/openet/ptjpl/tests/test_a_utils.py b/openet/ptjpl/tests/test_a_utils.py index 6533630..719a2c0 100644 --- a/openet/ptjpl/tests/test_a_utils.py +++ b/openet/ptjpl/tests/test_a_utils.py @@ -18,29 +18,34 @@ def test_constant_image_value(expected=10.123456789, tol=0.000001): @pytest.mark.parametrize( 'image_id, xy, scale, expected, tol', [ - ['USGS/NED', [-106.03249, 37.17777], 10, 2364.351, 0.001], - ['USGS/NED', [-106.03249, 37.17777], 1, 2364.351, 0.001], + ['USGS/3DEP/10m', [-106.03249, 37.17777], 30, 2364.169, 0.001], + ['USGS/3DEP/10m', [-106.03249, 37.17777], 10, 2364.138, 0.001], + ['USGS/3DEP/10m', [-106.03249, 37.17777], 1, 2364.138, 0.001], + ['NASA/NASADEM_HGT/001', [-106.03249, 37.17777], 30, 2361, 0.001], ] ) def test_point_image_value(image_id, xy, scale, expected, tol): - output = utils.point_image_value(ee.Image(image_id).rename('output'), xy) + output = utils.point_image_value( + ee.Image(image_id).select(['elevation'], ['output']), xy, scale + ) assert abs(output['output'] - expected) <= tol @pytest.mark.parametrize( 'image_id, image_date, xy, scale, expected, tol', [ - # CGM - This test stopped working for a scale of 1 and returns a different - # value for a scale of 10 than the point_image_value() function above. - # This function uses getRegion() instead of a reduceRegion() call, - # so there might have been some sort of change in getRegion(). - ['USGS/NED', '2012-04-04', [-106.03249, 37.17777], 10, 2364.286, 0.001], - # CGM - The default scale of 1 now returns None/Null for some reason - # ['USGS/NED', '2012-04-04', [-106.03249, 37.17777], 1, 2364.351, 0.001], + ['USGS/3DEP/10m', '2012-04-04', [-106.03249, 37.17777], 30, 2364.169, 0.001], + ['USGS/3DEP/10m', '2012-04-04', [-106.03249, 37.17777], 10, 2364.097, 0.001], + ['USGS/3DEP/10m', '2012-04-04', [-106.03249, 37.17777], 1, 2364.138, 0.001], + ['NASA/NASADEM_HGT/001', '2012-04-04', [-106.03249, 37.17777], 30, 2361, 0.001], ] ) def test_point_coll_value(image_id, image_date, xy, scale, expected, tol): - input_img = ee.Image(image_id).rename(['output']) + # The image must have a system:time_start for this function to work correctly + input_img = ( + ee.Image(image_id).select(['elevation'], ['output']) + .set({'system:time_start': ee.Date(image_date).millis()}) + ) output = utils.point_coll_value(ee.ImageCollection([input_img]), xy, scale) assert abs(output['output'][image_date] - expected) <= tol diff --git a/openet/ptjpl/tests/test_d_image.py b/openet/ptjpl/tests/test_d_image.py index 6c37ef1..007c3fc 100644 --- a/openet/ptjpl/tests/test_d_image.py +++ b/openet/ptjpl/tests/test_d_image.py @@ -651,8 +651,9 @@ def test_Image_from_landsat_c2_sr_scaling(): """Test if Landsat SR images images are being scaled""" sr_img = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044033_20170716') input_img = ( - ee.Image.constant([10909, 10909, 10909, 10909, 10909, 10909, 44177.6, 21824]) - .rename(['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', 'ST_B10', 'QA_PIXEL']) + ee.Image.constant([10909, 10909, 10909, 10909, 10909, 10909, 44177.6, 21824, 0]) + .rename(['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', + 'ST_B10', 'QA_PIXEL', 'QA_RADSAT']) .set({'SPACECRAFT_ID': ee.String(sr_img.get('SPACECRAFT_ID')), 'system:id': ee.String(sr_img.get('system:id')), 'system:index': ee.String(sr_img.get('system:index')), diff --git a/pyproject.toml b/pyproject.toml index d5dd65e..2be922d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openet-ptjpl" -version = "0.3.0" +version = "0.3.1" authors = [ { name = "Gregory Halverson", email = "Gregory.H.Halverson@jpl.nasa.gov" }, { name = "Josh Fisher", email = "joshbfisher@gmail.com" }, @@ -20,9 +20,9 @@ classifiers = [ "Operating System :: OS Independent", ] dependencies = [ - "earthengine-api>=0.1.367", - "openet-core>=0.4.0", - # "openet-refet-gee>=0.2.0", + "earthengine-api >= 0.1.367", + "openet-core >= 0.4.0", + # "openet-refet-gee >= 0.2.0", "python-dateutil", ]