stixdcpy 2.2__tar.gz → 4.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.
- stixdcpy-4.0/PKG-INFO +68 -0
- stixdcpy-4.0/README.md +35 -0
- stixdcpy-4.0/setup.py +30 -0
- stixdcpy-2.2/stixdcpy/io.py → stixdcpy-4.0/stixdcpy/algorithms.py +9 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/auxiliary.py +23 -1
- stixdcpy-4.0/stixdcpy/cfl.py +0 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/continuous_spectrogram.py +9 -0
- stixdcpy-4.0/stixdcpy/detector_view.py +122 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/energylut.py +16 -7
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/housekeeping.py +7 -2
- stixdcpy-4.0/stixdcpy/imgspec.py +245 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/instrument.py +54 -5
- stixdcpy-4.0/stixdcpy/integer_compression.py +125 -0
- stixdcpy-4.0/stixdcpy/io.py +71 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/net.py +194 -48
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/quicklook.py +40 -25
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/science.py +380 -141
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/spectrogram.py +17 -8
- stixdcpy-4.0/stixdcpy/time_util.py +117 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/transmission.py +78 -10
- stixdcpy-4.0/stixdcpy/utils.py +12 -0
- stixdcpy-4.0/stixdcpy.egg-info/PKG-INFO +68 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy.egg-info/SOURCES.txt +5 -2
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy.egg-info/requires.txt +9 -4
- stixdcpy-2.2/PKG-INFO +0 -49
- stixdcpy-2.2/README.md +0 -34
- stixdcpy-2.2/setup.py +0 -17
- stixdcpy-2.2/stixdcpy/ancillary.py +0 -172
- stixdcpy-2.2/stixdcpy/detector_view.py +0 -251
- stixdcpy-2.2/stixdcpy/time.py +0 -92
- stixdcpy-2.2/stixdcpy/transmission_backup.py +0 -484
- stixdcpy-2.2/stixdcpy.egg-info/PKG-INFO +0 -49
- {stixdcpy-2.2 → stixdcpy-4.0}/LICENSE.md +0 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/setup.cfg +0 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/__init__.py +0 -0
- /stixdcpy-2.2/stixdcpy/cfl.py → /stixdcpy-4.0/stixdcpy/ancillary.py +0 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/logger.py +0 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy/stix_map.py +0 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy.egg-info/dependency_links.txt +0 -0
- {stixdcpy-2.2 → stixdcpy-4.0}/stixdcpy.egg-info/top_level.txt +0 -0
stixdcpy-4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stixdcpy
|
|
3
|
+
Version: 4.0
|
|
4
|
+
Summary: STIX data center APIs and data analysis tools
|
|
5
|
+
Home-page: https://github.com/i4ds/stixdcpy
|
|
6
|
+
Author: Hualin Xiao
|
|
7
|
+
Author-email: hualin.xiao@fhnw.ch
|
|
8
|
+
Requires-Python: >=3.7
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE.md
|
|
11
|
+
Requires-Dist: numpy
|
|
12
|
+
Requires-Dist: requests
|
|
13
|
+
Requires-Dist: python-dateutil
|
|
14
|
+
Requires-Dist: ipython
|
|
15
|
+
Requires-Dist: astropy
|
|
16
|
+
Requires-Dist: matplotlib
|
|
17
|
+
Requires-Dist: tqdm
|
|
18
|
+
Requires-Dist: pandas
|
|
19
|
+
Requires-Dist: joblib
|
|
20
|
+
Requires-Dist: roentgen
|
|
21
|
+
Requires-Dist: simplejson
|
|
22
|
+
Requires-Dist: sunpy
|
|
23
|
+
Requires-Dist: wget
|
|
24
|
+
Dynamic: author
|
|
25
|
+
Dynamic: author-email
|
|
26
|
+
Dynamic: description
|
|
27
|
+
Dynamic: description-content-type
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
Dynamic: requires-dist
|
|
31
|
+
Dynamic: requires-python
|
|
32
|
+
Dynamic: summary
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
[](https://doi.org/10.5281/zenodo.7180433)
|
|
36
|
+
|
|
37
|
+
stixdcpy is a Python library for STIX data users to retrieve and analyze STIX data. It provides user-friendly APIs for querying and fetching data from the STIX data center (https://datacenter.stix.i4ds.net/), along with a suite of utilities for visualizing data and conducting common analysis tasks. With stixdcpy, users can effortlessly access and manipulate various data types from the STIX data center, including:
|
|
38
|
+
|
|
39
|
+
* Quick-look light curves
|
|
40
|
+
* Housekeeping data
|
|
41
|
+
* Science data
|
|
42
|
+
* Energy calibration data
|
|
43
|
+
* Auxiliary data
|
|
44
|
+
* STIX solar flare list
|
|
45
|
+
* STIX operations events
|
|
46
|
+
* Ephemeris data
|
|
47
|
+
# Installation
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
pip install git+https://github.com/i4ds/stixdcpy.git
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Tutorial and documentation
|
|
56
|
+
|
|
57
|
+
- [Tutorial](https://github.com/i4ds/stixdcpy/blob/master/examples/tutorial.ipynb)
|
|
58
|
+
- [Documentation](https://drhlxiao.github.io/stixdcpy/)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# Cite this work
|
|
63
|
+
If you use the stixdcpy in your research and publications, we would definitely appreciate an appropriate acknowledgment and citation! We suggest the following BibTex:
|
|
64
|
+
* [1] STIX data center paper published on A&A: https://doi.org/10.1051/0004-6361/202346031
|
|
65
|
+
* [2] Hualin Xiao, Säm Krucker, Lastufka Erica, & William Setterberg. (2022). stixdcpy – a python package that facilitates access and analysis of STIX data (v2.0). Zenodo. https://doi.org/10.5281/zenodo.7180433
|
|
66
|
+
|
|
67
|
+
# Reporting Issues and Contributing
|
|
68
|
+
Open an issue on GitHub to report a problem. Pull requests welcome.
|
stixdcpy-4.0/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
[](https://doi.org/10.5281/zenodo.7180433)
|
|
3
|
+
|
|
4
|
+
stixdcpy is a Python library for STIX data users to retrieve and analyze STIX data. It provides user-friendly APIs for querying and fetching data from the STIX data center (https://datacenter.stix.i4ds.net/), along with a suite of utilities for visualizing data and conducting common analysis tasks. With stixdcpy, users can effortlessly access and manipulate various data types from the STIX data center, including:
|
|
5
|
+
|
|
6
|
+
* Quick-look light curves
|
|
7
|
+
* Housekeeping data
|
|
8
|
+
* Science data
|
|
9
|
+
* Energy calibration data
|
|
10
|
+
* Auxiliary data
|
|
11
|
+
* STIX solar flare list
|
|
12
|
+
* STIX operations events
|
|
13
|
+
* Ephemeris data
|
|
14
|
+
# Installation
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
pip install git+https://github.com/i4ds/stixdcpy.git
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Tutorial and documentation
|
|
23
|
+
|
|
24
|
+
- [Tutorial](https://github.com/i4ds/stixdcpy/blob/master/examples/tutorial.ipynb)
|
|
25
|
+
- [Documentation](https://drhlxiao.github.io/stixdcpy/)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Cite this work
|
|
30
|
+
If you use the stixdcpy in your research and publications, we would definitely appreciate an appropriate acknowledgment and citation! We suggest the following BibTex:
|
|
31
|
+
* [1] STIX data center paper published on A&A: https://doi.org/10.1051/0004-6361/202346031
|
|
32
|
+
* [2] Hualin Xiao, Säm Krucker, Lastufka Erica, & William Setterberg. (2022). stixdcpy – a python package that facilitates access and analysis of STIX data (v2.0). Zenodo. https://doi.org/10.5281/zenodo.7180433
|
|
33
|
+
|
|
34
|
+
# Reporting Issues and Contributing
|
|
35
|
+
Open an issue on GitHub to report a problem. Pull requests welcome.
|
stixdcpy-4.0/setup.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="stixdcpy",
|
|
5
|
+
description="STIX data center APIs and data analysis tools",
|
|
6
|
+
version="4.0",
|
|
7
|
+
author="Hualin Xiao",
|
|
8
|
+
author_email="hualin.xiao@fhnw.ch",
|
|
9
|
+
long_description=open("README.md").read(),
|
|
10
|
+
install_requires=[
|
|
11
|
+
"numpy",
|
|
12
|
+
"requests",
|
|
13
|
+
"python-dateutil",
|
|
14
|
+
"ipython",
|
|
15
|
+
"astropy",
|
|
16
|
+
"matplotlib",
|
|
17
|
+
"tqdm",
|
|
18
|
+
"pandas",
|
|
19
|
+
"joblib",
|
|
20
|
+
"roentgen",
|
|
21
|
+
"simplejson",
|
|
22
|
+
"sunpy",
|
|
23
|
+
"wget",
|
|
24
|
+
],
|
|
25
|
+
long_description_content_type="text/markdown",
|
|
26
|
+
# packages=find_packages(where='stixdcpy'),
|
|
27
|
+
url="https://github.com/i4ds/stixdcpy",
|
|
28
|
+
packages=["stixdcpy"],
|
|
29
|
+
python_requires=">=3.7",
|
|
30
|
+
)
|
|
@@ -6,10 +6,15 @@ from matplotlib import pyplot as plt
|
|
|
6
6
|
|
|
7
7
|
from stixdcpy import io as sio
|
|
8
8
|
from stixdcpy.logger import logger
|
|
9
|
-
from stixdcpy.net import
|
|
9
|
+
from stixdcpy.net import Request as jreq
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class Ephemeris(sio.IO):
|
|
13
|
+
"""_summary_
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
sio (_type_): _description_
|
|
17
|
+
"""
|
|
13
18
|
def __init__(self, start_utc, end_utc, data):
|
|
14
19
|
self.start_utc = start_utc
|
|
15
20
|
self.end_utc = end_utc
|
|
@@ -83,6 +88,15 @@ class Ephemeris(sio.IO):
|
|
|
83
88
|
return self.data
|
|
84
89
|
|
|
85
90
|
def peek(self, ax=None):
|
|
91
|
+
"""_summary_
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
ax (_type_, optional): _description_. Defaults to None.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
_type_: _description_
|
|
98
|
+
"""
|
|
99
|
+
|
|
86
100
|
if not self.data:
|
|
87
101
|
logger.error(f'Data not loaded. ')
|
|
88
102
|
return None
|
|
@@ -135,6 +149,14 @@ class Pointing(Ephemeris):
|
|
|
135
149
|
return cls(utc, data)
|
|
136
150
|
|
|
137
151
|
def peek(self, ax=None):
|
|
152
|
+
"""
|
|
153
|
+
Plot the solar ephemeris data
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
ax (_type_, optional): _description_. Defaults to None.
|
|
157
|
+
Returns:
|
|
158
|
+
ax: matplotlib axes
|
|
159
|
+
"""
|
|
138
160
|
if not self.data:
|
|
139
161
|
logger.error(f'Data not loaded. ')
|
|
140
162
|
return None
|
|
File without changes
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
def fetch_spectrogram(start_utc, end_utc):
|
|
2
|
+
"""
|
|
3
|
+
Fetch spectrogram from the STIX data center
|
|
4
|
+
Args:
|
|
5
|
+
start_utc (_type_): _description_
|
|
6
|
+
end_utc (_type_): _description_
|
|
7
|
+
|
|
8
|
+
Returns:
|
|
9
|
+
a diect containing the spectrogram
|
|
10
|
+
"""
|
|
2
11
|
url='https://datacenter.stix.i4ds.net/request/bsd/spectrograms'
|
|
3
12
|
res=requests.post(url, data={'begin':start_utc, 'end':end_utc})
|
|
4
13
|
data=res.json()
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
import tempfile
|
|
3
|
+
import numpy as np
|
|
4
|
+
import webbrowser
|
|
5
|
+
try:
|
|
6
|
+
import IPython
|
|
7
|
+
from IPython.display import display, HTML
|
|
8
|
+
from IPython.display import Javascript
|
|
9
|
+
except ImportError:
|
|
10
|
+
pass
|
|
11
|
+
class DetectorView(object):
|
|
12
|
+
def __init__(self):
|
|
13
|
+
self.counts=[0]*384
|
|
14
|
+
self.toolbar_enabled='true'
|
|
15
|
+
self.is_jupyter_env=False
|
|
16
|
+
self.js_url="https://datacenter.stix.i4ds.net/static/js/pystix.js"
|
|
17
|
+
self.js2=''
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
if 'ipykernel' in str(IPython.get_ipython()):
|
|
21
|
+
self.is_jupyter_env=True
|
|
22
|
+
except Exception :
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_html(self):
|
|
27
|
+
self.js2=f'''
|
|
28
|
+
$(document).ready(function() {{
|
|
29
|
+
StixDetectorView.showGridParameterOnHover(true);
|
|
30
|
+
StixDetectorView.plotDetector("#dv", {{
|
|
31
|
+
counts: {self.counts}, vW: 1140,
|
|
32
|
+
vH: 1140,
|
|
33
|
+
legend: false,
|
|
34
|
+
detectorViewToolbar: {self.toolbar_enabled},
|
|
35
|
+
reset:true}});
|
|
36
|
+
$("#save").on("click",function() {{StixDetectorView.saveSVG();}});
|
|
37
|
+
}});
|
|
38
|
+
'''
|
|
39
|
+
head='''
|
|
40
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
41
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
42
|
+
<head> <title>STIX detector view</title>
|
|
43
|
+
'''
|
|
44
|
+
js1=f'''<script src="{self.js_url}" type="text/javascript"></script>'''
|
|
45
|
+
css='''
|
|
46
|
+
<link rel="stylesheet" href="https://datacenter.stix.i4ds.net/static/css/pystix.css">
|
|
47
|
+
<style>
|
|
48
|
+
.center {
|
|
49
|
+
display: flex;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
align-items: center;
|
|
52
|
+
}
|
|
53
|
+
#copy-data{display:none;}
|
|
54
|
+
</style>
|
|
55
|
+
'''
|
|
56
|
+
container='''
|
|
57
|
+
<div class="center">
|
|
58
|
+
<button type="button" id="save" >Save as SVG</button>
|
|
59
|
+
</div>
|
|
60
|
+
<div id="dv" style="width:500px;" >Please execute the cell again if you see this message!</div>
|
|
61
|
+
'''
|
|
62
|
+
if not self.is_jupyter_env:
|
|
63
|
+
html=f'{head} {css} {js1} </head><body> {container} <script>{self.js2}</script></body></html>'
|
|
64
|
+
else:
|
|
65
|
+
html=f'<div>{css} {js1}{container} <script>{self.js2}</script></div>'
|
|
66
|
+
return html
|
|
67
|
+
def plot(self, pixel_counts, toolbar=True):
|
|
68
|
+
"""
|
|
69
|
+
Generate a detector view figure.
|
|
70
|
+
Parameters
|
|
71
|
+
-------------
|
|
72
|
+
pixel_counts: list or numpy.array
|
|
73
|
+
counts of 384 pixels
|
|
74
|
+
toolbar: boolean
|
|
75
|
+
display the toolbar on the plot if True.
|
|
76
|
+
Returns:
|
|
77
|
+
None
|
|
78
|
+
"""
|
|
79
|
+
if toolbar and self.is_jupyter_env:
|
|
80
|
+
display(HTML('''<div style="border: 1;color: #ffc107!important; " >The toolbar allows normalizing counts in an interactive way.
|
|
81
|
+
Unfortunately, this feature is not available in the Jupyter notebook environment. To use the feature, please run d.save("detector_view.html")
|
|
82
|
+
to save the figure a html file, and then open the saved file with a web browser</div>'''))
|
|
83
|
+
#toolbar=False
|
|
84
|
+
|
|
85
|
+
self.toolbar_enabled='false' if not toolbar else 'true'
|
|
86
|
+
if isinstance(pixel_counts, np.ndarray):
|
|
87
|
+
pixel_counts=pixel_counts.flatten().tolist()
|
|
88
|
+
|
|
89
|
+
if len(pixel_counts)!=384:
|
|
90
|
+
raise ValueError('counts must be a list of length 384')
|
|
91
|
+
self.counts=pixel_counts
|
|
92
|
+
html=self.get_html()
|
|
93
|
+
if self.is_jupyter_env:
|
|
94
|
+
display(HTML(html))
|
|
95
|
+
return
|
|
96
|
+
#not in notebook
|
|
97
|
+
with tempfile.NamedTemporaryFile(suffix=".html", delete=False) as temp_file:
|
|
98
|
+
temp_file.write(html.encode('utf-8'))
|
|
99
|
+
temp_file.close()
|
|
100
|
+
webbrowser.open_new_tab(temp_file.name)
|
|
101
|
+
|
|
102
|
+
def save(self, filename='detector_view.html'):
|
|
103
|
+
"""
|
|
104
|
+
Save the figure to the specified html file.
|
|
105
|
+
One can open the html file using a web browser and export the figure to SVG format by clicking the button
|
|
106
|
+
"""
|
|
107
|
+
if not filename.endswith('html'):
|
|
108
|
+
filename+='html'
|
|
109
|
+
with open(filename,'w') as f:
|
|
110
|
+
f.write(self.get_html())
|
|
111
|
+
print(f'Saved to {filename}. One can open it with a web browser and export it to SVG format')
|
|
112
|
+
|
|
113
|
+
def test():
|
|
114
|
+
counts=[i for i in range(384)]
|
|
115
|
+
dv=DetectorView()
|
|
116
|
+
dv.plot(counts)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if __name__=='__main__':
|
|
120
|
+
test()
|
|
121
|
+
|
|
122
|
+
|
|
@@ -7,14 +7,14 @@ from pprint import pprint
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
from stixdcpy.logger import logger
|
|
9
9
|
from stixdcpy import io as sio
|
|
10
|
-
from stixdcpy.net import
|
|
11
|
-
from stixdcpy.transmission import Transmission
|
|
10
|
+
from stixdcpy.net import Request as jreq
|
|
11
|
+
#from stixdcpy.transmission import Transmission
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class EnergyLUT(sio.IO):
|
|
15
15
|
def __init__(self, data):
|
|
16
16
|
self.data = data
|
|
17
|
-
self.tran = Transmission()
|
|
17
|
+
#self.tran = Transmission()
|
|
18
18
|
|
|
19
19
|
@classmethod
|
|
20
20
|
def request(cls, utc):
|
|
@@ -44,10 +44,6 @@ class EnergyLUT(sio.IO):
|
|
|
44
44
|
def info(self):
|
|
45
45
|
try:
|
|
46
46
|
pprint(self.data['info'])
|
|
47
|
-
# pprint('Pixel 0 true energy bin edges: ')
|
|
48
|
-
# pprint(self.get_pixel_true_ebins(0))
|
|
49
|
-
# pprint('...')
|
|
50
|
-
|
|
51
47
|
except KeyError as e:
|
|
52
48
|
logger.error(e)
|
|
53
49
|
|
|
@@ -72,6 +68,16 @@ class EnergyLUT(sio.IO):
|
|
|
72
68
|
return None
|
|
73
69
|
|
|
74
70
|
def get_onboard_elut(self):
|
|
71
|
+
"""
|
|
72
|
+
Retrieve the onboard energy lookup table (ELUT) data.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
onboard_elut (dict): The onboard ELUT data, or None if not available.
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
KeyError: If the onboard ELUT data is not present in the STI-1 data.
|
|
79
|
+
TypeError: If the STI-1 data does not contain a 'data' key.
|
|
80
|
+
"""
|
|
75
81
|
try:
|
|
76
82
|
return self.data['data']['onboard']
|
|
77
83
|
except (KeyError, TypeError):
|
|
@@ -102,6 +108,8 @@ class EnergyLUT(sio.IO):
|
|
|
102
108
|
A numpy array with a shape of 32 x12 x 32. The three dimensions indicate detector, pixel, and transmission for 32 energy channels.
|
|
103
109
|
The transmission for the last energy bin set to 0
|
|
104
110
|
"""
|
|
111
|
+
pass
|
|
112
|
+
"""
|
|
105
113
|
true_ebins = np.array(
|
|
106
114
|
self.data['data']
|
|
107
115
|
['true_energy_bin_edges']) # an 2d array: 33 x 384
|
|
@@ -121,3 +129,4 @@ class EnergyLUT(sio.IO):
|
|
|
121
129
|
trans[:, :,
|
|
122
130
|
0] = 0 # set the transmission for the first energy bin to 0
|
|
123
131
|
return trans
|
|
132
|
+
"""
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
import pandas as pd
|
|
7
7
|
from astropy.io import fits
|
|
8
8
|
from matplotlib import pyplot as plt
|
|
9
|
+
import matplotlib.dates as mdates
|
|
9
10
|
|
|
10
11
|
from stixdcpy import io as sio
|
|
11
|
-
from stixdcpy import
|
|
12
|
-
from stixdcpy.net import
|
|
12
|
+
from stixdcpy import time_util as sdt
|
|
13
|
+
from stixdcpy.net import Request as jreq
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class Housekeeping(sio.IO):
|
|
@@ -73,4 +74,8 @@ class Housekeeping(sio.IO):
|
|
|
73
74
|
_, ax = plt.subplots()
|
|
74
75
|
ax.plot(self.data['datetime'], self.data['eng_values']['NIX00081'])
|
|
75
76
|
ax.set_title(self.data['names']['NIX00081'])
|
|
77
|
+
locator = mdates.AutoDateLocator(minticks=3, maxticks=7)
|
|
78
|
+
formatter = mdates.ConciseDateFormatter(locator)
|
|
79
|
+
ax.xaxis.set_major_locator(locator)
|
|
80
|
+
ax.xaxis.set_major_formatter(formatter)
|
|
76
81
|
return ax
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
"""
|
|
3
|
+
This module provides APIs to retrieve STIX preview images from STIX data center,
|
|
4
|
+
and provides tools to display the data.
|
|
5
|
+
"""
|
|
6
|
+
import numpy as np
|
|
7
|
+
import pandas as pd
|
|
8
|
+
from astropy.io import fits
|
|
9
|
+
from astropy.time import Time
|
|
10
|
+
from astropy.table import Table
|
|
11
|
+
from astropy import units as u
|
|
12
|
+
from matplotlib import pyplot as plt
|
|
13
|
+
from stixdcpy import time_util as sdt
|
|
14
|
+
from stixdcpy.logger import logger
|
|
15
|
+
from stixdcpy import io as sio
|
|
16
|
+
from stixdcpy import utils
|
|
17
|
+
from stixdcpy import net
|
|
18
|
+
from stixdcpy import instrument as inst
|
|
19
|
+
from pathlib import PurePath
|
|
20
|
+
from datetime import datetime as dt
|
|
21
|
+
from datetime import timedelta as td
|
|
22
|
+
from pprint import pprint
|
|
23
|
+
try:
|
|
24
|
+
from IPython.display import Image, display, HTML
|
|
25
|
+
except ImportError:
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ImgSpecArchive(sio.IO):
|
|
30
|
+
"""
|
|
31
|
+
A class to interact with the STIX data center, retrieve preview images,
|
|
32
|
+
and provide tools to display the data.
|
|
33
|
+
|
|
34
|
+
Attributes:
|
|
35
|
+
response (dict): The response obtained from the STIX data center.
|
|
36
|
+
flare_ephemeris (list): List of flare ephemeris data.
|
|
37
|
+
|
|
38
|
+
Methods:
|
|
39
|
+
query(flare_id=None, start_utc=None, end_utc=None): Query preview images
|
|
40
|
+
based on flare_id or time range.
|
|
41
|
+
data(): Returns the data of the imgspec_results.
|
|
42
|
+
display_images(imgspec_results, map_name='CLEAN'): Display preview images and associated information.
|
|
43
|
+
peek(image_type='clean'): Display a peek of the loaded flare image list.
|
|
44
|
+
draw_map(imap, fig=None, panel_grid=111, title='', descr='', draw_image=True,
|
|
45
|
+
contour_levels=[], zoom_ratio=1, cmap='std_gamma_2', color='w', grid_spacing=5*u.deg,
|
|
46
|
+
text_xy=[0.02, 0.95], desc_xy=[0.95, 0.98], vmin=None): Draw a map using sunpy map.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
def __init__(self, response=None):
|
|
50
|
+
"""
|
|
51
|
+
Initializes the ImgSpecArchive object.
|
|
52
|
+
|
|
53
|
+
Parameters:
|
|
54
|
+
response (dict): The response obtained from the STIX data center.
|
|
55
|
+
"""
|
|
56
|
+
self.response = response
|
|
57
|
+
self.flare_ephemeris = []
|
|
58
|
+
try:
|
|
59
|
+
self.imgspec_results = response['data']
|
|
60
|
+
self.flare_ephemeris = [
|
|
61
|
+
x['flare_ephemeris'] for x in self.imgspec_results
|
|
62
|
+
if 'flare_ephemeris' in x
|
|
63
|
+
]
|
|
64
|
+
except:
|
|
65
|
+
self.imgspec_results = None
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def query(cls, *args, **kwargs):
|
|
69
|
+
"""
|
|
70
|
+
Downloads flare meta data from the STIX data center.
|
|
71
|
+
|
|
72
|
+
Parameters
|
|
73
|
+
----------
|
|
74
|
+
flare_id : int
|
|
75
|
+
Flare unique id.
|
|
76
|
+
start_utc : str
|
|
77
|
+
Start UTC to search for flares.
|
|
78
|
+
end_utc : str
|
|
79
|
+
End UTC to search for flares.
|
|
80
|
+
|
|
81
|
+
Returns
|
|
82
|
+
-------
|
|
83
|
+
ImgSpecArchive
|
|
84
|
+
The queried image archive.
|
|
85
|
+
"""
|
|
86
|
+
flare_id = None
|
|
87
|
+
start_utc = None
|
|
88
|
+
end_utc = None
|
|
89
|
+
|
|
90
|
+
if len(args) == 1:
|
|
91
|
+
flare_id = int(args[0])
|
|
92
|
+
elif len(args) == 2:
|
|
93
|
+
start_utc, end_utc = args
|
|
94
|
+
elif 'flare_id' in kwargs:
|
|
95
|
+
flare_id = kwargs['flare_id']
|
|
96
|
+
|
|
97
|
+
if 'start_utc' in kwargs:
|
|
98
|
+
start_utc = kwargs['start_utc']
|
|
99
|
+
if 'end_utc' in kwargs:
|
|
100
|
+
end_utc = kwargs['end_utc']
|
|
101
|
+
|
|
102
|
+
if flare_id:
|
|
103
|
+
logger.info(f'Querying preview images for flare #{flare_id}')
|
|
104
|
+
res = net.Request.query_imaging_spectroscopy_for_flare(flare_id)
|
|
105
|
+
elif start_utc and end_utc:
|
|
106
|
+
logger.info(f'Querying preview images {start_utc} {end_utc}')
|
|
107
|
+
res = net.Request.query_imaging_spectroscopy_list(
|
|
108
|
+
start_utc, end_utc)
|
|
109
|
+
else:
|
|
110
|
+
raise ValueError('Invalid arguments')
|
|
111
|
+
|
|
112
|
+
return cls(res)
|
|
113
|
+
@property
|
|
114
|
+
def data(self):
|
|
115
|
+
"""
|
|
116
|
+
Returns the data of the imgspec_results.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
dict: The data of the imgspec_results.
|
|
120
|
+
"""
|
|
121
|
+
return self.imgspec_results
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# The implementation of this method goes here (omitted for brevity).
|
|
126
|
+
def animate(self, image_type='CLEAN'):
|
|
127
|
+
pass
|
|
128
|
+
|
|
129
|
+
def peek(self, image_type='CLEAN'):
|
|
130
|
+
"""
|
|
131
|
+
Display a peek of the loaded flare image list.
|
|
132
|
+
|
|
133
|
+
Parameters:
|
|
134
|
+
image_type (str): The type of image to display (default='clean').
|
|
135
|
+
"""
|
|
136
|
+
if not utils.is_notebook():
|
|
137
|
+
pprint(result)
|
|
138
|
+
return
|
|
139
|
+
ishown = 0
|
|
140
|
+
for data in self.imgspec_results:
|
|
141
|
+
display(HTML(f'<h3>Image ID # {data["_id"]}</h3>'))
|
|
142
|
+
uid = data['unique_id']
|
|
143
|
+
start_utc = data['utc_range'][0]
|
|
144
|
+
work_dir=data['work_dir']
|
|
145
|
+
try:
|
|
146
|
+
peak= data['peak_utc']
|
|
147
|
+
display(
|
|
148
|
+
HTML(f'<h3>STIX flare observed at {peak} </h3>'))
|
|
149
|
+
except KeyError:
|
|
150
|
+
pass
|
|
151
|
+
try:
|
|
152
|
+
flare_meta = data['flare_ephemeris']
|
|
153
|
+
display(pd.DataFrame(flare_meta, index=[0]).T)
|
|
154
|
+
except KeyError:
|
|
155
|
+
pprint(data)
|
|
156
|
+
pass
|
|
157
|
+
report=data.get('report',None)
|
|
158
|
+
if not isinstance(report,dict):
|
|
159
|
+
return
|
|
160
|
+
for key, val in report.items():
|
|
161
|
+
if image_type not in val['title']:
|
|
162
|
+
continue
|
|
163
|
+
url = f'{net.HOST}/image-archive/{work_dir}/{val["filename"]}'
|
|
164
|
+
display(HTML(f'<b>{val.get("title","")}</b>'))
|
|
165
|
+
display(Image(url=url, width=400, height=300))
|
|
166
|
+
ishown += 1
|
|
167
|
+
if ishown >= 10:
|
|
168
|
+
display(
|
|
169
|
+
HTML(
|
|
170
|
+
f'<div style="color:red">Only 10 of {len(self.imgspec_results)} flare images are shown!</div >'
|
|
171
|
+
))
|
|
172
|
+
break
|
|
173
|
+
|
|
174
|
+
@staticmethod
|
|
175
|
+
def draw_map(self,
|
|
176
|
+
imap,
|
|
177
|
+
fig=None,
|
|
178
|
+
panel_grid=111,
|
|
179
|
+
title='',
|
|
180
|
+
descr='',
|
|
181
|
+
draw_image=True,
|
|
182
|
+
contour_levels=[],
|
|
183
|
+
zoom_ratio=1,
|
|
184
|
+
cmap='std_gamma_2',
|
|
185
|
+
color='w',
|
|
186
|
+
grid_spacing=5 * u.deg,
|
|
187
|
+
text_xy=[0.02, 0.95],
|
|
188
|
+
desc_xy=[0.95, 0.98],
|
|
189
|
+
vmin=None):
|
|
190
|
+
"""
|
|
191
|
+
Draw a map using sunpy map.
|
|
192
|
+
|
|
193
|
+
Parameters:
|
|
194
|
+
imap: Sunpy map.
|
|
195
|
+
fig: Figure to plot on (default=None).
|
|
196
|
+
panel_grid: Subplot (default=111).
|
|
197
|
+
title: Title for the plot (default='').
|
|
198
|
+
descr: Description for the plot (default='').
|
|
199
|
+
draw_image: Boolean flag to draw the image (default=True).
|
|
200
|
+
contour_levels: Contour levels (default=[]).
|
|
201
|
+
zoom_ratio: Zoom ratio (default=1).
|
|
202
|
+
cmap: Color map for plotting (default='std_gamma_2').
|
|
203
|
+
color: Color for grid and limb (default='w').
|
|
204
|
+
grid_spacing: Grid spacing (default=5*u.deg).
|
|
205
|
+
text_xy: Coordinates for the text (default=[0.02, 0.95]).
|
|
206
|
+
desc_xy: Coordinates for the description (default=[0.95, 0.98]).
|
|
207
|
+
vmin: Minimum value for the plot (default=None).
|
|
208
|
+
|
|
209
|
+
Returns:
|
|
210
|
+
Axes: The axes for the plot.
|
|
211
|
+
"""
|
|
212
|
+
if not fig:
|
|
213
|
+
fig = plt.figure()
|
|
214
|
+
ax = fig.add_subplot(panel_grid, projection=imap)
|
|
215
|
+
if draw_image:
|
|
216
|
+
if vmin is None:
|
|
217
|
+
imap.plot(cmap=cmap, axes=ax, title="")
|
|
218
|
+
else:
|
|
219
|
+
imap.plot(cmap=cmap, axes=ax, title="", vmin=vmin * imap.max())
|
|
220
|
+
imap.draw_grid(color=color, ls='--', grid_spacing=grid_spacing)
|
|
221
|
+
imap.draw_limb(axes=ax, color=color, alpha=0.5)
|
|
222
|
+
if title:
|
|
223
|
+
ax.text(text_xy[0],
|
|
224
|
+
text_xy[1],
|
|
225
|
+
title,
|
|
226
|
+
horizontalalignment='left',
|
|
227
|
+
verticalalignment='center',
|
|
228
|
+
transform=ax.transAxes,
|
|
229
|
+
color=color)
|
|
230
|
+
if descr:
|
|
231
|
+
ax.text(desc_xy[0],
|
|
232
|
+
desc_xy[1],
|
|
233
|
+
descr,
|
|
234
|
+
horizontalalignment='right',
|
|
235
|
+
verticalalignment='top',
|
|
236
|
+
transform=ax.transAxes,
|
|
237
|
+
color=color)
|
|
238
|
+
if contour_levels:
|
|
239
|
+
clevels = contour_levels * u.percent
|
|
240
|
+
cs = imap.draw_contours(clevels)
|
|
241
|
+
h, _ = cs.legend_elements()
|
|
242
|
+
labels = [f'{x}%' for x in contour_levels]
|
|
243
|
+
ax.legend(h, labels, framealpha=0)
|
|
244
|
+
ax.set_aspect('equal')
|
|
245
|
+
return ax
|