Skip to content

Commit

Permalink
Fixes to address extent/clipping issues in lst correction images
Browse files Browse the repository at this point in the history
Removed emissivity soil clipping call.
Removed pass image to .unmask() call.
Simplified and restructured the get matched functions.
Removed some old unused code.
Started updating function docstring.
Changed output band name to just "lst".
  • Loading branch information
cgmorton committed Mar 9, 2024
1 parent b5ca169 commit 147dae5
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 147 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Development and Testing

Please see the `CONTRIBUTING.rst <CONTRIBUTING.rst>`__.

.. |build| image:: https://github.com/Open-ET/openet-core/workflows/build/badge.svg
.. |build| image:: https://github.com/Open-ET/openet-core/actions/workflows/test.yml/badge.svg
:alt: Build status
:target: https://github.com/Open-ET/openet-core
.. |version| image:: https://badge.fury.io/py/openet-core.svg
Expand Down
300 changes: 174 additions & 126 deletions openet/core/common.py

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions openet/core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ def test_init():
EE_KEY_FILE = 'privatekey.json'
with open(EE_KEY_FILE, 'w') as f:
f.write(content)
ee.Initialize(ee.ServiceAccountCredentials('test', key_file=EE_KEY_FILE))
ee.Initialize(ee.ServiceAccountCredentials('', key_file=EE_KEY_FILE))
else:
ee.Initialize()

# Make a simple EE request
# logging.debug(ee.Number(1).getInfo())
30 changes: 20 additions & 10 deletions openet/core/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_landsat_c2_sr_lst_correct():
ndvi_img = sr_img.multiply(0.0000275).add(-0.2).normalizedDifference(['SR_B5', 'SR_B4'])
output_img = common.landsat_c2_sr_lst_correct(sr_img, ndvi_img)
output = utils.get_info(output_img)
assert output['bands'][0]['id'] == 'surface_temperature'
assert output['bands'][0]['id'] == 'lst'


def test_landsat_c2_sr_lst_parameter_keywords():
Expand All @@ -132,31 +132,41 @@ def test_landsat_c2_sr_lst_parameter_keywords():
ndvi_img = sr_img.multiply(0.0000275).add(-0.2).normalizedDifference(['SR_B5', 'SR_B4'])
output_img = common.landsat_c2_sr_lst_correct(ndvi=ndvi_img, sr_image=sr_img)
output = utils.get_info(output_img)
assert output['bands'][0]['id'] == 'surface_temperature'
assert output['bands'][0]['id'] == 'lst'


# TODO: Consider reworking this test to compare the before and after value
# instead of testing the values themselves
@pytest.mark.parametrize(
"image_id, xy, expected",
"image_id, xy, expected, uncorrected",
[
# First two points are in the same field but the second one is in an
# area of bad emissivity data and needs correction
['LANDSAT/LC08/C02/T1_L2/LC08_030036_20210725', [-102.266679, 34.368470], 309.95],
['LANDSAT/LC08/C02/T1_L2/LC08_030036_20210725', [-102.266754, 34.367682], 309.93],
['LANDSAT/LC08/C02/T1_L2/LC08_030036_20210725', [-102.266679, 34.368470], 309.95, 310.0],
['LANDSAT/LC08/C02/T1_L2/LC08_030036_20210725', [-102.266754, 34.367682], 309.93, 312.1],
# This point is just outside the field and should stay the same
['LANDSAT/LC08/C02/T1_L2/LC08_030036_20210725', [-102.269769, 34.366115], 318.10],
['LANDSAT/LC08/C02/T1_L2/LC08_030036_20210725', [-102.269769, 34.366115], 317.75, 318.1],
# These two points are in the ASTER GED hole and have no L2 temperature
# The first his a high NDVI field, the second is a low NDVI field
['LANDSAT/LC08/C02/T1_L2/LC08_031034_20160702', [-102.08284, 37.81728], 306.83],
['LANDSAT/LC08/C02/T1_L2/LC08_031034_20160702', [-102.04696, 37.81796], 297.88],
['LANDSAT/LC08/C02/T1_L2/LC08_031034_20160702', [-102.08284, 37.81728], 306.83, None],
['LANDSAT/LC08/C02/T1_L2/LC08_031034_20160702', [-102.04696, 37.81796], 297.88, None],
# This scene (and path/row) is having issues when used in the LST sharpening
# Test four points in each quadrant of the scene and one point outside
['LANDSAT/LC08/C02/T1_L2/LC08_035031_20160714', [-107.4, 42.2], 321.0, 321.2],
['LANDSAT/LC08/C02/T1_L2/LC08_035031_20160714', [-106.3, 42.0], 323.0, 323.2],
['LANDSAT/LC08/C02/T1_L2/LC08_035031_20160714', [-107.4, 41.5], 318.0, 317.8],
['LANDSAT/LC08/C02/T1_L2/LC08_035031_20160714', [-106.5, 41.3], 306.0, 305.9],
['LANDSAT/LC08/C02/T1_L2/LC08_035031_20160714', [-107.9, 42.6], None, None],
]
)
def test_landsat_c2_sr_lst_correct_values(image_id, xy, expected, tol=0.25):
def test_landsat_c2_sr_lst_correct_values(image_id, xy, expected, uncorrected, tol=0.25):
input_img = ee.Image(image_id)
ndvi_img = input_img.multiply(0.0000275).add(-0.2).normalizedDifference(['SR_B5', 'SR_B4'])
# lst_img = input_img.select(['ST_B10']).multiply(0.00341802).add(149.0)
# original = utils.point_image_value(lst_img, xy, scale=30)['ST_B10']
output_img = common.landsat_c2_sr_lst_correct(input_img, ndvi_img)
corrected = utils.point_image_value(output_img, xy, scale=30)
assert abs(corrected['surface_temperature'] - expected) <= tol
if expected is None:
assert corrected['lst'] is None
else:
assert abs(corrected['lst'] - expected) <= tol
8 changes: 3 additions & 5 deletions openet/core/tests/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,18 +582,16 @@ def test_from_scene_et_fraction_t_interval_monthly_interp_args_et_reference(tol=
'et_reference_source': 'IDAHO_EPSCOR/GRIDMET',
'et_reference_band': 'etr',
'et_reference_factor': 1.0,
'et_reference_resample': 'bilinear'},
'et_reference_resample': 'nearest'},
model_args={},
t_interval='monthly')

TEST_POINT = (-121.5265, 38.7399)
output = utils.point_coll_value(output_coll, TEST_POINT, scale=10)
assert abs(output['ndvi']['2017-07-01'] - 0.6) <= tol
# CGM - Reference ET and ET test values are slightly different with bilinear resampling
# but ET fraction should be the same
assert abs(output['et_fraction']['2017-07-01'] - 0.4) <= tol
assert abs(output['et_reference']['2017-07-01'] - 309.4364929) <= tol
assert abs(output['et']['2017-07-01'] - (309.43649 * 0.4)) <= tol
assert abs(output['et_reference']['2017-07-01'] - 310.3) <= tol
assert abs(output['et']['2017-07-01'] - (310.3 * 0.4)) <= tol
assert output['count']['2017-07-01'] == 3


Expand Down
21 changes: 21 additions & 0 deletions openet/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,24 @@ def point_coll_value(coll, xy, scale=1):

return info_dict
# return pd.DataFrame.from_dict(info_dict)


# def build_parent_folders(folder_id, set_public=False):
# """Build the asset folder including parents"""
# # Build any parent folders above the "3rd" level
# # i.e. after "projects/openet/assets" or "projects/openet/folder"
# public_policy = {'bindings': [{'role': 'roles/viewer', 'members': ['allUsers']}]}
# folder_id_split = folder_id.replace('projects/earthengine-legacy/assets/', '').split('/')
# for i in range(len(folder_id_split)):
# if i <= 3:
# continue
# folder_id = '/'.join(folder_id_split[:i])
# if not ee.data.getInfo(folder_id):
# print(f' Building folder: {folder_id}')
# ee.data.createAsset({'type': 'FOLDER'}, folder_id)
# if set_public:
# ee.data.setIamPolicy(folder_id, public_policy)


# def get_transform(image):
# return ee.List(ee.Dictionary(ee.Algorithms.Describe(image.projection())).get('transform'))
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "openet-core"
version = "0.3.0"
version = "0.4.0"
authors = [
{ name="Charles Morton", email="charles.morton@dri.edu" },
]
Expand Down

0 comments on commit 147dae5

Please sign in to comment.