Skip to content

Commit

Permalink
bump version to 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Taoning Wang committed Oct 23, 2023
1 parent d978e89 commit c6811c8
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pyradiance/px.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ def ra_ppm(

@handle_called_process_error
def falsecolor(
inp: [Union[str, Path, bytes]],
inp: Union[str, Path, bytes],
pic_overlay: Optional[str] = None,
contour: Optional[str] = None,
contour: Optional[str] = None,
extrema: bool = False,
scale: Optional[str] = None,
digits: Optional[int] = None,
Expand Down Expand Up @@ -474,8 +474,8 @@ def 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])
if isinstance(inp, (str, Path)):
cmd.extend(["-i", str(inp)])
stdin = None
else:
stdin = inp
Expand Down Expand Up @@ -528,4 +528,4 @@ def falsecolor(
if bluv:
cmd.extend(["-b", bluv])

return sp.run(cmd, stdout=sp.PIPE, check=True, input=stdin).stdout
return sp.run(cmd, stdout=sp.PIPE, check=True, input=stdin).stdout
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def get_ext_filename(self, ext_name):
name="pyradiance",
author="LBNL",
author_email="taoningwang@lbl.gov",
version="0.2.0",
version="0.3.0",
description="Python interface for Radiance",
long_description=Path("README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
Expand Down
97 changes: 97 additions & 0 deletions test/Resources/comp_dirdir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

from typing import Tuple
from math import floor, sqrt, radians, sin, cos, tan, atan2, degrees, pi

import pyradiance as pr

def lrand(x: float) -> float:
"""Psudo-random number generator."""
x *= 1.0/(1.0 + x*x) + 2.71828182845904
x += .785398163397447 - floor(x)
x = 1e5 / x
return x - floor(x);

def vec_from_deg(theta: float, phi: float) -> Tuple[float, float, float]:
theta = radians(theta)
phi = radians(phi)
v0 = v1 = sin(theta)
v0 *= cos(phi)
v1 *= sin(phi)
v2 = round(cos(theta), 2)
return v0, v1, v2

def deg_from_vec(x: float, y: float, z: float) -> Tuple[float, float]:
theta = atan2(sqrt(x*x + y*y), z)
phi = atan2(y, x)
return degrees(theta), degrees(phi)


def apex_to_solid_angle(apex: float) -> float:
"""Convert apex angle to solid angle.
Args:
apex: Apex angle in radians.
Returns:
Solid angle in steradians.
"""
return 2 * pi * (1 - cos(apex))

# Input file
xml_path = "t3.xml"

# Cone radius
max_gamma = 2.5

# Incident directions, theta, phi
idirs = [
[0, 0],
[10, 0],
[20, 0],
[30, 0],
[40, 0],
[50, 0],
[60, 0],
[70, 0],
[80, 0],
[87.5, 0],
]

# Number of samples per incident direction
nsamps = 10000

# Incident direction vectors
idirsn = [vec_from_deg(*d) for d in idirs]

isdir_bundles = []

nsamps_root = sqrt(nsamps)
max_gamma_r = radians(max_gamma)
for id, d in enumerate(idirsn):
isdirs = []
for ins in range(nsamps):
recno = id * nsamps + ins + 1
og = max_gamma_r / nsamps_root * sqrt(ins+.5)
refDx = -d[0]
refDy = -d[1]
refDz = -d[2]
randDx = 1 - 2 * lrand(0.5813*recno-18.387)
randDy = 1 - 2 * lrand(-7.3885*recno + 5.6192)
randDz = 1 - 2 * lrand(3.57174*recno + 6.261943)
upDx = randDy * refDz - randDz * refDy
upDy = randDz * refDx - randDx * refDz
upDz =randDx * refDy - randDy * refDx
tanTn = tan(og) / sqrt(upDx**2+upDy**2+upDz**2+1e-10)
sDx = refDx + tanTn * upDx
sDy = refDy + tanTn * upDy
sDz = refDz + tanTn * upDz
isdirs.append([*idirs[id], *deg_from_vec(sDx, sDy, sDz)])
isdir_bundles.append(isdirs)

assert len(isdir_bundles[0][0]) == 4
assert len(isdir_bundles[0]) == nsamps

with pr.BSDF(xml_path) as sd:
for bundle in isdir_bundles:
sample_results = [sd.eval(*d)[1] for d in bundle]
print(bundle[0][:2], sum(sample_results) / nsamps * apex_to_solid_angle(max_gamma_r))
13 changes: 13 additions & 0 deletions test/Resources/dirs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
0.0 0.0, 1.0
0.17364817766693033 0.0, 0.98
0.3420201433256687 0.0, 0.94
0.49999999999999994 0.0, 0.87
0.6427876096865393 0.0, 0.77
0.766044443118978 0.0, 0.64
0.8660254037844386 0.0, 0.5
0.9396926207859083 0.0, 0.34
0.984807753012208 0.0, 0.17)
0.9998476951563913 0.0, 0.02
1.0 0.0, 0.0
0.0 1.0, 0.0

34 changes: 34 additions & 0 deletions test/_bsdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
"""

from pathlib import Path
import math

import pyradiance as pr

def get_dir_dir(fpath: str | Path, idirs: list[list[float]]) -> float:
if not isinstance(fpath, Path):
fpath = Path(fpath)
if fpath.suffix != '.xml' and fpath.suffix != ".sir":
raise ValueError(f"File {fpath} must be an XML or SIR file")
ndirs = len(idirs)
nsamps: int = 10000
cnt = pr.cnt(ndirs, nsamps)
pr.rcalc(cnt, source="", expr=rcalc_e)
res = pr.bsdfquery()
pr.total(res)
res = pr.rcalc()
return float(res.decode())

rcalc_e = (
'nf=1/sqrt(iDx($1+1)^2+iDy($1+1)^2+iDz($1+1)^2);'
'inDx=nf*iDx($1+1);inDy=nf*iDy($1+1);inDz=nf*iDz($1+1);'
'refDx=-inDx;refDy=-inDy;refDz=-inDz;'
'randDx=1-2*rand(.5813*recno-18.387);randDy=1-2*rand(-7.3885*recno+5.6192);'
'randDz=1-2*rand(3.57174*recno+6.261943);'
'upDx=randDy*refDz-randDz*refDy;'
'upDy=randDz*refDx-randDx*refDz;upDz=randDx*refDy-randDy*refDx'
'tanTn=tan(og)/sqrt(upDx*upDx+upDy*upDy+upDz*upDz+1e-10)'
'sDx=refDx+tanTn*upDx;sDy=refDy+tanTn*upDy;sDz=refDz+tanTn*upDz'
'$1=inDx;$2=inDy;$3=inDz;$4=sDx;$5=sDy;$6=sDz'
)
11 changes: 11 additions & 0 deletions test/test_rt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pyradiance import lib


lib.LIBRC.initotypes()
lib.LIBRC.readoct(octname, loadflags, &thescene, NULL)

lib.LIBRC.ray_init_pmap()
lib.LIBRC.marksources()
lib.LIBRC.setambient()

lib.LIBRC.rtrace

0 comments on commit c6811c8

Please sign in to comment.