Skip to content

Commit

Permalink
feat(rmtxop): Allow matrices to be read from another command
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkelkp authored and mostaphaRoudsari committed Mar 14, 2022
1 parent 7753aeb commit 71a23d7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
13 changes: 13 additions & 0 deletions honeybee_radiance_command/_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"""

import warnings
import os

from .options import OptionCollection
from ._command_util import run_command
Expand Down Expand Up @@ -125,6 +126,18 @@ def pipe_to(self, command):
)
self._pipe_to_command = command
self.validate()

def enclose_command(self, stdin_input=False):
"""Enclose command in quotes and exclamation point ('!'). This method should be
used when reading the input of a command from another Radiance command.
Example:
rmtxop -c 47.4 119.9 11.6 "!rmtxop view transmission daylight sky" > output
"""
if os.name == 'posix':
return '\'!%s\'' % self.to_radiance(stdin_input)
else:
return '\"!%s\"' % self.to_radiance(stdin_input)

def to_radiance(self, stdin_input=False):
"""Radiance command.
Expand Down
12 changes: 11 additions & 1 deletion honeybee_radiance_command/rmtxop.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,17 @@ def matrices(self):

@matrices.setter
def matrices(self, value):
self._matrices = typing.path_checker_multiple(value)
if value is not None:
if not isinstance(value, (tuple, list)):
value = [value]
# check if values are Radiance commands
if value and any([isinstance(v, Command) for v in value]):
self._matrices = [cmd.enclose_command() if isinstance(cmd, Command) else \
typing.path_checker(cmd) for cmd in value]
else:
self._matrices = typing.path_checker_multiple(value)
else:
self._matrices = []

@property
def transforms(self):
Expand Down
37 changes: 36 additions & 1 deletion tests/rmtxop_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,42 @@ def test_input_matrix_limit():
def test_stdin_input():
"""Test assignments."""
rmtxop = Rmtxop()

rmtxop.matrices = ['dc.mtx', 'sky.mtx']
rmtxop.transforms = [['47.4', '119.9', '11.6']]
assert rmtxop.to_radiance(stdin_input=True) == 'rmtxop -c 47.4 119.9 11.6 -'


def test_from_command():
"""Test reading matrices input from another command."""
multiplication = Rmtxop()
multiplication.matrices = ['view.vmx', 'clear.xml', 'daylight.dmx', 'sky.smx']

rmtxop = Rmtxop()
rmtxop.transforms = [['47.4', '119.9', '11.6']]
rmtxop.matrices = multiplication
if os.name == 'posix':
assert rmtxop.to_radiance() == 'rmtxop -c 47.4 119.9 11.6 \'!rmtxop view.vmx ' \
'clear.xml daylight.dmx sky.smx\''
else:
assert rmtxop.to_radiance() == 'rmtxop -c 47.4 119.9 11.6 "!rmtxop view.vmx ' \
'clear.xml daylight.dmx sky.smx"'

def test_from_command_multiple():
"""Test reading multiple matrices input from another command."""
total = Rmtxop()
total.matrices = ['total.mtx', 'sky.smx']
direct = Rmtxop()
direct.matrices = ['direct.mtx', 'direct.smx']

rmtxop = Rmtxop()
rmtxop.operators = ['+', '+']
rmtxop.scalars = [None, -1, None]
rmtxop.matrices = [total, direct, 'sun.ill']
if os.name == 'posix':
assert rmtxop.to_radiance() == 'rmtxop \'!rmtxop total.mtx sky.smx\' ' \
'+ -s -1.0 \'!rmtxop direct.mtx direct.smx\' ' \
'+ sun.ill'
else:
assert rmtxop.to_radiance() == 'rmtxop "!rmtxop total.mtx sky.smx" ' \
'+ -s -1.0 "!rmtxop direct.mtx direct.smx" ' \
'+ sun.ill'

0 comments on commit 71a23d7

Please sign in to comment.