Skip to content

Commit

Permalink
Merge pull request #17 from LBNL-ETA/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
taoning committed Jul 19, 2023
2 parents 583942e + 704d6ee commit ec35da3
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 60 deletions.
7 changes: 6 additions & 1 deletion pyradiance/anci.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@

BINPATH = Path(__file__).parent / "bin"


def handle_called_process_error(func):
"""
Decorator to handle subprocess.CalledProcessError.
"""

@wraps(func)
def wrapper(*args, **kwargs):
try:
result = func(*args, **kwargs)
except CalledProcessError as e:
errmsg = e.stderr or b""
raise RuntimeError(f"An error occurred with exit code {e.returncode}: {errmsg.decode()}")
raise RuntimeError(
f"An error occurred with exit code {e.returncode}: {errmsg.decode()}"
)
else:
return result

return wrapper
42 changes: 21 additions & 21 deletions pyradiance/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def cnt(

@handle_called_process_error
def rcalc(
inp,
sep=None,
inform=None,
incount=1,
outform=None,
passive=False,
pass_negative=False,
inp,
sep=None,
inform=None,
incount=1,
outform=None,
passive=False,
pass_negative=False,
inlimit=None,
outlimit=None,
source=None,
Expand All @@ -56,32 +56,32 @@ def rcalc(
stdin = None
cmd = [str(BINPATH / "rcalc")]
if sep is not None:
cmd.append(f'-t{sep}')
cmd.append(f"-t{sep}")
if inform is not None:
cmd.append(f'-i{inform}{incount}')
cmd.append(f"-i{inform}{incount}")
if outform is not None:
cmd.append(f'-o{outform}')
cmd.append(f"-o{outform}")
if inform and outform:
if passive:
cmd.append('-p')
cmd.append("-p")
elif pass_negative:
cmd.append('-P')
cmd.append("-P")
if inlimit is not None:
cmd.extend(['-in', str(inlimit)])
cmd.extend(["-in", str(inlimit)])
if outlimit is not None:
cmd.extend(['-on', str(outlimit)])
if source is not None:
cmd.extend(['-f', source])
cmd.extend(["-on", str(outlimit)])
if expr is not None:
cmd.extend(['-e', expr])
cmd.extend(["-e", expr])
if assign is not None:
cmd.extend(['-s', assign])
cmd.extend(["-s", assign])
if source is not None:
cmd.extend(["-f", source])
if exact_only:
cmd.append('-b')
cmd.append("-b")
if ignore_newlines:
cmd.append('-l')
cmd.append("-l")
if silent:
cmd.append('-w')
cmd.append("-w")
if isinstance(inp, (Path, str)):
cmd.append(str(inp))
elif isinstance(inp, bytes):
Expand Down
79 changes: 42 additions & 37 deletions pyradiance/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,43 +194,46 @@ class _FullXf(Structure):
]


class _Ray(Structure): pass
class _Ray(Structure):
pass


_Ray._fields_ = [
("rorg", _FVect),
("rdir", _FVect),
("rmax", c_double),
("rot", c_double),
("rop", _FVect),
("ron", _FVect),
("rod", c_double),
("uv", c_double * 2),
("pert", _FVect),
("rmt", c_double),
("rxt", c_double),
("parent", POINTER(_Ray)),
("clipset", POINTER(_Object)),
("newcset", POINTER(_Object)),
("revf", c_void_p),
("hitf", c_void_p),
("ro", POINTER(_ObjRec)),
("rox", POINTER(_FullXf)),
("slights", POINTER(c_int)),
("rno", _RNumber),
("robj", _Object),
("rsrc", c_int),
("rweight", c_float),
("gecc", c_float),
("rcoef", _Color),
("pcol", _Color),
("mcol", _Color),
("rcol", _Color),
("cext", _Color),
("albedo", _Color),
("rflips", c_short),
("rlvl", c_short),
("rtype", c_short),
("crtype", c_short),
]
("rorg", _FVect),
("rdir", _FVect),
("rmax", c_double),
("rot", c_double),
("rop", _FVect),
("ron", _FVect),
("rod", c_double),
("uv", c_double * 2),
("pert", _FVect),
("rmt", c_double),
("rxt", c_double),
("parent", POINTER(_Ray)),
("clipset", POINTER(_Object)),
("newcset", POINTER(_Object)),
("revf", c_void_p),
("hitf", c_void_p),
("ro", POINTER(_ObjRec)),
("rox", POINTER(_FullXf)),
("slights", POINTER(c_int)),
("rno", _RNumber),
("robj", _Object),
("rsrc", c_int),
("rweight", c_float),
("gecc", c_float),
("rcoef", _Color),
("pcol", _Color),
("mcol", _Color),
("rcol", _Color),
("cext", _Color),
("albedo", _Color),
("rflips", c_short),
("rlvl", c_short),
("rtype", c_short),
("crtype", c_short),
]


class _View(Structure):
Expand Down Expand Up @@ -633,7 +636,9 @@ def get_view_resolu(path) -> Tuple[View, Resolu]:
return view, resolu


def spec_xyz(spec: List[float], wlmin: float, wlmax: float) -> Tuple[float, float, float]:
def spec_xyz(
spec: List[float], wlmin: float, wlmax: float
) -> Tuple[float, float, float]:
"""Convert a spectrum into CIE XYZ.
Args:
spec: A list of spectral values, must be equally spaced in wavelength.
Expand Down
14 changes: 14 additions & 0 deletions pyradiance/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ class Primitive:
sargs: Sequence[str]
fargs: Sequence[float]

@property
def bytes(self):
out = f"{self.modifier} {self.ptype} {self.identifier} "
if len(self.sargs) > 0:
out += f"{len(self.sargs)} {' '.join(self.sargs)} "
else:
out += "0 "
out += "0 "
if len(self.fargs) > 0:
out += f"{len(self.fargs)} {str(self.fargs)[1:-1].replace(',', '')} "
else:
out += "0 "
return out.encode("utf-8")

def __str__(self) -> str:
return (
f"{self.modifier} {self.ptype} {self.identifier}\n"
Expand Down
3 changes: 2 additions & 1 deletion pyradiance/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def add_mist_args(parser):
parser.add_argument("-ms", type=float, default=None)
return parser


def add_view_args(parser):
parser.add_argument("-v", action="store", dest="vt")
parser.add_argument("-vp", nargs=3, type=float, default=(0, 0, 0))
Expand Down Expand Up @@ -284,7 +285,7 @@ def add_rtrace_args(parser):

def add_rcontrib_args(parser):
parser = add_rtrace_args(parser)
parser.add_argument("-c", type=int)
parser.add_argument("-c", type=int)
return parser


Expand Down
6 changes: 6 additions & 0 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
LOGGER = logging.getLogger(__name__)



def test_primitive():
prim = pr.Primitive("void", "plastic", "white", [], [0.5, 0.6, 0.7, 0, 0])
assert prim.ptype == "plastic"
assert prim.bytes == b"void plastic white 0 0 5 0.5 0.6 0.7 0 0 "

def test_install():
radiance_version = pr.rtrace(None, None, version=True)
assert radiance_version != ""
Expand Down

0 comments on commit ec35da3

Please sign in to comment.