rainbowkit 0.0.1__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.
- rainbowkit/__init__.py +0 -0
- rainbowkit/linelist.py +1216 -0
- rainbowkit/rainbowkit.py +238 -0
- rainbowkit-0.0.1.dist-info/LICENSE +21 -0
- rainbowkit-0.0.1.dist-info/METADATA +29 -0
- rainbowkit-0.0.1.dist-info/RECORD +8 -0
- rainbowkit-0.0.1.dist-info/WHEEL +5 -0
- rainbowkit-0.0.1.dist-info/top_level.txt +1 -0
rainbowkit/rainbowkit.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import matplotlib.offsetbox as offsetbox
|
|
4
|
+
|
|
5
|
+
import linelist as ll
|
|
6
|
+
|
|
7
|
+
class Spectrum():
|
|
8
|
+
"""
|
|
9
|
+
class for a spectrum object.
|
|
10
|
+
The filename (incl extension name) of the file having four cols
|
|
11
|
+
first col: wavelengths, 2nd col: flux, 3rd col: err, 4th col: continuum
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
imp_lines = (
|
|
15
|
+
'HI_1215', 'HI_1025', 'DI_1215', 'DI_1025',
|
|
16
|
+
'HeI_584', 'HeI_537', 'HeII_303', 'HeII_256',
|
|
17
|
+
'CI_1656', 'CI_1560', 'CII_1334', 'CII_1036',
|
|
18
|
+
'CIII_977', 'CIV_1548', 'CIV_1550',
|
|
19
|
+
'NI_1200a', 'NI_1200b', 'NII_1083', 'NII_915',
|
|
20
|
+
'NIII_684', 'NIII_685', 'NIII_763', 'NIII_989',
|
|
21
|
+
'NIV_765', 'NV_1238', 'NV_1242',
|
|
22
|
+
'OI_1302', 'OI_988', 'OI_971', 'OII_834',
|
|
23
|
+
'OII_833', 'OII_832', 'OIII_832', 'OIII_702',
|
|
24
|
+
'OIV_553', 'OIV_554', 'OIV_608', 'OIV_787',
|
|
25
|
+
'OV_629', 'OVI_1031', 'OVI_1037', 'OVII_21', 'OVII_18',
|
|
26
|
+
'NeIV_543', 'NeIV_542', 'NeIV_541', 'NeV_568',
|
|
27
|
+
'NeVI_558', 'NeVIII_780', 'NeVIII_770',
|
|
28
|
+
'NaI_5897', 'NaI_5891',
|
|
29
|
+
'MgI_2026', 'MgI_2852', 'MgII_2803', 'MgII_2796',
|
|
30
|
+
'SiI_1845', 'SiI_1693', 'SiI_1631', 'SiI_1562',
|
|
31
|
+
'SiII_1808', 'SiII_1526', 'SiII_1304', 'SiII_1260',
|
|
32
|
+
'SiII_1193', 'SiII_1190', 'SiII_1020', 'SiII_989',
|
|
33
|
+
'SiIII_1206', 'SiIV_1402', 'SiIV_1393',
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def __init__(self, filename, ):
|
|
37
|
+
self.filename = filename
|
|
38
|
+
f = open(self.filename)
|
|
39
|
+
wvlength = []
|
|
40
|
+
flux = []
|
|
41
|
+
cont = [] # continuum
|
|
42
|
+
|
|
43
|
+
for line in f.readlines():
|
|
44
|
+
line = line.split()
|
|
45
|
+
wvlength.append(float(line[0].lstrip().rstrip()))
|
|
46
|
+
flux.append(float(line[1].lstrip().rstrip()))
|
|
47
|
+
cont.append(float(line[3].lstrip().rstrip()))
|
|
48
|
+
|
|
49
|
+
f.close()
|
|
50
|
+
|
|
51
|
+
self.wvlength = np.asarray(wvlength)
|
|
52
|
+
self.flux = np.asarray(flux)
|
|
53
|
+
self.cont = np.asarray(cont)
|
|
54
|
+
cont_mean = np.mean(self.cont)
|
|
55
|
+
self.ylim = (0, 4*cont_mean)
|
|
56
|
+
|
|
57
|
+
# Keep track of added lines and annotations
|
|
58
|
+
self.added_lines = []
|
|
59
|
+
self.added_annotations = []
|
|
60
|
+
|
|
61
|
+
# Store the clicked coordinates
|
|
62
|
+
self.clicked_coords = None
|
|
63
|
+
self.cid = None
|
|
64
|
+
|
|
65
|
+
# Storing the transition value of getz
|
|
66
|
+
self.transition = None
|
|
67
|
+
|
|
68
|
+
def fplot(self):
|
|
69
|
+
"""
|
|
70
|
+
Method to plot flux vs wavelength
|
|
71
|
+
"""
|
|
72
|
+
plt.ion()
|
|
73
|
+
plt.figure(figsize=(20,6))
|
|
74
|
+
plt.ylim(self.ylim[0], self.ylim[1])
|
|
75
|
+
plt.plot(self.wvlength, self.flux, 'k', lw=0.6)
|
|
76
|
+
plt.show()
|
|
77
|
+
|
|
78
|
+
def nfplot(self):
|
|
79
|
+
"""
|
|
80
|
+
Method to plot normalized flux vs wavelength
|
|
81
|
+
"""
|
|
82
|
+
plt.ion()
|
|
83
|
+
plt.figure(figsize=(20,6))
|
|
84
|
+
plt.ylim(-0.25, max(self.flux/self.cont)*0.01)
|
|
85
|
+
plt.plot(self.wvlength, self.flux/self.cont, 'k', lw=0.6)
|
|
86
|
+
# Adjust the subplot to decrease padding
|
|
87
|
+
plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.1)
|
|
88
|
+
|
|
89
|
+
plt.show()
|
|
90
|
+
|
|
91
|
+
def marklines(self, z=0):
|
|
92
|
+
"""
|
|
93
|
+
Method to mark transition lines at certain wavelengths
|
|
94
|
+
"""
|
|
95
|
+
plt.ion()
|
|
96
|
+
|
|
97
|
+
for line in self.imp_lines:
|
|
98
|
+
line_wvlength = ll.wl[line]
|
|
99
|
+
if z: line_wvlength = (1+z)*line_wvlength
|
|
100
|
+
if min(self.wvlength) <= line_wvlength <= max(self.wvlength):
|
|
101
|
+
lineobj = plt.axvline(line_wvlength, color='purple', linestyle='dotted')
|
|
102
|
+
self.added_lines.append(lineobj)
|
|
103
|
+
# plt.text(line_wvlength, 0.95, line, rotation=90, va='top', ha='center', color='purple')
|
|
104
|
+
# plt.annotate(line, xy=(line_wvlength, 0.95), xycoords='data',
|
|
105
|
+
# xytext=(0, 5), textcoords='offset points',
|
|
106
|
+
# rotation=90, va='bottom', ha='center', color='purple')
|
|
107
|
+
|
|
108
|
+
# Create a fixed annotation box for the label
|
|
109
|
+
# Refer: https://matplotlib.org/stable/gallery/text_labels_and_annotations/demo_annotation_box.html
|
|
110
|
+
label_box = offsetbox.TextArea(f'{line}', textprops={'color': 'purple', 'rotation': 90, 'va': 'bottom', 'ha': 'right'})
|
|
111
|
+
ab = offsetbox.AnnotationBbox(label_box, (line_wvlength, 0.75), xycoords=('data', 'axes fraction'), frameon=False)
|
|
112
|
+
plt.gca().add_artist(ab)
|
|
113
|
+
self.added_annotations.append(ab)
|
|
114
|
+
|
|
115
|
+
# def unmark(self):
|
|
116
|
+
# """
|
|
117
|
+
# Method to remove marked transition lines and labels
|
|
118
|
+
# """
|
|
119
|
+
# plt.ion()
|
|
120
|
+
|
|
121
|
+
# # ax = plt.gca() # Get the current Axes object
|
|
122
|
+
|
|
123
|
+
# # # Find all lines and text annotations in the Axes
|
|
124
|
+
# # lines = ax.lines
|
|
125
|
+
# # annotations = ax.texts
|
|
126
|
+
|
|
127
|
+
# # # Remove each line and annotation added by marklines method
|
|
128
|
+
# # for line in lines:
|
|
129
|
+
# # if line.get_color() == 'purple' and line.get_linestyle() == 'dotted':
|
|
130
|
+
# # ax.lines.remove(line)
|
|
131
|
+
# # for annotation in annotations:
|
|
132
|
+
# # if annotation.get_color() == 'purple':
|
|
133
|
+
# # ax.texts.remove(annotation)
|
|
134
|
+
|
|
135
|
+
# # plt.draw() # Redraw the plot to reflect the changes
|
|
136
|
+
# plt.clf() # Clear the current figure
|
|
137
|
+
|
|
138
|
+
# # Plot the original spectrum without marked lines and labels
|
|
139
|
+
# self.nfplot()
|
|
140
|
+
|
|
141
|
+
# plt.draw() # Redraw the plot
|
|
142
|
+
|
|
143
|
+
# def unmark(self):
|
|
144
|
+
# """
|
|
145
|
+
# Method to remove marked transition lines and labels
|
|
146
|
+
# """
|
|
147
|
+
# plt.ion()
|
|
148
|
+
|
|
149
|
+
# ax = plt.gca() # Get the current Axes object
|
|
150
|
+
|
|
151
|
+
# # Find all lines and text annotations in the Axes
|
|
152
|
+
# lines = list(ax.lines) # Convert to a regular list
|
|
153
|
+
# annotations = list(ax.texts) # Convert to a regular list
|
|
154
|
+
|
|
155
|
+
# # Remove each line and annotation added by marklines method
|
|
156
|
+
# for line in lines:
|
|
157
|
+
# if line.get_color() == 'purple' and line.get_linestyle() == 'dotted':
|
|
158
|
+
# line.remove()
|
|
159
|
+
# for annotation in annotations:
|
|
160
|
+
# if annotation.get_color() == 'gray':
|
|
161
|
+
# annotation.remove()
|
|
162
|
+
|
|
163
|
+
# plt.draw() # Redraw the plot to reflect the changes
|
|
164
|
+
|
|
165
|
+
# def unmarklines(self):
|
|
166
|
+
# """
|
|
167
|
+
# Method to remove marked transition lines and labels
|
|
168
|
+
# """
|
|
169
|
+
# plt.ion()
|
|
170
|
+
|
|
171
|
+
# ax = plt.gca() # Get the current Axes object
|
|
172
|
+
|
|
173
|
+
# # Iterate through the lines and annotations and set their visibility to False
|
|
174
|
+
# for line in ax.lines:
|
|
175
|
+
# if line.get_color() == 'purple' and line.get_linestyle() == 'dotted':
|
|
176
|
+
# line.set_visible(False)
|
|
177
|
+
# for annotation in ax.texts:
|
|
178
|
+
# if annotation.get_color() == 'purple':
|
|
179
|
+
# annotation.set_visible(False)
|
|
180
|
+
|
|
181
|
+
# plt.draw() # Redraw the plot to reflect the changes
|
|
182
|
+
|
|
183
|
+
def unmark(self):
|
|
184
|
+
"""
|
|
185
|
+
Method to remove marked transition lines and labels
|
|
186
|
+
"""
|
|
187
|
+
plt.ion()
|
|
188
|
+
|
|
189
|
+
# Remove added lines and annotations
|
|
190
|
+
for line in self.added_lines:
|
|
191
|
+
line.remove()
|
|
192
|
+
for annotation in self.added_annotations:
|
|
193
|
+
annotation.remove()
|
|
194
|
+
|
|
195
|
+
# Clear the added lines and annotations lists
|
|
196
|
+
self.added_lines = []
|
|
197
|
+
self.added_annotations = []
|
|
198
|
+
|
|
199
|
+
plt.draw() # Redraw the plot to reflect the changes
|
|
200
|
+
|
|
201
|
+
def getz(self, transition):
|
|
202
|
+
"""
|
|
203
|
+
Prints the redshift of transition line by mouseclick event
|
|
204
|
+
"""
|
|
205
|
+
print('Click to find z')
|
|
206
|
+
plt.ion()
|
|
207
|
+
|
|
208
|
+
ax = plt.gca() # Get the current Axes object
|
|
209
|
+
|
|
210
|
+
# Find the transition wavelength
|
|
211
|
+
line_wavelength = ll.wl[transition]
|
|
212
|
+
self.transition = transition
|
|
213
|
+
|
|
214
|
+
# Connect the onclick event
|
|
215
|
+
self.cid = plt.gcf().canvas.mpl_connect('button_press_event', self._onclick)
|
|
216
|
+
plt.draw()
|
|
217
|
+
|
|
218
|
+
def _onclick(self, event):
|
|
219
|
+
"""
|
|
220
|
+
Callback function for mouse click event
|
|
221
|
+
"""
|
|
222
|
+
# print('onclick called')
|
|
223
|
+
if event.inaxes:
|
|
224
|
+
self.clicked_coords = (event.xdata, event.ydata)
|
|
225
|
+
plt.gcf().canvas.mpl_disconnect(self.cid) # Disconnect the onclick event
|
|
226
|
+
# plt.close() # Close the plot
|
|
227
|
+
# print('onclick finished')
|
|
228
|
+
self.print_clicked_coords()
|
|
229
|
+
|
|
230
|
+
def print_clicked_coords(self):
|
|
231
|
+
"""
|
|
232
|
+
Method to print clicked coordinates (for testing)
|
|
233
|
+
"""
|
|
234
|
+
# print("Clicked Coordinates:", self.clicked_coords)
|
|
235
|
+
# print(type(self.clicked_coords))
|
|
236
|
+
# clicked_coords is a tuple with x and y value
|
|
237
|
+
z = (self.clicked_coords[0]/ll.wl[self.transition]) - 1.0
|
|
238
|
+
print(z)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Sourav Das
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: rainbowkit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Tools to work with spectra
|
|
5
|
+
Author-email: Sourav Das <souravdas.sd20@gmail.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
|
|
13
|
+
# RainbowKit
|
|
14
|
+
|
|
15
|
+
RainbowKit is a Python toolkit for spectral analysis. It allows you to create spectrum objects and execute various methods, such as plotting and marking lines.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- Create and manipulate spectrum objects
|
|
20
|
+
- Plot spectra with ease
|
|
21
|
+
- Mark spectral lines for analysis
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
You can install RainbowKit using pip:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install rainbowkit
|
|
29
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rainbowkit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
rainbowkit/linelist.py,sha256=nWdRYEPfGhsc23zWDudBlAF_tjKBWBSg9U4bkSIfnts,33508
|
|
3
|
+
rainbowkit/rainbowkit.py,sha256=0VClZyaldC78fOM5hRyNzV9jbpZESO3H9EhZGjKvWkQ,8560
|
|
4
|
+
rainbowkit-0.0.1.dist-info/LICENSE,sha256=JdiF6K0Oe6U5UFo8NDQav2nuGDzv9nAiivierHieAps,1067
|
|
5
|
+
rainbowkit-0.0.1.dist-info/METADATA,sha256=9aeyZ_QH63yXnyrSLEa0cpCNsfNe6zkl4FbNKx2LIfw,752
|
|
6
|
+
rainbowkit-0.0.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
7
|
+
rainbowkit-0.0.1.dist-info/top_level.txt,sha256=hUiTT-FTUQxnVhkyUHDWceIqMM8ygcNspDAESoMLCUc,11
|
|
8
|
+
rainbowkit-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rainbowkit
|