isgri 0.3.0__py3-none-any.whl → 0.5.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.
@@ -1,39 +1,210 @@
1
- from astropy.time import Time
2
-
3
-
4
- def ijd2utc(t):
5
- """
6
- Converts IJD (INTEGRAL Julian Date) time to UTC ISO format.
7
-
8
- Args:
9
- t (float or ndarray): IJD time value(s).
10
-
11
- Returns:
12
- str or ndarray: UTC time in ISO format (YYYY-MM-DD HH:MM:SS.sss).
13
-
14
- Examples:
15
- >>> ijd2utc(0.0)
16
- '1999-12-31 23:58:55.817'
17
- >>> ijd2utc(1000.5)
18
- '2002-09-27 11:58:55.816'
19
- """
20
- return Time(t + 51544, format="mjd", scale="tt").utc.iso
21
-
22
-
23
- def utc2ijd(t):
24
- """
25
- Converts UTC ISO format time to IJD (INTEGRAL Julian Date).
26
-
27
- Args:
28
- t (str or ndarray): UTC time in ISO format (YYYY-MM-DD HH:MM:SS).
29
-
30
- Returns:
31
- float or ndarray: IJD time value(s).
32
-
33
- Examples:
34
- >>> utc2ijd('1999-12-31 23:58:55.817')
35
- 0.0
36
- >>> utc2ijd('2002-09-27 00:00:00')
37
- 1000.0
38
- """
39
- return Time(t, format="iso", scale="utc").tt.mjd - 51544
1
+ """
2
+ Time Conversion Utilities for INTEGRAL
3
+ =======================================
4
+
5
+ Convert between INTEGRAL Julian Date (IJD) and other time formats.
6
+
7
+ INTEGRAL uses IJD as its standard time format:
8
+ - IJD 0.0 = 2000-01-01 00:00:00 TT (Terrestrial Time)
9
+ - IJD = MJD - 51544.0
10
+ - IJD uses TT time scale (atomic time)
11
+
12
+ Functions
13
+ ---------
14
+ ijd2utc : Convert IJD to UTC ISO format
15
+ utc2ijd : Convert UTC ISO format to IJD
16
+ ijd2mjd : Convert IJD to Modified Julian Date
17
+ mjd2ijd : Convert Modified Julian Date to IJD
18
+
19
+ Examples
20
+ --------
21
+ >>> from isgri.utils import ijd2utc, utc2ijd
22
+ >>>
23
+ >>> # Convert IJD to readable format
24
+ >>> utc_str = ijd2utc(3000.5)
25
+ >>> print(utc_str)
26
+ 2008-03-17 11:58:55.816
27
+ >>>
28
+ >>> # Round trip conversion
29
+ >>> ijd = utc2ijd("2010-01-01 12:00:00")
30
+ >>> print(f"IJD: {ijd:.3f}")
31
+ IJD: 3653.500
32
+
33
+ Notes
34
+ -----
35
+ - IJD uses TT (Terrestrial Time) scale for consistency with spacecraft clock
36
+ - UTC conversions account for leap seconds automatically
37
+ - Precision: ~1 microsecond for typical astronomical observations
38
+ """
39
+
40
+ from astropy.time import Time
41
+ from typing import Union
42
+ import numpy as np
43
+ from numpy.typing import NDArray
44
+
45
+ # INTEGRAL epoch: MJD 51544.0 = 2000-01-01 00:00:00 TT
46
+ INTEGRAL_EPOCH_MJD = 51544.0
47
+
48
+
49
+ def ijd2utc(ijd_time: Union[float, NDArray[np.float64]]) -> Union[str, NDArray[np.str_]]:
50
+ """
51
+ Convert IJD (INTEGRAL Julian Date) to UTC ISO format.
52
+
53
+ Parameters
54
+ ----------
55
+ ijd_time : float or ndarray
56
+ IJD time value(s). Can be scalar or array.
57
+
58
+ Returns
59
+ -------
60
+ utc_str : str or ndarray of str
61
+ UTC time in ISO format 'YYYY-MM-DD HH:MM:SS.sss'
62
+ Scalar if input is scalar, array if input is array.
63
+
64
+ Examples
65
+ --------
66
+ >>> ijd2utc(0.0)
67
+ '1999-12-31 23:58:55.816'
68
+
69
+ >>> ijd2utc(1000.5)
70
+ '2002-09-27 11:58:55.816'
71
+
72
+ >>> # Array conversion
73
+ >>> ijds = np.array([0.0, 1000.0, 2000.0])
74
+ >>> utcs = ijd2utc(ijds)
75
+ >>> print(utcs[0])
76
+ 1999-12-31 23:58:55.816
77
+
78
+ See Also
79
+ --------
80
+ utc2ijd : Inverse conversion (UTC to IJD)
81
+ ijd2mjd : Convert IJD to MJD
82
+
83
+ Notes
84
+ -----
85
+ - IJD 0.0 corresponds to 2000-01-01 00:00:00 TT
86
+ - Accounts for leap seconds via UTC scale
87
+ - Output precision is milliseconds (3 decimal places)
88
+ """
89
+ mjd = ijd_time + INTEGRAL_EPOCH_MJD
90
+ t = Time(mjd, format="mjd", scale="tt")
91
+ return t.utc.iso
92
+
93
+
94
+ def utc2ijd(utc_time: Union[str, NDArray[np.str_]]) -> Union[float, NDArray[np.float64]]:
95
+ """
96
+ Convert UTC ISO format to IJD (INTEGRAL Julian Date).
97
+
98
+ Parameters
99
+ ----------
100
+ utc_time : str or ndarray of str
101
+ UTC time in ISO format. Accepts:
102
+ - 'YYYY-MM-DD HH:MM:SS' (space separator)
103
+ - 'YYYY-MM-DDTHH:MM:SS' (T separator)
104
+ - Can include fractional seconds
105
+
106
+ Returns
107
+ -------
108
+ ijd_time : float or ndarray
109
+ IJD time value(s)
110
+
111
+ Examples
112
+ --------
113
+ >>> utc2ijd('1999-12-31 23:58:55.816')
114
+ 0.0
115
+
116
+ >>> utc2ijd('2002-09-27 00:00:00')
117
+ 1000.0
118
+
119
+ >>> # ISO 8601 format (with T separator)
120
+ >>> utc2ijd('2010-01-01T12:00:00')
121
+ 3653.5
122
+
123
+ >>> # Array conversion
124
+ >>> utcs = ['2000-01-01 00:00:00', '2000-01-02 00:00:00']
125
+ >>> ijds = utc2ijd(utcs)
126
+ >>> print(ijds)
127
+ [0.00074287 1.00074287]
128
+
129
+ See Also
130
+ --------
131
+ ijd2utc : Inverse conversion (IJD to UTC)
132
+ mjd2ijd : Convert MJD to IJD
133
+
134
+ Notes
135
+ -----
136
+ - Automatically handles both space and T separators
137
+ - Accounts for leap seconds
138
+ - Returns TT (Terrestrial Time) scale
139
+ """
140
+ # Handle T separator in ISO 8601 format
141
+ if isinstance(utc_time, str):
142
+ utc_time = utc_time.replace("T", " ")
143
+ elif isinstance(utc_time, np.ndarray):
144
+ # Vectorized string replacement for arrays
145
+ utc_time = np.char.replace(utc_time, "T", " ")
146
+
147
+ t = Time(utc_time, format="iso", scale="utc")
148
+ return t.tt.mjd - INTEGRAL_EPOCH_MJD
149
+
150
+
151
+ def ijd2mjd(ijd_time: Union[float, NDArray[np.float64]]) -> Union[float, NDArray[np.float64]]:
152
+ """
153
+ Convert IJD to Modified Julian Date (MJD).
154
+
155
+ Simple offset: MJD = IJD + 51544.0
156
+
157
+ Parameters
158
+ ----------
159
+ ijd_time : float or ndarray
160
+ IJD time value(s)
161
+
162
+ Returns
163
+ -------
164
+ mjd_time : float or ndarray
165
+ MJD time value(s)
166
+
167
+ Examples
168
+ --------
169
+ >>> ijd2mjd(0.0)
170
+ 51544.0
171
+
172
+ >>> ijd2mjd(3653.5)
173
+ 55197.5
174
+
175
+ See Also
176
+ --------
177
+ mjd2ijd : Inverse conversion
178
+ """
179
+ return ijd_time + INTEGRAL_EPOCH_MJD
180
+
181
+
182
+ def mjd2ijd(mjd_time: Union[float, NDArray[np.float64]]) -> Union[float, NDArray[np.float64]]:
183
+ """
184
+ Convert Modified Julian Date (MJD) to IJD.
185
+
186
+ Simple offset: IJD = MJD - 51544.0
187
+
188
+ Parameters
189
+ ----------
190
+ mjd_time : float or ndarray
191
+ MJD time value(s)
192
+
193
+ Returns
194
+ -------
195
+ ijd_time : float or ndarray
196
+ IJD time value(s)
197
+
198
+ Examples
199
+ --------
200
+ >>> mjd2ijd(51544.0)
201
+ 0.0
202
+
203
+ >>> mjd2ijd(55197.5)
204
+ 3653.5
205
+
206
+ See Also
207
+ --------
208
+ ijd2mjd : Inverse conversion
209
+ """
210
+ return mjd_time - INTEGRAL_EPOCH_MJD
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: isgri
3
+ Version: 0.5.0
4
+ Summary: Python package for INTEGRAL IBIS/ISGRI lightcurve analysis
5
+ Author: Dominik Patryk Pacholski
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.10
9
+ Requires-Dist: astropy
10
+ Requires-Dist: click
11
+ Requires-Dist: numpy
12
+ Requires-Dist: platformdirs
13
+ Requires-Dist: tomli-w
14
+ Requires-Dist: tomli>=2.0.0; python_version < '3.11'
15
+ Description-Content-Type: text/markdown
16
+
17
+ # ISGRI
18
+
19
+ Python toolkit for INTEGRAL/ISGRI data analysis.
20
+
21
+ ## Features
22
+
23
+ ### Command Line Interface
24
+ Query catalogs directly from the terminal:
25
+ - Filter by time, position, quality, revolution
26
+ - Export results to FITS/CSV
27
+ - List SWIDs for batch processing
28
+
29
+ ### SCW Catalog Query
30
+ Query INTEGRAL Science Window catalogs with a fluent Python API:
31
+ - Filter by time, position, quality, revolution
32
+ - Calculate detector offsets
33
+ - Export results to FITS/CSV
34
+
35
+ ### Light Curve Analysis
36
+ Extract and analyze ISGRI light curves:
37
+ - Event loading with PIF weighting
38
+ - Custom time binning
39
+ - Module-by-module analysis
40
+ - Quality metrics (chi-squared tests)
41
+ - Time conversions (IJD to/from UTC)
42
+
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install isgri
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ### CLI Usage
53
+
54
+ ```bash
55
+ # Configure default paths (once)
56
+ isgri config-set --catalog ~/data/scw_catalog.fits
57
+
58
+ # Query by time range
59
+ isgri query --tstart 2010-01-01 --tstop 2010-12-31
60
+
61
+ # Query Crab with quality cut
62
+ isgri query --ra 83.63 --dec 22.01 --max-chi 2.0 --fov full
63
+
64
+ # Get list of SWIDs for processing
65
+ isgri query --tstart 3000 --tstop 3100 --list-swids > swids.txt
66
+
67
+ # Export results
68
+ isgri query --tstart 3000 --tstop 3100 --output results.fits
69
+ ```
70
+
71
+ ### Query SCW Catalog
72
+
73
+ ```python
74
+ from isgri.catalog import ScwQuery
75
+
76
+ # Load catalog
77
+ cat = ScwQuery("path_to_catalog.fits")
78
+
79
+ # Find Crab observations in 2010 with good quality
80
+ results = (cat
81
+ .time(tstart="2010-01-01", tstop="2010-12-31")
82
+ .quality(max_chi=2.0)
83
+ .position(ra=83.63, dec=22.01, fov_mode="full")
84
+ .get()
85
+ )
86
+
87
+ print(f"Found {len(results)} observations")
88
+ ```
89
+
90
+ ### Analyze Light Curves
91
+
92
+ ```python
93
+ from isgri.utils import LightCurve, QualityMetrics
94
+
95
+ # Load events with PIF weighting
96
+ lc = LightCurve.load_data(
97
+ events_path="isgri_events.fits",
98
+ pif_path="source_model.fits",
99
+ pif_threshold=0.5
100
+ )
101
+
102
+ # Create 1-second binned light curve
103
+ time, counts = lc.rebin(binsize=1.0, emin=20, emax=100)
104
+
105
+ # Compute quality metrics
106
+ qm = QualityMetrics(lc, binsize=1.0, emin=20, emax=100)
107
+ chi = qm.raw_chi_squared()
108
+ print(f"Chisq/dof = {chi:.2f}")
109
+ ```
110
+
111
+ ## Configuration
112
+
113
+ ISGRI stores configuration in default config folder for each system (see: platformdirs package)
114
+
115
+ ```bash
116
+ # View current config
117
+ isgri config
118
+
119
+ # Set paths
120
+ isgri config-set --archive /path/to/archive --catalog /path/to/catalog.fits
121
+ ```
122
+
123
+ Config can also be used in Python:
124
+
125
+ ```python
126
+ from isgri.config import get_config
127
+
128
+ cfg = get_config()
129
+ print(cfg.archive_path)
130
+ print(cfg.catalog_path)
131
+ ```
132
+
133
+ Local config file `isgri_config.toml` in current directory overrides global config.
134
+
135
+
136
+ ## Documentation
137
+
138
+ - **CLI Reference**: Run `isgri --help` or `isgri <command> --help`
139
+ - **Catalog Tutorial**: [scwquery_walkthrough.ipynb](https://github.com/dominp/isgri/blob/main/demo/scwquery_walkthrough.ipynb)
140
+ - **Light Curve Tutorial**: [lightcurve_walkthrough.ipynb](https://github.com/dominp/isgri/blob/main/demo/lightcurve_walkthrough.ipynb)
141
+ - **API Reference**: Use `help()` in Python or see docstrings
142
+
143
+ ## Project Structure
144
+
145
+ ```
146
+ isgri/
147
+ ├── catalog/ # SCW catalog query tools
148
+ │ ├── scwquery.py # Main query interface
149
+ │ └── wcs.py # Coordinate transformations
150
+ ├── utils/ # Light curve analysis utilities
151
+ │ ├── lightcurve.py # Light curve class
152
+ │ ├── quality.py # Quality metrics
153
+ │ ├── pif.py # PIF tools
154
+ │ ├── file_loaders.py
155
+ │ └── time_conversion.py
156
+ ├── config.py # Configuration management
157
+ └── cli.py # Command line interface
158
+ ```
159
+
160
+ ## Requirements
161
+
162
+ - Python ≥ 3.10
163
+ - astropy
164
+ - numpy
@@ -0,0 +1,19 @@
1
+ isgri/__init__.py,sha256=V2hnOxXKcjMiusdGP8sOAR4QsBlWHQ0pZZMN2Cean6o,38
2
+ isgri/__version__.py,sha256=pVYhOkVS5PHJd_cIEx6PTaY6VggXFTC3pqWdf0I8zao,21
3
+ isgri/cli.py,sha256=ESrhtFCo-VEYuC3y4CL9Hv2Mdr6MVESCkRZ0N6kLgKs,7211
4
+ isgri/config.py,sha256=i1ibczZsmgqELv4ik2h2nWLnHyl68_5KGsz5Ec8Uf4E,4365
5
+ isgri/catalog/__init__.py,sha256=CT9Zd1WISpv7kowf3bqagKewZ8SjLr1rZzVSFkwEj3o,58
6
+ isgri/catalog/builder.py,sha256=C1M1rBXOWyRE85Nru1Dl9pq6FbmyUEl63v-4cbV57y8,3493
7
+ isgri/catalog/scwquery.py,sha256=KKsiAXkJHsm2WlQjYRN-knzHBhIJVCaM4jUAh_FaBYs,17603
8
+ isgri/catalog/wcs.py,sha256=mD6bZxiBxKYpuYCl8f2tSCc8uuWFzMRL2jf5SuFAhfg,5562
9
+ isgri/utils/__init__.py,sha256=H83Al7urc6LNW5KUzUBRdtRBUTahiZmkehKFiK90RrU,183
10
+ isgri/utils/file_loaders.py,sha256=g-LUfYw35hPePlFeicymaL-NbZXzZWfNmM127XJjCKY,12497
11
+ isgri/utils/lightcurve.py,sha256=Pjys-eIyKShDKHqFpGa9SZ0Dzz7LiLIwBpUkp_6s41g,14133
12
+ isgri/utils/pif.py,sha256=LixlkShy1j_ymfdJLyCV8zl0EeHgfVDVjddSex18GLQ,8648
13
+ isgri/utils/quality.py,sha256=Na-sNEX1E4xWQJx0FYe9vbOAgPrTcLohHeUAnmlKYSw,13348
14
+ isgri/utils/time_conversion.py,sha256=MNPVjrsrmwRDbCWmqdWN0xRs8PtHkFGli-H2cYwF9Ns,5204
15
+ isgri-0.5.0.dist-info/METADATA,sha256=uc6rHgLYHLqZxiNm2MlXQAlLKDTKgCXt-PEsRyqHZAU,4019
16
+ isgri-0.5.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
17
+ isgri-0.5.0.dist-info/entry_points.txt,sha256=ZziremOhrp8Lrk9Znu5L1lo7FmkrtMf6FDo8r1900Zc,41
18
+ isgri-0.5.0.dist-info/licenses/LICENSE,sha256=Q8oxmHR1cSnEXSHCjY3qeXMtupZI_1ZQZ1MBt4oeANE,1102
19
+ isgri-0.5.0.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ isgri = isgri.cli:main
@@ -1,66 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: isgri
3
- Version: 0.3.0
4
- Summary: Python package for INTEGRAL IBIS/ISGRI lightcurve analysis
5
- Author: Dominik Patryk Pacholski
6
- License: MIT
7
- License-File: LICENSE
8
- Requires-Python: >=3.10
9
- Requires-Dist: astropy
10
- Requires-Dist: numpy
11
- Description-Content-Type: text/markdown
12
-
13
- # isgri
14
-
15
- Python package for ISGRI (INTEGRAL Soft Gamma-Ray Imager) lightcurve analysis.
16
-
17
- ## Installation
18
-
19
- ```bash
20
- pip install isgri
21
- ```
22
-
23
- Or from source:
24
- ```bash
25
- git clone https://github.com/dominp/isgri.git
26
- cd isgri
27
- pip install -e .
28
- ```
29
-
30
- ## Quick Start
31
-
32
- ```python
33
- from isgri.utils import LightCurve, QualityMetrics
34
-
35
- # Load data
36
- lc = LightCurve.load_data(
37
- events_path='/path/to/isgri_events.fits',
38
- pif_path='/path/to/source_model.fits'
39
- )
40
-
41
- # Create lightcurve
42
- time, counts = lc.rebin(binsize=1.0, emin=30, emax=300)
43
-
44
- # Create lightcurve per each module
45
- times, module_counts = lc.rebin_by_modules(binsize=1.0, emin=30, emax=300)
46
-
47
- # Compute quality metrics
48
- qm = QualityMetrics(lc, binsize=1.0, emin=30, emax=300)
49
- chi = qm.raw_chi_squared()
50
- ```
51
-
52
- **About PIF files:** PIF (Pixel Illumination Fraction) files contain per-pixel sensitivity maps generated by OSA task `ii_pif`. They weight events based on source position to improve signal-to-noise ratio. Using PIF files is recommended but optional.
53
-
54
- ## Features
55
-
56
- - Load ISGRI events and PIF files
57
- - Rebin lightcurves with custom binning
58
- - Module-by-module analysis (8 detector modules)
59
- - Quality metrics (chi-squared variability tests)
60
- - Time conversions (IJD ↔ UTC)
61
- - Custom event filtering
62
-
63
- ## Documentation
64
-
65
- - **Tutorial**: - **Tutorial**: See [demo notebook](https://github.com/dominp/isgri/blob/main/demo/lightcurve_walkthrough.ipynb) on GitHub
66
- - **API docs**: All functions have docstrings - use `help(LightCurve)`
@@ -1,11 +0,0 @@
1
- isgri/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- isgri/utils/__init__.py,sha256=H83Al7urc6LNW5KUzUBRdtRBUTahiZmkehKFiK90RrU,183
3
- isgri/utils/file_loaders.py,sha256=HBQ-n-jFhcP1cxykemBFYTZ72ydJNQrZMUQTeZ2dSnw,5509
4
- isgri/utils/lightcurve.py,sha256=VGRWcpOMnh8Rrbo-EETKAevhYYBZe55IuRQOw_cIfvY,10243
5
- isgri/utils/pif.py,sha256=oxndfoZp-y9FO_TXcCP3dmesvh-sC7hAy2u_1YwGitw,1317
6
- isgri/utils/quality.py,sha256=TZGXnao6hQ2STlI8S8JIfaldPAfdMORQJ0IH_rilFu4,7930
7
- isgri/utils/time_conversion.py,sha256=47aTXn6cvi-LjOptDY2W-rjeF_PjthZer61VIsJqsro,908
8
- isgri-0.3.0.dist-info/METADATA,sha256=MofiJhRbXTPhMNOQAtOSc4QmsYEIm8ckXayvr2LTIMQ,1767
9
- isgri-0.3.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
10
- isgri-0.3.0.dist-info/licenses/LICENSE,sha256=Q8oxmHR1cSnEXSHCjY3qeXMtupZI_1ZQZ1MBt4oeANE,1102
11
- isgri-0.3.0.dist-info/RECORD,,
File without changes