-
Notifications
You must be signed in to change notification settings - Fork 0
/
HH46.py
186 lines (184 loc) · 6.48 KB
/
HH46.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import matplotlib.pyplot as plt
from astro_utils import *
rgb = auto_plot('HH46', exp='*.fits', png='deband.png', pow=[1, 1, 1], pkl=False, resize=True, method='rrgggbb', plot=False,
adj_args={'factor': 4}, max_color=False, fill=True, deband=True)
rgb[890:, :800, 2] = 0
plt.imsave('blue_zeroed.png', rgb, origin='lower')
##
img = plt.imread('/media/innereye/My Passport/Data/JWST/data/HH46/deband.png')
img = np.flipud(img)
##
rgb = img.copy()
tofix = rgb[800:, :877, :]
tofix[tofix[..., 0] < 0.1, 2] = 0
tofix = rgb[:800, :590, :]
tofix[tofix[..., 0] < 0.1, 2] = 0
tofix = rgb[:, 1172:, :]
tofix[tofix[..., 0] < 0.1, 2] = 0
# tofix[...] = 0
# rgb[800:, :877, 2] = tofix
# rgb[800:, :877, 2] = 0
plt.imshow(rgb, origin='lower')
plt.imsave('deblue.png', rgb, origin='lower')
# from time import time
#
# ##
# auto_plot('HH46', png='deband.png', pow=[1, 1, 1], pkl=True, resize=False, method='rrgggbb', plot=False,
# adj_args={'factor': 2}, max_color=False, fill=True, deband=True)
# ##
#
#
# win = 101
# data = fits.open('/media/innereye/My Passport/Data/JWST/data/HH46/jw04441-o096_t008_nircam_clear-f335m_i2d.fits')[1].data.copy()
# data = level_adjust(data, factor=2)
# t0 = time()
# hp = data.copy()
# print('medfilt 0...')
# for ii in range(hp.shape[0]):
# hp[ii, :] = medfilt(hp[ii, :], 101)
# print(f'{ii}/{hp.shape[0]}', end='\r')
# t1 = time()-t0
#
# t0 = time()
# half0 = int(win/2)
# half1 = win-half0
# hp = data.copy()
# print('medfilt 0...')
# for ii in range(hp.shape[0]):
# toavg = np.nan * np.ones((data.shape[1] + win - 1, win))
# for shift in np.arange(win):
# toavg[shift:data.shape[1]+shift, shift] = data[ii, :]
# hp[ii, :] = np.nanmedian(toavg, axis=1)[half0:-half1+1]
# print(f'{ii}/{hp.shape[0]}', end='\r')
# t2 = time()-t0
#
# t0 = time()
# smoothed = smooth_width(data, win=101)
# t3 = time()-t0
# t0 = time()
# smoothed = smooth_width(smoothed.T, win=101)
# t4 = time()-t0
#
# t0 = time()
# kernel = Gaussian2DKernel(12)
# lp = convolve(data, kernel=kernel)
# t5 = time()-t0
#
# # half0 = int(win/2)
# # half1 = win-half0
# # for ic in range(data.shape[1]):
# # # create a matrix of nans with the same shape as the data
# # toavg = np.nan * np.ones((data.shape[0]+win-1, win))
# # for shift in np.arange(win):
# # toavg[shift:data.shape[0]+shift, shift] = data[:, ic]
# # if 'mean' in method:
# # avg = np.nanmean(toavg, axis=1)
# # elif 'median' in method:
# # avg = np.nanmedian(toavg, axis=1)
# def deband_layer(layer):
# # kernel = Ring2DKernel(50, 3)
# # print('ring...')
# # kernel = Gaussian2DKernel(12)
# # print('gaus...')
# # lp = convolve(layer, kernel=kernel)
# # lp = median_filter(layer, footprint=kernel.array)
# # lp = smooth_yx(layer, 101, 1)
# hp = layer.copy()
# print('medfilt 0...')
# for ii in range(hp.shape[0]):
# hp[ii, :] = medfilt(hp[ii, :], 101)
# print(f'{ii}/{hp.shape[0]}', end='\r')
# print('medfilt 1...')
# lp = layer.copy()
# for ii in range(hp.shape[0]):
# lp[:, ii] = medfilt(hp[:, ii], 101)
# # print(f'{ii}/{hp.shape[0]}')
# hp = layer - hp
# clean = lp + hp
# clean[clean < 0] = 0
# return clean
# # _ = auto_plot('NGC-1433', exp='log', png=False, pow=[1, 1, 1], pkl=True, method='mnn', resize=True, plot=True, adj_args={'lims': [0.95, 1.0], 'ignore0': True}) # adj_args={'lims': [0.03, 1.0]}
# # from astro_list_ngc import
# # auto_plot('NGC-346', exp='*w_i2d.fits', png='all.png', pow=[1, 1, 1], pkl=True, method='mnn', crop=False, plot=False)
# # auto_plot('ORIBAR-IMAGING-NIRCAM', exp='*_f*.fits', png='f.png', pow=[1, 1, 1], pkl=False, crop=True, method='rrgggbb')
# # hdu = fits.open('/home/innereye/astro/data/M83/jw02219-o011_t002_miri_f2100w_i2d.fits')
# # image = hdu[1].data.copy()
# # ##
# # lims = [0.03, 0.98]
# # hist_dat = image.flatten()
# # hist_dat = hist_dat[hist_dat > 0]
# # # nonzeros = np.abs(np.sign(fits_arr))
# # minval = np.quantile(hist_dat, lims[0])
# # maxval = np.quantile(hist_dat, lims[1])
# # # minval, maxval = np.quantile(hist_dat, lims)
# # rescaled = (image - minval) / (maxval - minval)
# # rescaled_no_outliers = np.maximum(rescaled, np.quantile(rescaled, 0.002))
# # rescaled_no_outliers = np.minimum(rescaled_no_outliers, np.quantile(rescaled_no_outliers, 1.0 - 0.002))
# #
# #
# # ##
# # number_bins=10000
# # image_histogram, bins = np.histogram(image.flatten(), number_bins, density=True)
# # cdf = image_histogram.cumsum() # cumulative distribution function
# # cdf = cdf / cdf[-1] # normalize
# # # use linear interpolation of cdf to find new pixel values
# # image_equalized = np.interp(image.flatten(), bins[:-1], cdf)
# # imageq = image_equalized.reshape(image.shape)
# # import matplotlib.pyplot as plt
# #
# # # Load and display the image
# # image = plt.imread('/media/innereye/My Passport/Data/JWST/SPT2147-50/rgb.png')
# # plt.imshow(image)
# # plt.axis('off')
# #
# # # Create a list to store the coordinates of the mouse clicks
# # click_coordinates = []
# #
# #
# # # Define a function to handle mouse click events
# # def onclick(event):
# # if len(click_coordinates) < 2:
# # # Append the coordinates of the clicked point to the list
# # click_coordinates.append((event.xdata, event.ydata))
# #
# # # Plot a red dot at the clicked point
# # plt.plot(event.xdata, event.ydata, 'ro')
# # plt.draw()
# #
# # if len(click_coordinates) == 2:
# # # After collecting two points, close the figure to proceed
# # plt.close()
# #
# #
# # # Connect the onclick function to the figure
# # plt.connect('button_press_event', onclick)
# #
# # # Display the figure
# # plt.show()
# #
# # # Retrieve the coordinates of the two mouse clicks
# # p1, p2 = click_coordinates
# #
# # # Crop the image based on the selected rectangle
# # x1, y1 = int(min(p1[0], p2[0])), int(min(p1[1], p2[1]))
# # x2, y2 = int(max(p1[0], p2[0])), int(max(p1[1], p2[1]))
# # cropped_image = image[y1:y2, x1:x2]
# #
# # # Display the cropped image
# # plt.imshow(cropped_image)
# # plt.axis('off')
# # plt.show()
# #
# # # (token, frob) = flickr.get_token_part_one(perms='write')
# # # auth_url = flickr.auth_url(token)
# #
# #
# # # from astro_list_ngc import ngc_html_thumb
# # # ngc_html_thumb()
# # #
# # # from astro_list_ngc import make_thumb
# # # import os
# # # os.chdir('/media/innereye/My Passport/Data/JWST/data/NGC-7469-MRS/')
# # # make_thumb('NGC-7469-MRS_MIRI.png', '2022-07-04')
# # # from astro_list_ngc import remake_thumb
# # # remake_thumb()