jinwu-swift 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,233 @@
1
+ Metadata-Version: 2.4
2
+ Name: jinwu-swift
3
+ Version: 0.2.1
4
+ Summary: Swift/BAT instrument support for the jinwu analysis toolkit.
5
+ Author-email: Xinxiang Sun <sunxx@nao.cas.cn>
6
+ License: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/xinxiangsun/jinwu
8
+ Project-URL: Repository, https://github.com/xinxiangsun/jinwu
9
+ Project-URL: Documentation, https://jinwu.readthedocs.io
10
+ Keywords: astrophysics,transient,swift,bat,jinwu
11
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
17
+ Classifier: Development Status :: 3 - Alpha
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ Requires-Dist: jinwu<0.3,>=0.2
21
+ Requires-Dist: swiftbat
22
+ Provides-Extra: gdt
23
+ Requires-Dist: astro-gdt-swift>=2.2; extra == "gdt"
24
+ Provides-Extra: ukssdc
25
+ Requires-Dist: swifttools>=3.0; extra == "ukssdc"
26
+ Provides-Extra: survey
27
+ Requires-Dist: batanalysis>=2.1; extra == "survey"
28
+ Requires-Dist: astroquery>=0.4; extra == "survey"
29
+
30
+ # jinwu-swift
31
+
32
+ Swift/BAT instrument support for the
33
+ [jinwu](https://pypi.org/project/jinwu/) analysis toolkit: BAT observation
34
+ handling, attitude reconstruction and survey/posted data products.
35
+
36
+ ```bash
37
+ pip install jinwu-swift
38
+ ```
39
+
40
+ Import as `jinwu.swift`, e.g. `from jinwu.swift.bat import BATObservation`.
41
+
42
+ ## Optional extras
43
+
44
+ ```bash
45
+ pip install "jinwu-swift[gdt]" # gdt-swift: SAO/poshist 指向文件读取与天图
46
+ pip install "jinwu-swift[ukssdc]" # swifttools: UKSSDC 目录查询与 Burst Analyser 下载
47
+ pip install "jinwu-swift[survey]" # BatAnalysis + HEASARC query for BAT survey
48
+ ```
49
+
50
+ Without the `gdt` extra the core BAT workflows work; SAO/poshist-based
51
+ features degrade gracefully (`jinwu.swift.bat.bat_observation.HAS_GDT_SWIFT`
52
+ is `False`).
53
+
54
+ ## BAT+XRT GRB pipeline (`jinwu.swift.grb`)
55
+
56
+ Resumable per-GRB pipeline ported from the `swift_highz_grb` research
57
+ workflow, registered as `"swift.grb"` and built on `jinwu.core.pipeline`:
58
+
59
+ ```
60
+ catalog → download → {lightcurve, prompt, galactic_absorption, bblocks}
61
+ → spectra → fit → report
62
+ ```
63
+
64
+ - **catalog** — resolve the GRB in `catalog/swift_grb_catalog_merged.csv`
65
+ (research merge of SDC/UK_XRT/BAT_GRB) with redshift priority selection and
66
+ the NASA BAT duration windows (`bat_t90_start_s/stop_s`).
67
+ - **download** — verify Burst Analyser `parsed/` products; optionally fetch
68
+ via `SwiftBurstAnalyserFetcher` (3-tier strategy, BadBin preservation,
69
+ requires the `ukssdc` extra). Local XRT product directories are preferred.
70
+ `--request-xrt` is the only switch that can submit an UKSSDC job; its saved
71
+ state is resumed by `--poll-xrt` and an ambiguous submission is never sent a
72
+ second time automatically.
73
+ - **lightcurve** — BadBin-filtered BAT + XRT WT/PC flux series → NPZ +
74
+ three-panel figure (flux / N_H / Γ) in the research styling.
75
+ - **prompt** — strict prompt-stage judgment (XRT start inside the absolute
76
+ BAT T90 window); missing inputs yield `UNDECIDED`.
77
+ - **galactic_absorption** — weighted Galactic N_H via
78
+ `jinwu.core.galactic.resolve_galactic_absorption` (cached per workspace).
79
+ - **bblocks** — Bayesian blocks on XRT source/background events (WT per-GTI,
80
+ PC per observation, GTI fallback), Li-Ma significance with SRCAREA/BGAREA
81
+ alpha, and low-SNR merging. An absent area scale stops that segment rather
82
+ than assuming alpha = 1.
83
+ - **spectra** — XSELECT source/background PHA per segment (right edge +ε),
84
+ `grppha_hsp` grouping with interval0 RMF/ARF links.
85
+ - **fit** — `jinwu.core.fit.fit_prepared` per segment with the research
86
+ model `tbabs*ztbabs*cflux*powerlaw`, frozen Galactic N_H, catalog redshift
87
+ (requires a HEASoft/PyXspec environment).
88
+ - **report** — `grb_summary.json`, `summary.txt`, and
89
+ `spectral_parameters.csv`; the optional overlay is written as a separate
90
+ report NPZ/PNG and never rewrites the lightcurve-stage NPZ.
91
+
92
+ `SwiftGRB` in `jinwu.core.config` is the public preset. Its BAT Burst
93
+ Analyser product is `SNR5_sinceT0:BATBand` and **BATBand is 15--50 keV**;
94
+ that product band is distinct from Swift/BAT's 15--150 keV instrument range.
95
+ XRT fitting uses 0.3--10 keV, C-stat (reported as W-stat when a Poisson
96
+ background is loaded), group 20, and Δstat=1 profile errors.
97
+
98
+ Run from the command line against a research-style workspace:
99
+
100
+ ```bash
101
+ python -m jinwu.swift.grb \
102
+ --root ~/research/swift_highz_grb/output \
103
+ --grb 050904 --nh 0.09 --output-dir /tmp/grb050904_jinwu
104
+ # --until bblocks 只跑到某阶段;--no-resume 忽略缓存;缺失网络产品时该阶段
105
+ # 记为 needs_review,补齐数据后重跑即从断点继续
106
+
107
+ # Only with a registered UKSSDC XRT-product account:
108
+ python -m jinwu.swift.grb --root ~/research/swift_highz_grb/output --grb 050904 \
109
+ --request-xrt --xrt-user "$SWIFT_XRT_USER"
110
+ ```
111
+
112
+ Python API:
113
+
114
+ ```python
115
+ from jinwu.core.config import SwiftGRB
116
+ from jinwu.core.pipeline import pipeline
117
+ from jinwu.swift.grb import SwiftGRBInput
118
+
119
+ result = pipeline(
120
+ SwiftGRB(),
121
+ SwiftGRBInput(target_id="050904", root=workspace,
122
+ output_root="/tmp/grb050904_jinwu",
123
+ xrt_products_dir=workspace / "xrt_product_requests_maybe/downloads/GRB_050904"),
124
+ ).run()
125
+ ```
126
+
127
+ ## BAT survey 单目标管线 (`jinwu.swift.bat.survey`)
128
+
129
+ 该入口处理一个已知位置的 Swift/BAT survey 目标,流程为:
130
+
131
+ ```
132
+ 预检 → 观测发现 → 可选下载 → survey → 光变 → 可选 mosaic → PHA/响应 → 拟合或上限 → 报告
133
+ ```
134
+
135
+ ```python
136
+ from jinwu.core.config import BATSurvey
137
+ from jinwu.swift.bat.survey import BATSurveyInput, BATSurveyPipeline
138
+
139
+ job = BATSurveyInput(
140
+ target_id="NGC4253",
141
+ root="/data/swift/batdata",
142
+ output_root="/tmp/ngc4253_bat_survey",
143
+ source_name="NGC4253",
144
+ coord=(183.5625, 29.8125), # ICRS degrees
145
+ obsids=("00098092002",),
146
+ time_windows=(("2024-07-16T12:00:00", "2024-07-16T13:00:00"),),
147
+ download=False, # local-first; explicit opt-in
148
+ mosaic=False,
149
+ )
150
+ result = BATSurveyPipeline(job, config=BATSurvey()).run()
151
+ print(result.science_status, result.products["report"])
152
+ ```
153
+
154
+ 命令行等价用法:
155
+
156
+ ```bash
157
+ python -m jinwu.swift.bat.survey NGC4253 \
158
+ --root /data/swift/batdata --output /tmp/ngc4253_bat_survey \
159
+ --source-name NGC4253 --ra 183.5625 --dec 29.8125 \
160
+ --obsid 00098092002 \
161
+ --window 2024-07-16T12:00:00 2024-07-16T13:00:00
162
+ ```
163
+
164
+ 同样的参数也可直接运行带注释的
165
+ [`examples/bat_survey_pipeline.py`](examples/bat_survey_pipeline.py);它支持
166
+ `--until`、`--no-resume`、本地 survey/mosaic 路径以及与命令行一致的查询、下载、
167
+ 并行和超时选项。
168
+
169
+ 已有结果可用 `--survey-products` 或 `--mosaic-products` 直接接入;原始单观测目录
170
+ 可用 `--raw-products` 指定。`--until` 和 `--no-resume` 分别控制阶段停止和缓存恢复。
171
+
172
+ `--query` 和 `--download` 分别显式启用在线发现和下载,`--mosaic` 启用时间窗
173
+ mosaic,`--profile lmjagn` 使用参考项目的 8000/0.01 筛选配置,默认配置仍为
174
+ 10000/0.05。survey 率保留 `CENT_RATE` 的正负号,优先使用 `RATE_ERR`,并保留
175
+ `BKG_VAR` 供产品定义的 SNR 和缺失误差回退;它们是 Gaussian count/s/fully
176
+ illuminated detector 测量,不是能流。请求窗口
177
+ 和实际完整指向曝光分开写入报告,短窗口不会把完整指向 PHA 按比例缩放。
178
+ 每个 survey CAT 的八个原生能道会保留,并在没有附带总能段时按误差平方和推导一个
179
+ 第九个总能段;已有第九列不会再次累加。`RATE_ERR` 优先作为源率误差,只有缺失时
180
+ 才回退到 `BKG_VAR`,而 `Flux/ECF` 推导的结果会标记为计数率来源。仅有
181
+ `batsurvey.pickle` 或完成标记的目录不会被当作可用科学产品;PHA、响应和处理状态
182
+ 会在光谱阶段重新核验。兼容的 QDP 光变会标记为 `native_qdp_rate`,但因其只给出
183
+ 单点时间误差,不会被当作完整指向曝光参与窗口谱选择。
184
+ 若结果树含有逐指向 `*.gti`,光变选择会记录真实 GTI 重叠;该重叠只用于窗口覆盖
185
+ 判定,完整 survey 曝光和 PHA 不会按重叠比例缩放。
186
+
187
+ BAT survey 光谱的上限使用带符号 `RATE` 的 Gaussian profile:`STAT_ERR` 是统计误差,
188
+ OGIP `SYS_ERR` 只转换并加入一次,`BKG_VAR` 只用于原生 TOTSNR 的灵敏度校准,不会
189
+ 混入光谱拟合误差。响应模板用同一 PHA/RSP 通过 `fakeit(applyStats=False)` 生成,默认
190
+ 固定 Γ=2、`Δχ²=9`(单侧高斯等效置信度 `0.9986501019683699`)。每个结果分别保存
191
+ `observed_upper_bound`(本次观测的条件 profile)和 `detection_sensitivity`(空白控制
192
+ 样本加固定位置注入的 90% 检出灵敏度);没有足够控制尾部时后者明确为
193
+ `calibration_status=unavailable`,不会用人工 `nσ×BKG_VAR` PHA 代替。
194
+
195
+ ```bash
196
+ # 明确提供空白 survey 控制表后才会估计固定位置灵敏度
197
+ python -m jinwu.swift.bat.survey AT20G_J182338-345412 \
198
+ --root /data/swift/batdata --survey-products /data/swift/00097302084_surveyresult \
199
+ --sensitivity-controls /data/swift/blank_sky_sources.fits \
200
+ --output /tmp/at20g_bat --obsid 00097302084 \
201
+ --window 2024-07-16T12:06:10 2024-07-16T12:19:58
202
+ ```
203
+
204
+ `--sensitivity-controls` 必须来自源不活跃、质量筛选一致的八能道 survey 产品;其
205
+ `BKG_VAR` 是局部天空噪声,不与 PHA `STAT_ERR` 相加。`--profile lmjagn` 只改变参考项目
206
+ 确认过的 8000/0.01 筛选和 0.01 mosaic 部分编码门槛,不改变能段或上限统计契约。
207
+
208
+ 需要控制资源时,可在命令行追加 `--processes N`、`--internal-threads 1` 和
209
+ `--task-timeout SECONDS`。网络阶段可分别用 `--network-timeout`、`--retries`、
210
+ `--retry-wait` 和 `--query-margin` 调整;每个阶段仍会在工作区下使用独立的
211
+ PFILES 和日志位置。
212
+
213
+ HEASoft/XSPEC 测试应在 `hea` 环境中运行。`conda run` 不会自动 source
214
+ HEASoft 的初始化脚本,因此管线在可选的 Swift 后端边界补齐
215
+ `heainit.sh` 所需的 `HEADAS`、Perl/PGPLOT 运行变量,并为每个阶段建立可写的
216
+ `HOME`、PFILES 和临时目录;核心配置导入仍不会加载 BatAnalysis 或发起网络请求。
217
+
218
+ ```bash
219
+ # 纯离线契约测试
220
+ PYTHONPATH=$PWD/packages/jinwu/src:$PWD/packages/jinwu-swift/src \
221
+ conda run --no-capture-output -n hea python -m pytest \
222
+ packages/jinwu-swift/tests/test_bat_survey.py -q -p no:cacheprovider
223
+
224
+ # 本地 AT20G PHA/RSP 的 XSPEC 上限验收(显式 opt-in)
225
+ JINWU_RUN_REAL_DATA=1 \
226
+ PYTHONPATH=$PWD/packages/jinwu/src:$PWD/packages/jinwu-swift/src \
227
+ conda run --no-capture-output -n hea python -m pytest \
228
+ packages/jinwu-swift/tests/test_bat_survey_heasoft.py -q -p no:cacheprovider
229
+ ```
230
+
231
+ 真实观测查询、下载和在线 mosaic 均默认关闭;只有显式加入 `--query`、
232
+ `--download` 或 `--mosaic` 才会启用相应阶段。未设置注册的 Swift/UKSSDC 账号时,
233
+ 不要提交在线产品请求。
@@ -0,0 +1,204 @@
1
+ # jinwu-swift
2
+
3
+ Swift/BAT instrument support for the
4
+ [jinwu](https://pypi.org/project/jinwu/) analysis toolkit: BAT observation
5
+ handling, attitude reconstruction and survey/posted data products.
6
+
7
+ ```bash
8
+ pip install jinwu-swift
9
+ ```
10
+
11
+ Import as `jinwu.swift`, e.g. `from jinwu.swift.bat import BATObservation`.
12
+
13
+ ## Optional extras
14
+
15
+ ```bash
16
+ pip install "jinwu-swift[gdt]" # gdt-swift: SAO/poshist 指向文件读取与天图
17
+ pip install "jinwu-swift[ukssdc]" # swifttools: UKSSDC 目录查询与 Burst Analyser 下载
18
+ pip install "jinwu-swift[survey]" # BatAnalysis + HEASARC query for BAT survey
19
+ ```
20
+
21
+ Without the `gdt` extra the core BAT workflows work; SAO/poshist-based
22
+ features degrade gracefully (`jinwu.swift.bat.bat_observation.HAS_GDT_SWIFT`
23
+ is `False`).
24
+
25
+ ## BAT+XRT GRB pipeline (`jinwu.swift.grb`)
26
+
27
+ Resumable per-GRB pipeline ported from the `swift_highz_grb` research
28
+ workflow, registered as `"swift.grb"` and built on `jinwu.core.pipeline`:
29
+
30
+ ```
31
+ catalog → download → {lightcurve, prompt, galactic_absorption, bblocks}
32
+ → spectra → fit → report
33
+ ```
34
+
35
+ - **catalog** — resolve the GRB in `catalog/swift_grb_catalog_merged.csv`
36
+ (research merge of SDC/UK_XRT/BAT_GRB) with redshift priority selection and
37
+ the NASA BAT duration windows (`bat_t90_start_s/stop_s`).
38
+ - **download** — verify Burst Analyser `parsed/` products; optionally fetch
39
+ via `SwiftBurstAnalyserFetcher` (3-tier strategy, BadBin preservation,
40
+ requires the `ukssdc` extra). Local XRT product directories are preferred.
41
+ `--request-xrt` is the only switch that can submit an UKSSDC job; its saved
42
+ state is resumed by `--poll-xrt` and an ambiguous submission is never sent a
43
+ second time automatically.
44
+ - **lightcurve** — BadBin-filtered BAT + XRT WT/PC flux series → NPZ +
45
+ three-panel figure (flux / N_H / Γ) in the research styling.
46
+ - **prompt** — strict prompt-stage judgment (XRT start inside the absolute
47
+ BAT T90 window); missing inputs yield `UNDECIDED`.
48
+ - **galactic_absorption** — weighted Galactic N_H via
49
+ `jinwu.core.galactic.resolve_galactic_absorption` (cached per workspace).
50
+ - **bblocks** — Bayesian blocks on XRT source/background events (WT per-GTI,
51
+ PC per observation, GTI fallback), Li-Ma significance with SRCAREA/BGAREA
52
+ alpha, and low-SNR merging. An absent area scale stops that segment rather
53
+ than assuming alpha = 1.
54
+ - **spectra** — XSELECT source/background PHA per segment (right edge +ε),
55
+ `grppha_hsp` grouping with interval0 RMF/ARF links.
56
+ - **fit** — `jinwu.core.fit.fit_prepared` per segment with the research
57
+ model `tbabs*ztbabs*cflux*powerlaw`, frozen Galactic N_H, catalog redshift
58
+ (requires a HEASoft/PyXspec environment).
59
+ - **report** — `grb_summary.json`, `summary.txt`, and
60
+ `spectral_parameters.csv`; the optional overlay is written as a separate
61
+ report NPZ/PNG and never rewrites the lightcurve-stage NPZ.
62
+
63
+ `SwiftGRB` in `jinwu.core.config` is the public preset. Its BAT Burst
64
+ Analyser product is `SNR5_sinceT0:BATBand` and **BATBand is 15--50 keV**;
65
+ that product band is distinct from Swift/BAT's 15--150 keV instrument range.
66
+ XRT fitting uses 0.3--10 keV, C-stat (reported as W-stat when a Poisson
67
+ background is loaded), group 20, and Δstat=1 profile errors.
68
+
69
+ Run from the command line against a research-style workspace:
70
+
71
+ ```bash
72
+ python -m jinwu.swift.grb \
73
+ --root ~/research/swift_highz_grb/output \
74
+ --grb 050904 --nh 0.09 --output-dir /tmp/grb050904_jinwu
75
+ # --until bblocks 只跑到某阶段;--no-resume 忽略缓存;缺失网络产品时该阶段
76
+ # 记为 needs_review,补齐数据后重跑即从断点继续
77
+
78
+ # Only with a registered UKSSDC XRT-product account:
79
+ python -m jinwu.swift.grb --root ~/research/swift_highz_grb/output --grb 050904 \
80
+ --request-xrt --xrt-user "$SWIFT_XRT_USER"
81
+ ```
82
+
83
+ Python API:
84
+
85
+ ```python
86
+ from jinwu.core.config import SwiftGRB
87
+ from jinwu.core.pipeline import pipeline
88
+ from jinwu.swift.grb import SwiftGRBInput
89
+
90
+ result = pipeline(
91
+ SwiftGRB(),
92
+ SwiftGRBInput(target_id="050904", root=workspace,
93
+ output_root="/tmp/grb050904_jinwu",
94
+ xrt_products_dir=workspace / "xrt_product_requests_maybe/downloads/GRB_050904"),
95
+ ).run()
96
+ ```
97
+
98
+ ## BAT survey 单目标管线 (`jinwu.swift.bat.survey`)
99
+
100
+ 该入口处理一个已知位置的 Swift/BAT survey 目标,流程为:
101
+
102
+ ```
103
+ 预检 → 观测发现 → 可选下载 → survey → 光变 → 可选 mosaic → PHA/响应 → 拟合或上限 → 报告
104
+ ```
105
+
106
+ ```python
107
+ from jinwu.core.config import BATSurvey
108
+ from jinwu.swift.bat.survey import BATSurveyInput, BATSurveyPipeline
109
+
110
+ job = BATSurveyInput(
111
+ target_id="NGC4253",
112
+ root="/data/swift/batdata",
113
+ output_root="/tmp/ngc4253_bat_survey",
114
+ source_name="NGC4253",
115
+ coord=(183.5625, 29.8125), # ICRS degrees
116
+ obsids=("00098092002",),
117
+ time_windows=(("2024-07-16T12:00:00", "2024-07-16T13:00:00"),),
118
+ download=False, # local-first; explicit opt-in
119
+ mosaic=False,
120
+ )
121
+ result = BATSurveyPipeline(job, config=BATSurvey()).run()
122
+ print(result.science_status, result.products["report"])
123
+ ```
124
+
125
+ 命令行等价用法:
126
+
127
+ ```bash
128
+ python -m jinwu.swift.bat.survey NGC4253 \
129
+ --root /data/swift/batdata --output /tmp/ngc4253_bat_survey \
130
+ --source-name NGC4253 --ra 183.5625 --dec 29.8125 \
131
+ --obsid 00098092002 \
132
+ --window 2024-07-16T12:00:00 2024-07-16T13:00:00
133
+ ```
134
+
135
+ 同样的参数也可直接运行带注释的
136
+ [`examples/bat_survey_pipeline.py`](examples/bat_survey_pipeline.py);它支持
137
+ `--until`、`--no-resume`、本地 survey/mosaic 路径以及与命令行一致的查询、下载、
138
+ 并行和超时选项。
139
+
140
+ 已有结果可用 `--survey-products` 或 `--mosaic-products` 直接接入;原始单观测目录
141
+ 可用 `--raw-products` 指定。`--until` 和 `--no-resume` 分别控制阶段停止和缓存恢复。
142
+
143
+ `--query` 和 `--download` 分别显式启用在线发现和下载,`--mosaic` 启用时间窗
144
+ mosaic,`--profile lmjagn` 使用参考项目的 8000/0.01 筛选配置,默认配置仍为
145
+ 10000/0.05。survey 率保留 `CENT_RATE` 的正负号,优先使用 `RATE_ERR`,并保留
146
+ `BKG_VAR` 供产品定义的 SNR 和缺失误差回退;它们是 Gaussian count/s/fully
147
+ illuminated detector 测量,不是能流。请求窗口
148
+ 和实际完整指向曝光分开写入报告,短窗口不会把完整指向 PHA 按比例缩放。
149
+ 每个 survey CAT 的八个原生能道会保留,并在没有附带总能段时按误差平方和推导一个
150
+ 第九个总能段;已有第九列不会再次累加。`RATE_ERR` 优先作为源率误差,只有缺失时
151
+ 才回退到 `BKG_VAR`,而 `Flux/ECF` 推导的结果会标记为计数率来源。仅有
152
+ `batsurvey.pickle` 或完成标记的目录不会被当作可用科学产品;PHA、响应和处理状态
153
+ 会在光谱阶段重新核验。兼容的 QDP 光变会标记为 `native_qdp_rate`,但因其只给出
154
+ 单点时间误差,不会被当作完整指向曝光参与窗口谱选择。
155
+ 若结果树含有逐指向 `*.gti`,光变选择会记录真实 GTI 重叠;该重叠只用于窗口覆盖
156
+ 判定,完整 survey 曝光和 PHA 不会按重叠比例缩放。
157
+
158
+ BAT survey 光谱的上限使用带符号 `RATE` 的 Gaussian profile:`STAT_ERR` 是统计误差,
159
+ OGIP `SYS_ERR` 只转换并加入一次,`BKG_VAR` 只用于原生 TOTSNR 的灵敏度校准,不会
160
+ 混入光谱拟合误差。响应模板用同一 PHA/RSP 通过 `fakeit(applyStats=False)` 生成,默认
161
+ 固定 Γ=2、`Δχ²=9`(单侧高斯等效置信度 `0.9986501019683699`)。每个结果分别保存
162
+ `observed_upper_bound`(本次观测的条件 profile)和 `detection_sensitivity`(空白控制
163
+ 样本加固定位置注入的 90% 检出灵敏度);没有足够控制尾部时后者明确为
164
+ `calibration_status=unavailable`,不会用人工 `nσ×BKG_VAR` PHA 代替。
165
+
166
+ ```bash
167
+ # 明确提供空白 survey 控制表后才会估计固定位置灵敏度
168
+ python -m jinwu.swift.bat.survey AT20G_J182338-345412 \
169
+ --root /data/swift/batdata --survey-products /data/swift/00097302084_surveyresult \
170
+ --sensitivity-controls /data/swift/blank_sky_sources.fits \
171
+ --output /tmp/at20g_bat --obsid 00097302084 \
172
+ --window 2024-07-16T12:06:10 2024-07-16T12:19:58
173
+ ```
174
+
175
+ `--sensitivity-controls` 必须来自源不活跃、质量筛选一致的八能道 survey 产品;其
176
+ `BKG_VAR` 是局部天空噪声,不与 PHA `STAT_ERR` 相加。`--profile lmjagn` 只改变参考项目
177
+ 确认过的 8000/0.01 筛选和 0.01 mosaic 部分编码门槛,不改变能段或上限统计契约。
178
+
179
+ 需要控制资源时,可在命令行追加 `--processes N`、`--internal-threads 1` 和
180
+ `--task-timeout SECONDS`。网络阶段可分别用 `--network-timeout`、`--retries`、
181
+ `--retry-wait` 和 `--query-margin` 调整;每个阶段仍会在工作区下使用独立的
182
+ PFILES 和日志位置。
183
+
184
+ HEASoft/XSPEC 测试应在 `hea` 环境中运行。`conda run` 不会自动 source
185
+ HEASoft 的初始化脚本,因此管线在可选的 Swift 后端边界补齐
186
+ `heainit.sh` 所需的 `HEADAS`、Perl/PGPLOT 运行变量,并为每个阶段建立可写的
187
+ `HOME`、PFILES 和临时目录;核心配置导入仍不会加载 BatAnalysis 或发起网络请求。
188
+
189
+ ```bash
190
+ # 纯离线契约测试
191
+ PYTHONPATH=$PWD/packages/jinwu/src:$PWD/packages/jinwu-swift/src \
192
+ conda run --no-capture-output -n hea python -m pytest \
193
+ packages/jinwu-swift/tests/test_bat_survey.py -q -p no:cacheprovider
194
+
195
+ # 本地 AT20G PHA/RSP 的 XSPEC 上限验收(显式 opt-in)
196
+ JINWU_RUN_REAL_DATA=1 \
197
+ PYTHONPATH=$PWD/packages/jinwu/src:$PWD/packages/jinwu-swift/src \
198
+ conda run --no-capture-output -n hea python -m pytest \
199
+ packages/jinwu-swift/tests/test_bat_survey_heasoft.py -q -p no:cacheprovider
200
+ ```
201
+
202
+ 真实观测查询、下载和在线 mosaic 均默认关闭;只有显式加入 `--query`、
203
+ `--download` 或 `--mosaic` 才会启用相应阶段。未设置注册的 Swift/UKSSDC 账号时,
204
+ 不要提交在线产品请求。
@@ -0,0 +1,49 @@
1
+ [build-system]
2
+ requires = ["setuptools>=64"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "jinwu-swift"
7
+ version = "0.2.1"
8
+ description = "Swift/BAT instrument support for the jinwu analysis toolkit."
9
+ readme = "README.md"
10
+ license = { text = "GPL-3.0-or-later" }
11
+ authors = [
12
+ { name = "Xinxiang Sun", email = "sunxx@nao.cas.cn" }
13
+ ]
14
+ requires-python = ">=3.11"
15
+ dependencies = [
16
+ "jinwu>=0.2,<0.3",
17
+ "swiftbat",
18
+ ]
19
+ keywords = ["astrophysics", "transient", "swift", "bat", "jinwu"]
20
+
21
+ classifiers = [
22
+ "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3 :: Only",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Intended Audience :: Science/Research",
27
+ "Topic :: Scientific/Engineering :: Astronomy",
28
+ "Development Status :: 3 - Alpha"
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ # gdt-swift 提供 SAO/poshist 指向文件读取(bat_observation 可选导入)
33
+ gdt = ["astro-gdt-swift>=2.2"]
34
+ # swifttools 提供 UKSSDC 目录查询与 Burst Analyser 下载(grb.pipeline 下载档可选导入)
35
+ ukssdc = ["swifttools>=3.0"]
36
+ # BatAnalysis and HEASARC query support for the single-target survey pipeline.
37
+ survey = ["batanalysis>=2.1", "astroquery>=0.4"]
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/xinxiangsun/jinwu"
41
+ Repository = "https://github.com/xinxiangsun/jinwu"
42
+ Documentation = "https://jinwu.readthedocs.io"
43
+
44
+ [project.entry-points."jinwu.instruments"]
45
+ swift = "jinwu.swift"
46
+
47
+ [tool.setuptools.packages.find]
48
+ where = ["src"]
49
+ include = ["jinwu.swift*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,7 @@
1
+ # Swift module for jinwu
2
+ # Swift 模块
3
+
4
+ from . import bat
5
+ from . import grb
6
+
7
+ __all__ = ['bat', 'grb']
@@ -0,0 +1,19 @@
1
+ """Compatibility shim: module renamed to :mod:`jinwu.swift.bat.bat_observation`.
2
+
3
+ New code should use ``from jinwu.swift.bat import BATObservation``.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import warnings
9
+
10
+ warnings.warn(
11
+ "The jinwu.swift.bat.BATObservation module is deprecated; import "
12
+ "BATObservation from jinwu.swift.bat or jinwu.swift.bat.bat_observation",
13
+ DeprecationWarning,
14
+ stacklevel=2,
15
+ )
16
+
17
+ from .bat_observation import BATObservation # noqa: F401
18
+
19
+ __all__ = ["BATObservation"]
@@ -0,0 +1,35 @@
1
+ # BAT submodule for jinwu
2
+ # BAT 子模块
3
+
4
+ from .bat_observation import BATObservation
5
+ from .attitude import Attitude
6
+
7
+ # Keep the optional BatAnalysis adapter lazy. Besides avoiding an optional
8
+ # dependency at package import time, this prevents ``python -m
9
+ # jinwu.swift.bat.survey`` from importing the module once through the package
10
+ # and then executing it a second time under ``__main__``.
11
+ _SURVEY_EXPORTS = (
12
+ 'BATSurveyInput', 'BATSurveyPipeline', 'BATSurveyResult',
13
+ 'BatAnalysisSurveyBackend', 'AreaRow', 'SurveyRatePoint',
14
+ 'SurveyPhaValidation', 'SurveyUpperLimitResult', 'build_source_catalog',
15
+ 'calculate_background_scale', 'read_gti_intervals',
16
+ 'gti_overlap_duration', 'parse_area_table', 'read_bat_survey_rates',
17
+ 'safe_extract_archive', 'select_overlapping_pointings', 'signed_snr',
18
+ 'validate_observation_directory', 'validate_survey_pha',
19
+ 'profile_survey_upper_limit', 'estimate_bat_survey_sensitivity',
20
+ 'BATSurveySensitivityAdapter',
21
+ )
22
+
23
+ __all__ = [
24
+ 'BATObservation', 'Attitude',
25
+ *_SURVEY_EXPORTS,
26
+ ]
27
+
28
+
29
+ def __getattr__(name):
30
+ if name in _SURVEY_EXPORTS:
31
+ from . import survey
32
+ value = getattr(survey, name)
33
+ globals()[name] = value
34
+ return value
35
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")