Skip to content

Commit

Permalink
Merge pull request #245 from ASFHyP3/insar_tops
Browse files Browse the repository at this point in the history
Fix insar_tops workflow
  • Loading branch information
forrestfwilliams authored Aug 26, 2024
2 parents 0542044 + b327ef1 commit 9684116
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
20 changes: 7 additions & 13 deletions src/hyp3_isce2/insar_tops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import argparse
import logging
import os
import sys
from pathlib import Path
from shutil import copyfile, make_archive
Expand Down Expand Up @@ -30,7 +29,6 @@ def insar_tops(
azimuth_looks: int = 4,
range_looks: int = 20,
apply_water_mask: bool = False,
download: bool = True,
) -> Path:
"""Create a full-SLC interferogram
Expand All @@ -41,6 +39,7 @@ def insar_tops(
polarization: Polarization to use
azimuth_looks: Number of azimuth looks
range_looks: Number of range looks
apply_water_mask: Apply water mask to unwrapped phase
Returns:
Path to the output files
Expand All @@ -49,12 +48,9 @@ def insar_tops(
aux_cal_dir = Path('aux_cal')
dem_dir = Path('dem')

if download:
ref_dir = slc.get_granule(reference_scene)
sec_dir = slc.get_granule(secondary_scene)
else:
ref_dir = Path(reference_scene + '.SAFE')
sec_dir = Path(secondary_scene + '.SAFE')
ref_dir = slc.get_granule(reference_scene)
sec_dir = slc.get_granule(secondary_scene)

roi = slc.get_dem_bounds(ref_dir, sec_dir)
log.info(f'DEM ROI: {roi}')

Expand Down Expand Up @@ -122,7 +118,6 @@ def insar_tops_packaged(
azimuth_looks: Number of azimuth looks
range_looks: Number of range looks
apply_water_mask: Apply water mask to unwrapped phase
download: Download the SLCs
bucket: AWS S3 bucket to upload the final product to
bucket_prefix: Bucket prefix to prefix to use when uploading the final product
Expand All @@ -133,8 +128,6 @@ def insar_tops_packaged(

log.info('Begin ISCE2 TopsApp run')

do_download = os.path.exists(f'{reference}.SAFE') and os.path.exists(f'{secondary}.SAFE')

insar_tops(
reference_scene=reference,
secondary_scene=secondary,
Expand All @@ -143,12 +136,13 @@ def insar_tops_packaged(
azimuth_looks=azimuth_looks,
range_looks=range_looks,
apply_water_mask=apply_water_mask,
download=do_download
)

log.info('ISCE2 TopsApp run completed successfully')

product_name = packaging.get_product_name(reference, secondary, pixel_spacing=int(pixel_size))
product_name = packaging.get_product_name(
reference, secondary, pixel_spacing=int(pixel_size), polarization=polarization, slc=True
)

product_dir = Path(product_name)
product_dir.mkdir(parents=True, exist_ok=True)
Expand Down
20 changes: 15 additions & 5 deletions src/hyp3_isce2/packaging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import glob
import os
import subprocess
from dataclasses import dataclass
Expand Down Expand Up @@ -48,13 +47,16 @@ def find_product(pattern: str) -> str:
return product


def get_product_name(reference: str, secondary: str, pixel_spacing: int, slc: bool = True) -> str:
def get_product_name(
reference: str, secondary: str, pixel_spacing: int, polarization: Optional[str] = None, slc: bool = True
) -> str:
"""Get the name of the interferogram product.
Args:
reference: The reference burst name.
secondary: The secondary burst name.
pixel_spacing: The spacing of the pixels in the output image.
polarization: The polarization of the input data. Only required for SLCs.
slc: Whether the input scenes are SLCs or bursts.
Returns:
Expand All @@ -69,15 +71,23 @@ def get_product_name(reference: str, secondary: str, pixel_spacing: int, slc: bo
platform = reference_split[0]
reference_date = reference_split[5][0:8]
secondary_date = secondary_split[5][0:8]
polarization = os.path.basename(glob.glob(f'{reference}.SAFE/annotation/s1*')[0]).split('-')[3].upper()
if not polarization:
raise ValueError('Polarization is required for SLCs')
elif polarization not in ['VV', 'VH', 'HV', 'HH']:
raise ValueError('Polarization must be one of VV, VH, HV, or HH')
ref_manifest_xml = etree.parse(f'{reference}.SAFE/manifest.safe', parser)
metadata_path = './/metadataObject[@ID="measurementOrbitReference"]//xmlData//'
relative_orbit_number_query = metadata_path + safe + 'relativeOrbitNumber'
orbit_number = ref_manifest_xml.find(relative_orbit_number_query).text.zfill(3)
footprint = get_geometry_from_manifest(Path(f'{reference}.SAFE/manifest.safe'))
lons, lats = footprint.exterior.coords.xy
def lat_string(lat): return ('N' if lat >= 0 else 'S') + f"{('%.1f' % np.abs(lat)).zfill(4)}".replace('.', '_')
def lon_string(lon): return ('E' if lon >= 0 else 'W') + f"{('%.1f' % np.abs(lon)).zfill(5)}".replace('.', '_')

def lat_string(lat):
return ('N' if lat >= 0 else 'S') + f"{('%.1f' % np.abs(lat)).zfill(4)}".replace('.', '_')

def lon_string(lon):
return ('E' if lon >= 0 else 'W') + f"{('%.1f' % np.abs(lon)).zfill(5)}".replace('.', '_')

lat_lims = [lat_string(lat) for lat in [np.min(lats), np.max(lats)]]
lon_lims = [lon_string(lon) for lon in [np.min(lons), np.max(lons)]]
name_parts = [platform, orbit_number, lon_lims[0], lat_lims[0], lon_lims[1], lat_lims[1]]
Expand Down

0 comments on commit 9684116

Please sign in to comment.