python

Hello:

In Ubuntu, I do not have much knowledge of shell programming about bash. Is
that a good choice to use python script to run Radiance (I did find some
posts about using python to run Radiance programs) if I hope to run other
numeric simulation at the same time?

Thank you,
Jia

Hi Jia,

You can use Python or any other script language to run Radiance programs.
For example if you need some complex numerical calculations, python is good
(you can use Numpy or similar), and then call radiance programs where
needed.
For radiance programs calling I use 'subprocess' python module.

Hope this helps,
Marija

···

On Fri, Jul 9, 2010 at 8:09 AM, Jia Hu <[email protected]> wrote:

Hello:

In Ubuntu, I do not have much knowledge of shell programming about
bash. Is that a good choice to use python script to run Radiance (I did
find some posts about using python to run Radiance programs) if I hope to
run other numeric simulation at the same time?

Thank you,
Jia

If you only want to run multiple Radiance processes at the same time
or automate your calculation processes BASH may be a better choice
because it is your standard environment in Unix and so the commands
are identical on the command line and in a script. However, for anything
more complex (even as simple as floating point arithmetic) you will need
other Unix tools like bc, awk and sed which means you will have to
learn their command syntax, too.

If you plan on post-processing your results (calculate average, create plots
or summary reports) then I would recommend Python. It's a powerful
language but still easy to learn. Once you have worked out how to read
files or how to use the "subprocess" module to run Radiance commands
you can do everything you could do with BASH.

For both there are good learning resources available on the net and
they are a common choice to control Radiance simulations. So you
can't really go wrong here.

Regards,
Thomas

···

On Fri, Jul 9, 2010 at 7:09 AM, Jia Hu <[email protected]> wrote:

Hello:

In Ubuntu, I do not have much knowledge of shell programming about bash. Is
that a good choice to use python script to run Radiance (I did find some
posts about using python to run Radiance programs) if I hope to run other
numeric simulation at the same time?

Hi,

I think that for most types of Radiance automation/scripting, I would suggest the following:

    * make - for automating basic repetitive tasks including calls to
      rad or other radiance programs
    * perl or python - offer robust programming capabilities. Both are
      quiet industrial strength, although I have been a perl person for
      a long time, my impression is that coding in python is perhaps a
      bit cleaner (shocked gasps from those who know me...)

This being said, a few comments on the following:

    * bash/csh - if you end up needing to reference/modify any of the
      scripts that are included with the Radiance distribution then you
      will need to get some understanding of these scripting languages
    * bc/awk/sed - it has been a long time since I have had to deal with
      any of these, I would suggest that it would be easier to do in
      perl/python

Regards,

-Jack

···

--
# Jack de Valpine
# president
#
# visarc incorporated
# http://www.visarc.com
#
# channeling technology for superior design and construction

Thomas Bleicher wrote:

On Fri, Jul 9, 2010 at 7:09 AM, Jia Hu <[email protected]> wrote:
  

Hello:

In Ubuntu, I do not have much knowledge of shell programming about bash. Is
that a good choice to use python script to run Radiance (I did find some
posts about using python to run Radiance programs) if I hope to run other
numeric simulation at the same time?
    
If you only want to run multiple Radiance processes at the same time
or automate your calculation processes BASH may be a better choice
because it is your standard environment in Unix and so the commands
are identical on the command line and in a script. However, for anything
more complex (even as simple as floating point arithmetic) you will need
other Unix tools like bc, awk and sed which means you will have to
learn their command syntax, too.

If you plan on post-processing your results (calculate average, create plots
or summary reports) then I would recommend Python. It's a powerful
language but still easy to learn. Once you have worked out how to read
files or how to use the "subprocess" module to run Radiance commands
you can do everything you could do with BASH.

For both there are good learning resources available on the net and
they are a common choice to control Radiance simulations. So you
can't really go wrong here.

Regards,
Thomas

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

Just to add to the mix, I've started playing with Ruby and like it a lot,
similar functionality to Python, though certainly a lot less add-ons
available than Python (such as SciPy and NumPY). But, SketchUp's API is in
Ruby, which is a nice way to link a 3D drawing program with Radiance, as
Thomas Bleicher has done with his su2rad plug-in...

···

On 7/9/10 8:10 AM, "Jack de Valpine" <[email protected]> wrote:

Hi,

I think that for most types of Radiance automation/scripting, I would
suggest the following:

    * make - for automating basic repetitive tasks including calls to
      rad or other radiance programs
    * perl or python - offer robust programming capabilities. Both are
      quiet industrial strength, although I have been a perl person for
      a long time, my impression is that coding in python is perhaps a
      bit cleaner (shocked gasps from those who know me...)

This being said, a few comments on the following:

    * bash/csh - if you end up needing to reference/modify any of the
      scripts that are included with the Radiance distribution then you
      will need to get some understanding of these scripting languages
    * bc/awk/sed - it has been a long time since I have had to deal with
      any of these, I would suggest that it would be easier to do in
      perl/python

Regards,

-Jack

--
# Jack de Valpine
# president
#
# visarc incorporated
# http://www.visarc.com
#
# channeling technology for superior design and construction

Thomas Bleicher wrote:

On Fri, Jul 9, 2010 at 7:09 AM, Jia Hu <[email protected]> wrote:

Hello:

In Ubuntu, I do not have much knowledge of shell programming about bash. Is
that a good choice to use python script to run Radiance (I did find some
posts about using python to run Radiance programs) if I hope to run other
numeric simulation at the same time?
   
If you only want to run multiple Radiance processes at the same time
or automate your calculation processes BASH may be a better choice
because it is your standard environment in Unix and so the commands
are identical on the command line and in a script. However, for anything
more complex (even as simple as floating point arithmetic) you will need
other Unix tools like bc, awk and sed which means you will have to
learn their command syntax, too.

If you plan on post-processing your results (calculate average, create plots
or summary reports) then I would recommend Python. It's a powerful
language but still easy to learn. Once you have worked out how to read
files or how to use the "subprocess" module to run Radiance commands
you can do everything you could do with BASH.

For both there are good learning resources available on the net and
they are a common choice to control Radiance simulations. So you
can't really go wrong here.

Regards,
Thomas

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

My experiences with Python as a control language are very positive. There's a similar case to be made for all the "concise" interpretive languages: Python, Ruby, Perl, Lua, and so on, which even includes such tools as LISP, which is the granddaddy of them all. I like Python because of the computer science attitudes which underly its design: it is readable (at least if one grew up with a European language), reliable, and *small*--the manual for the basic language can be read in an hour, though the libraries are extensive.

Rhino 5 is planned to use the .NET implementation of Python as its primary scripting language, though other .NET languages will be available.

···

--
Randolph Fritz • [email protected]
Environmental Energy Technologies Division • Lawrence Berkeley Labs

Hello:

I made a simplified python code as bellow.

#!/usr/bin/python
import subprocess
fileHandle = open ('final.txt', 'w')
fileHandle.write ('%s %s %s \n' % (12,25,89))
fileHandle.close()

# valueIll = open ('final.txt', 'a')
creBlinds = subprocess.Popen("genblinds %s %s %d %d %d %d %d \
          > xform -rz -90 -t 2 2 2 >> final.txt " % ('white', 'VBlinds', \
          0.03, 2, 3, 15, 30), shell=True)
fileHandle .close()

fileHandle = open ('final.txt', 'a')
fileHandle.write ('%s %s %s \n' % (52,86,506))
fileHandle.close()

What I expect is the text generated by "Gneblinds" are located between '12
25 89" and "52 86 506". But I find the text in the second line is (52 86
506) and the following text is generated by "genblinds". Could someone give
me some advice to fix this problem?

Thank you in advance.

Jia

···

On Fri, Jul 9, 2010 at 5:08 PM, R Fritz <[email protected]> wrote:

My experiences with Python as a control language are very positive. There's
a similar case to be made for all the "concise" interpretive languages:
Python, Ruby, Perl, Lua, and so on, which even includes such tools as LISP,
which is the granddaddy of them all. I like Python because of the computer
science attitudes which underly its design: it is readable (at least if one
grew up with a European language), reliable, and *small*--the manual for the
basic language can be read in an hour, though the libraries are extensive.

Rhino 5 is planned to use the .NET implementation of Python as its primary
scripting language, though other .NET languages will be available.
--
Randolph Fritz • [email protected]
Environmental Energy Technologies Division • Lawrence Berkeley Labs

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

Jia

Comments are below

Hello:

I made a simplified python code as bellow.

#!/usr/bin/python
import subprocess
fileHandle = open ('final.txt', 'w')
fileHandle.write ('%s %s %s \n' % (12,25,89))
fileHandle.close()
# valueIll = open ('final.txt', 'a')
creBlinds = subprocess.Popen("genblinds %s %s %d %d %d %d %d \
> xform -rz -90 -t 2 2 2 >> final.txt " % ('white', 'VBlinds', \
0.03, 2, 3, 15, 30), shell=True)
fileHandle .close()
fileHandle = open ('final.txt', 'a')
fileHandle.write ('%s %s %s \n' % (52,86,506))
fileHandle.close()

What I expect is the text generated by "Gneblinds" are located between '12
25 89" and "52 86 506". But I find the text in the second line is (52 86
506) and the following text is generated by "genblinds". Could someone give
me some advice to fix this problem?

You have two processes accessing the same file in a very short time.
Due to some caching that's controlled by the OS you can't guarantee
that the access happens in the right order. The best way to solve this
is to use Python to do all the writing:

#!/usr/bin/python
import subprocess
fileHandle = open ('final.txt', 'w')
fileHandle.write ("%s %s %s \n" % (12,25,89))

## create gensky command
cmd = "genblinds %s %s %d %d %d %d %d | xform -rz -90 -t 2 2 2 " %
('white', 'VBlinds', 0.03, 2, 3, 15, 30)

## execute in subprocess and read output of gensky command
output = subprocess.Popen(cmd.split(), stdout=PIPE, shell=True).communicate()[0]

## now write to file
fileHandle.write(output + "\n")

fileHandle.write ('%s %s %s \n' % (52,86,506))
fileHandle.close()

This is untested. The pipe to xform might mess things up here but I
hope it works.

Regards,
Thomas

···

On Tue, Jul 13, 2010 at 6:37 AM, Jia Hu <[email protected]> wrote:

Thank you very much. It works now. A very small error in your code is that
using "cmd" instead of cmd.split(), and
using stdout = subprocess.PIPE.

Thank you,
Jia

···

On Tue, Jul 13, 2010 at 4:58 AM, Thomas Bleicher <[email protected]>wrote:

Jia

Comments are below

On Tue, Jul 13, 2010 at 6:37 AM, Jia Hu <[email protected]> wrote:
> Hello:
>
> I made a simplified python code as bellow.
>
> #!/usr/bin/python
> import subprocess
> fileHandle = open ('final.txt', 'w')
> fileHandle.write ('%s %s %s \n' % (12,25,89))
> fileHandle.close()
> # valueIll = open ('final.txt', 'a')
> creBlinds = subprocess.Popen("genblinds %s %s %d %d %d %d %d \
> > xform -rz -90 -t 2 2 2 >> final.txt " % ('white', 'VBlinds',
\
> 0.03, 2, 3, 15, 30), shell=True)
> fileHandle .close()
> fileHandle = open ('final.txt', 'a')
> fileHandle.write ('%s %s %s \n' % (52,86,506))
> fileHandle.close()
>
> What I expect is the text generated by "Gneblinds" are located between
'12
> 25 89" and "52 86 506". But I find the text in the second line is (52 86
> 506) and the following text is generated by "genblinds". Could someone
give
> me some advice to fix this problem?

You have two processes accessing the same file in a very short time.
Due to some caching that's controlled by the OS you can't guarantee
that the access happens in the right order. The best way to solve this
is to use Python to do all the writing:

#!/usr/bin/python
import subprocess
fileHandle = open ('final.txt', 'w')
fileHandle.write ("%s %s %s \n" % (12,25,89))

## create gensky command
cmd = "genblinds %s %s %d %d %d %d %d | xform -rz -90 -t 2 2 2 " %
('white', 'VBlinds', 0.03, 2, 3, 15, 30)

## execute in subprocess and read output of gensky command
output = subprocess.Popen(cmd.split(), stdout=PIPE,
shell=True).communicate()[0]

## now write to file
fileHandle.write(output + "\n")

fileHandle.write ('%s %s %s \n' % (52,86,506))
fileHandle.close()

This is untested. The pipe to xform might mess things up here but I
hope it works.

Regards,
Thomas

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general