def AIA_MakeFrames(FILE): print("FILE: " + str(FILE)) date = 0 time = 0 wavelength = 0 b, g, r, a = 191, 191, 191, 0 framenum = database.index(FILE) framenum = str(framenum).zfill(4) print("FRAMENUM: " + str(framenum)) entry = FILE # img = aia.aiaprep(img) #leaving this here because it might be useful, but right now we're working with pre-prepped images. print("working on " + str(entry)) if os.stat( entry ).st_size != 0: #Check to see if our fits file is empty (this apparently happens sometimes) hdulist = fits.open(entry) priheader = hdulist[ 1].header #This is looking at the second header of older fits files from AIA, which have two. The newer Synoptic files seem to have just 1. date_obs = priheader['DATE-OBS'] wavelength = priheader['WAVELNTH'] else: date_obs = 0 print("File is empty.") if date_obs != 0: date = date_obs.split("T")[0] time = date_obs.split("T")[1] img = mm.aia_mkimage(entry, w0=4096, h0=4096, time_stamp=False) outfi = mm.aia_mkimage.format_img(img) subprocess.call("mv " + outfi + " working/" + str(framenum) + ".png", shell=True) # #Convert our image from a numpy array to something PIL can deal with if glob.glob("working/" + str(framenum) + ".png"): img_pil = Image.open("working/" + str(framenum) + ".png") # # Convert to RGB mode. Do I want to do this? I should maybe try RGBA if img_pil.mode != "RGB": img_pil = img_pil.convert("RGB") # # Render it to a frame draw = ImageDraw.Draw(img_pil) # # #Put our text on it print("applying timestamp... " + str(date_obs)) draw.text((3468, 386), str(date), font=font, fill=(b, g, r, a)) draw.text((3468, 456), str(time), font=font, fill=(b, g, r, a)) # # #Turn it back in to a numpy array for OpenCV to deal with frameStamp = np.array(img_pil) print("printing frame: " + str(framenum)) cv2.imwrite( "working/Frame_Out" + str(framenum) + ".png", cv2.cvtColor(frameStamp, cv2.COLOR_RGB2BGR) ) #It's critical to convert from BGR to RGB here, because OpenCV sees things differently from everyone else else: print("Could not locate working/" + str(framenum) + ".png. Dropping frame") else: print("Entry header contains no date. Skipping...")
def AIA_MakeFrames(FILE): print("FILE: " + str(FILE)) date = 0 time = 0 wavelength = 0 b, g, r, a = 191, 191, 191, 0 framenum = database.index(FILE) framenum = str(framenum).zfill(4) print("FRAMENUM: " + str(framenum)) entry = FILE # img = aia.aiaprep(img) #leaving this here because it might be useful, but right now we're working with pre-prepped images. print("working on " + str(entry)) if os.stat( entry ).st_size != 0: #Check to see if our fits file is empty (this apparently happens sometimes) hdulist = fits.open(entry) priheader = hdulist[ 0].header #Changed to 0 for newer synoptic files. 1 for older level1 fits files. date_obs = priheader['DATE-OBS'] wavelength = priheader['WAVELNTH'] else: date_obs = 0 print("File is empty.") if date_obs != 0: date = date_obs.split("T")[0] global_date = date time = date_obs.split("T")[1] img = mm.aia_mkimage(entry, w0=1024, h0=1024, time_stamp=False, synoptic=True) outfi = mm.aia_mkimage.format_img(img) subprocess.call("mv " + outfi + " working/" + str(framenum) + ".png", shell=True) # #Convert our image from a numpy array to something PIL can deal with if glob.glob("working/" + str(framenum) + ".png"): img_pil = Image.open("working/" + str(framenum) + ".png") # # Convert to RGB mode. Do I want to do this? I should maybe try RGBA if img_pil.mode != "RGB": img_pil = img_pil.convert("RGB") # # Render it to a frame draw = ImageDraw.Draw(img_pil) # # #Put our text on it print("Annotating: " + str(FILE)) draw.text((64, 875), "Temperature: ", font=font, fill=(b, g, r, a)) draw.text((64, 897), temperatures_celsius[target_wavelengths.index( str(wavelength).zfill(4))], font=font, fill=(b, g, r, a)) draw.text((870, 875), "Observation Time:", font=font, fill=(b, g, r, a)) draw.text((870, 897), str(date), font=font, fill=(b, g, r, a)) draw.text((870, 919), str(time), font=font, fill=(b, g, r, a)) # draw.text((102, 930), "Earth Added for Size Scale", font = ImageFont.truetype(fontpath, 15), fill = (b, g, r, a)) # # #Turn it back in to a numpy array for OpenCV to deal with frameStamp = np.array(img_pil) print("printing frame: " + str(framenum)) cv2.imwrite( "working/Frame_Out" + str(framenum) + ".png", cv2.cvtColor(frameStamp, cv2.COLOR_RGB2BGR) ) #It's critical to convert from BGR to RGB here, because OpenCV sees things differently from everyone else else: print("Could not locate working/" + str(framenum) + ".png. Dropping frame") else: print("Entry header contains no date. Skipping...")