Skip to content

Commit

Permalink
Merge pull request #55 from benbart/EW-filename-fix
Browse files Browse the repository at this point in the history
EWs will have 2-digit zero padded burst index in filename
  • Loading branch information
forrestfwilliams authored Feb 6, 2024
2 parents f84febc + 432000b commit da8b804
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.2]

### Changed
* Naming convention of output image/index to have a zero-padded burst number. This is to maintain consistency with scenes that have more than 9 bursts per swath.

## [0.2.1]

### Added
Expand Down
4 changes: 3 additions & 1 deletion src/index_safe/create_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def create_burst_name(slc_name: str, swath_name: str, burst_index: str) -> str:
Name of burst
"""
_, swath, _, polarization, *_ = swath_name.split('-')
all_parts = [slc_name, swath.upper(), polarization.upper(), str(burst_index)]
# EWs can have burst index values over 9, so we will zeropad the burst number.
filename_burst_idx = str(burst_index).zfill(2)
all_parts = [slc_name, swath.upper(), polarization.upper(), filename_burst_idx]
return '_'.join(all_parts) + '.tiff'


Expand Down
11 changes: 7 additions & 4 deletions tests/test_create_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ def test_create_xml_metadata():
def test_create_burst_name():
test_name = 'SLCNAME'
test_swath = 'foo-iw2-bar-vv-baz.tiff'
test_burst_index = 1
burst_name = create_index.create_burst_name(test_name, test_swath, test_burst_index)
assert burst_name == 'SLCNAME_IW2_VV_1.tiff'

burst_name1 = create_index.create_burst_name(test_name, test_swath, 1)
assert burst_name1 == 'SLCNAME_IW2_VV_01.tiff'

burst_name2 = create_index.create_burst_name(test_name, test_swath, 11)
assert burst_name2 == 'SLCNAME_IW2_VV_11.tiff'


def test_create_burst_dflidx(zip_deflated):
Expand Down Expand Up @@ -54,7 +57,7 @@ def test_create_index(zip_deflated, annotation_xml):
keys = list(test_burst_metadata.keys())
first_burst = test_burst_metadata[keys[0]]
golden_burst = utils.BurstMetadata(
name='SLCNAME_IW2_VV_0.tiff',
name='SLCNAME_IW2_VV_00.tiff',
slc='SLCNAME',
swath='IW2',
burst_index=0,
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def slc_zip_path(test_data_dir):
@pytest.fixture()
def golden_burst_metadata():
burst_metadata = utils.BurstMetadata(
name='S1A_IW_SLC__1SDV_20200604T022251_20200604T022318_032861_03CE65_7C85_IW2_VV_7.tiff',
name='S1A_IW_SLC__1SDV_20200604T022251_20200604T022318_032861_03CE65_7C85_IW2_VV_07.tiff',
slc='S1A_IW_SLC__1SDV_20200604T022251_20200604T022318_032861_03CE65_7C85',
swath='IW2',
burst_index=7,
Expand All @@ -67,7 +67,7 @@ def golden_burst_metadata():

@pytest.fixture()
def golden_burst_index(test_data_dir):
index_name = 'S1A_IW_SLC__1SDV_20200604T022251_20200604T022318_032861_03CE65_7C85_IW2_VV_7.dflidx'
index_name = 'S1A_IW_SLC__1SDV_20200604T022251_20200604T022318_032861_03CE65_7C85_IW2_VV_07.dflidx'
index_path = test_data_dir / index_name
index = zran.Index.read_file(str(index_path))
return index
Expand All @@ -82,7 +82,7 @@ def golden_burst(test_data_dir, slc_zip_path, golden_burst_metadata):
if not (test_data_dir / zinfo.filename).exists():
zip_file.extract(zinfo, path=test_data_dir)

golden_array = load_geotiff(str(test_data_dir / 'valid_IW2_VV_7.vrt'))[0]
golden_array = load_geotiff(str(test_data_dir / 'valid_IW2_VV_07.vrt'))[0]
yield golden_array


Expand Down Expand Up @@ -151,7 +151,7 @@ def test_create_index(slc_zip_path, golden_xml_metadata, golden_burst_metadata):
test_xml = [xml for xml in xml_metadatas if xml.name == golden_xml.name][0]
assert test_xml == golden_xml

index_path = [index for index in indexes if 'IW2_VV_7.json' in index.name][0]
index_path = [index for index in indexes if 'IW2_VV_07.json' in index.name][0]
index, burst_metadata = json_to_burst_metadata(index_path)
assert golden_burst_metadata == burst_metadata

Expand Down

0 comments on commit da8b804

Please sign in to comment.