Added saving error images

This commit is contained in:
Jeremy Karst 2024-07-02 11:00:56 -04:00
parent dad3a80b9a
commit d0fcee35d5

View file

@ -17,7 +17,7 @@ from skimage.morphology import skeletonize
import cv2 as cv
def lowpriority():
""" Set the priority of the process to below-normal."""
""" Set the priority of the process to lowest possible."""
import sys
try:
@ -28,25 +28,26 @@ def lowpriority():
isWindows = True
if isWindows:
# Based on:
# "Recipe 496767: Set Process Priority In Windows" on ActiveState
# http://code.activestate.com/recipes/496767/
import win32api,win32process,win32con # pywin32
pid = win32api.GetCurrentProcessId()
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
win32process.SetPriorityClass(handle, win32process.BELOW_NORMAL_PRIORITY_CLASS)
phandle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
win32process.SetPriorityClass(phandle, win32process.THREAD_PRIORITY_LOWEST)
# win32process.SetPriorityClass(phandle, win32process.IDLE_PRIORITY_CLASS)
# tid = win32api.GetCurrentThreadId()
# thandle = win32api.OpenThread(win32con.PROCESS_ALL_ACCESS, True, tid)
# win32process.SetThreadPriority(thandle, win32process.THREAD_MODE_BACKGROUND_BEGIN)
else:
import os
os.nice(1)
os.nice(19)
measurement_names = ["094", "131", "171", "195", "284", "304"]
thresholds = [0.050, 0.10 , 1.00, 1.40, 0.93, 2.50]
thresholds = [0.050, 0.10 , 1.00, 1.40, 0.95, 2.50]
max_center_skew = 7
circle_hough_thresh = 0.75
expected_dims = 1280
ratio_above_thresh_max = 0.5
ratio_above_thresh_max = 0.4
def filter_fits(work_queue):
lowpriority()
@ -75,18 +76,17 @@ def filter_fits(work_queue):
new_name = job.split(".fits")[0] + "_e.fits"
os.rename(job, new_name)
# plt.figure(f"Data {measurement}")
# plt.imshow(data, cmap='jet')
# plt.figure(f"Circle")
# plt.imshow(filtered_data, cmap='jet')
# plt.show()
plt.figure(f"Exceeded ratio_above_thresh_max", figsize=[10.24, 7.68])
plt.imshow(filtered_data, cmap='jet')
plt.savefig(job.split(".fits")[0] + "_e.jpg")
plt.close('all')
continue
hough_radii = np.arange(383, 393, 1)
hough_radii = np.arange(383, 394, 2)
hough_res = hough_circle(filtered_data, hough_radii)
vals, cxs, cys, rads = hough_circle_peaks(hough_res, hough_radii, threshold=circle_hough_thresh, total_num_peaks=20)
vals, cxs, cys, rads = hough_circle_peaks(hough_res, hough_radii, threshold=circle_hough_thresh, total_num_peaks=40)
found_circle = None
for v, cx, cy, rad in zip(vals, cxs, cys, rads):
xskew = abs(639 - cx)
@ -96,10 +96,10 @@ def filter_fits(work_queue):
break
# print(f"Plotting file: {job}")
# plt.figure(f"Data {measurement}")
# plt.figure(f"Data {measurement}", figsize=[10.24, 7.68])
# if found_circle: cv.circle(data, (int(found_circle[0]),int(found_circle[1])), int(found_circle[2]), float(np.max(np.max(data))), 1)
# plt.imshow(data, cmap='jet')
# plt.figure(f"Circle: {found_circle}")
# plt.figure(f"Circle: {found_circle}", figsize=[10.24, 7.68])
# if found_circle: cv.circle(filtered_data, (int(found_circle[0]),int(found_circle[1])), int(found_circle[2]), 0.5, 1)
# plt.imshow(filtered_data, cmap='jet')
# plt.show()
@ -109,6 +109,13 @@ def filter_fits(work_queue):
new_name = job.split(".fits")[0] + "_e.fits"
os.rename(job, new_name)
plt.figure(f"No Solar Disc Found", figsize=[10.24, 7.68])
for x, y, r in zip(cxs, cys, rads):
cv.circle(filtered_data, (int(x),int(y)), int(r), 0.5, 1)
plt.imshow(filtered_data, cmap='jet')
plt.savefig(job.split(".fits")[0] + "_e.jpg")
plt.close('all')
continue
# We have validated this file, rename it appropriately
@ -143,11 +150,9 @@ if __name__ == "__main__":
stoptime = calendar.timegm(datetime.datetime(2024, 1, 1, tzinfo=datetime.timezone.utc).timetuple())
reprocess_errors = False
nworkers = 20
nworkers = 16
regex_filename = r"dr_suvi-l2-ci\d{3}_g(16|18)_s\S*\.fits$"
work_queue = Queue(maxsize = nworkers)
workers = []
@ -178,8 +183,16 @@ if __name__ == "__main__":
continue # Already filtered from a previous run
elif file_name_end == "e":
if reprocess_errors:
# Rename file to remove error designation
new_file_name = "_".join(file_parts[:-1]) + ".fits"
os.rename(os.path.join(root,f), os.path.join(root,new_file_name))
# Check if error image exists and delete if needed
img_name = new_file_name.split(".fits")[0] + "_e.jpg"
try:
os.remove(os.path.join(root, img_name))
except:
pass
# Add job to queue
files_by_timestamp[measure_end_time].append(os.path.join(root, new_file_name))
else:
continue