From 29634414bc2dbd29eecf6de02fe76598bab31595 Mon Sep 17 00:00:00 2001 From: NickSwainston Date: Tue, 5 Mar 2024 04:32:02 +1100 Subject: [PATCH] Instead of DPI use PIL to reduce side --- meerpipe/scripts/generate_images_results.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/meerpipe/scripts/generate_images_results.py b/meerpipe/scripts/generate_images_results.py index 8e0fba5..f32674d 100644 --- a/meerpipe/scripts/generate_images_results.py +++ b/meerpipe/scripts/generate_images_results.py @@ -4,6 +4,7 @@ import subprocess import numpy as np import argparse +from PIL import Image import matplotlib matplotlib.use('Agg') @@ -168,11 +169,26 @@ def dynamic_spectra( logger = setup_logging(console=True) dyn = Dynspec(dynspec_file, process=False, verbose=False) - dyn.plot_dyn(filename=f"{dynspec_file}.png", display=False, title=f"Dynamic Spectral ({label})", dpi=80) + dynspec_image = f"{dynspec_file}.png" + dyn.plot_dyn(filename=dynspec_image, display=False, title=f"Dynamic Spectral ({label})", dpi=150) logger.info("Refilling") dyn.trim_edges() dyn.refill(linear=False) + image_size = os.path.getsize(dynspec_image) + if image_size > 1e6: + # Reduce the size of the image + logger.info(f"Reducing size of {dynspec_image} of size {image_size} bytes to less than 1MB") + img = Image.open(dynspec_image) + reduce_by = 7e5 / image_size + # Resize the image to maintain the same aspect ratio + new_width = int(img.width * reduce_by) + new_height = int(img.height * reduce_by) + resized_img = img.resize((new_width, new_height), Image.ANTIALIAS) + + # Save the resized image with compression + resized_img.save(dynspec_image, quality=85) # Adjust the quality as needed + def generate_images( pid,