工具集
工具集是一组用于支持和简化 InSAR 处理工作流的工具。
选择配对
根据时间和垂直基线标准,从 ASF 搜索结果中选择干涉图配对。
from insarhub import Downloader
from insarhub.utils import select_pairs
s1 = Downloader.create('S1_SLC',
intersectsWith=[-113.05, 37.74, -112.68, 38.00],
start='2020-01-01',
end='2020-12-31',
relativeOrbit=100,
frame=466,
workdir='path/to/dir')
results = s1.search()
pairs, baselines, scene_bperp, _ = select_pairs(search_results=results)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_results
|
list[ASFProduct] | dict[tuple[int, int], list[ASFProduct]]
|
Either a flat list (single stack) or a dictionary keyed by (path, frame). |
required |
dt_targets
|
list[float]
|
Preferred temporal spacings in days. A candidate pair passes if |dt - target| <= dt_tol for at least one target. |
SELECT_PAIRS_DEFAULTS['dt_targets']
|
dt_tol
|
float
|
Tolerance in days added to each entry in dt_targets. |
SELECT_PAIRS_DEFAULTS['dt_tol']
|
dt_max
|
float
|
Maximum temporal baseline in days. |
SELECT_PAIRS_DEFAULTS['dt_max']
|
pb_max
|
float
|
Maximum perpendicular baseline in meters. |
SELECT_PAIRS_DEFAULTS['pb_max']
|
min_degree
|
int
|
Minimum interferogram connections per scene. Enforced when force_connect is True. |
SELECT_PAIRS_DEFAULTS['min_degree']
|
max_degree
|
int
|
Maximum interferogram connections per scene. |
SELECT_PAIRS_DEFAULTS['max_degree']
|
force_connect
|
bool
|
If a scene falls below min_degree after primary selection, add its nearest-time neighbors that satisfy pb_max and dt_max. May introduce lower-quality pairs; a warning is logged. |
SELECT_PAIRS_DEFAULTS['force_connect']
|
max_workers
|
int
|
Number of threads for API fallback. Has no effect if all products have local baseline data (common for Sentinel-1 and ALOS). Set to 1 to disable threading (useful for debugging). |
SELECT_PAIRS_DEFAULTS['max_workers']
|
aoi_wkt
|
str
|
WKT geometry of the area of interest, recorded in the folder config so pair-quality scoring later reads back the same region. Defaults to None. |
None
|
burst
|
bool
|
Select pairs for an SLC-BURST stack. Nodes become |
False
|
safe_dir
|
str | Path | None
|
Burst mode only: directory of assembled |
None
|
eof_dir
|
str | Path | None
|
Burst mode only: directory of precise-orbit |
None
|
poeorb_cache
|
str | Path | None
|
Burst mode only: directory for POEORB downloads keyed by date + mission (online fallback). |
None
|
Source code in src/insarhub/utils/tool.py
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 | |
绘制配对网络
绘制由 select_pairs 返回的 SBAS 干涉图网络。
from insarhub.utils import plot_pair_network
fig = plot_pair_network(pairs=pairs, baselines=baselines, scene_baselines=scene_bperp)
fig.show()
示例:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pairs
|
list[Pair] | PairGroup
|
A flat list of pairs or a dictionary keyed by (path, frame)
with lists of pairs. Each pair is a tuple |
required |
baselines
|
BaselineTable
|
Table or mapping containing temporal and perpendicular baseline information for each interferogram pair. |
required |
title
|
str
|
Main title of the network plot. Defaults to "Interferogram Network". |
'Interferogram Network'
|
figsize
|
tuple[int, int]
|
Figure size (width, height) in inches. Defaults to (18, 7). |
(18, 7)
|
save_path
|
str | Path | None
|
Path to save the generated figure. If None, figure is not saved. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If any scene name in |
ValueError
|
If a scene name cannot be parsed into a valid date. |
Source code in src/insarhub/utils/tool.py
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 | |
ERA5 下载器
下载用于 MintPy 大气延迟校正的 ERA5 压力层天气数据。自动从 HyP3 zip 文件中确定所需的获取日期和空间范围,并使用 MintPy 兼容命名规则(ERA5_S*_N*_W*_E*_YYYYMMDD_HH.grb)保存文件。需要包含 CDS API 凭据的 ~/.cdsapirc 文件。
from insarhub.utils import ERA5Downloader
era5 = ERA5Downloader(output_dir='path/to/era5', num_processes=3, max_retries=3)
era5.download_batch(batch_dir='path/to/hyp3/outputs')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str
|
Directory to save ERA5 |
None
|
num_processes
|
int
|
Number of parallel download workers. Defaults to 3. |
3
|
max_retries
|
int
|
Retry attempts per file on download failure. Defaults to 3. |
3
|
Source code in src/insarhub/utils/batch.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
download_batch(batch_dir)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_dir
|
str
|
Directory containing HyP3 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no valid geometry can be extracted from any zip file in the batch directory. |
Source code in src/insarhub/utils/batch.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
Earthdata 凭据池
如果用户拥有多个 Earthdata 凭据,可将其存储在 ~/.credit_pool 中,格式为:
from insarhub import Processor
processor= Processor.create('Hyp3_S1', earthdata_credentials_pool=ec_pool, ....)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
earthdata_credentials_pool_path
|
Path
|
Path to the Earthdata credentials file. Defaults to
|
joinpath('.credit_pool')
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified credentials file does not exist. |
ValueError
|
If any line in the file does not contain a single ':' separating key and value. |
OSError
|
For any other I/O related errors while reading the file. |
Source code in src/insarhub/utils/tool.py
SLURM 任务配置
此类封装了生成 SLURM 批处理脚本所需的所有参数,包括资源分配、任务设置、环境配置和执行命令。
from insarhub.utils import Slurmjob_Config
config = SlurmJobConfig(
job_name="my_analysis",
time="02:00:00",
command="python analyze.py"
)
config.to_script("analysis.slurm")
Attributes:
| Name | Type | Description |
|---|---|---|
job_name |
str
|
Name of the SLURM job. |
output_file |
str
|
Path for standard output. Use %j for job ID. |
error_file |
str
|
Path for standard error. Use %j for job ID. |
time |
str
|
Maximum wall time in HH:MM:SS format. |
partition |
str
|
SLURM partition name to submit to. |
nodes |
int
|
Number of nodes to allocate. |
ntasks |
int
|
Number of tasks to run. |
cpus_per_task |
int
|
CPUs per task. |
mem |
str
|
Memory allocation per node (e.g., "4G", "500M"). |
nodelist |
Optional[str]
|
Specific nodes to use (e.g., "node[01-05]"). |
gpus |
Optional[str]
|
GPU allocation (e.g., "1", "2", "1g"). |
array |
Optional[str]
|
Array job specification (e.g., "0-9", "1-100%10"). |
dependency |
Optional[str]
|
Job dependency condition (e.g., "afterok:123456"). |
mail_user |
Optional[str]
|
Email address for job notifications. |
mail_type |
str
|
When to send email notifications (BEGIN, END, FAIL, ALL). |
account |
Optional[str]
|
Account to charge resources to. |
qos |
Optional[str]
|
Quality of Service specification. |
modules |
List[str]
|
List of environment modules to load. |
conda_env |
Optional[str]
|
Name of conda environment to activate. |
export_env |
Dict[str, str]
|
Dictionary of environment variables to export. |
command |
str
|
Bash command(s) to execute. |
Source code in src/insarhub/utils/tool.py
2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 | |
