Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Falsecolor #31

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyradiance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
pcond,
pfilt,
ra_tiff,
falsecolor,
)

from .rt import (
Expand Down Expand Up @@ -107,6 +108,7 @@
"cnt",
"dctimestep",
"evalglare",
"falsecolor"
"genblinds",
"genbsdf",
"gendaylit",
Expand Down
102 changes: 102 additions & 0 deletions pyradiance/px.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'cnt',
'dctimestep',
'evalglare',
'falsecolor',
'getbbox',
'getinfo',
'genblinds',
Expand Down