-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAvg_IMG_Viewer_single.py
executable file
·151 lines (125 loc) · 4.22 KB
/
Avg_IMG_Viewer_single.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
#MMAvg_IMG_Viewer.py created by BWM 11/29/22
#program to create pretty averaged images plot and save them for MM
import numpy as np
import Big_keck_load as BKL
import os
import matplotlib.pyplot as plt
import sys
import tkinter.filedialog as fd
def file_select(Type):
filename = fd.askopenfilename(
title = "Open " + str(Type),
initialdir = "/mnt/raid/keckpad/set-HeadRework",
)
return filename
# backFile = file_select("Background File")
#foreFile = file_select("Foreground File")
foreFile = "/Users/benjaminmartin/Desktop/S01_CompB_04_00000001.raw"
cwd = os.getcwd()
foreImage = open(foreFile,"rb")
# backImage = open(backFile,"rb")
numImagesF = int(os.path.getsize(foreFile)/(1024+512*512*2))
# numImagesB = int(os.path.getsize(backFile)/(1024+512*512*2))
foreStack = np.zeros((8,512,512),dtype=np.double)
# backStack = np.zeros((8,512,512),dtype=np.double)
##################################
#Adjust for clipping
##################################
clipHigh = 5e4
clipLow = 0
#read all the image files
# for fIdex in range(numImagesB):
# payloadB = BKL.keckFrame(backImage)
# backStack[(payloadB[3]-1)%8,:,:] += np.resize(payloadB[4],[512,512])
# avgBack = backStack/(numImagesB/8.0)
for fIdex in range(numImagesF):
payload = BKL.keckFrame(foreImage)
foreStack[(payload[3]-1)%8,:,:] += np.resize(payload[4],[512,512])
avgFore = foreStack/(numImagesF/8.0)
plotData = avgFore #-avgBack
plotDataClip = np.clip(plotData, clipLow, clipHigh)
avgplotData = np.average(plotDataClip, axis=0)
avg,axs = plt.subplots(1)
imageAvg = axs.imshow(avgplotData, cmap = "viridis")
Acbar = avg.colorbar(imageAvg, aspect=10)
axs.set_title('Keck Cap Average')
axs.set_ylabel("Pixel")
axs.set_xlabel("Pixel")
Acbar.set_label ("Counts (ADU)")
# fig.set_size_inches(20, 10)
# fig.subplots_adjust(wspace = 0.545)
avg.savefig(foreFile + "_Avg.png")
plt.show()
# plt.imshow(plotData)
allplot = []
for val in range(8):
allplot.append(plotDataClip[val,:,:])
# indexVal = (-1)
# fig,ax = plt.subplots(2,4)
# for pic in allplot:
# indexVal += 1
# indexRow = int(indexVal/4)
# indexCol = int(indexVal%4)
# #indexVal = allplot.index(pic)
# image = ax[indexRow,indexCol].imshow(pic, cmap = "viridis")
# # ax.imshow(pic)
# # fig,ax = plt.subplots(1)
# #needed to add more stuff
# # image = ax.imshow(clipData, cmap = "viridis")
# cbar = fig.colorbar(image, aspect=10, ax = ax[indexRow,indexCol])
# ax[indexRow,indexCol].set_title('Keck Cap'+ str(indexVal))
# ax[indexRow,indexCol].set_ylabel("Pixel")
# ax[indexRow,indexCol].set_xlabel("Pixel")
# cbar.set_label ("Counts (ADU)")
# fig.set_size_inches(20, 10)
# fig.subplots_adjust(wspace = 0.545)
# fig.savefig(foreFile + "_AvgAll.png")
# plotData1 = plotData[0,:,:]
# #average the data across all 8 caps
# plotData = np.average(plotData, axis=0)
# #clip data below to get rid of hot pixels and negative pixels
# clipData = np.clip(plotData, clipLow, clipHigh)
# ########################
# #code to plot all 8 caps individually
# ########################
# plt.imshow(plotData)
fig,axs = plt.subplots(2,4)
axs[0,0].imshow(plotData[0,:,:])
axs[0,1].imshow(plotData[1,:,:])
axs[0,2].imshow(plotData[2,:,:])
axs[0,3].imshow(plotData[3,:,:])
axs[1,0].imshow(plotData[4,:,:])
axs[1,1].imshow(plotData[5,:,:])
axs[1,2].imshow(plotData[6,:,:])
axs[1,3].imshow(plotData[7,:,:])
# plt.imshow(fmb[3,:,:])
plt.show()
# ###################
# #Code to plot and save one image with labels and such
# ###################
# # fig,ax = plt.subplots(1)
# # image = ax.imshow(clipData, cmap = "viridis")
# # cbar = fig.colorbar(image, aspect=10)
# # ax.set_title('DCS Keck')
# # ax.set_ylabel("Pixel")
# # ax.set_xlabel("Pixel")
# # cbar.set_label ("Counts (ADU)")
# #fig.savefig(foreFile + "_Avg.png")
# # plt.show()
# #################
# #3d Projection plot code example
# ########################
# # fig = plt.figure()
# # # syntax for 3-D projection
# # fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
# # # defining all 3 axes
# # z = clipData
# # x = range(512)
# # y = range(512)
# # X, Y = np.meshgrid(x, y)
# # # plotting
# # surf = ax.plot_surface(X, Y, z,cmap ='viridis')
# # fig.colorbar(surf, shrink=0.5, aspect=5)
# # ax.set_title('DCSKeck')
# # plt.show()
# #############################