From 3391f762cdee47826d0eab3c9c05e974c4a68a4d Mon Sep 17 00:00:00 2001 From: Sarith Subramaniam Date: Mon, 23 Oct 2023 15:45:53 +0200 Subject: [PATCH 1/2] feat(px.py): Added falsecolor --- pyradiance/px.py | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/pyradiance/px.py b/pyradiance/px.py index eae04fa..480d496 100644 --- a/pyradiance/px.py +++ b/pyradiance/px.py @@ -427,3 +427,105 @@ def ra_ppm( elif isinstance(inp, bytes): stdin = inp return sp.run(cmd, check=True, input=stdin, stdout=sp.PIPE).stdout + +@handle_called_process_error +def falsecolor( + inp: [Union[str, Path, bytes]], + pic_overlay: Optional[str] = None, + contour: Optional[str] = None, + extrema: bool = False, + scale: Optional[str] = None, + digits: Optional[int] = None, + label: Optional[str] = None, + ndivs: Optional[int] = None, + lwidth: Optional[int] = None, + lheight: Optional[int] = None, + decades: Optional[int] = None, + multiplier: Optional[float] = None, + palette: Optional[str] = None, + redv: Optional[str] = None, + grnv: Optional[str] = None, + bluv: Optional[str] = None, +) -> bytes: + """ + Generate a falsecolor Radiance picture. + + Args: + inp: Path or bytes to input picture file. + pic_overlay: Path to another picture to overlay with contours. + contour: Type of contour ('b' for bands, 'l' for lines, 'p' for posterization). + extrema: Flag to print extrema points on the brightest and darkest pixels. + scale: Scale for the false color (e.g., 'auto' or specific scale). + digits: Max number of decimal places for legend entries. + label: Label for the new image. + ndivs: Number of contours and corresponding legend entries. + lwidth: Width of the legend. + lheight: Height of the legend. + decades: Number of decades below the maximum scale for logarithmic mapping. + multiplier: Multiplier for the scale (e.g., to convert units). + palette: Color palette to use for false color. + redv: Expression for mapping values to red. + grnv: Expression for mapping values to green. + bluv: Expression for mapping values to blue. + + Returns: + bytes: Output of falsecolor. + """ + cmd = [str(BINPATH / "falsecolor")] + + # In the man-page, it is mentioned that stdin is used if no input file is specified. + if isinstance(inp, str): + cmd.extend(["-i", inp]) + stdin = None + else: + stdin = inp + + if pic_overlay: + cmd.extend(["-p", pic_overlay]) + + if contour: + if contour in ['b', 'l', 'p']: + cmd.append(f"-c{contour}") + else: + raise ValueError("Invalid value for contour. Allowed values are 'b', 'l', or 'p'.") + + if extrema: + cmd.append("-e") + + if scale: + cmd.extend(["-s", scale]) + + if digits is not None: + cmd.extend(["-d", str(digits)]) + + if label: + cmd.extend(["-l", label]) + + if ndivs is not None: + cmd.extend(["-n", str(ndivs)]) + + if lwidth is not None: + cmd.extend(["-lw", str(lwidth)]) + + if lheight is not None: + cmd.extend(["-lh", str(lheight)]) + + if decades is not None: + cmd.extend(["-log", str(decades)]) + + if multiplier is not None: + cmd.extend(["-m", str(multiplier)]) + + if palette: + cmd.extend(["-pal", palette]) + + if redv: + cmd.extend(["-r", redv]) + + if grnv: + cmd.extend(["-g", grnv]) + + if bluv: + cmd.extend(["-b", bluv]) + + return sp.run(cmd, stdout=sp.PIPE, check=True, input=stdin).stdout \ No newline at end of file From 2edf2d108588708d22d13aafb0b9be5768a358a9 Mon Sep 17 00:00:00 2001 From: Sarith Subramaniam Date: Mon, 23 Oct 2023 15:48:35 +0200 Subject: [PATCH 2/2] feat(__init__.py, setup.py): Bring falsecolor to toplevel and enable compilation --- pyradiance/__init__.py | 2 ++ setup.py | 1 + 2 files changed, 3 insertions(+) diff --git a/pyradiance/__init__.py b/pyradiance/__init__.py index 4c09cbc..86bd88a 100644 --- a/pyradiance/__init__.py +++ b/pyradiance/__init__.py @@ -59,6 +59,7 @@ pcond, pfilt, ra_tiff, + falsecolor, ) from .rt import ( @@ -107,6 +108,7 @@ "cnt", "dctimestep", "evalglare", + "falsecolor" "genblinds", "genbsdf", "gendaylit", diff --git a/setup.py b/setup.py index 0b1603d..7d2fdba 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,7 @@ 'cnt', 'dctimestep', 'evalglare', + 'falsecolor', 'getbbox', 'getinfo', 'genblinds',