bat-glimpse 0.1.0__py3-none-any.whl
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.
- bat_glimpse-0.1.0.dist-info/METADATA +116 -0
- bat_glimpse-0.1.0.dist-info/RECORD +12 -0
- bat_glimpse-0.1.0.dist-info/WHEEL +5 -0
- bat_glimpse-0.1.0.dist-info/entry_points.txt +3 -0
- bat_glimpse-0.1.0.dist-info/top_level.txt +1 -0
- batglimpse/__init__.py +3 -0
- batglimpse/__main__.py +5 -0
- batglimpse/bat_glimpse.py +141 -0
- batglimpse/bat_glimpse_helpers.py +1 -0
- batglimpse/bat_glimpse_pipeline.py +1089 -0
- batglimpse/bat_glimpse_plotting.py +691 -0
- batglimpse/bat_glimpse_utils.py +461 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bat-glimpse
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Swift BAT GUANO imaging and mosaic pipeline.
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: BatAnalysis==2.1.0
|
|
8
|
+
Requires-Dist: astroquery>=0.4.10
|
|
9
|
+
Requires-Dist: astropy>=4.3.1
|
|
10
|
+
Requires-Dist: dpath>=2.1.4
|
|
11
|
+
Requires-Dist: emcee
|
|
12
|
+
Requires-Dist: healpy>=1.16.6
|
|
13
|
+
Requires-Dist: histpy>=2.0.2
|
|
14
|
+
Requires-Dist: joblib>=1.1.0
|
|
15
|
+
Requires-Dist: ligo-gracedb
|
|
16
|
+
Requires-Dist: ligo.skymap>=2.1.2
|
|
17
|
+
Requires-Dist: matplotlib>=3.4.2
|
|
18
|
+
Requires-Dist: mhealpy>=0.3.5
|
|
19
|
+
Requires-Dist: numpy>=1.24.4
|
|
20
|
+
Requires-Dist: pandas
|
|
21
|
+
Requires-Dist: reproject>=0.13.1
|
|
22
|
+
Requires-Dist: requests>=2.20
|
|
23
|
+
Requires-Dist: scipy>=1.7.2
|
|
24
|
+
Requires-Dist: setuptools>=58.0.4
|
|
25
|
+
Requires-Dist: swiftbat>=0.1.5
|
|
26
|
+
Requires-Dist: swifttools==3.0.22
|
|
27
|
+
Requires-Dist: tqdm
|
|
28
|
+
Requires-Dist: astro-gdt-swift>=1.0.1
|
|
29
|
+
Requires-Dist: astro-gdt-fermi
|
|
30
|
+
Requires-Dist: scikit-learn
|
|
31
|
+
|
|
32
|
+
# BAT Glimpse
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
After publishing to PyPI:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python -m pip install bat-glimpse
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
From the repository root before publishing:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m pip install .
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Developer Mode
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
git clone <repository-url>
|
|
52
|
+
cd BAT-GLIMPSE
|
|
53
|
+
python3.10 -m venv .venv
|
|
54
|
+
source .venv/bin/activate
|
|
55
|
+
python -m pip install --upgrade pip
|
|
56
|
+
python -m pip install -e .
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Editable mode links the installed command to this checkout, so changes under
|
|
60
|
+
`batglimpse/` are picked up without reinstalling the package.
|
|
61
|
+
|
|
62
|
+
Run the local checkout with:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
bat-glimpse --workdir /path/to/workdir --trigtime 2026-01-01T00:00:00.000
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
or:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
python -m batglimpse --workdir /path/to/workdir --trigtime 2026-01-01T00:00:00.000
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The pipeline also expects the Swift/BAT analysis environment required by
|
|
75
|
+
`batanalysis` to be configured, including HEASoft/CALDB where applicable.
|
|
76
|
+
BAT Glimpse uses `BatAnalysis==2.1.0` and requires Python 3.10 or newer.
|
|
77
|
+
|
|
78
|
+
## Run
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
bat-glimpse --workdir /path/to/workdir --trigtime 2026-01-01T00:00:00.000
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
You can also run the package module directly:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
python -m batglimpse --workdir /path/to/workdir --trigtime 2026-01-01T00:00:00.000
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
If `--trigtime` is omitted, BAT Glimpse reads `trigtime` from
|
|
91
|
+
`<workdir>/config.json`.
|
|
92
|
+
|
|
93
|
+
## Main options
|
|
94
|
+
|
|
95
|
+
- `--workdir`: required working directory for inputs and outputs.
|
|
96
|
+
- `--trigtime`: trigger time in `YYYY-MM-DDTHH:MM:SS.sss` format.
|
|
97
|
+
- `--tmin` and `--tmax`: explicit ad-hoc analysis window.
|
|
98
|
+
- `--pipe`: `imaging` or `mosaic` for ad-hoc analysis.
|
|
99
|
+
- `--ext_obsid`: override the GUANO obsid.
|
|
100
|
+
- `--healpix_nside`: mosaic HEALPix resolution.
|
|
101
|
+
- `--skyview_nprocs`: processes used while creating skyviews.
|
|
102
|
+
- `--mosaic_nprocs`: processes used while mosaicing.
|
|
103
|
+
|
|
104
|
+
## Outputs
|
|
105
|
+
|
|
106
|
+
BAT Glimpse writes logs, CSV detections, maps, and diagnostic plots into the
|
|
107
|
+
working directory. The main detection tables are `imaging.csv` and
|
|
108
|
+
`mosaic.csv`.
|
|
109
|
+
|
|
110
|
+
## Authentication
|
|
111
|
+
|
|
112
|
+
Set `ECHO_API_TOKEN` if Echo trigger metadata is required:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
export ECHO_API_TOKEN=your-token
|
|
116
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
batglimpse/__init__.py,sha256=LWs8Dbiozwjb9xisnKjGXKZ75dPhPpOe4ruMnQbNde4,50
|
|
2
|
+
batglimpse/__main__.py,sha256=BNd5pAZEZkdZsZWiFb4TCSI3ri3QwoKfyEwfrVGIpLA,70
|
|
3
|
+
batglimpse/bat_glimpse.py,sha256=_f-M0JclGfs7kzSgG9IN4nrHWdjmMi_wv0aYkMrFfwI,5059
|
|
4
|
+
batglimpse/bat_glimpse_helpers.py,sha256=92ahT9vFP3PSFLO_sufi8n0BCeeadHzghbxGO8aR8sQ,33
|
|
5
|
+
batglimpse/bat_glimpse_pipeline.py,sha256=liBmawPdbVGtZFPQhu9420zRoBui4rSLGEmUscjHeMc,53917
|
|
6
|
+
batglimpse/bat_glimpse_plotting.py,sha256=2gd7MuBUNgDhsrqhiJVCNN7KH2me23TIxMUN3L7e4Qw,32448
|
|
7
|
+
batglimpse/bat_glimpse_utils.py,sha256=NHCI-C1AGyt-XHa82wmBwrYgwiFSNTGB5GvY7SqLnl0,18874
|
|
8
|
+
bat_glimpse-0.1.0.dist-info/METADATA,sha256=0FkUdsYU6I2kdqMrXBUzvqWkilDcaBWjlXPolYf7OK8,2931
|
|
9
|
+
bat_glimpse-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
10
|
+
bat_glimpse-0.1.0.dist-info/entry_points.txt,sha256=9ZI3dypGRmAUDVnF-23DCR6l6NJuLadWa77oXzBLeYA,101
|
|
11
|
+
bat_glimpse-0.1.0.dist-info/top_level.txt,sha256=D0BNHdHHgPvHRPjWbZXbGVf2vvdhP0qV_05Ch1KuKoM,11
|
|
12
|
+
bat_glimpse-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
batglimpse
|
batglimpse/__init__.py
ADDED
batglimpse/__main__.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import logging
|
|
4
|
+
import multiprocessing
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
import warnings
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from swifttools.swift_too import Clock
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
from EchoAPI import API
|
|
14
|
+
except ModuleNotFoundError:
|
|
15
|
+
API = None
|
|
16
|
+
|
|
17
|
+
from . import bat_glimpse_helpers as helpers
|
|
18
|
+
from .bat_glimpse_pipeline import guano_query
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
DEFAULT_API_TOKEN = os.getenv("ECHO_API_TOKEN")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def parse_args():
|
|
25
|
+
parser = argparse.ArgumentParser(description="Process some time.")
|
|
26
|
+
parser.add_argument("--trigtime", required=False, type=str, help="Time in the format YYYY-MM-DDTHH:MM:SS.sss")
|
|
27
|
+
parser.add_argument("--workdir", required=True, type=str, help="work directory")
|
|
28
|
+
parser.add_argument("--tmin", required=False, type=str, help="min time to start")
|
|
29
|
+
parser.add_argument("--tmax", required=False, type=str, help="max time to start")
|
|
30
|
+
parser.add_argument("--ext_obsid", required=False, type=str, help="obsid")
|
|
31
|
+
parser.add_argument("--pipe", required=False, type=str, help="pipeline, either imaging or mosaic")
|
|
32
|
+
parser.add_argument("--healpix_nside", type=int, default=512, help="Nside of mosaic healpix map")
|
|
33
|
+
parser.add_argument("--skyview_nprocs", type=int, default=8, help="Number of processes to use when creating skyviews in parallel")
|
|
34
|
+
parser.add_argument("--mosaic_nprocs", type=int, default=8, help="Number of processes to use when creating mosaic in parallel. NOTE: ALLOCATE ~10GB OF MEMORY PER PROCESS.")
|
|
35
|
+
return parser.parse_args()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def load_trigger_metadata(trigid):
|
|
39
|
+
if API is None:
|
|
40
|
+
logging.warning("EchoAPI is not available; continuing without external trigger metadata.")
|
|
41
|
+
return [], []
|
|
42
|
+
api = API(api_token=DEFAULT_API_TOKEN)
|
|
43
|
+
parsed_results = [json.loads(entry) for entry in api.get_trigs()]
|
|
44
|
+
match_ = next((entry for entry in parsed_results if entry.get("trigid") == float(trigid)), None)
|
|
45
|
+
if match_ is None:
|
|
46
|
+
logging.error(f"No matching trigger found for trigid {trigid}.")
|
|
47
|
+
return [], []
|
|
48
|
+
return match_["event_name"], match_["trigger_instruments"]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def prepare_runtime(args):
|
|
52
|
+
# Normalize path to avoid empty basename when a trailing slash is used.
|
|
53
|
+
workdir = os.path.abspath(os.path.normpath(args.workdir))
|
|
54
|
+
trigid = os.path.basename(workdir)[:9]
|
|
55
|
+
if not trigid:
|
|
56
|
+
raise ValueError(f"Unable to derive trigid from workdir: {workdir}")
|
|
57
|
+
os.makedirs(workdir, exist_ok=True)
|
|
58
|
+
warnings.filterwarnings("ignore")
|
|
59
|
+
log_path = os.path.join(workdir, "batglimpse.log")
|
|
60
|
+
logging.basicConfig(
|
|
61
|
+
filename=log_path,
|
|
62
|
+
level=logging.INFO,
|
|
63
|
+
format="%(asctime)s - %(levelname)s - %(message)s",
|
|
64
|
+
filemode="w",
|
|
65
|
+
force=True,
|
|
66
|
+
)
|
|
67
|
+
ext_trig, trig_instr = load_trigger_metadata(trigid)
|
|
68
|
+
helpers.set_runtime_context(workdir=workdir, trigid=trigid, ext_trig=ext_trig, trig_instr=trig_instr)
|
|
69
|
+
return workdir, trigid, ext_trig, trig_instr
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def create_nitrates_config(
|
|
73
|
+
trigger_time,
|
|
74
|
+
output_file="config.json",
|
|
75
|
+
trigger_id=0,
|
|
76
|
+
queue_id=0,
|
|
77
|
+
):
|
|
78
|
+
|
|
79
|
+
config = {
|
|
80
|
+
"ERRORS": [],
|
|
81
|
+
"WARNINGS": [],
|
|
82
|
+
"config": {
|
|
83
|
+
"BkgPost": "true",
|
|
84
|
+
"BkgPre": "true",
|
|
85
|
+
"BkgSrcPosFit": "null",
|
|
86
|
+
"Epeaks": [97.7, 212.1, 460.6],
|
|
87
|
+
"Gammas": [0.1, 0.6, 1.1],
|
|
88
|
+
"MaxDT": 20.48,
|
|
89
|
+
"MaxDur": 16.384,
|
|
90
|
+
"MinDT": -20.48,
|
|
91
|
+
"MinDur": 0.128,
|
|
92
|
+
"id": 99,
|
|
93
|
+
"minSNR": 2.5,
|
|
94
|
+
"name": "Default",
|
|
95
|
+
"version": "0.0.0",
|
|
96
|
+
},
|
|
97
|
+
"queueID": queue_id,
|
|
98
|
+
"triggerID": trigger_id,
|
|
99
|
+
"trigtime": trigger_time,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
with open(output_file, "w") as f:
|
|
103
|
+
json.dump(config, f, indent=4)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def main():
|
|
107
|
+
start_time = time.time()
|
|
108
|
+
print(f"Number of CPU cores available: {multiprocessing.cpu_count()}")
|
|
109
|
+
args = parse_args()
|
|
110
|
+
workdir, trigid, ext_trig, trig_instr = prepare_runtime(args)
|
|
111
|
+
|
|
112
|
+
create_nitrates_config(
|
|
113
|
+
trigger_time=args.trigtime,
|
|
114
|
+
output_file=os.path.join(args.workdir, "config.json"),
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
triggertime = args.trigtime
|
|
118
|
+
tmin = args.tmin
|
|
119
|
+
tmax = args.tmax
|
|
120
|
+
ext_obsid = args.ext_obsid
|
|
121
|
+
pipe = args.pipe
|
|
122
|
+
healpix_nside = args.healpix_nside
|
|
123
|
+
skyview_nprocs = args.skyview_nprocs
|
|
124
|
+
mosaic_nprocs = args.mosaic_nprocs
|
|
125
|
+
|
|
126
|
+
if triggertime is not None:
|
|
127
|
+
logging.info("Trying using already existing data")
|
|
128
|
+
with open(os.path.join(workdir, "config.json"), "r", encoding="utf-8") as handle:
|
|
129
|
+
config = json.load(handle)
|
|
130
|
+
triggertime = config.get("trigtime")
|
|
131
|
+
fail = False
|
|
132
|
+
start_time_try = time.time()
|
|
133
|
+
helpers.search_ext_maps(triggertime, workdir)
|
|
134
|
+
guano_query(triggertime, ext_obsid, workdir, tmin, tmax, pipe, healpix_nside, skyview_nprocs, mosaic_nprocs)
|
|
135
|
+
|
|
136
|
+
logging.info(f"Time spent: {time.time() - start_time} seconds")
|
|
137
|
+
try:
|
|
138
|
+
log_file = os.path.join(workdir, "batglimpse.log")
|
|
139
|
+
name_id = os.path.basename(workdir)
|
|
140
|
+
except Exception:
|
|
141
|
+
logging.error(f"Error in copying log file: {helpers.traceback.format_exc()}")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .bat_glimpse_utils import *
|