Added saving error images
This commit is contained in:
parent
dad3a80b9a
commit
d0fcee35d5
1 changed files with 34 additions and 21 deletions
|
|
@ -17,7 +17,7 @@ from skimage.morphology import skeletonize
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
|
|
||||||
def lowpriority():
|
def lowpriority():
|
||||||
""" Set the priority of the process to below-normal."""
|
""" Set the priority of the process to lowest possible."""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
try:
|
try:
|
||||||
|
|
@ -28,25 +28,26 @@ def lowpriority():
|
||||||
isWindows = True
|
isWindows = True
|
||||||
|
|
||||||
if isWindows:
|
if isWindows:
|
||||||
# Based on:
|
|
||||||
# "Recipe 496767: Set Process Priority In Windows" on ActiveState
|
|
||||||
# http://code.activestate.com/recipes/496767/
|
|
||||||
import win32api,win32process,win32con # pywin32
|
import win32api,win32process,win32con # pywin32
|
||||||
|
|
||||||
pid = win32api.GetCurrentProcessId()
|
pid = win32api.GetCurrentProcessId()
|
||||||
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
|
phandle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
|
||||||
win32process.SetPriorityClass(handle, win32process.BELOW_NORMAL_PRIORITY_CLASS)
|
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:
|
else:
|
||||||
import os
|
import os
|
||||||
|
|
||||||
os.nice(1)
|
os.nice(19)
|
||||||
|
|
||||||
measurement_names = ["094", "131", "171", "195", "284", "304"]
|
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
|
max_center_skew = 7
|
||||||
circle_hough_thresh = 0.75
|
circle_hough_thresh = 0.75
|
||||||
expected_dims = 1280
|
expected_dims = 1280
|
||||||
ratio_above_thresh_max = 0.5
|
ratio_above_thresh_max = 0.4
|
||||||
|
|
||||||
def filter_fits(work_queue):
|
def filter_fits(work_queue):
|
||||||
lowpriority()
|
lowpriority()
|
||||||
|
|
@ -75,18 +76,17 @@ def filter_fits(work_queue):
|
||||||
new_name = job.split(".fits")[0] + "_e.fits"
|
new_name = job.split(".fits")[0] + "_e.fits"
|
||||||
os.rename(job, new_name)
|
os.rename(job, new_name)
|
||||||
|
|
||||||
# plt.figure(f"Data {measurement}")
|
plt.figure(f"Exceeded ratio_above_thresh_max", figsize=[10.24, 7.68])
|
||||||
# plt.imshow(data, cmap='jet')
|
plt.imshow(filtered_data, cmap='jet')
|
||||||
# plt.figure(f"Circle")
|
plt.savefig(job.split(".fits")[0] + "_e.jpg")
|
||||||
# plt.imshow(filtered_data, cmap='jet')
|
plt.close('all')
|
||||||
# plt.show()
|
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
hough_radii = np.arange(383, 393, 1)
|
hough_radii = np.arange(383, 394, 2)
|
||||||
hough_res = hough_circle(filtered_data, hough_radii)
|
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
|
found_circle = None
|
||||||
for v, cx, cy, rad in zip(vals, cxs, cys, rads):
|
for v, cx, cy, rad in zip(vals, cxs, cys, rads):
|
||||||
xskew = abs(639 - cx)
|
xskew = abs(639 - cx)
|
||||||
|
|
@ -96,10 +96,10 @@ def filter_fits(work_queue):
|
||||||
break
|
break
|
||||||
|
|
||||||
# print(f"Plotting file: {job}")
|
# 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)
|
# 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.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)
|
# 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.imshow(filtered_data, cmap='jet')
|
||||||
# plt.show()
|
# plt.show()
|
||||||
|
|
@ -109,6 +109,13 @@ def filter_fits(work_queue):
|
||||||
|
|
||||||
new_name = job.split(".fits")[0] + "_e.fits"
|
new_name = job.split(".fits")[0] + "_e.fits"
|
||||||
os.rename(job, new_name)
|
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
|
continue
|
||||||
|
|
||||||
# We have validated this file, rename it appropriately
|
# 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())
|
stoptime = calendar.timegm(datetime.datetime(2024, 1, 1, tzinfo=datetime.timezone.utc).timetuple())
|
||||||
|
|
||||||
reprocess_errors = False
|
reprocess_errors = False
|
||||||
nworkers = 20
|
nworkers = 16
|
||||||
|
|
||||||
|
|
||||||
regex_filename = r"dr_suvi-l2-ci\d{3}_g(16|18)_s\S*\.fits$"
|
regex_filename = r"dr_suvi-l2-ci\d{3}_g(16|18)_s\S*\.fits$"
|
||||||
|
|
||||||
|
|
||||||
work_queue = Queue(maxsize = nworkers)
|
work_queue = Queue(maxsize = nworkers)
|
||||||
workers = []
|
workers = []
|
||||||
|
|
@ -178,8 +183,16 @@ if __name__ == "__main__":
|
||||||
continue # Already filtered from a previous run
|
continue # Already filtered from a previous run
|
||||||
elif file_name_end == "e":
|
elif file_name_end == "e":
|
||||||
if reprocess_errors:
|
if reprocess_errors:
|
||||||
|
# Rename file to remove error designation
|
||||||
new_file_name = "_".join(file_parts[:-1]) + ".fits"
|
new_file_name = "_".join(file_parts[:-1]) + ".fits"
|
||||||
os.rename(os.path.join(root,f), os.path.join(root,new_file_name))
|
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))
|
files_by_timestamp[measure_end_time].append(os.path.join(root, new_file_name))
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue