[Radiance-general] RADIANCE and Unix shells

Mark Shewfelt MShewfelt at enermodal.com
Thu Sep 29 20:36:20 CEST 2005


Another vote for Python here - you could certainly do what I've done
here in a shell script, but I chose to use (and learn) Python. If you
stick with Python you can eventually add a GUI relatively easily to your
scripts using Glade and pyGTK. 

I used Python to automate the creation of illuminance calculation grids.
This is a budget example, but this snippet is what I've done in the past
to calculate illuminance by repeated calls to rtrace. I used the
os.popen() call in Python to call rtrace as I would on the command line.
My apologies if this example is too trivial, but here it is anyways, in
case you find it useful: 

for i in range(len(Grid1.CalcPoints)):
	    #call to rtrace returns 3 values, each representing the
irradiance for r,g,b.
	    #first prepare the string representation of the point:
	    point_str = "\'" + str(Grid1.CalcPoints[i].x) + " " +
str(Grid1.CalcPoints[i].y) + \
			  " " + str(Grid1.CalcPoints[i].z) + "  " +
str(Grid1.CalcPoints[i].xdir) + \
			  " " + str(Grid1.CalcPoints[i].ydir) + " " +
str(Grid1.CalcPoints[i].zdir) + "\'"
	    rtrace_str = "echo " + point_str + " | rtrace -I -ab " +
str(options.ab) + rad_opts + " -h -w " + options.octfile
	    print rtrace_str
	    fd = os.popen( rtrace_str, 'r', -1 )
	   	    
	    buffer = fd.readline()
	    rgb_irrad = buffer.split()
	    illuminance = 179*(float(rgb_irrad[0])*0.265 +
float(rgb_irrad[1])*0.670 + float(rgb_irrad[2])*0.065)
	    Grid1.CalcPoints[i].illuminance = illuminance
	    print "( " + str(Grid1.CalcPoints[i].x) + ", " +
str(Grid1.CalcPoints[i].y) + ", " + \
		  str(Grid1.CalcPoints[i].z) + " ): " + str(illuminance)
+ " lux" 

It's ugly but seems to work OK.  This snippet is part of a larger script
that takes in some user options, grid size, and prints out illuminance
values.

Cheers,

Mark Shewfelt
Electrical Engineering Intern
Enermodal Engineering Ltd.
ph: 519 743 8777 x232
fx: 519 743-8778
mshewfelt at enermodal.com



-----Original Message-----
From: radiance-general-bounces at radiance-online.org
[mailto:radiance-general-bounces at radiance-online.org] On Behalf Of Jack
de Valpine
Sent: September 29, 2005 2:05 PM
To: Radiance general discussion
Subject: Re: [Radiance-general] RADIANCE and Unix shells

Hey Rob,

I follow-up on that. I probably could have used a more robust cup of jo
this morning as I repeated the word in every darn sentence. Ack!

In general, I think that if you learn one of these things then entry
into the next becomes easier. I started out with csh, sed and awk, ages
ago, and while it worked it is ugly, I had to learn how to use three
different tools (heck, I think that you can by an O'Reilly book for each
of these). Nevertheless, shell scripting is definitely the most quick
and dirty way to get things done.

Rob is correct. A hugely confusing element to Perl (for which you can
buy a lot more than 3 O'Reilly books) is the fact that there are lots
and lots of way to do things, this can be both a pro and a con. Though I
think in general looking at other peoples code is always painful unless
it is extremely well documented. I cannot really speak for Python,
though I think it is probably a bit "cleaner" than Perl.

I think the crux of it all though is having an actual problem that you
are trying to solve and access to some good books with examples. This is
the best way to learn that I have found.

-Jack

Rob Guglielmetti wrote:

> Jack de Valpine wrote:
>
>> Hi Kirk,
>>
>> Depending on what you are trying to do you may want to consider 
>> something more robust in terms of programming features such as Perl 
>> or Python. I am a huge fan of Perl which is extremely robust. On the 
>> other hand I know that Georg Mischler is quite a proponent of Python 
>> which is also quite robust.
>
>
> Starbucks coffee is also known for their robustness, but then again 
> that doesn't really help you with programming.  =8-) Ahem.
> Kirk, Jack is steering you in the right direction, but I'd also like 
> to cast a vote for good old fashioned shell scripting, using either 
> bash or tsh.  Some of the radiance commands are actually shell 
> scripts, usually written in tsh, which may be a case for learning tsh.

> I learned shell scripting by dissecting some of the stuff Greg Ward 
> and John Mardaljevic wrote, which served me well for many years.
> Bash has more features than tsh, but then again like Jack said 
> languages like Python and Perl have many more than Bash.  It comes 
> down to what you're trying to do, and how much you expect to borrow 
> from other sources too.
> Also, regarding Perl: Jack's a Perl fan because he knows it well.  But

> I'd caution that Perl can be a bear when working with Other People's 
> Code, because it is so "loose".  There is a saying among Perl People 
> that goes "There's more than one way to do it", which can be an 
> obstacle when trying to read someone else's programs (which is how I 
> learned programming in the first place).  I grow fonder of Python all 
> the time.
>
> Whatever way you go, have fun!  Scripting is the key to unlocking the 
> power of Radiance.
>
> - Rob Guglielmetti
>
>
>
>
>
> _______________________________________________
> Radiance-general mailing list
> Radiance-general at radiance-online.org
> http://www.radiance-online.org/mailman/listinfo/radiance-general
>
>



_______________________________________________
Radiance-general mailing list
Radiance-general at radiance-online.org
http://www.radiance-online.org/mailman/listinfo/radiance-general



More information about the Radiance-general mailing list