bat-glimpse 0.1.0__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,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,85 @@
1
+ # BAT Glimpse
2
+
3
+ ## Install
4
+
5
+ After publishing to PyPI:
6
+
7
+ ```bash
8
+ python -m pip install bat-glimpse
9
+ ```
10
+
11
+ From the repository root before publishing:
12
+
13
+ ```bash
14
+ python -m pip install .
15
+ ```
16
+
17
+ ## Developer Mode
18
+
19
+ ```bash
20
+ git clone <repository-url>
21
+ cd BAT-GLIMPSE
22
+ python3.10 -m venv .venv
23
+ source .venv/bin/activate
24
+ python -m pip install --upgrade pip
25
+ python -m pip install -e .
26
+ ```
27
+
28
+ Editable mode links the installed command to this checkout, so changes under
29
+ `batglimpse/` are picked up without reinstalling the package.
30
+
31
+ Run the local checkout with:
32
+
33
+ ```bash
34
+ bat-glimpse --workdir /path/to/workdir --trigtime 2026-01-01T00:00:00.000
35
+ ```
36
+
37
+ or:
38
+
39
+ ```bash
40
+ python -m batglimpse --workdir /path/to/workdir --trigtime 2026-01-01T00:00:00.000
41
+ ```
42
+
43
+ The pipeline also expects the Swift/BAT analysis environment required by
44
+ `batanalysis` to be configured, including HEASoft/CALDB where applicable.
45
+ BAT Glimpse uses `BatAnalysis==2.1.0` and requires Python 3.10 or newer.
46
+
47
+ ## Run
48
+
49
+ ```bash
50
+ bat-glimpse --workdir /path/to/workdir --trigtime 2026-01-01T00:00:00.000
51
+ ```
52
+
53
+ You can also run the package module directly:
54
+
55
+ ```bash
56
+ python -m batglimpse --workdir /path/to/workdir --trigtime 2026-01-01T00:00:00.000
57
+ ```
58
+
59
+ If `--trigtime` is omitted, BAT Glimpse reads `trigtime` from
60
+ `<workdir>/config.json`.
61
+
62
+ ## Main options
63
+
64
+ - `--workdir`: required working directory for inputs and outputs.
65
+ - `--trigtime`: trigger time in `YYYY-MM-DDTHH:MM:SS.sss` format.
66
+ - `--tmin` and `--tmax`: explicit ad-hoc analysis window.
67
+ - `--pipe`: `imaging` or `mosaic` for ad-hoc analysis.
68
+ - `--ext_obsid`: override the GUANO obsid.
69
+ - `--healpix_nside`: mosaic HEALPix resolution.
70
+ - `--skyview_nprocs`: processes used while creating skyviews.
71
+ - `--mosaic_nprocs`: processes used while mosaicing.
72
+
73
+ ## Outputs
74
+
75
+ BAT Glimpse writes logs, CSV detections, maps, and diagnostic plots into the
76
+ working directory. The main detection tables are `imaging.csv` and
77
+ `mosaic.csv`.
78
+
79
+ ## Authentication
80
+
81
+ Set `ECHO_API_TOKEN` if Echo trigger metadata is required:
82
+
83
+ ```bash
84
+ export ECHO_API_TOKEN=your-token
85
+ ```
@@ -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,15 @@
1
+ README.md
2
+ pyproject.toml
3
+ bat_glimpse.egg-info/PKG-INFO
4
+ bat_glimpse.egg-info/SOURCES.txt
5
+ bat_glimpse.egg-info/dependency_links.txt
6
+ bat_glimpse.egg-info/entry_points.txt
7
+ bat_glimpse.egg-info/requires.txt
8
+ bat_glimpse.egg-info/top_level.txt
9
+ batglimpse/__init__.py
10
+ batglimpse/__main__.py
11
+ batglimpse/bat_glimpse.py
12
+ batglimpse/bat_glimpse_helpers.py
13
+ batglimpse/bat_glimpse_pipeline.py
14
+ batglimpse/bat_glimpse_plotting.py
15
+ batglimpse/bat_glimpse_utils.py
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ bat-glimpse = batglimpse.bat_glimpse:main
3
+ batglimpse = batglimpse.bat_glimpse:main
@@ -0,0 +1,24 @@
1
+ BatAnalysis==2.1.0
2
+ astroquery>=0.4.10
3
+ astropy>=4.3.1
4
+ dpath>=2.1.4
5
+ emcee
6
+ healpy>=1.16.6
7
+ histpy>=2.0.2
8
+ joblib>=1.1.0
9
+ ligo-gracedb
10
+ ligo.skymap>=2.1.2
11
+ matplotlib>=3.4.2
12
+ mhealpy>=0.3.5
13
+ numpy>=1.24.4
14
+ pandas
15
+ reproject>=0.13.1
16
+ requests>=2.20
17
+ scipy>=1.7.2
18
+ setuptools>=58.0.4
19
+ swiftbat>=0.1.5
20
+ swifttools==3.0.22
21
+ tqdm
22
+ astro-gdt-swift>=1.0.1
23
+ astro-gdt-fermi
24
+ scikit-learn
@@ -0,0 +1 @@
1
+ batglimpse
@@ -0,0 +1,3 @@
1
+ """BAT Glimpse package."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,5 @@
1
+ from .bat_glimpse import main
2
+
3
+
4
+ if __name__ == "__main__":
5
+ main()
@@ -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 *