-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_FlatField.py
executable file
·112 lines (90 loc) · 3.16 KB
/
make_FlatField.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
#make_FlatField.py created by BWM 1/28/22
#program to create a flat field correction file and save per cap version of normalized correction
import numpy as np
import Big_keck_load as BKL
import os
import matplotlib.pyplot as plt
import sys
import tkinter.filedialog as fd
import pickle as pkl
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 = "/Volumes/BMARTIN/set-Geod/run-f3ms/frames/f3ms_00000001.raw"
#backFile = "/Volumes/BMARTIN/set-Geod/run-b3ms/frames/b3ms_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 = 5e2
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)
normFore = np.zeros((8,512,512), dtype=np.double)
for cap in range(8):
dataMax = np.max(1/avgFore[cap,:,:])
normFore[cap,:,:] += 1/avgFore[cap,:,:] * dataMax
fileName = cwd + '/FF.pickle'
fileObject = open(fileName, 'wb')
pkl.dump(normFore, fileObject)
fileObject.close()
#######################
#Code to unpickle, need pickle import
# fileObject = open(fileName, 'rb')
# modelInput = pkl.load(fileObject2)
# fileObject2.close()
plotData = normFore
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)
#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)
plotData1 = plotData[0,:,:]
plt.show()