-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIC348.py
102 lines (94 loc) · 3.51 KB
/
IC348.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# import os.path
# import pickle
#
# import matplotlib.pyplot as plt
# from matplotlib import colors
from astro_utils import *
os.chdir('/media/innereye/My Passport/Data/JWST/data/IC348-MOSAIC/')
if not os.path.isfile('IC348-MOSAIC.pkl'):
auto_plot('IC348-MOSAIC', exp='log', png='deband.png', pkl=True, resize=False, method='rrgggbb', plot=False,
max_color=False, fill=False, deband=True, adj_args={'factor': 2})
##
if os.path.isfile('adjusted.pkl'):
layers = np.load('adjusted.pkl', allow_pickle=True)
else:
layers = np.load('IC348-MOSAIC.pkl', allow_pickle=True)
for lay in range(layers.shape[2]):
layers[..., lay] = level_adjust(layers[..., lay], factor=2)
with open('adjusted.pkl', 'wb') as f:
pickle.dump(layers, f)
##
notnan = ~np.any(np.isnan(layers), axis=2)
not0 = np.all(layers > 0, axis=2)
if os.path.isfile('med.pkl'):
med = np.load('med.pkl', allow_pickle=True)
else:
med = np.nanmedian(layers, 2)
with open('med.pkl', 'wb') as f:
pickle.dump(med, f)
##
hsv_win = 0.05
bl = plt.imread('baseline.png')[..., :3]
hue = matplotlib.colors.rgb_to_hsv(bl)[..., 0]
noise = (hue < hsv_win) | (np.abs(hue - 1/3) < hsv_win) | (np.abs(hue - 2/3) < hsv_win)
# noise = noise & (med < 0.9)
# noise = (np.abs(hue - 1/3) < hsv_win)
bl0 = bl.copy()
for b in range(3):
bb = bl0[..., b]
bb[noise] = 0
print('fill holes')
for lay in range(layers.shape[2]):
layer = layers[..., lay]
# noise0 = noise & (layer > 0.75)
layer[noise] = 0
layers[:, :, lay] = hole_conv_fill(layer, n_pixels_around=0, clean_below=0.01)
# filled = hole_conv_fill(filled, n_pixels_around=3, ringsize=15, clean_below_local=0.75, clean_below=2)
print(lay)
print('saving')
rgb = np.zeros((layers.shape[0], layers.shape[1], 3))
for ii in range(3):
rgb[..., ii] = np.nanmax(layers[..., ii*2:ii*2+2], 2)
rgb = rgb[..., ::-1]
plt.imsave('conv.png', rgb, origin='loewer')
example = np.zeros((1000, 3000, 3))
example[:,:1000,:] = bl[2500:3500, 3500:4500, :]
example[:,1000:2000,:] = bl0[2500:3500, 3500:4500, :]
example[:,2000:,:] = rgb[2500:3500, 3500:4500, :]
plt.imsave('example.png', example, origin='loewer')
# plt.figure()
# plt.imshow(example)
## last 3 layers
from astro_utils import *
os.chdir('/media/innereye/My Passport/Data/JWST/data/IC348-MOSAIC/')
if os.path.isfile('baseline3.png'):
bl = plt.imread('baseline3.png')[..., :3]
else:
layers = np.load('adjusted.pkl', allow_pickle=True)
layers = layers[..., 3:]
layers = layers[..., ::-1]
plt.figure()
plt.imshow(layers)
plt.imsave('baseline3.png', layers, origin='loewer')
hsv_win = 0.05
hue = matplotlib.colors.rgb_to_hsv(bl)[..., 0]
noise = (hue < hsv_win) | (np.abs(hue - 1/3) < hsv_win) | (np.abs(hue - 2/3) < hsv_win)
print('fill holes')
for lay in range(layers.shape[2]):
layer = layers[..., lay]
# noise0 = noise & (layer > 0.75)
layer[noise] = 0
layers[:, :, lay] = hole_conv_fill(layer, n_pixels_around=0, clean_below=0.01)
# filled = hole_conv_fill(filled, n_pixels_around=3, ringsize=15, clean_below_local=0.75, clean_below=2)
print(lay)
print('saving')
rgb = np.zeros((layers.shape[0], layers.shape[1], 3))
for ii in range(3):
rgb[..., ii] = np.nanmax(layers[..., ii*2:ii*2+2], 2)
rgb = rgb[..., ::-1]
plt.imsave('conv.png', rgb, origin='loewer')
example = np.zeros((1000, 3000, 3))
example[:,:1000,:] = bl[2500:3500, 3500:4500, :]
example[:,1000:2000,:] = bl0[2500:3500, 3500:4500, :]
example[:,2000:,:] = rgb[2500:3500, 3500:4500, :]
plt.imsave('example.png', example, origin='loewer')