-
Notifications
You must be signed in to change notification settings - Fork 0
/
MACS0647.py
70 lines (64 loc) · 1.87 KB
/
MACS0647.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
from astro_utils import *
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
import numpy as np
import os
from reproject import reproject_interp
from sklearn import decomposition
import pickle
path = list_files('/home/innereye/JWST/MACS J0647.7+7015/',search='*.fits')[:-1]
crop = [40, 4340, 40, 4340]
rgb = np.zeros((crop[1]-crop[0], crop[3]-crop[2], 3), 'uint8')
total = np.zeros((crop[1]-crop[0], crop[3]-crop[2]), 'float')
meds = 4
subt = 50
# if os.path.isfile('6layers.pkl'):
# layers = np.load('6layers.pkl', allow_pickle=True)
# else:
for ii in range(len(path)):
if ii == 0:
hdu0 = fits.open(path[ii])
img = hdu0[1].data[crop[0]:crop[1],crop[2]:crop[3]]
# img = fill_holes(img, pad=1, hole_size=50)
hdr0 = hdu0[1].header
del hdu0
else:
hdu = fits.open(path[ii])
img, _ = reproject_interp(hdu[1], hdr0)
img = img[crop[0]:crop[1],crop[2]:crop[3]]
img[np.isnan(img)] = 0
img = img ** 0.5
img[img == 0] = np.nan
med = np.nanmedian(img)
img[np.isnan(img)] = 0
img = img - med
img = img / (med * meds - med) * 255
if img.shape[0] == 0:
raise Exception('bad zero')
# rgb[:,:,1] += img
total += img
img[img > 255] = 255
img[img < 0] = 0
if ii == 0:
rgb[:, :, 0] = img
rgb[:, :, 2] = img
# with open('6layers.pkl', 'wb') as f:
# pickle.dump(layers, f)
total = total/len(path)
total[total > 255] = 255
total[total < 0] = 0
rgb[:, :, 1] = np.asarray(total, 'uint8')
plt.figure()
plt.imshow(rgb, origin='lower')
# plt.clim(20,200)
plt.show(block=False)
a = 1
#
# rgbt = np.zeros((total.shape[0], total.shape[1], 3))
# rgbt[..., 0] = np.mean(norm[:, :, :4]*1.5, axis=2)
# rgbt[..., 1] = total
# rgbt[..., 2] = np.mean(norm[:, :, 2:], axis=2)
# plt.figure()
# plt.imshow(rgbt.astype('uint8'), origin='lower')
# plt.show(block=False)