Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

64 add support for setting a custom lst source image collection in from landsat c2 sr and from image id methods #67

388 changes: 388 additions & 0 deletions examples/lst_source.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/single_image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.11"
"version": "3.12.1"
},
"pycharm": {
"stem_cell": {
Expand Down
173 changes: 107 additions & 66 deletions openet/ssebop/image.py

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions openet/ssebop/landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,21 @@ def ndwi(landsat_image):


def landsat_c2_qa_water_mask(landsat_image):
"""
Extract water mask from the Landsat Collection 2 SR QA_PIXEL band.
:return: ee.Image
"""
"""Extract water mask from the Landsat Collection 2 SR QA_PIXEL band.

img = ee.Image(landsat_image)
qa_img = img.select(['QA_PIXEL'])
water_mask = qa_img.rightShift(7).bitwiseAnd(1).neq(0)
return water_mask.rename(['qa_water'])
Parameters
----------
landsat_image : ee.Image
Image from a Landsat C02 image collection with a QA_PIXEL band.

Returns
-------
ee.Image

"""
return (
ee.Image(landsat_image)
.select(['QA_PIXEL'])
.rightShift(7).bitwiseAnd(1).neq(0)
.rename(['qa_water'])
)
66 changes: 64 additions & 2 deletions openet/ssebop/tests/test_c_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ def test_Image_init_default_parameters():
assert m._dt_source == 'projects/earthengine-legacy/assets/projects/usgs-ssebop/dt/daymet_median_v6'
assert m._tcorr_source == 'FANO'
assert m._tmax_source == 'projects/earthengine-legacy/assets/projects/usgs-ssebop/tmax/daymet_v4_mean_1981_2010'
assert m._elev_source is None
assert m._elr_flag is False
assert m.et_fraction_type == 'alfalfa'
assert m.et_fraction_grass_source is None
assert m._lst_source is None
assert m._elr_flag is False
assert m._elev_source is None
assert m._dt_resample == 'bilinear'
assert m._tmax_resample == 'bilinear'
assert m._tcorr_resample == 'bilinear'
Expand Down Expand Up @@ -481,6 +482,67 @@ def test_Image_from_landsat_c2_sr_c2_lst_correct_fill():
# assert abs(corrected['lst'] - 306.83) <= 0.25


def test_Image_from_landsat_c2_sr_lst_source_arg():
"""Test if the lst_source parameter can be set (not if it works)"""
# image_id = 'LANDSAT/LC08/C02/T1_L2/LC08_031034_20160702'
image_id = 'LANDSAT/LC08/C02/T1_L2/LC08_031035_20160702'
output = ssebop.Image.from_landsat_c2_sr(
image_id, lst_source='projects/openet/assets/lst/landsat/c02')
assert type(output) == type(default_image_obj())


def test_Image_from_landsat_c2_sr_lst_source_values():
"""Test if the lst_source image can be read"""
# CGM - The default image is not currently in the collection
# Using a different one that is for now
image_id = 'LANDSAT/LC08/C02/T1_L2/LC08_031035_20160702'
xy = (-102.4, 36.1)
# image_id = 'LANDSAT/LC08/C02/T1_L2/LC08_031034_20160702'
# xy = (-102.08284, 37.81728)
lst_source = 'projects/openet/assets/lst/landsat/c02'
output_img = ssebop.Image.from_landsat_c2_sr(image_id, lst_source=lst_source).lst
output = utils.point_image_value(output_img, xy)
assert abs(output['lst'] - 322.8) <= 0.25
assert output_img.get('lst_source_id').getInfo().startswith(lst_source)


def test_Image_from_landsat_c2_sr_lst_source_missing():
"""Test that the LST is masked if the scene is not present in lst_source"""
# This image does not currently exist in the source collection,
# but if this test stops working check to see if this image was added
image_id = 'LANDSAT/LC08/C02/T1_L2/LC08_031034_20160702'
xy = (-102.08284, 37.81728)
lst_source = 'projects/openet/assets/lst/landsat/c02'
output_img = ssebop.Image.from_landsat_c2_sr(image_id, lst_source=lst_source).lst
output = utils.point_image_value(output_img, xy)
assert output['lst'] == None
assert output_img.get('lst_source_id').getInfo() == 'None'


# # DEADBEEF - Keep for now in case approach changes for handling missing scenes in LST source
# def test_Image_from_landsat_c2_sr_lst_source_missing():
# """Test if the input LST image is used if the scene is not present in lst_source"""
# # This image does not currently exist in the source collection,
# # but if this test stops working check to see if this image was added
# image_id = 'LANDSAT/LC08/C02/T1_L2/LC08_031034_20160702'
# xy = (-102.08284, 37.81728)
# lst_source = 'projects/openet/assets/lst/landsat/c02'
# output_img = ssebop.Image.from_landsat_c2_sr(image_id, lst_source=lst_source).lst
# output = utils.point_image_value(output_img, xy)
# assert abs(output['lst'] - 306.83) <= 0.25
# assert output_img.get('lst_source_id').getInfo().startswith('LANDSAT/LC08')


# # DEADBEEF - Keep for now in case approach changes for handling missing scenes in LST source
# def test_Image_from_landsat_c2_sr_lst_source_missing():
# """Test if an exception is raised if the scene is not present in lst_source"""
# # Testing with a 100% CLOUD_COVER_LAND image that shouldn't be in the LST source collection
# image_id = 'LANDSAT/LC08/C02/T1_L2/LC08_031035_20220820'
# lst_source = 'projects/openet/assets/lst/landsat/c02'
# with pytest.raises(Exception):
# ssebop.Image.from_landsat_c2_sr(image_id, lst_source=lst_source).lst.getInfo()


@pytest.mark.parametrize(
'image_id',
[
Expand Down
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-ssebop"
version = "0.4.3"
version = "0.4.4"
authors = [
{ name = "Gabe Parrish", email = "gparrish@contractor.usgs.gov" },
{ name = "Mac Friedrichs", email = "mfriedrichs@contractor.usgs.gov" },
Expand Down
1 change: 0 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@
tmax_source='projects/usgs-ssebop/tmax/daymet_v4_mean_1981_2010'
)


et_property = model_obj.et_fraction
Loading