IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> Prepare ISCE topsApp interferograms for processing with MintPy -> 正文阅读

[Python知识库]Prepare ISCE topsApp interferograms for processing with MintPy

We often use topsApp.py to process sentinel-1 data. However, MintPy can only read the results of topsStack directly at present. We need some post-processing to make MintPy can produce the result of topsApp.py .

Prepare the structured folders

The folder structure required by Minpy to handle tops is as follows ISCE / topsStack:

$DATA_DIR/GalapagosSenDT128
├── baselines
│   ├── 20141213_20141225
│   │   └── 20141213_20141225.txt
│   └── ...
├── reference
│   ├── data.rsc    #generated by prep_isce.py
│   ├── IW1
│   ├── IW1.xml
│   ├── IW2
│   └── IW2.xml
├── merged
│   ├── geom_reference
│   │   ├── hgt.rdr
│   │   ├── hgt.rdr.full.vrt
│   │   ├── hgt.rdr.full.xml
│   │   ├── hgt.rdr.vrt
│   │   ├── hgt.rdr.xml
│   │   ├── lat.rdr
│   │   ├── lat.rdr.full.vrt
│   │   ├── lat.rdr.full.xml
│   │   ├── lat.rdr.vrt
│   │   ├── lat.rdr.xml
│   │   ├── lon.rdr
│   │   ├── lon.rdr.full.vrt
│   │   ├── lon.rdr.full.xml
│   │   ├── lon.rdr.vrt
│   │   ├── lon.rdr.xml
│   │   ├── los.rdr
│   │   ├── los.rdr.full.vrt
│   │   ├── los.rdr.full.xml
│   │   ├── los.rdr.vrt
│   │   ├── los.rdr.xml
│   │   ├── shadowMask.rdr
│   │   ├── shadowMask.rdr.full.vrt
│   │   ├── shadowMask.rdr.full.xml
│   │   ├── shadowMask.rdr.vrt
│   │   └── shadowMask.rdr.xml
│   └── interferograms
│       ├── 20141213_20141225
│       │   ├── filt_fine.cor
│       │   ├── filt_fine.cor.vrt
│       │   ├── filt_fine.cor.xml
│       │   ├── filt_fine.unw
│       │   ├── filt_fine.unw.conncomp
│       │   ├── filt_fine.unw.conncomp.vrt
│       │   ├── filt_fine.unw.conncomp.xml
│       │   ├── filt_fine.unw.vrt
│       │   ├── filt_fine.unw.xml
│       │   ├── ...
│       ├── 20141213_20150307
│       └── ...
├── secondarys
│   ├── 20141225
│   │   ├── IW1
│   │   ├── IW1.xml
│   │   ├── IW2
│   │   └── IW2.xml
│   ├── 20150307
│   └── ...
└── mintpy
    └── GalapagosSenDT128.txt

Suppose you process all interferograms in one folder, which has the folder structure as follows:

.
|-- 20210917_20210929
|-- 20210917_20211011
|-- 20210917_20211023
|-- 20210917_20211210
|-- 20210929_20211011
|-- 20210929_20211023
|-- 20210929_20211104
|-- ...

Firstly, import packages and specify the home directory.

import rasterio
import os
from pathlib import Path
import warnings
from tqdm import tqdm
import numpy as np

# the folder that contains the interferograms processed by topsApp.py
ifg_home = Path('/data/sentinel1/result/interferogams')  

# the folder that used to run MintPy
stack_home = Path('/data/sentinel1/result/stacks')

Now, let’s create the folder structure that MintPy required.

############  make dirs #############
def ensure_folder(folder):
    if not folder.is_dir():
        folder.mkdir(parents=True)

baseline_dir = stack_home / 'baselines'
reference_dir = stack_home / 'reference'
secondarys_dir = stack_home / 'secondarys'
mintpy_dir = stack_home / 'mintpy'

merged_dir = stack_home / 'merged'
geom_reference_dir = merged_dir / 'geom_reference'
interferograms_dir = merged_dir / 'interferograms'

stack_fld_list = [baseline_dir, reference_dir,
                  secondarys_dir, mintpy_dir,
                  merged_dir, geom_reference_dir,
                  interferograms_dir]

for fld in stack_fld_list:
    ensure_folder(fld)

Link files

We have created the folders that MintPy required. But there are no files in those folders. We need to link files from ISCE processed into those folders.

def looks(vrt_file, rdr_file, nlook_a, nlook_r):
    os.system(f'looks.py -i {vrt_file} -o {rdr_file} -a {nlook_a} -r {nlook_r}')

ifgs_files = sorted(ifg_home.iterdir())
for file in tqdm(ifgs_files, desc='link files'):
    name = file.name
    ref_name, sec_name = name.split('_')
    merged = file / 'merged'
    i = 0
    if merged.exists():
        os.chdir(file)
        if i == 0:
            ####################################################################
            # For the folder 'reference' and 'merged/geom_reference', you only 
            # need to get it from the first interferogram            
            #####################################################################
            i += 1
            
            ######### link to 'reference' folder ######
            ref_dir = file / ref_name
            ref_cmd = f'ln -sf {ref_dir}/* {reference_dir}/'
            os.system(ref_cmd)

            ####################################################################
            #     multi-looking for geo_info files to 'geom_reference' folder
            #####################################################################
            # For the files that contain the geo info of ifgs, only 'los' was 
            # processed well (multi-looked and with '.rdr' format). We need 
            # to convert the full resolution geo info files into multi-looked 
            # files with ISCE format('.rdr'). In this script, azimuth/range looks
            # are: 4*20.
			#####################################################################
            looks(merged.joinpath('z.rdr.full.xml'),
                    geom_reference_dir.joinpath('hgt.rdr'),
                    4,20)
            looks(merged.joinpath('lat.rdr.full.xml'),
                    geom_reference_dir.joinpath('lat.rdr'),
                    4,20)
            looks(merged.joinpath('lon.rdr.full.xml'),
                    geom_reference_dir.joinpath('lon.rdr'),
                    4,20)
            looks(merged.joinpath('los.rdr.full.xml'),
                    geom_reference_dir.joinpath('los.rdr'),
                    4,20)


        # ########## link ifgs  ################
        ifg_out = interferograms_dir / name
        ensure_folder(ifg_out)

        # ifgs
        ln_cmd1 = f'ln -sf {merged}/filt_* {ifg_out}/'
        os.system(ln_cmd1)

        # cor
        ln_cmd2 = f'ln -sf {merged}/phsig.cor* {ifg_out}/'
        os.system(ln_cmd2)
        # ########## link secondarys  ################
        sec_dir = file / sec_name
        sec_cmd = f'ln -sf {sec_dir} {secondarys_dir}/'
        os.system(sec_cmd)

generate baseline

We can use isce2/contrib/stack/topsStack/computeBaseline.py to generate baselines. This script was not installed by default, for example, installed by conda. You need to find its location from the source code of ISCE.

########## generate_baseline  #############
def get_dates_from_ifgs(ifgs):
    dates_all = []
    for ifg in ifgs:
        dates_all.extend(ifg.split('_'))
    dates = sorted(set(dates_all))
    return dates

ifgs = [i.name for i in ifgs_files]
dates = get_dates_from_ifgs(ifgs)

ref_name = dates[0]
ref_dir = ifgs_files[0] / ref_name
for sec_name in tqdm(dates[1:], desc='generate baselines'):
    sec_dir = secondarys_dir / sec_name

    bl_name = f'{ref_name}_{sec_name}'
    bl_dir = baseline_dir / bl_name
    ensure_folder(bl_dir)

    bl_file = bl_dir / f'{bl_name}.txt'
    bl_cmd = f'/data/isce2/contrib/stack/topsStack/computeBaseline.py -m {ref_dir}/ -s {sec_dir}/ -b {bl_file}'
    os.system(bl_cmd)

prep_isce.py

For the folder reference, we need to use prep_isce.py to generate the data.rsc file.

os.chdir(reference_dir)
prep_cmd = ('/root/miniconda3/bin/prep_isce.py'
            f' -f "{interferograms_dir}/*/filt_*.unw"'
            f' -m {reference_dir}/IW2.xml'
            f' -b {baseline_dir}/'
            f' -g {geom_reference_dir}/')
print(prep_cmd)
os.system(prep_cmd)

If everything is ok, no errors will be reported.

write options file for MintPy

cfg_file = mintpy_dir / 'mintpy_data_options.cfg'

cfg_info = f'''mintpy.load.processor        = isce
##---------for ISCE only:
mintpy.load.metaFile         = {reference_dir}/IW*.xml
mintpy.load.baselineDir      = {baseline_dir}
##---------interferogram datasets:
mintpy.load.unwFile          = {interferograms_dir}/*/filt_*.unw
mintpy.load.corFile          = {interferograms_dir}/*/phsig.cor
mintpy.load.connCompFile     = {interferograms_dir}/*/filt_*.unw.conncomp
##---------geometry datasets:
mintpy.load.demFile          = {geom_reference_dir}/hgt.rdr
mintpy.load.lookupYFile      = {geom_reference_dir}/lat.rdr
mintpy.load.lookupXFile      = {geom_reference_dir}/lon.rdr
mintpy.load.incAngleFile     = {geom_reference_dir}/los.rdr
mintpy.load.azAngleFile      = {geom_reference_dir}/los.rdr
# mintpy.load.shadowMaskFile   = {geom_reference_dir}/shadowMask.rdr
'''

with open(cfg_file, 'w') as f:
    f.write(cfg_info)
  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2022-09-24 20:53:29  更:2022-09-24 20:54:57 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 9:51:28-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码