This notebook demonstrates how to use the merge_tops_burst
workflow of the HyP3-ISCE2 plugin. This workflow merges multiple burst InSAR Products and takes a directory that includes multiple HyP3-ISCE2 Burst InSAR Products as its input. These input products can be created by the HyP3-ISCE2 on-demand service. To learn how to create HyP3 burst InSAR Products, check out our hyp3_isce2_burst_stack_for_ts_analysis notebook.
Note: This notebook does assume you have some familiarity with InSAR processing with HyP3 already, and is a minimal example without much context or explanations. If you're new to InSAR and HyP3, we suggest checking out the following resources. Note that some of these resources may be specific to our InSAR GAMMA products, so you may need to adapt them for use with our ISCE2-based burst InSAR products.
Our product guide for burst InSAR products
Our GitHub repository containg the workflow used to create burst InSAR products
To run this notebook, you will need a local copy of the HyP3-ISCE2 GitHub repository and to set up a conda environment with the required dependencies. In your terminal, you can do this with the following commands:
git clone https://github.com/ASFHyP3/hyp3-isce2.git
cd hyp3-isce2
mamba env create -f environment.yml
mamba activate hyp3-isce2
python -m pip install -e .
mamba install -c conda-forge pandas jupyter ipympl
jupyter notebook hyp3_isce2_burst_merge.ipynb
This workflow requires an Earth Data Cloud login. If you haven't yet, you can make an account for free and set up a .netrc
file in your home directory with your personal username and password.
echo ‘machine urs.earthdata.nasa.gov login $USERNAME password $PASSWORD’ >> ~/.netrc
Before using the HyP3-ISCE2 merge burst workflow, we must create burst InSAR products that are merge-compatible. This means that they must:
In this section, we'll create two such burst InSAR products and download them to a local directory.
from pathlib import Path
reference_granule1 = 'S1_136231_IW2_20200604T022312_VV_7C85-BURST'
secondary_granule1 = 'S1_136231_IW2_20200616T022313_VV_5D11-BURST'
reference_granule2 = 'S1_136232_IW2_20200604T022315_VV_7C85-BURST'
secondary_granule2 = 'S1_136232_IW2_20200616T022316_VV_5D11-BURST'
project_name = 'merge_demo'
current_dir = Path.cwd() # Make sure we preserve this in case we want to navigate back
work_dir = Path.cwd() / project_name
data_dir = work_dir / 'data'
data_dir.mkdir(parents=True, exist_ok=True)
import hyp3_sdk as sdk
hyp3 = sdk.HyP3(prompt=True)
jobs = sdk.Batch()
for reference, secondary in [(reference_granule1, secondary_granule1), (reference_granule2, secondary_granule2)]:
jobs += hyp3.submit_insar_isce_burst_job(
granule1 = reference,
granule2 = secondary,
apply_water_mask = False,
name = project_name,
looks = '20x4'
)
jobs = hyp3.watch(jobs)
from datetime import datetime
now = datetime.now()
start_of_today = datetime(now.year, now.month, now.day)
jobs = hyp3.find_jobs(name=project_name, start=start_of_today)
insar_products = jobs.download_files(data_dir)
insar_products = [sdk.util.extract_zipped_product(ii) for ii in insar_products]
Now we have all the data we need and can merge these two burst InSAR products! You would typically run the command below on the command line, but we'll run it through the Jupyter Notebook here.
cd $work_dir
# Use this command to actually view the options for the merge_tops_burst workflow
!python -m hyp3_isce2 ++process merge_tops_bursts --help
# Use this command to actually run the merge_tops_burst workflow
!python -m hyp3_isce2 ++process merge_tops_bursts $data_dir
We've successfully run the command, now let's look at the results!
%matplotlib inline
import numpy as np
from osgeo import gdal
import matplotlib
import matplotlib.pyplot as plt
tifs = [f for f in work_dir.glob("*/*.tif")]
unw_file = [f for f in tifs if 'unw_phase' in f.name][0]
wrapped_file = [f for f in tifs if 'wrapped_phase' in f.name][0]
corr_file = [f for f in tifs if 'corr' in f.name][0]
desired_tifs = [wrapped_file, unw_file, corr_file]
f, axs = plt.subplots(len(desired_tifs), figsize=(6,10))
for i, tif in enumerate(desired_tifs):
ds = gdal.Open(str(tif))
merged_bursts = np.ma.masked_equal(ds.GetRasterBand(1).ReadAsArray(), 0)
ds = None
axs[i].imshow(merged_bursts)
axs[i].set_title(tif.name)
plt.setp(plt.gcf().get_axes(), xticks=[], yticks=[])
plt.tight_layout()