Mercurial > repos > bimib > marea_2
changeset 281:d0a2043eb4d9 draft
Uploaded
author | luca_milaz |
---|---|
date | Sun, 04 Aug 2024 18:09:33 +0000 |
parents | 5bfc1b9cde50 |
children | ebc6bb8526c9 |
files | marea_2/flux_to_map.py |
diffstat | 1 files changed, 18 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/marea_2/flux_to_map.py Sun Aug 04 17:59:54 2024 +0000 +++ b/marea_2/flux_to_map.py Sun Aug 04 18:09:33 2024 +0000 @@ -814,23 +814,24 @@ dataset = dataset.drop(dataset.columns[0], axis = "columns").to_dict("list") return { id : list(map(utils.Float("Dataset values, not an argument"), values)) for id, values in dataset.items() }, IDs -def rgba_to_hex(rgba): - """Convert an RGBA color to HEX format including alpha.""" - return '#{:02x}{:02x}{:02x}{:02x}'.format(int(rgba[0] * 255), int(rgba[1] * 255), int(rgba[2] * 255), int(rgba[3] * 255)) - -def gray_to_red_cmap(value): +def jet_colormap(value): + # Ensure value is a single numeric value value = abs(value) + + # Define the red, green, and blue color components + red = np.clip(1.5 - np.abs(4 * (value - 0.75)), 0, 1) + green = np.clip(1.5 - np.abs(4 * (value - 0.5)), 0, 1) + blue = np.clip(1.5 - np.abs(4 * (value - 0.25)), 0, 1) + + # Combine the color components into an RGB array + rgb = np.array([red, green, blue]) + + return rgb - # Red color (1, 0, 0) - r = 1 - g = 0 - b = 0 - - # Log scale for opacity transition from 0.5 to 1 - log_value = math.log10(1 + 9 * value) / math.log10(10) # Log scale from 0 to 1 - alpha = 0.5 + 0.5 * log_value - - return (r, g, b, alpha) +def rgb_to_hex(rgb): + # Convert RGB values (0-1 range) to hexadecimal format + rgb = (rgb * 255).astype(int) + return '#{:02x}{:02x}{:02x}'.format(rgb[0], rgb[1], rgb[2]) def computeEnrichmentMeanMedian(metabMap :ET.ElementTree, class_pat :Dict[str, List[List[float]]], ids :List[str]) -> None: @@ -861,48 +862,28 @@ colors_median={} i=0 for rxn_id in ids: - colors_median[rxn_id] = rgba_to_hex(gray_to_red_cmap(medians[key][i])) + colors_median[rxn_id] = rgb_to_hex(jet_colormap(medians[key][i])) i+=1 colors_mean={} i=0 for rxn_id in ids: - colors_mean[rxn_id] = rgba_to_hex(gray_to_red_cmap(means[key][i])) + colors_mean[rxn_id] = rgb_to_hex(jet_colormap(means[key][i])) i+=1 for rxn_id in ids: arrow = Arrow(width=5, col=colors_median[rxn_id]) - #arrow.applyTo(arrow.getMapReactionId(rxn_id, mindReactionDir=False), metabMap_median, arrow.toStyleStr()) - #arrow.applyTo(getArrowBodyElementId(rxn_id), metabMap_median, arrow.toStyleStr()) arrow.styleReactionElements(metabMap_median, rxn_id, mindReactionDir=False) - idOpt1, idOpt2 = getArrowHeadElementId(rxn_id) arrow.applyTo(idOpt1, metabMap_median, arrow.toStyleStr(downSizedForTips = True)) if idOpt2: arrow.applyTo(idOpt2, metabMap_median, arrow.toStyleStr(downSizedForTips = True)) - # Now we style the arrow head(s): - #idOpt1, idOpt2 = getArrowHeadElementId(arrow.getMapReactionId(rxn_id, mindReactionDir=True)) - #arrow.applyTo(idOpt1, metabMap_median, arrow.toStyleStr(downSizedForTips = True)) - #if idOpt2: arrow.applyTo(idOpt2, metabMap_median, arrow.toStyleStr(downSizedForTips = True)) - #arrow = Arrow(width=5, col="#00FF00") - #arrow.styleReactionElements(metabMap_median, arrow.getMapReactionId(rxn_id, mindReactionDir=False), mindReactionDir=False) - arrow = Arrow(width=5, col=colors_mean[rxn_id]) - #arrow.applyTo(arrow.getMapReactionId(rxn_id, mindReactionDir=False), metabMap_mean, arrow.toStyleStr()) - #arrow.applyTo(getArrowBodyElementId(rxn_id), metabMap_mean, arrow.toStyleStr()) arrow.styleReactionElements(metabMap_mean, rxn_id, mindReactionDir=False) - idOpt1, idOpt2 = getArrowHeadElementId(rxn_id) arrow.applyTo(idOpt1, metabMap_mean, arrow.toStyleStr(downSizedForTips = True)) if idOpt2: arrow.applyTo(idOpt2, metabMap_mean, arrow.toStyleStr(downSizedForTips = True)) - # Now we style the arrow head(s): - #idOpt1, idOpt2 = getArrowHeadElementId(arrow.getMapReactionId(rxn_id, mindReactionDir=True)) - #arrow.applyTo(idOpt1, metabMap_mean, arrow.toStyleStr(downSizedForTips = True)) - #if idOpt2: arrow.applyTo(idOpt2, metabMap_mean, arrow.toStyleStr(downSizedForTips = True)) - #arrow = Arrow(width=5, col="#00FF00") - #arrow.styleReactionElements(metabMap_mean, arrow.getMapReactionId(rxn_id, mindReactionDir=False), mindReactionDir=False) - svgFilePath = utils.FilePath("SVG Map mean - " + str(key), ext = utils.FileFormat.SVG, prefix="result") utils.writeSvg(svgFilePath, metabMap_mean)