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

loose the limit of only processing the NADIR scenes #42

Merged
merged 33 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ea6b157
loose the limit of only processing the NADIR scenes
cirrusasf Apr 4, 2024
bf194be
update the CHANGELOG.md
cirrusasf Apr 4, 2024
e4e54aa
add test_get_stac_item function to test_main.py
cirrusasf Apr 4, 2024
2bbf4f2
add test function and test_get_landsat_pairs_for_reference_scene and…
cirrusasf Apr 5, 2024
6d9a8e4
updata CHANGELOG.md
cirrusasf Apr 5, 2024
cd637bd
Update CHANGELOG.md
cirrusasf Apr 6, 2024
5cfe39d
Update tests/landsat/test_main.py
cirrusasf Apr 6, 2024
1c9b874
modify test function code to adopt unittest mock class
cirrusasf Apr 9, 2024
3882759
remove unused data files
cirrusasf Apr 9, 2024
9d4831c
modified test to use hyp3-sdk rather than json
AndrewPlayer3 Apr 9, 2024
15ffb4f
remove unnecessary json files
AndrewPlayer3 Apr 9, 2024
173a2a4
add test_submit_pairs_for_processing function to test_main.py
cirrusasf Apr 9, 2024
db9a3dd
remove code for debug
cirrusasf Apr 9, 2024
697b880
modify main.py code
cirrusasf Apr 9, 2024
2fc4010
ruff format test_main.py
cirrusasf Apr 9, 2024
423743a
make variable name more sense
cirrusasf Apr 9, 2024
c10628d
Merge branch 'handle_off_nadir_scenes' of https://github.com/ASFHyP3/…
AndrewPlayer3 Apr 10, 2024
673457c
formatting
AndrewPlayer3 Apr 10, 2024
c49a67f
formatting
AndrewPlayer3 Apr 10, 2024
55497ef
Merge pull request #54 from ASFHyP3/off_nadir_andrew
AndrewPlayer3 Apr 10, 2024
35051b8
modify the main.py code
cirrusasf Apr 11, 2024
ae4db40
merge the test_main.py
cirrusasf Apr 11, 2024
e88799e
code style
cirrusasf Apr 11, 2024
88dca4e
modify test_main.py
cirrusasf Apr 11, 2024
a34baa2
modify the duplicate_hyp3_pairs function in the main.py
cirrusasf Apr 11, 2024
51405ba
modify duplicates function
cirrusasf Apr 11, 2024
2f3abcf
modify to satisfy ruff check
cirrusasf Apr 11, 2024
fe4c1ea
modify code to satisfy ruff format
cirrusasf Apr 11, 2024
cb91ae4
Merge branch 'develop' into handle_off_nadir_scenes
AndrewPlayer3 Apr 11, 2024
34e74cc
add sample jobs with job_status=SUCCESS to test the test_deduplicate_…
cirrusasf Apr 11, 2024
9bc3bfd
Merge branch 'handle_off_nadir_scenes' of github.com:ASFHyP3/its-live…
cirrusasf Apr 11, 2024
d0dafb2
fix ruff format
cirrusasf Apr 11, 2024
4903c60
fix job_status value to be SUCCEEDED
cirrusasf Apr 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.1]

### Fixed
- Off-NADIR scene can be processed as long as the secondary scene has the same wrs_path, wrs_row, and vire:off_nadir properties.

cirrusasf marked this conversation as resolved.
Show resolved Hide resolved
## [0.2.0]

### Added
Expand Down
Empty file added landsat/src/__init__.py
AndrewPlayer3 marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
14 changes: 10 additions & 4 deletions landsat/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ def _qualifies_for_processing(
log.log(log_level, f'{item.id} disqualifies for processing because it has too much cloud cover')
return False

if item.properties['view:off_nadir'] != 0:
log.log(log_level, f'{item.id} disqualifies for processing because it is off-nadir')
return False

log.log(log_level, f'{item.id} qualifies for processing')
return True

Expand Down Expand Up @@ -99,11 +95,17 @@ def get_landsat_pairs_for_reference_scene(
query=[
f'landsat:wrs_path={reference.properties["landsat:wrs_path"]}',
f'landsat:wrs_row={reference.properties["landsat:wrs_row"]}',
f'view:off_nadir={reference.properties["view:off_nadir"]}',
],
datetime=[reference.datetime - max_pair_separation, reference.datetime - timedelta(seconds=1)],
)

items = [item for page in results.pages() for item in page if _qualifies_for_processing(item, max_cloud_cover)]

if len(items) == 0:
log.info(f'Did not find secondary candidate scenes for the reference scene {reference.id}')
return None
AndrewPlayer3 marked this conversation as resolved.
Show resolved Hide resolved

features = []
for item in items:
feature = item.to_dict()
Expand Down Expand Up @@ -192,6 +194,10 @@ def process_scene(
return sdk.Batch()

pairs = get_landsat_pairs_for_reference_scene(reference, max_pair_separation, max_cloud_cover)

if pairs is None:
return None
AndrewPlayer3 marked this conversation as resolved.
Show resolved Hide resolved

log.info(f'Found {len(pairs)} pairs for {scene}')
with pd.option_context('display.max_rows', None, 'display.max_columns', None, 'display.width', None):
log.debug(pairs.loc[:, ['reference', 'secondary']])
Expand Down
Binary file not shown.
Binary file not shown.
86 changes: 82 additions & 4 deletions tests/landsat/test_main.py
AndrewPlayer3 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import unittest.mock
import pickle

import main
from landsat.src import main

import geopandas as gpd

Check failure on line 6 in tests/landsat/test_main.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (F401)

tests/landsat/test_main.py:6:21: F401 `geopandas` imported but unused

import pdb

Check failure on line 8 in tests/landsat/test_main.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (F401)

tests/landsat/test_main.py:8:8: F401 `pdb` imported but unused
cirrusasf marked this conversation as resolved.
Show resolved Hide resolved


def get_mock_pystac_item() -> unittest.mock.NonCallableMagicMock:

Check failure on line 11 in tests/landsat/test_main.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (I001)

tests/landsat/test_main.py:1:1: I001 Import block is un-sorted or un-formatted
Expand Down Expand Up @@ -73,6 +78,79 @@
item.properties['landsat:cloud_cover_land'] = main.MAX_CLOUD_COVER_PERCENT + 1
assert not main._qualifies_for_processing(item)

item = get_mock_pystac_item()
item.properties['view:off_nadir'] = 1
assert not main._qualifies_for_processing(item)

def test_get_stac_item():
scene1 = 'LC08_L1TP_138041_20240128_20240207_02_T1'
item1_id = 'LC08_L1TP_138041_20240128_20240207_02_T1'
item1_properties = {'datetime': '2024-01-28T04:29:49.361022Z',
'eo:cloud_cover': 11.59,
'view:sun_azimuth': 148.43311105,
'view:sun_elevation': 37.83753177,
'platform': 'LANDSAT_8',
'instruments': ['OLI', 'TIRS'],
'view:off_nadir': 0,
'landsat:cloud_cover_land': 11.59,
'landsat:wrs_type': '2',
'landsat:wrs_path': '138',
'landsat:wrs_row': '041',
'landsat:scene_id': 'LC81380412024028LGN00',
'landsat:collection_category': 'T1',
'landsat:collection_number': '02',
'landsat:correction': 'L1TP',
'accuracy:geometric_x_bias': 0,
'accuracy:geometric_y_bias': 0,
'accuracy:geometric_x_stddev': 3.926,
'accuracy:geometric_y_stddev': 3.525,
'accuracy:geometric_rmse': 5.277,
'proj:epsg': 32645,
'proj:shape': [7681, 7531],
'proj:transform': [30, 0, 674985, 0, -30, 3152415],
'created': '2024-02-07T18:27:27.558Z',
'updated': '2024-02-07T18:27:27.558Z'
}

assert (main._get_stac_item(scene1).id == item1_id
and main._get_stac_item(scene1).properties == item1_properties)

scene2 = 'LC08_L1GT_208119_20190225_20200829_02_T2'

item2_id = 'LC08_L1GT_208119_20190225_20200829_02_T2'

item2_properties = {'datetime': '2019-02-25T12:13:15.140373Z',
'eo:cloud_cover': 46.47,
'view:sun_azimuth': 87.63621418,
'view:sun_elevation': 9.4970641,
'platform': 'LANDSAT_8',
'instruments': ['OLI', 'TIRS'],
'view:off_nadir': 14.092,
'landsat:cloud_cover_land': 46.47,
'landsat:wrs_type': '2',
'landsat:wrs_path': '208',
'landsat:wrs_row': '119',
'landsat:scene_id': 'LC82081192019056LGN00',
'landsat:collection_category': 'T2',
'landsat:collection_number': '02',
'landsat:correction': 'L1GT',
'proj:epsg': 3031,
'proj:shape': [8901, 9151],
'proj:transform': [30, 0, -980415, 0, -30, 188115],
'created': '2022-07-06T18:15:03.664Z',
'updated': '2022-07-06T18:15:03.664Z'
}

assert (main._get_stac_item(scene2).id == item2_id and
main._get_stac_item(scene2).properties == item2_properties)
AndrewPlayer3 marked this conversation as resolved.
Show resolved Hide resolved


def test_get_landsat_pairs_for_reference_scene():
item = main._get_stac_item('LC08_L1TP_138041_20240128_20240207_02_T1')
df = main.get_landsat_pairs_for_reference_scene(item)
with open("tests/data/LC08_L1TP_138041_20240128_20240207_02_T1_pairs.pkl", 'rb') as file:

Check failure on line 148 in tests/landsat/test_main.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (PTH123)

tests/landsat/test_main.py:148:10: PTH123 `open()` should be replaced by `Path.open()`
df_expect = pickle.load(file)
assert df.equals(df_expect)
AndrewPlayer3 marked this conversation as resolved.
Show resolved Hide resolved

item = main._get_stac_item('LC08_L1GT_208119_20190225_20200829_02_T2')
df = main.get_landsat_pairs_for_reference_scene(item)
with open("tests/data/LC08_L1GT_208119_20190225_20200829_02_T2_pairs.pkl", 'rb') as file:

Check failure on line 154 in tests/landsat/test_main.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (PTH123)

tests/landsat/test_main.py:154:10: PTH123 `open()` should be replaced by `Path.open()`
df_expect = pickle.load(file)
assert df.equals(df_expect)
Loading