forked from OminousBlackCat/NJU_SEU_sun_data_process
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecompression.py
73 lines (56 loc) · 1.52 KB
/
decompression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from astropy.io import fits
import numpy as np
from matplotlib import pyplot as plt
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 13:16:29 2020
@author: jkf
@editor: wxy
"""
def fitsread(filein):
from astropy.io import fits
head = ' '
hdul = fits.open(filein, do_not_scale_image_data=True)
try:
data0 = hdul[0].data.astype(np.float32)
head = hdul[0].header
except:
hdul.verify('silentfix')
data0 = hdul[1].data
head = hdul[1].header
return data0, head
def show_SPEC(SPEC, DSPEC):
X = SPEC.shape[1]
Y = SPEC.shape[0]
figSPEC = plt.figure('Ha Image', figsize=(12, 7))
ax = plt.subplot(121)
ax.imshow(SPEC, cmap='gray')
plt.draw()
ax.set_title('Ha Image')
bx = plt.subplot(122)
bx.set_title('Ha Specturm')
plt.tight_layout()
def onclick(event):
ix, iy = event.xdata, event.ydata
if (ix < X) and (iy < Y):
get_x(ix, iy)
def get_x(pX, pY):
x = np.round(pX).astype('int')
y = np.round(pY).astype('int')
print(x, y)
ax.plot(x, y, '+', ms=10)
plt.draw()
bx.plot(DSPEC[:, y, x], '.-')
plt.tight_layout()
cid = figSPEC.canvas.mpl_connect('button_press_event', onclick)
plt.show()
return SPEC
def main():
filename = 'data/decompression_test/RSM20221017T182100_0005_FE.fts'
file = filename
print('Reading fits file....')
dat = fitsread(file)[0]
SPEC = dat[26]
show_SPEC(SPEC, dat)
if __name__ == '__main__':
main()