changeset 314:e8c20e0b4f27 draft

Uploaded
author luca_milaz
date Mon, 05 Aug 2024 12:29:48 +0000
parents 376afe557f90
children 48d2973faacf
files marea_2/flux_to_map.py
diffstat 1 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/marea_2/flux_to_map.py	Mon Aug 05 12:23:58 2024 +0000
+++ b/marea_2/flux_to_map.py	Mon Aug 05 12:29:48 2024 +0000
@@ -17,7 +17,6 @@
 import pyvips
 from PIL import Image, ImageDraw, ImageFont
 from typing import Tuple, Union, Optional, List, Dict
-import seaborn as sns
 import matplotlib.pyplot as plt
 
 ERRORS = []
@@ -854,18 +853,16 @@
         max_value (float): The maximum value of the colormap range.
         filename (str): The filename for saving the image.
     """
-    # Generate a range of values
-    values = np.linspace(min_value, max_value, 256)
 
-    # Create a colormap using seaborn
-    cmap = sns.color_palette("jet", as_cmap=True)
+    # Create a colormap using matplotlib
+    cmap = plt.get_cmap("jet")
 
     # Create a figure and axis
     fig, ax = plt.subplots(figsize=(6, 1))
     fig.subplots_adjust(bottom=0.5)
 
     # Create a gradient image
-    gradient = np.linspace(0, 1, 256)
+    gradient = np.linspace(min_value, max_value, 256)
     gradient = np.vstack((gradient, gradient))
 
     # Display the gradient image
@@ -904,16 +901,18 @@
     min_flux_medians = min(np.min(np.abs(arr)) for arr in medians.values())
     min_flux_means = min(np.min(np.abs(arr)) for arr in means.values())
 
-    medians = {key: median / max_flux_medians for key, median in medians.items()}
-    means = {key: mean / max_flux_means for key, mean in means.items()}
+    medians = {key: (median - min_flux_medians) / (max_flux_medians - min_flux_medians) for key, median in medians.items()}
+    means = {key: (mean - min_flux_means) / (max_flux_means - min_flux_means) for key, mean in means.items()}
 
     save_colormap_image(min_flux_medians, max_flux_medians, "colormap_median.png")
     save_colormap_image(min_flux_means, max_flux_means, "colormap_mean.png")
 
+    cmap = plt.get_cmap("jet")
+
     for key in class_pat:
         # Create color mappings for median and mean
-        colors_median = {rxn_id: rgb_to_hex(sns.color_palette("jet", as_cmap=True)((medians[key][i] + 1) / 2)) for i, rxn_id in enumerate(ids)}
-        colors_mean = {rxn_id: rgb_to_hex(sns.color_palette("jet", as_cmap=True)((means[key][i] + 1) / 2)) for i, rxn_id in enumerate(ids)}
+        colors_median = {rxn_id: rgb_to_hex(cmap(medians[key][i])) for i, rxn_id in enumerate(ids)}
+        colors_mean = {rxn_id: rgb_to_hex(cmap(means[key][i])) for i, rxn_id in enumerate(ids)}
 
         for i, rxn_id in enumerate(ids):
             isNegative = medians[key][i] < 0