In merger fixed timezone issue and added new font and black frame insertion
This commit is contained in:
parent
99c771322b
commit
2fa1297afc
2 changed files with 32 additions and 20 deletions
BIN
OpenSans-Regular.ttf
Normal file
BIN
OpenSans-Regular.ttf
Normal file
Binary file not shown.
|
|
@ -9,7 +9,7 @@ import queue
|
|||
import traceback
|
||||
|
||||
import tqdm
|
||||
from PIL import Image, ImageDraw
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
from astropy.io import fits
|
||||
|
|
@ -286,6 +286,8 @@ def generate_composite(work_queue, result_queue):
|
|||
gammas = [0.375, 0.40, 00.425, 00.45, 00.475, 00.5]
|
||||
trimx = 64
|
||||
trimy = 100
|
||||
fnt1 = ImageFont.truetype("OpenSans-Regular.ttf", size = 24)
|
||||
fnt2 = ImageFont.truetype("OpenSans-Regular.ttf", size = 16)
|
||||
while True:
|
||||
try:
|
||||
job = work_queue.get()
|
||||
|
|
@ -293,14 +295,21 @@ def generate_composite(work_queue, result_queue):
|
|||
result_queue.cancel_join_thread()
|
||||
return
|
||||
files_this_timestamp, timestamp, processed_images_dir, synthetic_data = job
|
||||
synthetic_filepath = os.path.join(processed_images_dir, f"Composite-{int(timestamp)}_s.jpg")
|
||||
normal_filepath = os.path.join(processed_images_dir, f"Composite-{int(timestamp)}.jpg")
|
||||
filepath = None
|
||||
if synthetic_data:
|
||||
filename = f"Composite-{int(timestamp)}_s.jpg"
|
||||
if os.path.isfile(synthetic_filepath):
|
||||
result_queue.put(("Exists", timestamp))
|
||||
continue
|
||||
filepath = synthetic_filepath
|
||||
else:
|
||||
filename = f"Composite-{int(timestamp)}.jpg"
|
||||
filepath = os.path.join(processed_images_dir, filename)
|
||||
if os.path.isfile(filepath):
|
||||
result_queue.put(("Exists", timestamp))
|
||||
continue
|
||||
if os.path.isfile(synthetic_filepath):
|
||||
os.remove(synthetic_filepath)
|
||||
if os.path.isfile(normal_filepath):
|
||||
result_queue.put(("Exists", timestamp))
|
||||
continue
|
||||
filepath = normal_filepath
|
||||
|
||||
base_imgs = []
|
||||
for i in range(6):
|
||||
|
|
@ -402,14 +411,14 @@ def generate_composite(work_queue, result_queue):
|
|||
|
||||
img = Image.fromarray((255 * composite_image_data).astype('uint8'))
|
||||
timestring = datetime.datetime.fromtimestamp(timestamp, tz = datetime.UTC).strftime('%Y-%m-%d %H:%M:%S')
|
||||
ImageDraw.Draw(img).text((605, 15), f"NOAA GOES Satellite SUVI Composite - {timestring} UTC",(255,255,255), font_size = 24)
|
||||
ImageDraw.Draw(img).text((602, 15), f"NOAA GOES Satellite SUVI Composite - {timestring} UTC",(255,255,255), font = fnt1)
|
||||
for i in range(6): # Draw component angstrom labels
|
||||
if i%2 == 0:
|
||||
xdimtxtoff = 5
|
||||
else:
|
||||
xdimtxtoff = composite_image_data.shape[1] - 44
|
||||
ydimtxtoff = i//2*new_dimy + new_dimy / 2.0 - 6
|
||||
ImageDraw.Draw(img).text((xdimtxtoff, ydimtxtoff), image_names[i], font_size = 16)
|
||||
ydimtxtoff = i//2*new_dimy + new_dimy / 2.0 - 14
|
||||
ImageDraw.Draw(img).text((xdimtxtoff, ydimtxtoff), image_names[i], font = fnt2)
|
||||
img.save(filepath, quality = 95)
|
||||
result_queue.put(("Created", timestamp))
|
||||
|
||||
|
|
@ -432,12 +441,12 @@ if __name__ == "__main__":
|
|||
r"..\Data\goes18\l2\data\suvi-l2-ci284\2024",
|
||||
r"..\Data\goes18\l2\data\suvi-l2-ci304\2024",]
|
||||
processed_images_dir = r"..\composite\goes18"
|
||||
starttime = time.mktime(datetime.datetime(2024, 1, 1).timetuple())
|
||||
stoptime = time.mktime(datetime.datetime(2025, 1, 1).timetuple())
|
||||
starttime = time.mktime(datetime.datetime(2024, 1, 1, tzinfo=datetime.timezone.utc).timetuple())
|
||||
stoptime = time.mktime(datetime.datetime(2025, 1, 1, tzinfo=datetime.timezone.utc).timetuple())
|
||||
|
||||
regex_filename = r"dr_suvi-l2-ci\d{3}_g(16|18)_s\S*\_f.fits$"
|
||||
nworkers = 20
|
||||
max_time_gap = 10
|
||||
max_time_gap = 3
|
||||
|
||||
file_prefixes = ["dr_suvi-l2-ci" + n[:-1] for n in image_names]
|
||||
|
||||
|
|
@ -456,6 +465,7 @@ if __name__ == "__main__":
|
|||
ncreated = 0
|
||||
nexists = 0
|
||||
nfailed = 0
|
||||
black_image = Image.fromarray(np.zeros((1080, 1920, 3), dtype='uint8'))
|
||||
try:
|
||||
files_sorted_by_timestamp = defaultdict(list)
|
||||
found_files = 0
|
||||
|
|
@ -467,11 +477,9 @@ if __name__ == "__main__":
|
|||
for f in files:
|
||||
if filename_tester.match(f):
|
||||
file_parts = f.split("_")
|
||||
measurement = file_parts[1]
|
||||
sattelite = file_parts[2]
|
||||
measure_end_time = datetime.datetime.strptime(file_parts[4][1:16], "%Y%m%dT%H%M%S")
|
||||
measure_end_time.replace(tzinfo=datetime.timezone.utc)
|
||||
measure_end_time = int(time.mktime(measure_end_time.timetuple()))
|
||||
# measurement = file_parts[1]
|
||||
# sattelite = file_parts[2]
|
||||
measure_end_time = int(datetime.datetime.strptime(file_parts[4][1:16] + " +0000", "%Y%m%dT%H%M%S %z").timestamp())
|
||||
files_sorted_by_timestamp[measure_end_time].append(os.path.join(root,f))
|
||||
found_files += 1
|
||||
|
||||
|
|
@ -531,8 +539,12 @@ if __name__ == "__main__":
|
|||
synthetic_data = True
|
||||
files_for_job.append(last_good_files[i])
|
||||
else:
|
||||
print(f"Detected a gap of {time_gap} frames at {timestamp}, skipping.")
|
||||
continue
|
||||
print(f"Detected a gap of {time_gap} frames at {timestamp}, inserting black frames.")
|
||||
filename = f"Composite-{int(timestamp)}_b.jpg"
|
||||
filepath = os.path.join(processed_images_dir, filename)
|
||||
if not os.path.isfile(filepath):
|
||||
black_image.save(filepath, quality = 95)
|
||||
break
|
||||
if len(files_for_job) == 6:
|
||||
work_queue.put((files_for_job, timestamp, processed_images_dir, synthetic_data))
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue