###### tags: `timeseries` `isce` `stripmap`
# ISCE Stripmap Stack 教學
isce是由NASA贊助下,開發出用來對雷達衛星影像做前處理之軟體。可以同時對大量影像做影像配準(coregistration)、干涉(interferometry)與解饞(unwrapping)。
# Stripmap 影像
stripmap 為一種雷達影像的拍攝模式,影像整體為一個像幅(frame),沒有burst與swath(條帶)。影像較小,處理方式較簡單。主要用來針對小區域、特定主題來做拍攝。
## 處理步驟
1. source stripmap-stack環境:
需要將 `isce_install_dir/contrib/stacks/stripmapStack` 加入PATH。
**請勿同時加入topsStack,避免套件衝突。**
2. 影像unpack: 將影像轉檔成ISCE的可處理的格式,因為不同影像的原始檔型不同(e.g. CSK影像為h5, TSX影像為COS),所使用的程式腳本也不同,如下所示:
* [Alos-1](#Alos-image-process)
* [Cosmo-SkyMED](#Cosmo-SkyMED-(CSK))
* [TerraSAR-X](#TerraSAR-X)
4. `stackStripMap.py`: 處理影像對位(coregistration)與干涉。依照不同的衛星、目的(PS, SBAS),所使用的參數也會有些許不同。
6. stacking處理完成後,可接續使用不同的軟體對影像做地表變形/時間序列分析:
* [isce-stamps](/Je0fJkX_TsS1nqCoaW2bwA) for PS-insar
* [isce-mintpy](https://hackmd.io/@sharkbig/rJJeRYBTd) for SBAS
## 處理之前須注意..
1. 影像的取得:ALOS-1 的影像,部份可以從[ASF](https://asf.alaska.edu/)的歷史影像集中取得,其他商用衛星影像(cosmo-skymed、terraSAR-X等)則可以分別聯絡購買。
2. DEM的使用:對於X波段的影像,越精細的DEM,其配準的成果越佳。ISCE也能透過dem.py的指令下載SRTM的DEM。
3. 使用自己的DEM可以透過gdal_translate來轉換為ISCE可讀模式。
## Step 1: Image unpack
### Alos-1
*必須使用ALOS 1.0 產品 非 ALOS-SLC (1.1)*
ALOS-1影像為**尚未經過聚焦**的影像。
1. 解壓縮檔案,執行指令:
`prepRawALOS.py -i download/ -o $PWD/SLC`
參數為傳入含有檔案之資料夾
2. 執行完後會產生 run_UnpackALOS 檔案,產生檔案結構如下:

4. 執行run_UnpackALOS:
sh run_UnpackALOS`
* 執行完後會在SLC/yyyymmdd的資料夾中產生 .raw 的影像檔
* run_UnpackALOS 是呼叫unpackFrame_ALOS_raw.py的指令
### Unknown Sensor
也許可以透過以下指令來將檔案轉換為ISCE SLC。
`prepRawSensor.py -i $PATH_TO_IMAGE -o $PWD/SLC`
*註:不知道怎麼處理的ALOS影像應該也可以如此處理?
### Cosmo-SkyMED (CSK)
CSK為已經經過聚焦的SLC影像,因此只要把檔案依照日期安排即可,並針對每一個日期依序執行:
`unpackFrame_CSK.py -i $FULLPATH_to_h5dir/20110518 -o $PWD/SLC/20110518`
***output 一定要填入絕對路徑,不要填入相對路徑!***
產生資料結構如下:

### TerraSAR-X
- 原始檔型為COS/XML
- 需要修改unpackFrame_TSX.py (line #26)
`
fname = glob.glob(os.path.join(hdf5,'TSX-1.SAR.L1B/*/T?X1*.xml'))[0]
`
- TRX的資料結構應如下:
```
unpackFrame_TSX.py -i $PWD/RAW/TerraSAR-X/dims_op_oc_dfd2_648064240_1 \
-o $PWD/SLC/20190722
# -i: 指向最外層資料夾(即xml的外面三層資料夾)
# -o: 需要自行取出影像時間!
```
## Step2: ISCE Create stackStripMap
執行stackStripMap
```bash=
stackStripMap.py -s SLC -d DEM --nofocus \
-a 2 -r 2 -t 300 -b 750 \
-S CSK -W interferogram \
-z -u snaphu \
-x "25 25.12 121.35 121.62"
-a,r: azimuth/range looks
--nofocus: 對於CSK、TRX影像必須增加此選項,ALOS不需要
-t: 最大時間基線
-b: 最大空間基線
-S: Sensor種類(CSK, etc.)
-W: 工作流程(slc, interferogram, ion)
-x: 範圍
-z: zero doopler (CSK、TRX必須加上,ALOS則不需要)
-u: 解饞方法(snaphu, snaphu2stage, icu),建議使用snaphu
```
執行stackStripMap.py,並執行run_files中的批次檔。
> NOTE:
> 1. -z 還在測試當中,可參考: [Coregistration error for CSK with stackStripMap.py · Issue #345 · isce-framework/isce2 (github.com)](https://github.com/isce-framework/isce2/issues/345)
> 2. 目前如果處理single looks(lk=1)時需要在第一步驟完成後執行:
> `ln -s $projectfolder/merged/geom_reference geom_reference 的步驟`
> 否則就會發生錯誤(因為single look的geom_reference與merged/geom_refernce為同一個檔案,但是預設沒有產生,才要自己建立softlink)
> 但是SLC流程本身會產出single look 的雷達影響,這裡的geom_reference資料夾應該是用在
> 3. 如果使用了影像裁切(-x),會產生一個新的SLC_crop資料夾,而原本unpack後產生的SLC資料架內的影像則無法在被ISCE讀取。
## Step4: application
都是從其產生的merged 檔來做應用
---
## Issues and Problems I met
1. In the arguments for stackStripmap.py, SLC should be written in "FULL" path rather than "SLC" only.
2. crop image: crop image will change the data.dat, data.dir, data.bak file which will remove all the information in the file.
4. run_4_refineSecondaryTiming
- what is the meaning of this step?
- What's the meaning of the no offset points left?
- If there's not enough point of OffSet, it will cause the **fail** of the following step.( The shelve file will correctly generate and raise the **KeyError of the azopoly**)
> solution:
> just remove that pair in the refineSecondary/pairs

<!--
4. code bug report in run_5
http://earthdef.caltech.edu/boards/4/topics/3305
-->
5. mintpy
real step: prep_isce -> load_data -> ...
(1) some problem with prep_isce.py
problem reading shelve file (read as binary, need to be decoded.)
6. translate cflaot32 to int and phase
```
a=image.vrt (ISCE format)
imageMath.py -e 'arg(a)' --a=$a -o $a.mph
imageMath.py -e 'conj(a)' --a=$a -o $a.int
```
6. h5dump
`h5dump -g "/S01/B001" -d -H CSKS2_SCS_B_HI_01_HH_RA_SF_20120213214529_20120213214536.h5`
---
## ALOS 參數
即可開始執行 stackStripmap.py
```bash=
stackStripmap.py -s SLC -demLat_N21_N25_E120_E122.dem.wgs84 \
-t 250 -b 1000 -a 14 -r 4 -u snaphu \
-W interferogram
# -s: SLC directory (full directory)
# -d: DEM file directory
# -t: 最長時間基線限制
# -b: 空間基線限制,可以先查看baselines中的基線長度資料,若限制的基線太短以至於無法產生網絡,可能會導致失敗(cascading coregistration is not connected)。
# -u: unwrapping method
# -W: 工作流程(小基線須指定為interferogram,PS須指定為slc)
# -S: Seneor type
```
### Run Mintpy
1. 建立專案資夾,
2. 建立CFG檔,並檔名必須已衛星名稱開頭(e.g. Alos*.cfg)
[template on github](https://github.com/insarlab/MintPy/blob/main/mintpy/data/input_files/KirishimaAlos2DT23F2970.template)
4. 執行`smallbaselineApp.py Alos*.cfg`
其他可參考: [ISCE-mintpy processing NOTE](/oPMP3nM7QD-woHP_KjN4BA)